From 59d0683c999bec5612f6ba91867bde4d02185204 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Fri, 11 Oct 2019 11:51:14 +0200 Subject: Introduce QVideoFrame::image() Since QVideoFrame::pixelFormat's do not 100% match QImage::Format's, introducing converstion function. Returns an image based on current frame. Converts data if needed to supported QImage format. Change-Id: I3331578c01cf9c999a380efc4a83bf9eddb07901 (cherry picked from commit 93f966335e1ed8ed47b7e8b32452d43c2f8a7bb1) Reviewed-by: Daniel Smith Reviewed-by: Volker Hilsheimer --- .../qcamerabackend/tst_qcamerabackend.cpp | 5 +- tests/auto/unit/qvideoframe/BLACKLIST | 2 + tests/auto/unit/qvideoframe/tst_qvideoframe.cpp | 169 +++++++++++++++++++++ 3 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 tests/auto/unit/qvideoframe/BLACKLIST (limited to 'tests') diff --git a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp index 894486230..27fc014aa 100644 --- a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp +++ b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp @@ -49,7 +49,6 @@ #include #include #include -#include QT_USE_NAMESPACE @@ -451,7 +450,7 @@ void tst_QCameraBackend::testCaptureToBuffer() QCOMPARE(imageAvailableSignal.first().first().toInt(), id); QVideoFrame frame = imageAvailableSignal.first().last().value(); - QVERIFY(!qt_imageFromVideoFrame(frame).isNull()); + QVERIFY(!frame.image().isNull()); frame = QVideoFrame(); capturedSignal.clear(); @@ -509,7 +508,7 @@ void tst_QCameraBackend::testCaptureToBuffer() QCOMPARE(imageAvailableSignal.first().first().toInt(), id); frame = imageAvailableSignal.first().last().value(); - QVERIFY(!qt_imageFromVideoFrame(frame).isNull()); + QVERIFY(!frame.image().isNull()); QString fileName = savedSignal.first().last().toString(); QVERIFY(QFileInfo(fileName).exists()); diff --git a/tests/auto/unit/qvideoframe/BLACKLIST b/tests/auto/unit/qvideoframe/BLACKLIST new file mode 100644 index 000000000..1fa752da5 --- /dev/null +++ b/tests/auto/unit/qvideoframe/BLACKLIST @@ -0,0 +1,2 @@ +[image:64x64 AYUV444,64x64 YUV444,64x64 YUV420P,64x64 YV12,64x64 UYVY,64x64 YUYV,64x64 NV12,64x64 NV21] +windows-10 ci diff --git a/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp b/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp index 6be039108..de9295c33 100644 --- a/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp +++ b/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp @@ -85,6 +85,9 @@ private slots: void isMapped(); void isReadable(); void isWritable(); + + void image_data(); + void image(); }; Q_DECLARE_METATYPE(QImage::Format) @@ -1128,6 +1131,172 @@ void tst_QVideoFrame::isWritable() frame.unmap(); } +void tst_QVideoFrame::image_data() +{ + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("bytes"); + QTest::addColumn("bytesPerLine"); + QTest::addColumn("imageFormat"); + + QTest::newRow("64x64 ARGB32") + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 ARGB32_Premultiplied") + << QSize(64, 64) + << QVideoFrame::Format_ARGB32_Premultiplied + << 16384 + << 256 + << QImage::Format_ARGB32_Premultiplied; + + QTest::newRow("64x64 RGB32") + << QSize(64, 64) + << QVideoFrame::Format_RGB32 + << 16384 + << 256 + << QImage::Format_RGB32; + + QTest::newRow("64x64 RGB24") + << QSize(64, 64) + << QVideoFrame::Format_RGB24 + << 16384 + << 192 + << QImage::Format_RGB888; + + QTest::newRow("64x64 RGB565") + << QSize(64, 64) + << QVideoFrame::Format_RGB565 + << 16384 + << 128 + << QImage::Format_RGB16; + + QTest::newRow("64x64 RGB555") + << QSize(64, 64) + << QVideoFrame::Format_RGB555 + << 16384 + << 128 + << QImage::Format_RGB555; + + QTest::newRow("64x64 BGRA32") + << QSize(64, 64) + << QVideoFrame::Format_BGRA32 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 BGRA32_Premultiplied") + << QSize(64, 64) + << QVideoFrame::Format_BGRA32_Premultiplied + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 BGR32") + << QSize(64, 64) + << QVideoFrame::Format_BGR32 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 BGR24") + << QSize(64, 64) + << QVideoFrame::Format_BGR24 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 BGR565") + << QSize(64, 64) + << QVideoFrame::Format_BGR565 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 BGR555") + << QSize(64, 64) + << QVideoFrame::Format_BGR555 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 AYUV444") + << QSize(64, 64) + << QVideoFrame::Format_AYUV444 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 YUV444") + << QSize(64, 64) + << QVideoFrame::Format_YUV444 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 YUV420P") + << QSize(64, 64) + << QVideoFrame::Format_YUV420P + << 13288 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 YV12") + << QSize(64, 64) + << QVideoFrame::Format_YV12 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 UYVY") + << QSize(64, 64) + << QVideoFrame::Format_UYVY + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 YUYV") + << QSize(64, 64) + << QVideoFrame::Format_YUYV + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 NV12") + << QSize(64, 64) + << QVideoFrame::Format_NV12 + << 16384 + << 256 + << QImage::Format_ARGB32; + + QTest::newRow("64x64 NV21") + << QSize(64, 64) + << QVideoFrame::Format_NV21 + << 16384 + << 256 + << QImage::Format_ARGB32; +} + +void tst_QVideoFrame::image() +{ + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(int, bytes); + QFETCH(int, bytesPerLine); + QFETCH(QImage::Format, imageFormat); + + QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + QImage img = frame.image(); + + QVERIFY(!img.isNull()); + QCOMPARE(img.format(), imageFormat); + QCOMPARE(img.size(), size); + QCOMPARE(img.bytesPerLine(), bytesPerLine); +} + QTEST_MAIN(tst_QVideoFrame) #include "tst_qvideoframe.moc" -- cgit v1.2.3