Imported Debian version 2.5.0~trusty1.1
[deb_ffmpeg.git] / ffmpeg / libavcodec / dxtory.c
index 1a59ae7a0485c08d53f3b7709916398dabbe85b5..4d8b7b29a63570bcc93c2fab8de25e7a6e384cbb 100644 (file)
@@ -82,10 +82,10 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic,
     V  = pic->data[2];
     for (h = 0; h < avctx->height; h += 4) {
         for (w = 0; w < avctx->width; w += 4) {
-            AV_COPY32(Y1 + w, src);
-            AV_COPY32(Y2 + w, src + 4);
-            AV_COPY32(Y3 + w, src + 8);
-            AV_COPY32(Y4 + w, src + 12);
+            AV_COPY32U(Y1 + w, src);
+            AV_COPY32U(Y2 + w, src + 4);
+            AV_COPY32U(Y3 + w, src + 8);
+            AV_COPY32U(Y4 + w, src + 12);
             U[w >> 2] = src[16] + 0x80;
             V[w >> 2] = src[17] + 0x80;
             src += 18;
@@ -410,7 +410,7 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
 {
     GetByteContext gb;
     GetBitContext  gb2;
-    int nslices, slice, slice_height, ref_slice_height;
+    int nslices, slice, slice_height;
     int cur_y, next_y;
     uint32_t off, slice_size;
     uint8_t *Y, *U, *V;
@@ -424,13 +424,12 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
         return AVERROR_INVALIDDATA;
     }
 
-    if (!nslices || avctx->height % nslices) {
+    if (!nslices) {
         avpriv_request_sample(avctx, "%d slices for %dx%d", nslices,
                               avctx->width, avctx->height);
         return AVERROR_PATCHWELCOME;
     }
 
-    ref_slice_height = avctx->height / nslices;
     if ((avctx->width & 3) || (avctx->height & 3)) {
         avpriv_request_sample(avctx, "Frame dimensions %dx%d",
                               avctx->width, avctx->height);
@@ -445,9 +444,9 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
     V = pic->data[2];
 
     cur_y  = 0;
-    next_y = ref_slice_height;
     for (slice = 0; slice < nslices; slice++) {
         slice_size   = bytestream2_get_le32(&gb);
+        next_y = ((slice + 1) * avctx->height) / nslices;
         slice_height = (next_y & ~3) - (cur_y & ~3);
         if (slice_size > src_size - off) {
             av_log(avctx, AV_LOG_ERROR,
@@ -475,7 +474,6 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
         V += pic->linesize[2] * (slice_height >> 2);
         off += slice_size;
         cur_y   = next_y;
-        next_y += ref_slice_height;
     }
 
     return 0;
@@ -514,7 +512,7 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
 {
     GetByteContext gb;
     GetBitContext  gb2;
-    int nslices, slice, slice_height, ref_slice_height;
+    int nslices, slice, slice_height;
     int cur_y, next_y;
     uint32_t off, slice_size;
     uint8_t *Y, *U, *V;
@@ -528,13 +526,12 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
         return AVERROR_INVALIDDATA;
     }
 
-    if (!nslices || avctx->height % nslices) {
+    if (!nslices) {
         avpriv_request_sample(avctx, "%d slices for %dx%d", nslices,
                               avctx->width, avctx->height);
         return AVERROR_PATCHWELCOME;
     }
 
-    ref_slice_height = avctx->height / nslices;
     if ((avctx->width & 1) || (avctx->height & 1)) {
         avpriv_request_sample(avctx, "Frame dimensions %dx%d",
                               avctx->width, avctx->height);
@@ -549,9 +546,9 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
     V = pic->data[2];
 
     cur_y  = 0;
-    next_y = ref_slice_height;
     for (slice = 0; slice < nslices; slice++) {
         slice_size   = bytestream2_get_le32(&gb);
+        next_y = ((slice + 1) * avctx->height) / nslices;
         slice_height = (next_y & ~1) - (cur_y & ~1);
         if (slice_size > src_size - off) {
             av_log(avctx, AV_LOG_ERROR,
@@ -579,7 +576,6 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
         V += pic->linesize[2] * (slice_height >> 1);
         off += slice_size;
         cur_y   = next_y;
-        next_y += ref_slice_height;
     }
 
     return 0;