From 4d49a4c55054571b56d3b1b1cd9fb9ac4c2bea6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Fri, 8 Apr 2016 19:49:07 +0200 Subject: [PATCH 1/2] apedec: Convert to the new bitstream reader --- libavcodec/apedec.c | 47 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 69ded9a670..da45e85e51 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -25,13 +25,14 @@ #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/opt.h" + #include "apedsp.h" #include "avcodec.h" +#include "bitstream.h" #include "bswapdsp.h" #include "bytestream.h" #include "internal.h" -#include "get_bits.h" -#include "unary_legacy.h" +#include "unary.h" /** * @file @@ -162,7 +163,7 @@ typedef struct APEContext { APERice riceX; ///< rice code parameters for the second channel APERice riceY; ///< rice code parameters for the first channel APEFilter filters[APE_FILTER_LEVELS][2]; ///< filters used for reconstruction - GetBitContext gb; + BitstreamContext bc; uint8_t *data; ///< current frame data uint8_t *data_end; ///< frame data end @@ -484,24 +485,24 @@ static inline void update_rice(APERice *rice, unsigned int x) rice->k++; } -static inline int get_rice_ook(GetBitContext *gb, int k) +static inline int get_rice_ook(BitstreamContext *bc, int k) { unsigned int x; - x = get_unary(gb, 1, get_bits_left(gb)); + x = get_unary(bc, 1, bitstream_bits_left(bc)); if (k) - x = (x << k) | get_bits(gb, k); + x = (x << k) | bitstream_read(bc, k); return x; } -static inline int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb, +static inline int ape_decode_value_3860(APEContext *ctx, BitstreamContext *bc, APERice *rice) { unsigned int x, overflow; - overflow = get_unary(gb, 1, get_bits_left(gb)); + overflow = get_unary(bc, 1, bitstream_bits_left(bc)); if (ctx->fileversion > 3880) { while (overflow >= 16) { @@ -513,7 +514,7 @@ static inline int ape_decode_value_3860(APEContext *ctx, GetBitContext *gb, if (!rice->k) x = overflow; else - x = (overflow << rice->k) + get_bits(gb, rice->k); + x = (overflow << rice->k) + bitstream_read(bc, rice->k); rice->ksum += x - (rice->ksum + 8 >> 4); if (rice->ksum < (rice->k ? 1 << (rice->k + 4) : 0)) @@ -607,7 +608,7 @@ static inline int ape_decode_value_3990(APEContext *ctx, APERice *rice) return -(x >> 1); } -static void decode_array_0000(APEContext *ctx, GetBitContext *gb, +static void decode_array_0000(APEContext *ctx, BitstreamContext *bc, int32_t *out, APERice *rice, int blockstodecode) { int i; @@ -615,19 +616,19 @@ static void decode_array_0000(APEContext *ctx, GetBitContext *gb, rice->ksum = 0; for (i = 0; i < FFMIN(blockstodecode, 5); i++) { - out[i] = get_rice_ook(&ctx->gb, 10); + out[i] = get_rice_ook(&ctx->bc, 10); rice->ksum += out[i]; } rice->k = av_log2(rice->ksum / 10) + 1; for (; i < FFMIN(blockstodecode, 64); i++) { - out[i] = get_rice_ook(&ctx->gb, rice->k); + out[i] = get_rice_ook(&ctx->bc, rice->k); rice->ksum += out[i]; rice->k = av_log2(rice->ksum / ((i + 1) * 2)) + 1; } ksummax = 1 << rice->k + 7; ksummin = rice->k ? (1 << rice->k + 6) : 0; for (; i < blockstodecode; i++) { - out[i] = get_rice_ook(&ctx->gb, rice->k); + out[i] = get_rice_ook(&ctx->bc, rice->k); rice->ksum += out[i] - out[i - 64]; while (rice->ksum < ksummin) { rice->k--; @@ -653,15 +654,15 @@ static void decode_array_0000(APEContext *ctx, GetBitContext *gb, static void entropy_decode_mono_0000(APEContext *ctx, int blockstodecode) { - decode_array_0000(ctx, &ctx->gb, ctx->decoded[0], &ctx->riceY, + decode_array_0000(ctx, &ctx->bc, ctx->decoded[0], &ctx->riceY, blockstodecode); } static void entropy_decode_stereo_0000(APEContext *ctx, int blockstodecode) { - decode_array_0000(ctx, &ctx->gb, ctx->decoded[0], &ctx->riceY, + decode_array_0000(ctx, &ctx->bc, ctx->decoded[0], &ctx->riceY, blockstodecode); - decode_array_0000(ctx, &ctx->gb, ctx->decoded[1], &ctx->riceX, + decode_array_0000(ctx, &ctx->bc, ctx->decoded[1], &ctx->riceX, blockstodecode); } @@ -670,7 +671,7 @@ static void entropy_decode_mono_3860(APEContext *ctx, int blockstodecode) int32_t *decoded0 = ctx->decoded[0]; while (blockstodecode--) - *decoded0++ = ape_decode_value_3860(ctx, &ctx->gb, &ctx->riceY); + *decoded0++ = ape_decode_value_3860(ctx, &ctx->bc, &ctx->riceY); } static void entropy_decode_stereo_3860(APEContext *ctx, int blockstodecode) @@ -680,9 +681,9 @@ static void entropy_decode_stereo_3860(APEContext *ctx, int blockstodecode) int blocks = blockstodecode; while (blockstodecode--) - *decoded0++ = ape_decode_value_3860(ctx, &ctx->gb, &ctx->riceY); + *decoded0++ = ape_decode_value_3860(ctx, &ctx->bc, &ctx->riceY); while (blocks--) - *decoded1++ = ape_decode_value_3860(ctx, &ctx->gb, &ctx->riceX); + *decoded1++ = ape_decode_value_3860(ctx, &ctx->bc, &ctx->riceX); } static void entropy_decode_mono_3900(APEContext *ctx, int blockstodecode) @@ -747,7 +748,7 @@ static int init_entropy_decoder(APEContext *ctx) return AVERROR_INVALIDDATA; ctx->CRC = bytestream_get_be32(&ctx->ptr); } else { - ctx->CRC = get_bits_long(&ctx->gb, 32); + ctx->CRC = bitstream_read(&ctx->bc, 32); } /* Read the frame flags if they exist */ @@ -1480,11 +1481,11 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, } s->ptr += offset; } else { - init_get_bits(&s->gb, s->ptr, (s->data_end - s->ptr) * 8); + bitstream_init8(&s->bc, s->ptr, s->data_end - s->ptr); if (s->fileversion > 3800) - skip_bits_long(&s->gb, offset * 8); + bitstream_skip(&s->bc, offset * 8); else - skip_bits_long(&s->gb, offset); + bitstream_skip(&s->bc, offset); } if (!nblocks || nblocks > INT_MAX) { From fd8de7f2d8c31195d309247cb129c0ad787ef76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Sat, 9 Apr 2016 19:37:46 +0200 Subject: [PATCH 2/2] dxtory: Convert to the new bitstream reader --- libavcodec/dxtory.c | 88 ++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c index b0fae2f5ef..05de4ac837 100644 --- a/libavcodec/dxtory.c +++ b/libavcodec/dxtory.c @@ -27,10 +27,10 @@ #define BITSTREAM_READER_LE #include "avcodec.h" +#include "bitstream.h" #include "bytestream.h" -#include "get_bits.h" #include "internal.h" -#include "unary_legacy.h" +#include "unary.h" static int dxtory_decode_v1_rgb(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size, @@ -176,13 +176,13 @@ static const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0x static const uint8_t def_lru_555[8] = { 0x00, 0x08, 0x10, 0x18, 0x1F }; static const uint8_t def_lru_565[8] = { 0x00, 0x08, 0x10, 0x20, 0x30, 0x3F }; -static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8]) +static inline uint8_t decode_sym(BitstreamContext *bc, uint8_t lru[8]) { uint8_t c, val; - c = get_unary(gb, 0, 8); + c = get_unary(bc, 0, 8); if (!c) { - val = get_bits(gb, 8); + val = bitstream_read(bc, 8); memmove(lru + 1, lru, sizeof(*lru) * (8 - 1)); } else { val = lru[c - 1]; @@ -243,14 +243,14 @@ static int load_buffer(AVCodecContext *avctx, return 0; } -static inline uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8], +static inline uint8_t decode_sym_565(BitstreamContext *bc, uint8_t lru[8], int bits) { uint8_t c, val; - c = get_unary(gb, 0, bits); + c = get_unary(bc, 0, bits); if (!c) { - val = get_bits(gb, bits); + val = bitstream_read(bc, bits); memmove(lru + 1, lru, sizeof(*lru) * (6 - 1)); } else { val = lru[c - 1]; @@ -261,7 +261,7 @@ static inline uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8], return val; } -typedef int (*decode_slice_func)(GetBitContext *gb, AVFrame *frame, +typedef int (*decode_slice_func)(BitstreamContext *bc, AVFrame *frame, int line, int height, uint8_t lru[3][8]); typedef void (*setup_lru_func)(uint8_t lru[3][8]); @@ -273,7 +273,7 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, enum AVPixelFormat fmt) { GetByteContext gb; - GetBitContext gb2; + BitstreamContext bc; int nslices, slice, line = 0; uint32_t off, slice_size; uint8_t lru[3][8]; @@ -296,9 +296,9 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, if (ret < 0) return ret; - init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8); + bitstream_init8(&bc, src + off + 16, slice_size - 16); - line += decode_slice(&gb2, pic, line, avctx->height - line, lru); + line += decode_slice(&bc, pic, line, avctx->height - line, lru); off += slice_size; } @@ -315,7 +315,7 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, } av_always_inline -static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_5x5(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8], int is_565) { @@ -325,11 +325,11 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame, int stride = frame->linesize[0]; uint8_t *dst = frame->data[0] + stride * line; - for (y = 0; y < left && get_bits_left(gb) > 16; y++) { + for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) { for (x = 0; x < width; x++) { - b = decode_sym_565(gb, lru[0], 5); - g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5); - r = decode_sym_565(gb, lru[2], 5); + b = decode_sym_565(bc, lru[0], 5); + g = decode_sym_565(bc, lru[1], is_565 ? 6 : 5); + r = decode_sym_565(bc, lru[2], 5); dst[x * 3 + 0] = (r << 3) | (r >> 2); dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2); dst[x * 3 + 2] = (b << 3) | (b >> 2); @@ -355,16 +355,16 @@ static void setup_lru_565(uint8_t lru[3][8]) memcpy(lru[2], def_lru_555, 8 * sizeof(*def_lru)); } -static int dx2_decode_slice_555(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_555(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8]) { - return dx2_decode_slice_5x5(gb, frame, line, left, lru, 0); + return dx2_decode_slice_5x5(bc, frame, line, left, lru, 0); } -static int dx2_decode_slice_565(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_565(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8]) { - return dx2_decode_slice_5x5(gb, frame, line, left, lru, 1); + return dx2_decode_slice_5x5(bc, frame, line, left, lru, 1); } static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic, @@ -383,7 +383,7 @@ static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic, fmt); } -static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_rgb(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8]) { int x, y; @@ -391,11 +391,11 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame *frame, int stride = frame->linesize[0]; uint8_t *dst = frame->data[0] + stride * line; - for (y = 0; y < left && get_bits_left(gb) > 16; y++) { + for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) { for (x = 0; x < width; x++) { - dst[x * 3 + 0] = decode_sym(gb, lru[0]); - dst[x * 3 + 1] = decode_sym(gb, lru[1]); - dst[x * 3 + 2] = decode_sym(gb, lru[2]); + dst[x * 3 + 0] = decode_sym(bc, lru[0]); + dst[x * 3 + 1] = decode_sym(bc, lru[1]); + dst[x * 3 + 2] = decode_sym(bc, lru[2]); } dst += stride; @@ -421,7 +421,7 @@ static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic, AV_PIX_FMT_BGR24); } -static int dx2_decode_slice_410(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_410(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8]) { @@ -436,13 +436,13 @@ static int dx2_decode_slice_410(GetBitContext *gb, AVFrame *frame, uint8_t *U = frame->data[1] + (ustride >> 2) * line; uint8_t *V = frame->data[2] + (vstride >> 2) * line; - for (y = 0; y < left - 3 && get_bits_left(gb) > 16; y += 4) { + for (y = 0; y < left - 3 && bitstream_bits_left(bc) > 16; y += 4) { for (x = 0; x < width; x += 4) { for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) - Y[x + i + j * ystride] = decode_sym(gb, lru[0]); - U[x >> 2] = decode_sym(gb, lru[1]) ^ 0x80; - V[x >> 2] = decode_sym(gb, lru[2]) ^ 0x80; + Y[x + i + j * ystride] = decode_sym(bc, lru[0]); + U[x >> 2] = decode_sym(bc, lru[1]) ^ 0x80; + V[x >> 2] = decode_sym(bc, lru[2]) ^ 0x80; } Y += ystride << 2; @@ -463,7 +463,7 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic, AV_PIX_FMT_YUV410P); } -static int dx2_decode_slice_420(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_420(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8]) { @@ -480,14 +480,14 @@ static int dx2_decode_slice_420(GetBitContext *gb, AVFrame *frame, uint8_t *V = frame->data[2] + (vstride >> 1) * line; - for (y = 0; y < left - 1 && get_bits_left(gb) > 16; y += 2) { + for (y = 0; y < left - 1 && bitstream_bits_left(bc) > 16; y += 2) { for (x = 0; x < width; x += 2) { - Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]); - Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]); - Y[x + 0 + 1 * ystride] = decode_sym(gb, lru[0]); - Y[x + 1 + 1 * ystride] = decode_sym(gb, lru[0]); - U[x >> 1] = decode_sym(gb, lru[1]) ^ 0x80; - V[x >> 1] = decode_sym(gb, lru[2]) ^ 0x80; + Y[x + 0 + 0 * ystride] = decode_sym(bc, lru[0]); + Y[x + 1 + 0 * ystride] = decode_sym(bc, lru[0]); + Y[x + 0 + 1 * ystride] = decode_sym(bc, lru[0]); + Y[x + 1 + 1 * ystride] = decode_sym(bc, lru[0]); + U[x >> 1] = decode_sym(bc, lru[1]) ^ 0x80; + V[x >> 1] = decode_sym(bc, lru[2]) ^ 0x80; } Y += ystride << 1; @@ -507,7 +507,7 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic, AV_PIX_FMT_YUV420P); } -static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame, +static int dx2_decode_slice_444(BitstreamContext *bc, AVFrame *frame, int line, int left, uint8_t lru[3][8]) { @@ -523,11 +523,11 @@ static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame, uint8_t *U = frame->data[1] + ustride * line; uint8_t *V = frame->data[2] + vstride * line; - for (y = 0; y < left && get_bits_left(gb) > 16; y++) { + for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) { for (x = 0; x < width; x++) { - Y[x] = decode_sym(gb, lru[0]); - U[x] = decode_sym(gb, lru[1]) ^ 0x80; - V[x] = decode_sym(gb, lru[2]) ^ 0x80; + Y[x] = decode_sym(bc, lru[0]); + U[x] = decode_sym(bc, lru[1]) ^ 0x80; + V[x] = decode_sym(bc, lru[2]) ^ 0x80; } Y += ystride;