summaryrefslogtreecommitdiffstats
path: root/src/multimedia/video
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-03-23 13:31:22 +0100
committerLars Knoll <lars.knoll@qt.io>2021-04-06 08:11:45 +0000
commitd6e52bea2da1d31bce91d1a175f9b9e84b8e37f5 (patch)
tree90e41da7f8a6abdd069da5e7fcd410d8accb8843 /src/multimedia/video
parent9aaec39aef634a9f2d972f35484a566bdd01ecd6 (diff)
Move the PixelFormat enum from QVideoFrame to QVideoSurfaceFormat
Change-Id: Ifa888c74c397c640b19387a9ce624dfcf8269c2c Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Doris Verria <doris.verria@qt.io>
Diffstat (limited to 'src/multimedia/video')
-rw-r--r--src/multimedia/video/qabstractvideosurface.h2
-rw-r--r--src/multimedia/video/qvideoframe.cpp265
-rw-r--r--src/multimedia/video/qvideoframe.h54
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper.cpp22
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper_p.h2
-rw-r--r--src/multimedia/video/qvideosink.cpp2
-rw-r--r--src/multimedia/video/qvideosurfaceformat.cpp193
-rw-r--r--src/multimedia/video/qvideosurfaceformat.h58
-rw-r--r--src/multimedia/video/qvideosurfaces.cpp6
-rw-r--r--src/multimedia/video/qvideosurfaces_p.h2
10 files changed, 305 insertions, 301 deletions
diff --git a/src/multimedia/video/qabstractvideosurface.h b/src/multimedia/video/qabstractvideosurface.h
index f47b7ac69..a437d7565 100644
--- a/src/multimedia/video/qabstractvideosurface.h
+++ b/src/multimedia/video/qabstractvideosurface.h
@@ -67,7 +67,7 @@ public:
explicit QAbstractVideoSurface(QObject *parent = nullptr);
~QAbstractVideoSurface();
- virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
+ virtual QList<QVideoSurfaceFormat::PixelFormat> supportedPixelFormats(
QVideoFrame::HandleType type = QVideoFrame::NoHandle) const = 0;
bool isFormatSupported(const QVideoSurfaceFormat &format) const;
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index 8ca606b4a..f9b15e0df 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -53,7 +53,7 @@
#include <QDebug>
QT_BEGIN_NAMESPACE
-static bool pixelFormatHasAlpha[QVideoFrame::NPixelFormats] =
+static bool pixelFormatHasAlpha[QVideoSurfaceFormat::NPixelFormats] =
{
false, //Format_Invalid,
true, //Format_ARGB32,
@@ -159,7 +159,7 @@ private:
*/
/*!
- \enum QVideoFrame::PixelFormat
+ \enum QVideoSurfaceFormat::PixelFormat
Enumerates video data types.
@@ -341,7 +341,8 @@ QVideoFrame::QVideoFrame(int bytes, int bytesPerLine, const QVideoSurfaceFormat
\sa pixelFormatFromImageFormat()
*/
QVideoFrame::QVideoFrame(const QImage &image)
- : d(new QVideoFramePrivate(QVideoSurfaceFormat(image.size(), pixelFormatFromImageFormat(image.format()))))
+ : d(new QVideoFramePrivate(QVideoSurfaceFormat(image.size(),
+ QVideoSurfaceFormat::pixelFormatFromImageFormat(image.format()))))
{
d->buffer = new QImageVideoBuffer(image);
}
@@ -416,7 +417,7 @@ bool QVideoFrame::isValid() const
/*!
Returns the pixel format of this video frame.
*/
-QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const
+QVideoSurfaceFormat::PixelFormat QVideoFrame::pixelFormat() const
{
return d->format.pixelFormat();
}
@@ -588,35 +589,35 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
auto pixelFmt = d->format.pixelFormat();
// If the plane count is 1 derive the additional planes for planar formats.
switch (pixelFmt) {
- case Format_Invalid:
- case Format_ARGB32:
- case Format_ARGB32_Premultiplied:
- case Format_RGB32:
- case Format_RGB24:
- case Format_RGB565:
- case Format_RGB555:
- case Format_ARGB8565_Premultiplied:
- case Format_BGRA32:
- case Format_BGRA32_Premultiplied:
- case Format_ABGR32:
- case Format_BGR32:
- case Format_BGR24:
- case Format_BGR565:
- case Format_BGR555:
- case Format_BGRA5658_Premultiplied:
- case Format_AYUV444:
- case Format_AYUV444_Premultiplied:
- case Format_YUV444:
- case Format_UYVY:
- case Format_YUYV:
- case Format_Y8:
- case Format_Y16:
- case Format_Jpeg:
+ case QVideoSurfaceFormat::Format_Invalid:
+ case QVideoSurfaceFormat::Format_ARGB32:
+ case QVideoSurfaceFormat::Format_ARGB32_Premultiplied:
+ case QVideoSurfaceFormat::Format_RGB32:
+ case QVideoSurfaceFormat::Format_RGB24:
+ case QVideoSurfaceFormat::Format_RGB565:
+ case QVideoSurfaceFormat::Format_RGB555:
+ case QVideoSurfaceFormat::Format_ARGB8565_Premultiplied:
+ case QVideoSurfaceFormat::Format_BGRA32:
+ case QVideoSurfaceFormat::Format_BGRA32_Premultiplied:
+ case QVideoSurfaceFormat::Format_ABGR32:
+ case QVideoSurfaceFormat::Format_BGR32:
+ case QVideoSurfaceFormat::Format_BGR24:
+ case QVideoSurfaceFormat::Format_BGR565:
+ case QVideoSurfaceFormat::Format_BGR555:
+ case QVideoSurfaceFormat::Format_BGRA5658_Premultiplied:
+ case QVideoSurfaceFormat::Format_AYUV444:
+ case QVideoSurfaceFormat::Format_AYUV444_Premultiplied:
+ case QVideoSurfaceFormat::Format_YUV444:
+ case QVideoSurfaceFormat::Format_UYVY:
+ case QVideoSurfaceFormat::Format_YUYV:
+ case QVideoSurfaceFormat::Format_Y8:
+ case QVideoSurfaceFormat::Format_Y16:
+ case QVideoSurfaceFormat::Format_Jpeg:
// Single plane or opaque format.
break;
- case Format_YUV420P:
- case Format_YUV422P:
- case Format_YV12: {
+ case QVideoSurfaceFormat::Format_YUV420P:
+ case QVideoSurfaceFormat::Format_YUV422P:
+ case QVideoSurfaceFormat::Format_YV12: {
// The UV stride is usually half the Y stride and is 32-bit aligned.
// However it's not always the case, at least on Windows where the
// UV planes are sometimes not aligned.
@@ -624,7 +625,7 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
// have a correct stride.
const int height = this->height();
const int yStride = d->mapData.bytesPerLine[0];
- const int uvHeight = pixelFmt == Format_YUV422P ? height : height / 2;
+ const int uvHeight = pixelFmt == QVideoSurfaceFormat::Format_YUV422P ? height : height / 2;
const int uvStride = (d->mapData.nBytes - (yStride * height)) / uvHeight / 2;
// Three planes, the second and third vertically (and horizontally for other than Format_YUV422P formats) subsampled.
@@ -634,18 +635,18 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
d->mapData.data[2] = d->mapData.data[1] + (uvStride * uvHeight);
break;
}
- case Format_NV12:
- case Format_NV21:
- case Format_IMC2:
- case Format_IMC4: {
+ case QVideoSurfaceFormat::Format_NV12:
+ case QVideoSurfaceFormat::Format_NV21:
+ case QVideoSurfaceFormat::Format_IMC2:
+ case QVideoSurfaceFormat::Format_IMC4: {
// Semi planar, Full resolution Y plane with interleaved subsampled U and V planes.
d->mapData.nPlanes = 2;
d->mapData.bytesPerLine[1] = d->mapData.bytesPerLine[0];
d->mapData.data[1] = d->mapData.data[0] + (d->mapData.bytesPerLine[0] * height());
break;
}
- case Format_IMC1:
- case Format_IMC3: {
+ case QVideoSurfaceFormat::Format_IMC1:
+ case QVideoSurfaceFormat::Format_IMC3: {
// Three planes, the second and third vertically and horizontally subsumpled,
// but with lines padded to the width of the first plane.
d->mapData.nPlanes = 3;
@@ -697,7 +698,7 @@ void QVideoFrame::unmap()
Returns the number of bytes in a scan line.
\note For planar formats this is the bytes per line of the first plane only. The bytes per line of subsequent
- planes should be calculated as per the frame \l{QVideoFrame::PixelFormat}{pixel format}.
+ planes should be calculated as per the frame \l{QVideoSurfaceFormat::PixelFormat}{pixel format}.
This value is only valid while the frame data is \l {map()}{mapped}.
@@ -868,103 +869,6 @@ void QVideoFrame::setEndTime(qint64 time)
d->endTime = time;
}
-/*!
- Returns a video pixel format equivalent to an image \a format. If there is no equivalent
- format QVideoFrame::InvalidType is returned instead.
-
- \note In general \l QImage does not handle YUV formats.
-
-*/
-QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format)
-{
- switch (format) {
- case QImage::Format_RGB32:
- case QImage::Format_RGBX8888:
- return Format_RGB32;
- case QImage::Format_ARGB32:
- case QImage::Format_RGBA8888:
- return Format_ARGB32;
- case QImage::Format_ARGB32_Premultiplied:
- case QImage::Format_RGBA8888_Premultiplied:
- return Format_ARGB32_Premultiplied;
- case QImage::Format_RGB16:
- return Format_RGB565;
- case QImage::Format_ARGB8565_Premultiplied:
- return Format_ARGB8565_Premultiplied;
- case QImage::Format_RGB555:
- return Format_RGB555;
- case QImage::Format_RGB888:
- return Format_RGB24;
- case QImage::Format_Grayscale8:
- return Format_Y8;
- case QImage::Format_Grayscale16:
- return Format_Y16;
- default:
- return Format_Invalid;
- }
-}
-
-/*!
- Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent
- format QImage::Format_Invalid is returned instead.
-
- \note In general \l QImage does not handle YUV formats.
-
-*/
-QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format)
-{
- switch (format) {
- case Format_ARGB32:
- return QImage::Format_ARGB32;
- case Format_ARGB32_Premultiplied:
- return QImage::Format_ARGB32_Premultiplied;
- case Format_RGB32:
- return QImage::Format_RGB32;
- case Format_RGB24:
- return QImage::Format_RGB888;
- case Format_RGB565:
- return QImage::Format_RGB16;
- case Format_RGB555:
- return QImage::Format_RGB555;
- case Format_ARGB8565_Premultiplied:
- return QImage::Format_ARGB8565_Premultiplied;
- case Format_Y8:
- return QImage::Format_Grayscale8;
- case Format_Y16:
- return QImage::Format_Grayscale16;
- case Format_ABGR32:
- case Format_BGRA32:
- case Format_BGRA32_Premultiplied:
- case Format_BGR32:
- case Format_BGR24:
- case Format_BGR565:
- case Format_BGR555:
- case Format_BGRA5658_Premultiplied:
- case Format_AYUV444:
- case Format_AYUV444_Premultiplied:
- case Format_YUV444:
- case Format_YUV420P:
- case Format_YUV422P:
- case Format_YV12:
- case Format_UYVY:
- case Format_YUYV:
- case Format_NV12:
- case Format_NV21:
- case Format_IMC1:
- case Format_IMC2:
- case Format_IMC3:
- case Format_IMC4:
- case Format_P010LE:
- case Format_P010BE:
- case Format_P016LE:
- case Format_P016BE:
- case Format_Jpeg:
- case Format_Invalid:
- return QImage::Format_Invalid;
- }
- return QImage::Format_Invalid;
-}
-
/*!
Based on the pixel format converts current video frame to image.
@@ -979,13 +883,13 @@ QImage QVideoFrame::image() const
return result;
// Formats supported by QImage don't need conversion
- QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat());
+ QImage::Format imageFormat = QVideoSurfaceFormat::imageFormatFromPixelFormat(frame.pixelFormat());
if (imageFormat != QImage::Format_Invalid) {
result = QImage(frame.bits(), frame.width(), frame.height(), frame.bytesPerLine(), imageFormat).copy();
}
// Load from JPG
- else if (frame.pixelFormat() == QVideoFrame::Format_Jpeg) {
+ else if (frame.pixelFormat() == QVideoSurfaceFormat::Format_Jpeg) {
result.loadFromData(frame.bits(), frame.mappedBytes(), "JPG");
}
@@ -1007,91 +911,6 @@ QImage QVideoFrame::image() const
}
#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, QVideoFrame::PixelFormat pf)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (pf) {
- case QVideoFrame::Format_Invalid:
- return dbg << "Format_Invalid";
- case QVideoFrame::Format_ARGB32:
- return dbg << "Format_ARGB32";
- case QVideoFrame::Format_ARGB32_Premultiplied:
- return dbg << "Format_ARGB32_Premultiplied";
- case QVideoFrame::Format_RGB32:
- return dbg << "Format_RGB32";
- case QVideoFrame::Format_RGB24:
- return dbg << "Format_RGB24";
- case QVideoFrame::Format_RGB565:
- return dbg << "Format_RGB565";
- case QVideoFrame::Format_RGB555:
- return dbg << "Format_RGB555";
- case QVideoFrame::Format_ARGB8565_Premultiplied:
- return dbg << "Format_ARGB8565_Premultiplied";
- case QVideoFrame::Format_BGRA32:
- return dbg << "Format_BGRA32";
- case QVideoFrame::Format_BGRA32_Premultiplied:
- return dbg << "Format_BGRA32_Premultiplied";
- case QVideoFrame::Format_ABGR32:
- return dbg << "Format_ABGR32";
- case QVideoFrame::Format_BGR32:
- return dbg << "Format_BGR32";
- case QVideoFrame::Format_BGR24:
- return dbg << "Format_BGR24";
- case QVideoFrame::Format_BGR565:
- return dbg << "Format_BGR565";
- case QVideoFrame::Format_BGR555:
- return dbg << "Format_BGR555";
- case QVideoFrame::Format_BGRA5658_Premultiplied:
- return dbg << "Format_BGRA5658_Premultiplied";
- case QVideoFrame::Format_AYUV444:
- return dbg << "Format_AYUV444";
- case QVideoFrame::Format_AYUV444_Premultiplied:
- return dbg << "Format_AYUV444_Premultiplied";
- case QVideoFrame::Format_YUV444:
- return dbg << "Format_YUV444";
- case QVideoFrame::Format_YUV420P:
- return dbg << "Format_YUV420P";
- case QVideoFrame::Format_YUV422P:
- return dbg << "Format_YUV422P";
- case QVideoFrame::Format_YV12:
- return dbg << "Format_YV12";
- case QVideoFrame::Format_UYVY:
- return dbg << "Format_UYVY";
- case QVideoFrame::Format_YUYV:
- return dbg << "Format_YUYV";
- case QVideoFrame::Format_NV12:
- return dbg << "Format_NV12";
- case QVideoFrame::Format_NV21:
- return dbg << "Format_NV21";
- case QVideoFrame::Format_IMC1:
- return dbg << "Format_IMC1";
- case QVideoFrame::Format_IMC2:
- return dbg << "Format_IMC2";
- case QVideoFrame::Format_IMC3:
- return dbg << "Format_IMC3";
- case QVideoFrame::Format_IMC4:
- return dbg << "Format_IMC4";
- case QVideoFrame::Format_Y8:
- return dbg << "Format_Y8";
- case QVideoFrame::Format_Y16:
- return dbg << "Format_Y16";
- case QVideoFrame::Format_P010LE:
- return dbg << "Format_P010LE";
- case QVideoFrame::Format_P010BE:
- return dbg << "Format_P010BE";
- case QVideoFrame::Format_P016LE:
- return dbg << "Format_P016LE";
- case QVideoFrame::Format_P016BE:
- return dbg << "Format_P016BE";
- case QVideoFrame::Format_Jpeg:
- return dbg << "Format_Jpeg";
-
- default:
- return dbg << QString(QLatin1String("UserType(%1)" )).arg(int(pf)).toLatin1().constData();
- }
-}
-
static QString qFormatTimeStamps(qint64 start, qint64 end)
{
// Early out for invalid.
diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h
index bd69095da..028286426 100644
--- a/src/multimedia/video/qvideoframe.h
+++ b/src/multimedia/video/qvideoframe.h
@@ -41,6 +41,7 @@
#define QVIDEOFRAME_H
#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtMultimedia/qvideosurfaceformat.h>
#include <QtCore/qmetatype.h>
#include <QtCore/qshareddata.h>
@@ -52,57 +53,10 @@ QT_BEGIN_NAMESPACE
class QSize;
class QVideoFramePrivate;
class QAbstractVideoBuffer;
-class QVideoSurfaceFormat;
class Q_MULTIMEDIA_EXPORT QVideoFrame
{
public:
- enum PixelFormat
- {
- Format_Invalid,
- Format_ARGB32,
- Format_ARGB32_Premultiplied,
- Format_RGB32,
- Format_RGB24,
- Format_RGB565,
- Format_RGB555,
- Format_ARGB8565_Premultiplied,
- Format_BGRA32,
- Format_BGRA32_Premultiplied,
- Format_ABGR32,
- Format_BGR32,
- Format_BGR24,
- Format_BGR565,
- Format_BGR555,
- Format_BGRA5658_Premultiplied,
-
- Format_AYUV444,
- Format_AYUV444_Premultiplied,
- Format_YUV444,
- Format_YUV420P,
- Format_YUV422P,
- Format_YV12,
- Format_UYVY,
- Format_YUYV,
- Format_NV12,
- Format_NV21,
- Format_IMC1,
- Format_IMC2,
- Format_IMC3,
- Format_IMC4,
- Format_Y8,
- Format_Y16,
-
- Format_P010LE,
- Format_P010BE,
- Format_P016LE,
- Format_P016BE,
-
- Format_Jpeg,
- };
-#ifndef Q_QDOC
- static constexpr int NPixelFormats = Format_Jpeg + 1;
-#endif
enum HandleType
{
@@ -133,7 +87,7 @@ public:
QAbstractVideoBuffer *buffer() const;
bool isValid() const;
- PixelFormat pixelFormat() const;
+ QVideoSurfaceFormat::PixelFormat pixelFormat() const;
QVideoSurfaceFormat surfaceFormat() const;
QVideoFrame::HandleType handleType() const;
@@ -171,9 +125,6 @@ public:
QImage image() const;
- static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
- static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
-
private:
QExplicitlySharedDataPointer<QVideoFramePrivate> d;
};
@@ -183,7 +134,6 @@ Q_DECLARE_METATYPE(QVideoFrame);
#ifndef QT_NO_DEBUG_STREAM
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoFrame&);
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrame::HandleType);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrame::PixelFormat);
#endif
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideoframeconversionhelper.cpp b/src/multimedia/video/qvideoframeconversionhelper.cpp
index b2d724703..7612c88c3 100644
--- a/src/multimedia/video/qvideoframeconversionhelper.cpp
+++ b/src/multimedia/video/qvideoframeconversionhelper.cpp
@@ -624,7 +624,7 @@ static void QT_FASTCALL qt_convert_P016BE_to_ARGB32(const QVideoFrame &frame, uc
}
-static VideoFrameConvertFunc qConvertFuncs[QVideoFrame::NPixelFormats] = {
+static VideoFrameConvertFunc qConvertFuncs[QVideoSurfaceFormat::NPixelFormats] = {
/* Format_Invalid */ nullptr, // Not needed
/* Format_ARGB32 */ nullptr, // Not needed
/* Format_ARGB32_Premultiplied */ nullptr, // Not needed
@@ -669,30 +669,30 @@ static void qInitConvertFuncsAsm()
#ifdef QT_COMPILER_SUPPORTS_SSE2
extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_sse2(const QVideoFrame&, uchar*);
if (qCpuHasFeature(SSE2)){
- qConvertFuncs[QVideoFrame::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_sse2;
- qConvertFuncs[QVideoFrame::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_sse2;
- qConvertFuncs[QVideoFrame::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_sse2;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_sse2;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_sse2;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_sse2;
}
#endif
#ifdef QT_COMPILER_SUPPORTS_SSSE3
extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_ssse3(const QVideoFrame&, uchar*);
if (qCpuHasFeature(SSSE3)){
- qConvertFuncs[QVideoFrame::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_ssse3;
- qConvertFuncs[QVideoFrame::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_ssse3;
- qConvertFuncs[QVideoFrame::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_ssse3;
}
#endif
#ifdef QT_COMPILER_SUPPORTS_AVX2
extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_avx2(const QVideoFrame&, uchar*);
if (qCpuHasFeature(AVX2)){
- qConvertFuncs[QVideoFrame::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_avx2;
- qConvertFuncs[QVideoFrame::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_avx2;
- qConvertFuncs[QVideoFrame::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_avx2;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_avx2;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_avx2;
+ qConvertFuncs[QVideoSurfaceFormat::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_avx2;
}
#endif
}
-VideoFrameConvertFunc qConverterForFormat(QVideoFrame::PixelFormat format)
+VideoFrameConvertFunc qConverterForFormat(QVideoSurfaceFormat::PixelFormat format)
{
static bool initAsmFuncsDone = false;
if (!initAsmFuncsDone) {
diff --git a/src/multimedia/video/qvideoframeconversionhelper_p.h b/src/multimedia/video/qvideoframeconversionhelper_p.h
index 0fdcbf8a3..58edd48f2 100644
--- a/src/multimedia/video/qvideoframeconversionhelper_p.h
+++ b/src/multimedia/video/qvideoframeconversionhelper_p.h
@@ -57,7 +57,7 @@
// Converts to RGB32 or ARGB32_Premultiplied
typedef void (QT_FASTCALL *VideoFrameConvertFunc)(const QVideoFrame &frame, uchar *output);
-VideoFrameConvertFunc qConverterForFormat(QVideoFrame::PixelFormat format);
+VideoFrameConvertFunc qConverterForFormat(QVideoSurfaceFormat::PixelFormat format);
inline quint32 qConvertBGRA32ToARGB32(quint32 bgra)
{
diff --git a/src/multimedia/video/qvideosink.cpp b/src/multimedia/video/qvideosink.cpp
index 8b6b088d2..fa9177e21 100644
--- a/src/multimedia/video/qvideosink.cpp
+++ b/src/multimedia/video/qvideosink.cpp
@@ -233,7 +233,7 @@ void QVideoSink::paint(QPainter *painter, const QVideoFrame &f)
return;
}
- auto imageFormat = QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat());
+ auto imageFormat = QVideoSurfaceFormat::imageFormatFromPixelFormat(frame.pixelFormat());
// Do not render into ARGB32 images using QPainter.
// Using QImage::Format_ARGB32_Premultiplied is significantly faster.
if (imageFormat == QImage::Format_ARGB32)
diff --git a/src/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/video/qvideosurfaceformat.cpp
index 986734a65..3ba143079 100644
--- a/src/multimedia/video/qvideosurfaceformat.cpp
+++ b/src/multimedia/video/qvideosurfaceformat.cpp
@@ -54,7 +54,7 @@ public:
QVideoSurfaceFormatPrivate(
const QSize &size,
- QVideoFrame::PixelFormat format)
+ QVideoSurfaceFormat::PixelFormat format)
: pixelFormat(format)
, frameSize(size)
, viewport(QPoint(0, 0), size)
@@ -80,7 +80,7 @@ public:
return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
}
- QVideoFrame::PixelFormat pixelFormat = QVideoFrame::Format_Invalid;
+ QVideoSurfaceFormat::PixelFormat pixelFormat = QVideoSurfaceFormat::Format_Invalid;
QVideoSurfaceFormat::Direction scanLineDirection = QVideoSurfaceFormat::TopToBottom;
QSize frameSize;
QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace = QVideoSurfaceFormat::YCbCr_Undefined;
@@ -169,7 +169,7 @@ QVideoSurfaceFormat::QVideoSurfaceFormat()
\a size and pixel \a format.
*/
QVideoSurfaceFormat::QVideoSurfaceFormat(
- const QSize& size, QVideoFrame::PixelFormat format)
+ const QSize& size, QVideoSurfaceFormat::PixelFormat format)
: d(new QVideoSurfaceFormatPrivate(size, format))
{
}
@@ -196,7 +196,7 @@ QVideoSurfaceFormat::~QVideoSurfaceFormat() = default;
*/
bool QVideoSurfaceFormat::isValid() const
{
- return d->pixelFormat != QVideoFrame::Format_Invalid && d->frameSize.isValid();
+ return d->pixelFormat != Format_Invalid && d->frameSize.isValid();
}
/*!
@@ -218,7 +218,7 @@ bool QVideoSurfaceFormat::operator !=(const QVideoSurfaceFormat &other) const
/*!
Returns the pixel format of frames in a video stream.
*/
-QVideoFrame::PixelFormat QVideoSurfaceFormat::pixelFormat() const
+QVideoSurfaceFormat::PixelFormat QVideoSurfaceFormat::pixelFormat() const
{
return d->pixelFormat;
}
@@ -383,6 +383,104 @@ QSize QVideoSurfaceFormat::sizeHint() const
return d->viewport.size();
}
+
+/*!
+ Returns a video pixel format equivalent to an image \a format. If there is no equivalent
+ format QVideoFrame::InvalidType is returned instead.
+
+ \note In general \l QImage does not handle YUV formats.
+
+*/
+QVideoSurfaceFormat::PixelFormat QVideoSurfaceFormat::pixelFormatFromImageFormat(QImage::Format format)
+{
+ switch (format) {
+ case QImage::Format_RGB32:
+ case QImage::Format_RGBX8888:
+ return QVideoSurfaceFormat::Format_RGB32;
+ case QImage::Format_ARGB32:
+ case QImage::Format_RGBA8888:
+ return QVideoSurfaceFormat::Format_ARGB32;
+ case QImage::Format_ARGB32_Premultiplied:
+ case QImage::Format_RGBA8888_Premultiplied:
+ return QVideoSurfaceFormat::Format_ARGB32_Premultiplied;
+ case QImage::Format_RGB16:
+ return QVideoSurfaceFormat::Format_RGB565;
+ case QImage::Format_ARGB8565_Premultiplied:
+ return QVideoSurfaceFormat::Format_ARGB8565_Premultiplied;
+ case QImage::Format_RGB555:
+ return QVideoSurfaceFormat::Format_RGB555;
+ case QImage::Format_RGB888:
+ return QVideoSurfaceFormat::Format_RGB24;
+ case QImage::Format_Grayscale8:
+ return QVideoSurfaceFormat::Format_Y8;
+ case QImage::Format_Grayscale16:
+ return QVideoSurfaceFormat::Format_Y16;
+ default:
+ return QVideoSurfaceFormat::Format_Invalid;
+ }
+}
+
+/*!
+ Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent
+ format QImage::Format_Invalid is returned instead.
+
+ \note In general \l QImage does not handle YUV formats.
+
+*/
+QImage::Format QVideoSurfaceFormat::imageFormatFromPixelFormat(QVideoSurfaceFormat::PixelFormat format)
+{
+ switch (format) {
+ case QVideoSurfaceFormat::Format_ARGB32:
+ return QImage::Format_ARGB32;
+ case QVideoSurfaceFormat::Format_ARGB32_Premultiplied:
+ return QImage::Format_ARGB32_Premultiplied;
+ case QVideoSurfaceFormat::Format_RGB32:
+ return QImage::Format_RGB32;
+ case QVideoSurfaceFormat::Format_RGB24:
+ return QImage::Format_RGB888;
+ case QVideoSurfaceFormat::Format_RGB565:
+ return QImage::Format_RGB16;
+ case QVideoSurfaceFormat::Format_RGB555:
+ return QImage::Format_RGB555;
+ case QVideoSurfaceFormat::Format_ARGB8565_Premultiplied:
+ return QImage::Format_ARGB8565_Premultiplied;
+ case QVideoSurfaceFormat::Format_Y8:
+ return QImage::Format_Grayscale8;
+ case QVideoSurfaceFormat::Format_Y16:
+ return QImage::Format_Grayscale16;
+ case QVideoSurfaceFormat::Format_ABGR32:
+ case QVideoSurfaceFormat::Format_BGRA32:
+ case QVideoSurfaceFormat::Format_BGRA32_Premultiplied:
+ case QVideoSurfaceFormat::Format_BGR32:
+ case QVideoSurfaceFormat::Format_BGR24:
+ case QVideoSurfaceFormat::Format_BGR565:
+ case QVideoSurfaceFormat::Format_BGR555:
+ case QVideoSurfaceFormat::Format_BGRA5658_Premultiplied:
+ case QVideoSurfaceFormat::Format_AYUV444:
+ case QVideoSurfaceFormat::Format_AYUV444_Premultiplied:
+ case QVideoSurfaceFormat::Format_YUV444:
+ case QVideoSurfaceFormat::Format_YUV420P:
+ case QVideoSurfaceFormat::Format_YUV422P:
+ case QVideoSurfaceFormat::Format_YV12:
+ case QVideoSurfaceFormat::Format_UYVY:
+ case QVideoSurfaceFormat::Format_YUYV:
+ case QVideoSurfaceFormat::Format_NV12:
+ case QVideoSurfaceFormat::Format_NV21:
+ case QVideoSurfaceFormat::Format_IMC1:
+ case QVideoSurfaceFormat::Format_IMC2:
+ case QVideoSurfaceFormat::Format_IMC3:
+ case QVideoSurfaceFormat::Format_IMC4:
+ case QVideoSurfaceFormat::Format_P010LE:
+ case QVideoSurfaceFormat::Format_P010BE:
+ case QVideoSurfaceFormat::Format_P016LE:
+ case QVideoSurfaceFormat::Format_P016BE:
+ case QVideoSurfaceFormat::Format_Jpeg:
+ case QVideoSurfaceFormat::Format_Invalid:
+ return QImage::Format_Invalid;
+ }
+ return QImage::Format_Invalid;
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, QVideoSurfaceFormat::YCbCrColorSpace cs)
{
@@ -443,6 +541,91 @@ QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f)
return dbg;
}
+
+QDebug operator<<(QDebug dbg, QVideoSurfaceFormat::PixelFormat pf)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (pf) {
+ case QVideoSurfaceFormat::Format_Invalid:
+ return dbg << "Format_Invalid";
+ case QVideoSurfaceFormat::Format_ARGB32:
+ return dbg << "Format_ARGB32";
+ case QVideoSurfaceFormat::Format_ARGB32_Premultiplied:
+ return dbg << "Format_ARGB32_Premultiplied";
+ case QVideoSurfaceFormat::Format_RGB32:
+ return dbg << "Format_RGB32";
+ case QVideoSurfaceFormat::Format_RGB24:
+ return dbg << "Format_RGB24";
+ case QVideoSurfaceFormat::Format_RGB565:
+ return dbg << "Format_RGB565";
+ case QVideoSurfaceFormat::Format_RGB555:
+ return dbg << "Format_RGB555";
+ case QVideoSurfaceFormat::Format_ARGB8565_Premultiplied:
+ return dbg << "Format_ARGB8565_Premultiplied";
+ case QVideoSurfaceFormat::Format_BGRA32:
+ return dbg << "Format_BGRA32";
+ case QVideoSurfaceFormat::Format_BGRA32_Premultiplied:
+ return dbg << "Format_BGRA32_Premultiplied";
+ case QVideoSurfaceFormat::Format_ABGR32:
+ return dbg << "Format_ABGR32";
+ case QVideoSurfaceFormat::Format_BGR32:
+ return dbg << "Format_BGR32";
+ case QVideoSurfaceFormat::Format_BGR24:
+ return dbg << "Format_BGR24";
+ case QVideoSurfaceFormat::Format_BGR565:
+ return dbg << "Format_BGR565";
+ case QVideoSurfaceFormat::Format_BGR555:
+ return dbg << "Format_BGR555";
+ case QVideoSurfaceFormat::Format_BGRA5658_Premultiplied:
+ return dbg << "Format_BGRA5658_Premultiplied";
+ case QVideoSurfaceFormat::Format_AYUV444:
+ return dbg << "Format_AYUV444";
+ case QVideoSurfaceFormat::Format_AYUV444_Premultiplied:
+ return dbg << "Format_AYUV444_Premultiplied";
+ case QVideoSurfaceFormat::Format_YUV444:
+ return dbg << "Format_YUV444";
+ case QVideoSurfaceFormat::Format_YUV420P:
+ return dbg << "Format_YUV420P";
+ case QVideoSurfaceFormat::Format_YUV422P:
+ return dbg << "Format_YUV422P";
+ case QVideoSurfaceFormat::Format_YV12:
+ return dbg << "Format_YV12";
+ case QVideoSurfaceFormat::Format_UYVY:
+ return dbg << "Format_UYVY";
+ case QVideoSurfaceFormat::Format_YUYV:
+ return dbg << "Format_YUYV";
+ case QVideoSurfaceFormat::Format_NV12:
+ return dbg << "Format_NV12";
+ case QVideoSurfaceFormat::Format_NV21:
+ return dbg << "Format_NV21";
+ case QVideoSurfaceFormat::Format_IMC1:
+ return dbg << "Format_IMC1";
+ case QVideoSurfaceFormat::Format_IMC2:
+ return dbg << "Format_IMC2";
+ case QVideoSurfaceFormat::Format_IMC3:
+ return dbg << "Format_IMC3";
+ case QVideoSurfaceFormat::Format_IMC4:
+ return dbg << "Format_IMC4";
+ case QVideoSurfaceFormat::Format_Y8:
+ return dbg << "Format_Y8";
+ case QVideoSurfaceFormat::Format_Y16:
+ return dbg << "Format_Y16";
+ case QVideoSurfaceFormat::Format_P010LE:
+ return dbg << "Format_P010LE";
+ case QVideoSurfaceFormat::Format_P010BE:
+ return dbg << "Format_P010BE";
+ case QVideoSurfaceFormat::Format_P016LE:
+ return dbg << "Format_P016LE";
+ case QVideoSurfaceFormat::Format_P016BE:
+ return dbg << "Format_P016BE";
+ case QVideoSurfaceFormat::Format_Jpeg:
+ return dbg << "Format_Jpeg";
+
+ default:
+ return dbg << QString(QLatin1String("UserType(%1)" )).arg(int(pf)).toLatin1().constData();
+ }
+}
#endif
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideosurfaceformat.h b/src/multimedia/video/qvideosurfaceformat.h
index 694dd9a79..5b9c9fcb8 100644
--- a/src/multimedia/video/qvideosurfaceformat.h
+++ b/src/multimedia/video/qvideosurfaceformat.h
@@ -40,12 +40,13 @@
#ifndef QVIDEOSURFACEFORMAT_H
#define QVIDEOSURFACEFORMAT_H
+#include <QtMultimedia/qtmultimediaglobal.h>
+
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qsize.h>
#include <QtGui/qimage.h>
-#include <QtMultimedia/qvideoframe.h>
QT_BEGIN_NAMESPACE
@@ -57,6 +58,53 @@ class QVideoSurfaceFormatPrivate;
class Q_MULTIMEDIA_EXPORT QVideoSurfaceFormat
{
public:
+ enum PixelFormat
+ {
+ Format_Invalid,
+ Format_ARGB32,
+ Format_ARGB32_Premultiplied,
+ Format_RGB32,
+ Format_RGB24,
+ Format_RGB565,
+ Format_RGB555,
+ Format_ARGB8565_Premultiplied,
+ Format_BGRA32,
+ Format_BGRA32_Premultiplied,
+ Format_ABGR32,
+ Format_BGR32,
+ Format_BGR24,
+ Format_BGR565,
+ Format_BGR555,
+ Format_BGRA5658_Premultiplied,
+
+ Format_AYUV444,
+ Format_AYUV444_Premultiplied,
+ Format_YUV444,
+ Format_YUV420P,
+ Format_YUV422P,
+ Format_YV12,
+ Format_UYVY,
+ Format_YUYV,
+ Format_NV12,
+ Format_NV21,
+ Format_IMC1,
+ Format_IMC2,
+ Format_IMC3,
+ Format_IMC4,
+ Format_Y8,
+ Format_Y16,
+
+ Format_P010LE,
+ Format_P010BE,
+ Format_P016LE,
+ Format_P016BE,
+
+ Format_Jpeg,
+ };
+#ifndef Q_QDOC
+ static constexpr int NPixelFormats = Format_Jpeg + 1;
+#endif
+
enum Direction
{
TopToBottom,
@@ -76,7 +124,7 @@ public:
QVideoSurfaceFormat();
QVideoSurfaceFormat(
const QSize &size,
- QVideoFrame::PixelFormat pixelFormat);
+ QVideoSurfaceFormat::PixelFormat pixelFormat);
QVideoSurfaceFormat(const QVideoSurfaceFormat &format);
~QVideoSurfaceFormat();
@@ -87,7 +135,7 @@ public:
bool isValid() const;
- QVideoFrame::PixelFormat pixelFormat() const;
+ QVideoSurfaceFormat::PixelFormat pixelFormat() const;
QSize frameSize() const;
void setFrameSize(const QSize &size);
@@ -113,6 +161,9 @@ public:
QSize sizeHint() const;
+ static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
+ static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
+
private:
QSharedDataPointer<QVideoSurfaceFormatPrivate> d;
};
@@ -121,6 +172,7 @@ private:
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &);
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoSurfaceFormat::Direction);
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoSurfaceFormat::YCbCrColorSpace);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoSurfaceFormat::PixelFormat);
#endif
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideosurfaces.cpp b/src/multimedia/video/qvideosurfaces.cpp
index 1870e6ebf..b3e07fb26 100644
--- a/src/multimedia/video/qvideosurfaces.cpp
+++ b/src/multimedia/video/qvideosurfaces.cpp
@@ -57,10 +57,10 @@ QVideoSurfaces::QVideoSurfaces(const QList<QAbstractVideoSurface *> &s, QObject
QVideoSurfaces::~QVideoSurfaces() = default;
-QList<QVideoFrame::PixelFormat> QVideoSurfaces::supportedPixelFormats(QVideoFrame::HandleType type) const
+QList<QVideoSurfaceFormat::PixelFormat> QVideoSurfaces::supportedPixelFormats(QVideoFrame::HandleType type) const
{
- QList<QVideoFrame::PixelFormat> result;
- QMap<QVideoFrame::PixelFormat, int> formats;
+ QList<QVideoSurfaceFormat::PixelFormat> result;
+ QMap<QVideoSurfaceFormat::PixelFormat, int> formats;
for (auto &s : m_surfaces) {
for (auto &p : s->supportedPixelFormats(type)) {
if (++formats[p] == m_surfaces.size())
diff --git a/src/multimedia/video/qvideosurfaces_p.h b/src/multimedia/video/qvideosurfaces_p.h
index f72bd0565..4d9a8a9df 100644
--- a/src/multimedia/video/qvideosurfaces_p.h
+++ b/src/multimedia/video/qvideosurfaces_p.h
@@ -62,7 +62,7 @@ public:
QVideoSurfaces(const QList<QAbstractVideoSurface *> &surfaces, QObject *parent = nullptr);
~QVideoSurfaces();
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QVideoFrame::HandleType type) const override;
+ QList<QVideoSurfaceFormat::PixelFormat> supportedPixelFormats(QVideoFrame::HandleType type) const override;
bool start(const QVideoSurfaceFormat &format) override;
void stop() override;
bool present(const QVideoFrame &frame) override;