]> git.sesse.net Git - ffmpeg/commitdiff
decode: fix the code reducing cropping to preserve alignment
authorAnton Khirnov <anton@khirnov.net>
Fri, 19 May 2017 09:47:21 +0000 (11:47 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sat, 20 May 2017 07:41:30 +0000 (09:41 +0200)
Currently it does not work at all.

Bug-Id: 1058

libavcodec/decode.c

index 8aa27095b63b931cff0643073e30364248a3fd7f..bb58dfc561941c31d63ca08c1bc8c16b15cdc575 100644 (file)
@@ -525,6 +525,7 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
 
     /* adjust the offsets to avoid breaking alignment */
     if (!(avctx->flags & AV_CODEC_FLAG_UNALIGNED)) {
+        int log2_crop_align = frame->crop_left ? av_ctz(frame->crop_left) : INT_MAX;
         int min_log2_align = INT_MAX;
 
         for (i = 0; frame->data[i]; i++) {
@@ -532,8 +533,13 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
             min_log2_align = FFMIN(log2_align, min_log2_align);
         }
 
+        /* we assume, and it should always be true, that the data alignment is
+         * related to the cropping alignment by a constant power-of-2 factor */
+        if (log2_crop_align < min_log2_align)
+            return AVERROR_BUG;
+
         if (min_log2_align < 5) {
-            frame->crop_left &= ~((1 << min_log2_align) - 1);
+            frame->crop_left &= ~((1 << (5 + log2_crop_align - min_log2_align)) - 1);
             calc_cropping_offsets(offsets, frame, desc);
         }
     }