Fix lines down the right-hand-side of exports in some cases.
authorCarl Hetherington <cth@carlh.net>
Tue, 26 Jul 2022 13:22:54 +0000 (15:22 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 8 Aug 2022 22:09:30 +0000 (00:09 +0200)
src/lib/image.cc
test/data
test/image_test.cc

index f86c105d4f8aa2d2ab76ce465fd8820d44bfa9bd..629fc0a64c1c1e38b26976b195d017bfab578273 100644 (file)
@@ -292,13 +292,15 @@ Image::crop_scale_window (
 
        sws_freeContext (scale_context);
 
-       if (corrected_crop != Crop() && cropped_size == inter_size) {
-               /* We are cropping without any scaling or pixel format conversion, so FFmpeg may have left some
-                  data behind in our image.  Clear it out.  It may get to the point where we should just stop
-                  trying to be clever with cropping.
-               */
-               out->make_part_black (corner.x + cropped_size.width, out_size.width - cropped_size.width);
-       }
+       /* There are some cases where there will be unwanted image data left in the image at this point:
+        *
+        * 1. When we are cropping without any scaling or pixel format conversion.
+        * 2. When we are scaling to certain sizes and placing the result into a larger
+        *    black frame.
+        *
+        * Clear out the left hand side of the image to take care of that.
+        */
+       out->make_part_black (corner.x + inter_size.width, (out_size.width - inter_size.width) / 2);
 
        if (
                video_range == VideoRange::VIDEO &&
index 6d4d01a10bc14f3a4a0db5c3e0a4be72176543bf..a92011d3c4ebe0e443b6ea37c749f27c9102c156 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 6d4d01a10bc14f3a4a0db5c3e0a4be72176543bf
+Subproject commit a92011d3c4ebe0e443b6ea37c749f27c9102c156
index 94b7ba017d07696bd47ab770db0787f8d46a673d..c638523a881c76038442dc03144ef927c2d6a559 100644 (file)
@@ -409,6 +409,23 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test7)
 }
 
 
+BOOST_AUTO_TEST_CASE (crop_scale_window_test8)
+{
+       using namespace boost::filesystem;
+
+       auto image = make_shared<Image>(AV_PIX_FMT_YUV420P, dcp::Size(800, 600), Image::Alignment::PADDED);
+       memset(image->data()[0], 41, image->stride()[0] * 600);
+       memset(image->data()[1], 240, image->stride()[1] * 300);
+       memset(image->data()[2], 41, image->stride()[2] * 300);
+       auto scaled = image->crop_scale_window(
+               Crop(), dcp::Size(1435, 1080), dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_YUV420P, VideoRange::FULL, Image::Alignment::PADDED, false
+               );
+       auto file = "crop_scale_window_test8.png";
+       write_image(scaled->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGB24, Image::Alignment::COMPACT, false), path("build") / "test" / file);
+       check_image(path("test") / "data" / file, path("build") / "test" / file, 10);
+}
+
+
 BOOST_AUTO_TEST_CASE (as_png_test)
 {
        auto proxy = make_shared<FFmpegImageProxy>("test/data/3d_test/000001.png");