Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-114436

Request: Add support for BGRA8888 QImage Format

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.5.1
    • Image formats
    • None
    • Windows 10, PySide6 6.5.1.1

    Description

      I am heavily using opencv in my application. Which works in BGR/BGRA format. QImage supports BGR888 (https://doc.qt.io/qt-6/qimage.html#Format-enum), but unfortunately not BGRA8888. See the following code in Python (using opencv-python-healdess and PySide6-Essentials):

      def set_preview_image(qlabel: QLabel, image: cv2.typing.MatLike):
          height, width, channels = image.shape
          if channels == BGRA_CHANNEL_COUNT:
              image_format = QtGui.QImage.Format.Format_RGBA8888
              capture = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
          else:
              image_format = QtGui.QImage.Format.Format_BGR888
              capture = image
          qimage = QtGui.QImage(capture.data, width, height, width * channels, image_format)
          qlabel.setPixmap(
              QtGui.QPixmap(qimage).scaled(
                  qlabel.size(),
                  QtCore.Qt.AspectRatioMode.IgnoreAspectRatio,
                  QtCore.Qt.TransformationMode.SmoothTransformation,
              ),
          )

      Could be simplified to:

      def set_preview_image(qlabel: QLabel, image: cv2.typing.MatLike):
          height, width, channels = image.shape
          image_format = QtGui.QImage.Format.Format_BGRA8888 \
              if channels == BGRA_CHANNEL_COUNT \
              else QtGui.QImage.Format.Format_BGR888
          qimage = QtGui.QImage(image.data, width, height, width * channels, image_format)
          qlabel.setPixmap(
              QtGui.QPixmap(qimage).scaled(
                  qlabel.size(),
                  QtCore.Qt.AspectRatioMode.IgnoreAspectRatio,
                  QtCore.Qt.TransformationMode.SmoothTransformation,
              ),
          ) 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            avasam Samuel Therrien
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes