]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/aic.c
Use av_frame_copy() to simplify code where appropriate.
[ffmpeg] / libavcodec / aic.c
index a87176255f67b5267ba2b9d55788423014db4b4b..5981dd80022932a56a601adcd721389963f31aba 100644 (file)
@@ -196,11 +196,11 @@ static int aic_decode_header(AICContext *ctx, const uint8_t *src, int size)
     } while (0)
 
 static int aic_decode_coeffs(GetBitContext *gb, int16_t *dst,
-                             int band, int slice_width)
+                             int band, int slice_width, int force_chroma)
 {
     int has_skips, coeff_type, coeff_bits, skip_type, skip_bits;
     const int num_coeffs = aic_num_band_coeffs[band];
-    const uint8_t *scan = aic_scan[band];
+    const uint8_t *scan = aic_scan[band | force_chroma];
     int mb, idx, val;
 
     has_skips  = get_bits1(gb);
@@ -215,12 +215,14 @@ static int aic_decode_coeffs(GetBitContext *gb, int16_t *dst,
             idx = -1;
             do {
                 GET_CODE(val, skip_type, skip_bits);
+                if (val < 0)
+                    return AVERROR_INVALIDDATA;
                 idx += val + 1;
                 if (idx >= num_coeffs)
                     break;
                 GET_CODE(val, coeff_type, coeff_bits);
                 val++;
-                if (val >= 0x10000)
+                if (val >= 0x10000 || val < 0)
                     return AVERROR_INVALIDDATA;
                 dst[scan[idx]] = val;
             } while (idx < num_coeffs - 1);
@@ -230,7 +232,7 @@ static int aic_decode_coeffs(GetBitContext *gb, int16_t *dst,
         for (mb = 0; mb < slice_width; mb++) {
             for (idx = 0; idx < num_coeffs; idx++) {
                 GET_CODE(val, coeff_type, coeff_bits);
-                if (val >= 0x10000)
+                if (val >= 0x10000 || val < 0)
                     return AVERROR_INVALIDDATA;
                 dst[scan[idx]] = val;
             }
@@ -319,7 +321,8 @@ static int aic_decode_slice(AICContext *ctx, int mb_x, int mb_y,
            sizeof(*ctx->slice_data) * slice_width * AIC_BAND_COEFFS);
     for (i = 0; i < NUM_BANDS; i++)
         if ((ret = aic_decode_coeffs(&gb, ctx->data_ptr[i],
-                                     i, slice_width)) < 0)
+                                     i, slice_width,
+                                     !ctx->interlaced)) < 0)
             return ret;
 
     for (mb = 0; mb < slice_width; mb++) {
@@ -334,7 +337,7 @@ static int aic_decode_slice(AICContext *ctx, int mb_x, int mb_y,
             ctx->dsp.idct(ctx->block);
 
             if (!ctx->interlaced) {
-                dst = Y + (blk & 1) * 8 * ystride + (blk >> 1) * 8;
+                dst = Y + (blk >> 1) * 8 * ystride + (blk & 1) * 8;
                 ctx->dsp.put_signed_pixels_clamped(ctx->block, dst,
                                                    ystride);
             } else {
@@ -466,6 +469,7 @@ static av_cold int aic_decode_close(AVCodecContext *avctx)
 
 AVCodec ff_aic_decoder = {
     .name           = "aic",
+    .long_name      = NULL_IF_CONFIG_SMALL("Apple Intermediate Codec"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_AIC,
     .priv_data_size = sizeof(AICContext),
@@ -473,5 +477,4 @@ AVCodec ff_aic_decoder = {
     .close          = aic_decode_close,
     .decode         = aic_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("Apple Intermediate Codec")
 };