Clamp results correctly when shifting video levels, and account for that in tests.
[dcpomatic.git] / test / video_level_test.cc
index acf7fb4e2919a1084fb5c4667f4b710249a18ea7..c974c938d3002f71a4fc86b9f1518ab8597bbd9b 100644 (file)
@@ -28,6 +28,7 @@
 #include "lib/content_factory.h"
 #include "lib/content_video.h"
 #include "lib/dcp_content.h"
+#include "lib/decoder_factory.h"
 #include "lib/film.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/ffmpeg_decoder.h"
@@ -125,17 +126,6 @@ BOOST_AUTO_TEST_CASE (ffmpeg_image_video_range_expanded)
 }
 
 
-static optional<ContentVideo> content_video;
-
-
-static
-void
-video_handler (ContentVideo cv)
-{
-       content_video = cv;
-}
-
-
 static
 pair<int, int>
 pixel_range (shared_ptr<const Image> image)
@@ -197,26 +187,13 @@ pixel_range (shared_ptr<const Image> image)
 
 static
 pair<int, int>
-pixel_range (shared_ptr<Film> film, shared_ptr<const FFmpegContent> content)
-{
-       auto decoder = make_shared<FFmpegDecoder>(film, content, false);
-       decoder->video->Data.connect (bind(&video_handler, _1));
-       content_video = boost::none;
-       while (!content_video) {
-               BOOST_REQUIRE (!decoder->pass());
-       }
-
-       return pixel_range (content_video->image->image().image);
-}
-
-
-static
-pair<int, int>
-pixel_range (shared_ptr<Film> film, shared_ptr<const ImageContent> content)
+pixel_range (shared_ptr<const Film> film, shared_ptr<const Content> content)
 {
-       auto decoder = make_shared<ImageDecoder>(film, content);
-       decoder->video->Data.connect (bind(&video_handler, _1));
-       content_video = boost::none;
+       auto decoder = decoder_factory(film, content, false, false, shared_ptr<Decoder>());
+       optional<ContentVideo> content_video;
+       decoder->video->Data.connect ([&content_video](ContentVideo cv) {
+               content_video = cv;
+       });
        while (!content_video) {
                BOOST_REQUIRE (!decoder->pass());
        }
@@ -367,8 +344,11 @@ image_FoV (string name)
        content->video->set_range (VideoRange::VIDEO);
 
        auto range = pixel_range (film, content);
-       BOOST_CHECK_EQUAL (range.first, 11);
-       BOOST_CHECK_EQUAL (range.second, 250);
+       /* We are taking some full-range content and saying it should be read as video range, after which its
+        * pixels will still be full range.
+        */
+       BOOST_CHECK_EQUAL (range.first, 0);
+       BOOST_CHECK_EQUAL (range.second, 255);
 
        return film;
 }
@@ -474,7 +454,10 @@ BOOST_AUTO_TEST_CASE (image_F_to_dcp)
 BOOST_AUTO_TEST_CASE (image_FoV_to_dcp)
 {
        auto range = dcp_range (image_FoV("image_FoV_to_dcp"));
-       check_int_close (range, {430, 4012}, 2);
+       /* The nearly-full-range of the input has become even more full, and clipped.
+        * XXX: I'm not sure why this doesn't quite hit 4095.
+        */
+       check_int_close (range, {0, 4095}, 16);
 }