Fix corrupted image when over-cropping black filler frames.
[dcpomatic.git] / test / image_test.cc
index 9fe793d709ed97b9bcc75051ff06cd922ff75ee4..2f66cf41d042919a7ed7374b867419ce5d94ded5 100644 (file)
@@ -393,3 +393,17 @@ BOOST_AUTO_TEST_CASE (fade_test)
        fade_test_format_red   (AV_PIX_FMT_RGB48LE,   0.5, "rgb48le_50");
        fade_test_format_red   (AV_PIX_FMT_RGB48LE,   1,   "rgb48le_100");
 }
+
+/** Make sure the image isn't corrupted if it is cropped too much.  This can happen when a
+ *  filler 128x128 black frame is emitted from the FFmpegDecoder and the overall crop in either direction
+ *  is greater than 128 pixels.
+ */
+BOOST_AUTO_TEST_CASE (over_crop_test)
+{
+       shared_ptr<Image> image (new Image (AV_PIX_FMT_RGB24, dcp::Size(128, 128), true));
+       image->make_black ();
+       shared_ptr<Image> scaled = image->crop_scale_window (Crop(0, 0, 128, 128), dcp::Size(1323, 565), dcp::Size(1349, 565), dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, true);
+       string const filename = "over_crop_test.png";
+       write_image (scaled, "build/test/" + filename, "RGB");
+       check_image ("test/data/" + filename, "build/test/" + filename);
+}