Home > Software design >  There is no Format_RGB24 in qt6
There is no Format_RGB24 in qt6

Time:10-19

In QT5 we have QVideoFrame::Format_RGB24 format (i have RGB images without alpha channel).

In QT6 (6.2.0) this format is missing.

Why this format has been removed? What's the best way to convert RGB -> RGBX (A) in QT6?

CodePudding user response:

If you are using QImage (or you can convert it to QImage) then you can convert the format to QImage::Format_RGBX8888 and then copy the bits:

#include <QGuiApplication>
#include <QImage>
#include <QVideoFrame>
#include <QVideoFrameFormat>

int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);
    QImage image(100, 100, QImage::Format_RGB888);
    image.fill(QColor(50, 100, 200));

    if(image.format() == QImage::Format_Invalid)
        return EXIT_FAILURE;
    QVideoFrameFormat video_frame_format(image.size(), QVideoFrameFormat::Format_RGBX8888);
    QImage rgbx = image.convertToFormat(QVideoFrameFormat::imageFormatFromPixelFormat(video_frame_format.pixelFormat()));
    QVideoFrame video_frame(video_frame_format);
    if(!video_frame.isValid() || !video_frame.map(QVideoFrame::WriteOnly)){
        qWarning() << "QVideoFrame is not valid or not writable";
        return EXIT_FAILURE;
    }
    int plane = 0;
    std::memcpy(video_frame.bits(plane), rgbx.bits(), video_frame.mappedBytes(plane));
    video_frame.unmap();

    qDebug() << video_frame << rgbx.format();

    return EXIT_SUCCESS;
}
  • Related