summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-11-25 00:11:55 +0100
committerCarl Hetherington <cth@carlh.net>2020-11-25 00:11:55 +0100
commitaccdec63a79b43c6349597b15243dc41e521521d (patch)
tree88dadb3eebc45c4980e9f4498bb9a065f0b562e4 /src
parent82faf2d5817af3ca8d303a8e1b62f23bb461dcaf (diff)
Fix corrupted image when over-cropping black filler frames.v2.14.45
FFmpegDecoder can emit small black frames (128x128 pixels) when it wants to fill in a gap. Image::crop_scale_window would do the wrong thing if we then applied a crop of greater than 128 in either direction; though cropped_size is correctly clamped, the crop value itself was not and is used to calculate the input data pointers. This would result in random frames, usually at the end of DCPs, often made up of blurry colour washes.
Diffstat (limited to 'src')
-rw-r--r--src/lib/image.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 97aeccd76..49acdb5c2 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -173,15 +173,26 @@ Image::crop_scale_window (
/* Round down so that we crop only the number of pixels that is straightforward
* considering any subsampling.
*/
- Crop rounded_crop(
+ Crop corrected_crop(
round_width_for_subsampling(crop.left, in_desc),
round_width_for_subsampling(crop.right, in_desc),
round_height_for_subsampling(crop.top, in_desc),
round_height_for_subsampling(crop.bottom, in_desc)
);
+ /* Also check that we aren't cropping more image than there actually is */
+ if ((corrected_crop.left + corrected_crop.right) >= (size().width - 4)) {
+ corrected_crop.left = 0;
+ corrected_crop.right = size().width - 4;
+ }
+
+ if ((corrected_crop.top + corrected_crop.bottom) >= (size().height - 4)) {
+ corrected_crop.top = 0;
+ corrected_crop.bottom = size().height - 4;
+ }
+
/* Size of the image after any crop */
- dcp::Size const cropped_size = rounded_crop.apply (size());
+ dcp::Size const cropped_size = corrected_crop.apply (size());
/* Hack: if we're not doing quite the crop that we were asked for, and we carry on scaling
* to the inter_size we were asked for, there is a small but noticeable wobble in the image
@@ -230,8 +241,8 @@ Image::crop_scale_window (
/* Prepare input data pointers with crop */
uint8_t* scale_in_data[planes()];
for (int c = 0; c < planes(); ++c) {
- int const x = lrintf(bytes_per_pixel(c) * rounded_crop.left);
- scale_in_data[c] = data()[c] + x + stride()[c] * (rounded_crop.top / vertical_factor(c));
+ int const x = lrintf(bytes_per_pixel(c) * corrected_crop.left);
+ scale_in_data[c] = data()[c] + x + stride()[c] * (corrected_crop.top / vertical_factor(c));
}
AVPixFmtDescriptor const * out_desc = av_pix_fmt_desc_get (out_format);
@@ -260,7 +271,7 @@ Image::crop_scale_window (
sws_freeContext (scale_context);
- if (rounded_crop != Crop() && cropped_size == inter_size) {
+ 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.