// Copyright (C) Videmo Intelligente Videoanalyse GmbH - All rights reserved. // Unauthorized copying of this file, via any medium is strictly prohibited. // Proprietary and confidential. #include #include extern "C" { #include #include #include #include } #include #include #include namespace { constexpr auto formats = std::array, 17>{ {{AV_PIX_FMT_ARGB, QVideoFrameFormat::Format_ARGB8888}, {AV_PIX_FMT_0RGB, QVideoFrameFormat::Format_XRGB8888}, {AV_PIX_FMT_RGBA, QVideoFrameFormat::Format_RGBA8888}, {AV_PIX_FMT_RGB0, QVideoFrameFormat::Format_RGBX8888}, {AV_PIX_FMT_ABGR, QVideoFrameFormat::Format_ABGR8888}, {AV_PIX_FMT_0BGR, QVideoFrameFormat::Format_XBGR8888}, {AV_PIX_FMT_BGRA, QVideoFrameFormat::Format_BGRA8888}, {AV_PIX_FMT_BGR0, QVideoFrameFormat::Format_BGRX8888}, {AV_PIX_FMT_UYVY422, QVideoFrameFormat::Format_UYVY}, {AV_PIX_FMT_YUYV422, QVideoFrameFormat::Format_YUYV}, {AV_PIX_FMT_YUV420P, QVideoFrameFormat::Format_YUV420P}, {AV_PIX_FMT_YUV422P, QVideoFrameFormat::Format_YUV422P}, {AV_PIX_FMT_GRAY8, QVideoFrameFormat::Format_Y8}, {AV_PIX_FMT_GRAY16LE, QVideoFrameFormat::Format_Y16}, {AV_PIX_FMT_NV12, QVideoFrameFormat::Format_NV12}, {AV_PIX_FMT_NV21, QVideoFrameFormat::Format_NV21}, {AV_PIX_FMT_YUV420P, QVideoFrameFormat::Format_YV12}}, // with U & V planes swapped }; } TEST_CASE("QVideoFrame.plane_sizes") { const auto [av_pix_fmt, qt_pix_fmt] = GENERATE(Catch::Generators::from_range(formats)); INFO("av_pix_fmt=" << av_get_pix_fmt_name(av_pix_fmt)); INFO("qt_pix_fmt=" << QVideoFrameFormat::pixelFormatToString(qt_pix_fmt).toStdString()); const int width = 1280; const int height = 720; INFO("width=" << width << ", height=" << height); const auto qt_fmt = QVideoFrameFormat({width, height}, qt_pix_fmt); const auto* desc = av_pix_fmt_desc_get(av_pix_fmt); REQUIRE(desc); const auto n_planes = av_pix_fmt_count_planes(av_pix_fmt); REQUIRE(n_planes > 0); REQUIRE(n_planes <= 4); REQUIRE(n_planes == qt_fmt.planeCount()); auto qt_frame = QVideoFrame(qt_fmt); qt_frame.map(QVideoFrame::WriteOnly); for (int plane = 0; plane < n_planes; ++plane) { INFO("plane=" << plane); const auto av_plane_linesize = av_image_get_linesize(av_pix_fmt, width, plane); const auto qt_plane_linesize = qt_frame.bytesPerLine(plane); CHECK(av_plane_linesize == qt_plane_linesize); const auto is_chroma = plane == 1 || plane == 2; const auto av_plane_height = is_chroma ? AV_CEIL_RSHIFT(height, desc->log2_chroma_h) : height; const auto av_plane_size = av_plane_height * av_plane_linesize; const auto qt_plane_size = qt_frame.mappedBytes(plane); REQUIRE(qt_plane_size > 0); const auto qt_plane_height = qt_plane_size / qt_plane_linesize; CHECK(av_plane_height == qt_plane_height); CHECK(av_plane_size == qt_plane_size); } }