]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dnxhddec.c
avcodec/motionpixels: use av_mallocz_array()
[ffmpeg] / libavcodec / dnxhddec.c
index 0f9fd16b5be24059eb99e2133c555f17c79f101c..e33593c1149ed36f3214398a3ee34281fd1e82f5 100644 (file)
@@ -57,9 +57,12 @@ typedef struct DNXHDContext {
 #define DNXHD_VLC_BITS 9
 #define DNXHD_DC_VLC_BITS 7
 
-static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, int16_t *block, int n, int qscale);
-static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, int16_t *block, int n, int qscale);
-static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block, int n, int qscale);
+static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, int16_t *block,
+                                     int n, int qscale);
+static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, int16_t *block,
+                                      int n, int qscale);
+static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block,
+                                          int n, int qscale);
 
 static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
 {
@@ -99,14 +102,16 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid)
                  ctx->cid_table->run_bits, 1, 1,
                  ctx->cid_table->run_codes, 2, 2, 0);
 
-        ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct);
+        ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable,
+                          ff_zigzag_direct);
         ctx->cid = cid;
     }
     return 0;
 }
 
 static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
-                               const uint8_t *buf, int buf_size, int first_field)
+                               const uint8_t *buf, int buf_size,
+                               int first_field)
 {
     static const uint8_t header_prefix[]    = { 0x00, 0x00, 0x02, 0x80, 0x01 };
     static const uint8_t header_prefix444[] = { 0x00, 0x00, 0x02, 0x80, 0x02 };
@@ -123,7 +128,8 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
         ctx->cur_field = buf[5] & 1;
         frame->interlaced_frame = 1;
         frame->top_field_first  = first_field ^ ctx->cur_field;
-        av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field);
+        av_log(ctx->avctx, AV_LOG_DEBUG,
+               "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field);
     }
 
     ctx->height = AV_RB16(buf + 0x18);
@@ -170,22 +176,24 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
         return AVERROR_INVALIDDATA;
     }
 
-    ctx->mb_width = ctx->width>>4;
+    ctx->mb_width  = ctx->width >> 4;
     ctx->mb_height = buf[0x16d];
 
-    av_dlog(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height);
+    av_dlog(ctx->avctx,
+            "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height);
 
-    if ((ctx->height+15)>>4 == ctx->mb_height && frame->interlaced_frame)
+    if ((ctx->height + 15) >> 4 == ctx->mb_height && frame->interlaced_frame)
         ctx->height <<= 1;
 
     if (ctx->mb_height > 68 ||
-        (ctx->mb_height << frame->interlaced_frame) > (ctx->height+15)>>4) {
-        av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height);
+        (ctx->mb_height << frame->interlaced_frame) > (ctx->height + 15) >> 4) {
+        av_log(ctx->avctx, AV_LOG_ERROR,
+               "mb height too big: %d\n", ctx->mb_height);
         return AVERROR_INVALIDDATA;
     }
 
     for (i = 0; i < ctx->mb_height; i++) {
-        ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2));
+        ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i << 2));
         av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]);
         if (buf_size < ctx->mb_scan_index[i] + 0x280LL) {
             av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n");
@@ -213,12 +221,12 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
     OPEN_READER(bs, &ctx->gb);
 
     if (!ctx->is_444) {
-        if (n&2) {
-            component = 1 + (n&1);
+        if (n & 2) {
+            component     = 1 + (n & 1);
             scale = ctx->chroma_scale;
             weight_matrix = ctx->cid_table->chroma_weight;
         } else {
-            component = 0;
+            component     = 0;
             scale = ctx->luma_scale;
             weight_matrix = ctx->cid_table->luma_weight;
         }
@@ -274,13 +282,13 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
             break;
         }
 
-        j = ctx->scantable.permutated[i];
+        j     = ctx->scantable.permutated[i];
         level *= scale[i];
         if (level_bias < 32 || weight_matrix[i] != level_bias)
             level += level_bias;
         level >>= level_shift;
 
-        block[j] = (level^sign) - sign;
+        block[j] = (level ^ sign) - sign;
 
         UPDATE_CACHE(bs, &ctx->gb);
         GET_VLC(index1, bs, &ctx->gb, ctx->ac_vlc.table,
@@ -308,7 +316,8 @@ static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block,
     dnxhd_decode_dct_block(ctx, block, n, qscale, 6, 32, 6);
 }
 
-static int dnxhd_decode_macroblock(DNXHDContext *ctx, AVFrame *frame, int x, int y)
+static int dnxhd_decode_macroblock(DNXHDContext *ctx, AVFrame *frame,
+                                   int x, int y)
 {
     int shift1 = ctx->bit_depth == 10;
     int dct_linesize_luma   = frame->linesize[0];
@@ -409,8 +418,8 @@ static int dnxhd_decode_macroblocks(DNXHDContext *ctx, AVFrame *frame,
     return 0;
 }
 
-static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
-                              AVPacket *avpkt)
+static int dnxhd_decode_frame(AVCodecContext *avctx, void *data,
+                              int *got_frame, AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
@@ -422,7 +431,7 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
     av_dlog(avctx, "frame size %d\n", buf_size);
 
- decode_coding_unit:
+decode_coding_unit:
     if ((ret = dnxhd_decode_header(ctx, picture, buf, buf_size, first_field)) < 0)
         return ret;