]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/indeo3.c
cbs_h264: Add utility functions to insert/delete SEI messages
[ffmpeg] / libavcodec / indeo3.c
index f222a06c5a600353f0b35ae17cf1fce483cae75c..22a072dea37b229878239400f882d560c2e3adbb 100644 (file)
 
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bytestream.h"
-#include "get_bits.h"
 #include "hpeldsp.h"
 #include "internal.h"
 
@@ -65,7 +66,7 @@ typedef struct Plane {
     uint8_t         *pixels[2]; ///< pointer to the actual pixel data of the buffers above
     uint32_t        width;
     uint32_t        height;
-    uint32_t        pitch;
+    ptrdiff_t       pitch;
 } Plane;
 
 #define CELL_STACK_MAX  20
@@ -83,7 +84,7 @@ typedef struct Indeo3DecodeContext {
     AVCodecContext *avctx;
     HpelDSPContext  hdsp;
 
-    GetBitContext   gb;
+    BitstreamContext bc;
     int             need_resync;
     int             skip_bits;
     const uint8_t   *next_cell_data;
@@ -117,8 +118,8 @@ static uint8_t requant_tab[8][128];
  */
 static av_cold void build_requant_tab(void)
 {
-    static int8_t offsets[8] = { 1, 1, 2, -3, -3, 3, 4, 4 };
-    static int8_t deltas [8] = { 0, 1, 0,  4,  4, 1, 0, 1 };
+    static const int8_t offsets[8] = { 1, 1, 2, -3, -3, 3, 4, 4 };
+    static const int8_t deltas [8] = { 0, 1, 0,  4,  4, 1, 0, 1 };
 
     int i, j, step;
 
@@ -151,7 +152,8 @@ static av_cold int allocate_frame_buffers(Indeo3DecodeContext *ctx,
                                           AVCodecContext *avctx)
 {
     int p, luma_width, luma_height, chroma_width, chroma_height;
-    int luma_pitch, chroma_pitch, luma_size, chroma_size;
+    int luma_size, chroma_size;
+    ptrdiff_t luma_pitch, chroma_pitch;
 
     luma_width  = ctx->width;
     luma_height = ctx->height;
@@ -415,7 +417,7 @@ if (*data_ptr >= last_ptr) \
 
 static int decode_cell_data(Indeo3DecodeContext *ctx, Cell *cell,
                             uint8_t *block, uint8_t *ref_block,
-                            int pitch, int h_zoom, int v_zoom, int mode,
+                            ptrdiff_t row_offset, int h_zoom, int v_zoom, int mode,
                             const vqEntry *delta[2], int swap_quads[2],
                             const uint8_t **data_ptr, const uint8_t *last_ptr)
 {
@@ -426,9 +428,8 @@ static int decode_cell_data(Indeo3DecodeContext *ctx, Cell *cell,
     unsigned int  dyad1, dyad2;
     uint64_t      pix64;
     int           skip_flag = 0, is_top_of_cell, is_first_row = 1;
-    int           row_offset, blk_row_offset, line_offset;
+    int           blk_row_offset, line_offset;
 
-    row_offset     =  pitch;
     blk_row_offset = (row_offset << (2 + v_zoom)) - (cell->width << 2);
     line_offset    = v_zoom ? row_offset : 0;
 
@@ -725,8 +726,8 @@ enum {
     ctx->need_resync = 1
 
 #define RESYNC_BITSTREAM \
-    if (ctx->need_resync && !(get_bits_count(&ctx->gb) & 7)) { \
-        skip_bits_long(&ctx->gb, ctx->skip_bits);              \
+    if (ctx->need_resync && !(bitstream_tell(&ctx->bc) & 7)) { \
+        bitstream_skip(&ctx->bc, ctx->skip_bits);              \
         ctx->skip_bits   = 0;                                  \
         ctx->need_resync = 0;                                  \
     }
@@ -773,7 +774,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
 
     while (1) { /* loop until return */
         RESYNC_BITSTREAM;
-        switch (code = get_bits(&ctx->gb, 2)) {
+        switch (code = bitstream_read(&ctx->bc, 2)) {
         case H_SPLIT:
         case V_SPLIT:
             if (parse_bintree(ctx, avctx, plane, code, &curr_cell, depth - 1, strip_width))
@@ -785,7 +786,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
                 curr_cell.tree   = 1; /* enter the VQ tree */
             } else { /* VQ tree NULL code */
                 RESYNC_BITSTREAM;
-                code = get_bits(&ctx->gb, 2);
+                code = bitstream_read(&ctx->bc, 2);
                 if (code >= 2) {
                     av_log(avctx, AV_LOG_ERROR, "Invalid VQ_NULL code: %d\n", code);
                     return AVERROR_INVALIDDATA;
@@ -805,7 +806,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
                 unsigned mv_idx;
                 /* get motion vector index and setup the pointer to the mv set */
                 if (!ctx->need_resync)
-                    ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
+                    ctx->next_cell_data = &ctx->bc.buffer[(bitstream_tell(&ctx->bc) + 7) >> 3];
                 mv_idx = *(ctx->next_cell_data++);
                 if (mv_idx >= ctx->num_vectors) {
                     av_log(avctx, AV_LOG_ERROR, "motion vector index out of range\n");
@@ -816,7 +817,7 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
                 UPDATE_BITPOS(8);
             } else { /* VQ tree DATA code */
                 if (!ctx->need_resync)
-                    ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
+                    ctx->next_cell_data = &ctx->bc.buffer[(bitstream_tell(&ctx->bc) + 7) >> 3];
 
                 CHECK_CELL
                 bytes_used = decode_cell(ctx, avctx, plane, &curr_cell,
@@ -831,8 +832,6 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
             break;
         }
     }//while
-
-    return 0;
 }
 
 
@@ -858,7 +857,7 @@ static int decode_plane(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
     ctx->mc_vectors  = num_vectors ? data : 0;
 
     /* init the bitreader */
-    init_get_bits(&ctx->gb, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3);
+    bitstream_init8(&ctx->bc, &data[num_vectors * 2], data_size - num_vectors * 2);
     ctx->skip_bits   = 0;
     ctx->need_resync = 0;
 
@@ -1011,11 +1010,11 @@ static int decode_frame_headers(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
  *  @param[in]  dst_height   output plane height
  */
 static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst,
-                         int dst_pitch, int dst_height)
+                         ptrdiff_t dst_pitch, int dst_height)
 {
     int             x,y;
     const uint8_t   *src  = plane->pixels[buf_sel];
-    uint32_t        pitch = plane->pitch;
+    ptrdiff_t       pitch = plane->pitch;
 
     dst_height = FFMIN(dst_height, plane->height);
     for (y = 0; y < dst_height; y++) {