Fix corruption of subsampled images that are being placed into black
authorCarl Hetherington <cth@carlh.net>
Fri, 2 Mar 2018 01:28:03 +0000 (01:28 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 2 Mar 2018 01:28:03 +0000 (01:28 +0000)
frames at odd offsets, using the same approach that is used when
cropping.  Should fix #1227.

ChangeLog
src/lib/image.cc

index 21492e29c9ff93eeb2fb0863b5d0a6cd0fbdd962..3e9e5a24bc32e35472cf6ebb4763b7546e4c0dec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-03-02  Carl Hetherington  <cth@carlh.net>
+
+       * Fix bad Prores exports in some cases (#1227).
+
 2018-02-27  Carl Hetherington  <cth@carlh.net>
 
        * Add a hint about the stereo-to-5.1 upmixers being
index 158bce1d901aab1b7ff3de884ce8b090bb035805..792bf3ab469c2ffd363b81de850a0bedb8fe98c6 100644 (file)
@@ -183,8 +183,8 @@ Image::crop_scale_window (
                0, 1 << 16, 1 << 16
                );
 
-       AVPixFmtDescriptor const * desc = av_pix_fmt_desc_get (_pixel_format);
-       if (!desc) {
+       AVPixFmtDescriptor const * in_desc = av_pix_fmt_desc_get (_pixel_format);
+       if (!in_desc) {
                throw PixelFormatError ("crop_scale_window()", _pixel_format);
        }
 
@@ -196,16 +196,23 @@ Image::crop_scale_window (
                   round down so that we don't crop a subsampled pixel until
                   we've cropped all of its Y-channel pixels.
                */
-               int const x = lrintf (bytes_per_pixel(c) * crop.left) & ~ ((int) desc->log2_chroma_w);
+               int const x = lrintf (bytes_per_pixel(c) * crop.left) & ~ ((int) in_desc->log2_chroma_w);
                scale_in_data[c] = data()[c] + x + stride()[c] * (crop.top / vertical_factor(c));
        }
 
        /* Corner of the image within out_size */
        Position<int> const corner ((out_size.width - inter_size.width) / 2, (out_size.height - inter_size.height) / 2);
 
+       AVPixFmtDescriptor const * out_desc = av_pix_fmt_desc_get (out_format);
+       if (!out_desc) {
+               throw PixelFormatError ("crop_scale_window()", out_format);
+       }
+
        uint8_t* scale_out_data[out->planes()];
        for (int c = 0; c < out->planes(); ++c) {
-               scale_out_data[c] = out->data()[c] + lrintf (out->bytes_per_pixel(c) * corner.x) + out->stride()[c] * (corner.y / out->vertical_factor(c));
+               /* See the note in the crop loop above */
+               int const x = lrintf (out->bytes_per_pixel(c) * corner.x) & ~ ((int) out_desc->log2_chroma_w);
+               scale_out_data[c] = out->data()[c] + x + out->stride()[c] * (corner.y / out->vertical_factor(c));
        }
 
        sws_scale (