summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-11-08 22:34:18 +0100
committerCarl Hetherington <cth@carlh.net>2020-11-16 01:40:36 +0100
commite64a1a9aae0200d14feed49a4c6cf537bf5708a4 (patch)
treeb1b01bb8e6f1872309eb246434120de3b769e9e5 /test
parentf5608308b17c72b3ee459c805663e0103de1d2a4 (diff)
Obey requests to change the video range of RGB content.
Video that comes in with RGB pixels will not have its video level ranges changed by libswscale (it only does this for YUV and greyscale). Here we add code to do it ourselves for RGB content coming in via image files (e.g. PNG/DPX etc). Part of #1851.
Diffstat (limited to 'test')
-rw-r--r--test/image_proxy_test.cc8
-rw-r--r--test/image_test.cc16
-rw-r--r--test/test.cc4
-rw-r--r--test/video_level_test.cc97
-rw-r--r--test/wscript1
5 files changed, 112 insertions, 14 deletions
diff --git a/test/image_proxy_test.cc b/test/image_proxy_test.cc
index 061df9eed..0999d4b10 100644
--- a/test/image_proxy_test.cc
+++ b/test/image_proxy_test.cc
@@ -53,14 +53,14 @@ BOOST_AUTO_TEST_CASE (j2k_image_proxy_same_test)
BOOST_AUTO_TEST_CASE (ffmpeg_image_proxy_same_test)
{
{
- shared_ptr<FFmpegImageProxy> proxy1(new FFmpegImageProxy(data_file0));
- shared_ptr<FFmpegImageProxy> proxy2(new FFmpegImageProxy(data_file0));
+ shared_ptr<FFmpegImageProxy> proxy1(new FFmpegImageProxy(data_file0, VIDEO_RANGE_FULL));
+ shared_ptr<FFmpegImageProxy> proxy2(new FFmpegImageProxy(data_file0, VIDEO_RANGE_FULL));
BOOST_CHECK (proxy1->same(proxy2));
}
{
- shared_ptr<FFmpegImageProxy> proxy1(new FFmpegImageProxy(data_file0));
- shared_ptr<FFmpegImageProxy> proxy2(new FFmpegImageProxy(data_file1));
+ shared_ptr<FFmpegImageProxy> proxy1(new FFmpegImageProxy(data_file0, VIDEO_RANGE_FULL));
+ shared_ptr<FFmpegImageProxy> proxy2(new FFmpegImageProxy(data_file1, VIDEO_RANGE_FULL));
BOOST_CHECK (!proxy1->same(proxy2));
}
}
diff --git a/test/image_test.cc b/test/image_test.cc
index bdd34c665..e2b1d71c7 100644
--- a/test/image_test.cc
+++ b/test/image_test.cc
@@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE (compact_image_test)
void
alpha_blend_test_one (AVPixelFormat format, string suffix)
{
- shared_ptr<FFmpegImageProxy> proxy (new FFmpegImageProxy (TestPaths::private_data() / "prophet_frame.tiff"));
+ shared_ptr<FFmpegImageProxy> proxy (new FFmpegImageProxy (TestPaths::private_data() / "prophet_frame.tiff", VIDEO_RANGE_FULL));
shared_ptr<Image> raw = proxy->image().image;
shared_ptr<Image> background = raw->convert_pixel_format (dcp::YUV_TO_RGB_REC709, format, true, false);
@@ -259,7 +259,7 @@ BOOST_AUTO_TEST_CASE (merge_test2)
/** Test Image::crop_scale_window with YUV420P and some windowing */
BOOST_AUTO_TEST_CASE (crop_scale_window_test)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/flat_red.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/flat_red.png", VIDEO_RANGE_FULL));
shared_ptr<Image> raw = proxy->image().image;
shared_ptr<Image> out = raw->crop_scale_window(Crop(), dcp::Size(1998, 836), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_YUV420P, true, false);
shared_ptr<Image> save = out->scale(dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false, false);
@@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test2)
BOOST_AUTO_TEST_CASE (crop_scale_window_test3)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png", VIDEO_RANGE_FULL));
shared_ptr<Image> xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false);
shared_ptr<Image> cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_RGB24, false, false);
write_image(cropped, "build/test/crop_scale_window_test3.png");
@@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test3)
BOOST_AUTO_TEST_CASE (crop_scale_window_test4)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png", VIDEO_RANGE_FULL));
shared_ptr<Image> xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false);
shared_ptr<Image> cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_XYZ12LE, false, false);
write_image(cropped, "build/test/crop_scale_window_test4.png");
@@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test4)
BOOST_AUTO_TEST_CASE (crop_scale_window_test5)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png", VIDEO_RANGE_FULL));
shared_ptr<Image> xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_XYZ12LE, true, false);
shared_ptr<Image> cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_RGB24, false, false);
write_image(cropped, "build/test/crop_scale_window_test5.png");
@@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test5)
BOOST_AUTO_TEST_CASE (crop_scale_window_test6)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png", VIDEO_RANGE_FULL));
shared_ptr<Image> xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_XYZ12LE, true, false);
shared_ptr<Image> cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_XYZ12LE, false, false);
write_image(cropped, "build/test/crop_scale_window_test6.png");
@@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test6)
BOOST_AUTO_TEST_CASE (as_png_test)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/3d_test/000001.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/3d_test/000001.png", VIDEO_RANGE_FULL));
shared_ptr<Image> image_rgb = proxy->image().image;
shared_ptr<Image> image_bgr = image_rgb->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_BGRA, true, false);
image_rgb->as_png().write ("build/test/as_png_rgb.png");
@@ -339,7 +339,7 @@ fade_test_format_black (AVPixelFormat f, string name)
static void
fade_test_format_red (AVPixelFormat f, float amount, string name)
{
- shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/flat_red.png"));
+ shared_ptr<FFmpegImageProxy> proxy(new FFmpegImageProxy("test/data/flat_red.png", VIDEO_RANGE_FULL));
shared_ptr<Image> red = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, f, true, false);
red->fade (amount);
string const filename = "fade_test_red_" + name + ".png";
diff --git a/test/test.cc b/test/test.cc
index 9ac202b80..5981697fb 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -336,9 +336,9 @@ static
double
rms_error (boost::filesystem::path ref, boost::filesystem::path check)
{
- FFmpegImageProxy ref_proxy (ref);
+ FFmpegImageProxy ref_proxy (ref, VIDEO_RANGE_FULL);
shared_ptr<Image> ref_image = ref_proxy.image().image;
- FFmpegImageProxy check_proxy (check);
+ FFmpegImageProxy check_proxy (check, VIDEO_RANGE_FULL);
shared_ptr<Image> check_image = check_proxy.image().image;
BOOST_REQUIRE_EQUAL (ref_image->pixel_format(), check_image->pixel_format());
diff --git a/test/video_level_test.cc b/test/video_level_test.cc
new file mode 100644
index 000000000..2849910b1
--- /dev/null
+++ b/test/video_level_test.cc
@@ -0,0 +1,97 @@
+/*
+ Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+/** @file test/video_level_test.cc
+ * @brief Test that video level ranges are handled correctly.
+ * @ingroup specific
+ */
+
+
+#include "lib/ffmpeg_image_proxy.h"
+#include "lib/image.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+
+using boost::shared_ptr;
+
+
+static
+shared_ptr<Image>
+grey_image (dcp::Size size, uint8_t pixel)
+{
+ shared_ptr<Image> grey(new Image(AV_PIX_FMT_RGB24, size, true));
+ for (int y = 0; y < size.height; ++y) {
+ uint8_t* p = grey->data()[0] + y * grey->stride()[0];
+ for (int x = 0; x < size.width; ++x) {
+ *p++ = pixel;
+ *p++ = pixel;
+ *p++ = pixel;
+ }
+ }
+
+ return grey;
+}
+
+
+BOOST_AUTO_TEST_CASE (ffmpeg_image_full_range_not_changed)
+{
+ dcp::Size size(640, 480);
+ uint8_t const grey_pixel = 128;
+ boost::filesystem::path const file = "build/test/ffmpeg_image_full_range_not_changed.png";
+
+ write_image (grey_image(size, grey_pixel), file);
+
+ FFmpegImageProxy proxy (file, VIDEO_RANGE_FULL);
+ ImageProxy::Result result = proxy.image ();
+ BOOST_REQUIRE (!result.error);
+
+ for (int y = 0; y < size.height; ++y) {
+ uint8_t* p = result.image->data()[0] + y * result.image->stride()[0];
+ for (int x = 0; x < size.width; ++x) {
+ BOOST_REQUIRE (*p++ == grey_pixel);
+ }
+ }
+}
+
+
+BOOST_AUTO_TEST_CASE (ffmpeg_image_video_range_expanded)
+{
+ dcp::Size size(640, 480);
+ uint8_t const grey_pixel = 128;
+ uint8_t const expanded_grey_pixel = static_cast<uint8_t>((grey_pixel - 16) * 256.0 / 219);
+ boost::filesystem::path const file = "build/test/ffmpeg_image_video_range_expanded.png";
+
+ write_image (grey_image(size, grey_pixel), file);
+
+ FFmpegImageProxy proxy (file, VIDEO_RANGE_VIDEO);
+ ImageProxy::Result result = proxy.image ();
+ BOOST_REQUIRE (!result.error);
+
+ for (int y = 0; y < size.height; ++y) {
+ uint8_t* p = result.image->data()[0] + y * result.image->stride()[0];
+ for (int x = 0; x < size.width; ++x) {
+ BOOST_REQUIRE_EQUAL (*p++, expanded_grey_pixel);
+ }
+ }
+}
+
+
diff --git a/test/wscript b/test/wscript
index 50fe91b43..176f4ca67 100644
--- a/test/wscript
+++ b/test/wscript
@@ -130,6 +130,7 @@ def build(bld):
util_test.cc
vf_test.cc
video_content_scale_test.cc
+ video_level_test.cc
video_mxf_content_test.cc
vf_kdm_test.cc
zipper_test.cc