2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file test/video_level_test.cc
23 * @brief Test that video level ranges are handled correctly.
28 #include "lib/ffmpeg_image_proxy.h"
29 #include "lib/image.h"
31 #include <boost/test/unit_test.hpp>
34 using boost::shared_ptr;
39 grey_image (dcp::Size size, uint8_t pixel)
41 shared_ptr<Image> grey(new Image(AV_PIX_FMT_RGB24, size, true));
42 for (int y = 0; y < size.height; ++y) {
43 uint8_t* p = grey->data()[0] + y * grey->stride()[0];
44 for (int x = 0; x < size.width; ++x) {
55 BOOST_AUTO_TEST_CASE (ffmpeg_image_full_range_not_changed)
57 dcp::Size size(640, 480);
58 uint8_t const grey_pixel = 128;
59 boost::filesystem::path const file = "build/test/ffmpeg_image_full_range_not_changed.png";
61 write_image (grey_image(size, grey_pixel), file);
63 FFmpegImageProxy proxy (file, VIDEO_RANGE_FULL);
64 ImageProxy::Result result = proxy.image ();
65 BOOST_REQUIRE (!result.error);
67 for (int y = 0; y < size.height; ++y) {
68 uint8_t* p = result.image->data()[0] + y * result.image->stride()[0];
69 for (int x = 0; x < size.width; ++x) {
70 BOOST_REQUIRE (*p++ == grey_pixel);
76 BOOST_AUTO_TEST_CASE (ffmpeg_image_video_range_expanded)
78 dcp::Size size(640, 480);
79 uint8_t const grey_pixel = 128;
80 uint8_t const expanded_grey_pixel = static_cast<uint8_t>((grey_pixel - 16) * 256.0 / 219);
81 boost::filesystem::path const file = "build/test/ffmpeg_image_video_range_expanded.png";
83 write_image (grey_image(size, grey_pixel), file);
85 FFmpegImageProxy proxy (file, VIDEO_RANGE_VIDEO);
86 ImageProxy::Result result = proxy.image ();
87 BOOST_REQUIRE (!result.error);
89 for (int y = 0; y < size.height; ++y) {
90 uint8_t* p = result.image->data()[0] + y * result.image->stride()[0];
91 for (int x = 0; x < size.width; ++x) {
92 BOOST_REQUIRE_EQUAL (*p++, expanded_grey_pixel);