hqx: Convert to the new bitstream header

Signed-off-by: Anton Khirnov <anton@khirnov.net>
pull/117/merge
Alexandra Hájková 9 years ago committed by Anton Khirnov
parent c5e01d9170
commit 1df549bfa2
  1. 60
      libavcodec/hqx.c
  2. 5
      libavcodec/hqx.h

@ -24,8 +24,8 @@
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "bitstream.h"
#include "canopus.h"
#include "get_bits.h"
#include "internal.h"
#include "hqx.h"
@ -95,23 +95,23 @@ static inline void put_blocks(HQXContext *ctx, int plane,
lsize * fields, block1, quant);
}
static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac,
static inline void hqx_get_ac(BitstreamContext *bc, const HQXAC *ac,
int *run, int *lev)
{
int val;
val = show_bits(gb, ac->lut_bits);
val = bitstream_peek(bc, ac->lut_bits);
if (ac->lut[val].bits == -1) {
GetBitContext gb2 = *gb;
skip_bits(&gb2, ac->lut_bits);
val = ac->lut[val].lev + show_bits(&gb2, ac->extra_bits);
BitstreamContext bc2 = *bc;
bitstream_skip(&bc2, ac->lut_bits);
val = ac->lut[val].lev + bitstream_peek(&bc2, ac->extra_bits);
}
*run = ac->lut[val].run;
*lev = ac->lut[val].lev;
skip_bits(gb, ac->lut[val].bits);
bitstream_skip(bc, ac->lut[val].bits);
}
static int decode_block(GetBitContext *gb, VLC *vlc,
static int decode_block(BitstreamContext *bc, VLC *vlc,
const int *quants, int dcb,
int16_t block[64], int *last_dc)
{
@ -120,14 +120,14 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
int run, lev, pos = 1;
memset(block, 0, 64 * sizeof(*block));
dc = get_vlc2(gb, vlc->table, HQX_DC_VLC_BITS, 2);
dc = bitstream_read_vlc(bc, vlc->table, HQX_DC_VLC_BITS, 2);
if (dc < 0)
return AVERROR_INVALIDDATA;
*last_dc += dc;
block[0] = sign_extend(*last_dc << (12 - dcb), 12);
q = quants[get_bits(gb, 2)];
q = quants[bitstream_read(bc, 2)];
if (q >= 128)
ac_idx = HQX_AC_Q128;
else if (q >= 64)
@ -142,7 +142,7 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
ac_idx = HQX_AC_Q0;
do {
hqx_get_ac(gb, &ff_hqx_ac[ac_idx], &run, &lev);
hqx_get_ac(bc, &ff_hqx_ac[ac_idx], &run, &lev);
pos += run;
if (pos >= 64)
break;
@ -155,24 +155,24 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
GetBitContext *gb = &slice->gb;
BitstreamContext *bc = &slice->bc;
const int *quants;
int flag;
int last_dc;
int i, ret;
if (ctx->interlaced)
flag = get_bits1(gb);
flag = bitstream_read_bit(bc);
else
flag = 0;
quants = hqx_quants[get_bits(gb, 4)];
quants = hqx_quants[bitstream_read(bc, 4)];
for (i = 0; i < 8; i++) {
int vlc_index = ctx->dcb - 9;
if (i == 0 || i == 4 || i == 6)
last_dc = 0;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@ -189,14 +189,14 @@ static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
GetBitContext *gb = &slice->gb;
BitstreamContext *bc = &slice->bc;
const int *quants;
int flag = 0;
int last_dc;
int i, ret;
int cbp;
cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
cbp = bitstream_read_vlc(bc, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
for (i = 0; i < 12; i++)
memset(slice->block[i], 0, sizeof(**slice->block) * 64);
@ -204,9 +204,9 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
slice->block[i][0] = -0x800;
if (cbp) {
if (ctx->interlaced)
flag = get_bits1(gb);
flag = bitstream_read_bit(bc);
quants = hqx_quants[get_bits(gb, 4)];
quants = hqx_quants[bitstream_read(bc, 4)];
cbp |= cbp << 4; // alpha CBP
if (cbp & 0x3) // chroma CBP - top
@ -218,7 +218,7 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
last_dc = 0;
if (cbp & (1 << i)) {
int vlc_index = ctx->dcb - 9;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@ -239,24 +239,24 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
GetBitContext *gb = &slice->gb;
BitstreamContext *bc = &slice->bc;
const int *quants;
int flag;
int last_dc;
int i, ret;
if (ctx->interlaced)
flag = get_bits1(gb);
flag = bitstream_read_bit(bc);
else
flag = 0;
quants = hqx_quants[get_bits(gb, 4)];
quants = hqx_quants[bitstream_read(bc, 4)];
for (i = 0; i < 12; i++) {
int vlc_index = ctx->dcb - 9;
if (i == 0 || i == 4 || i == 8)
last_dc = 0;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@ -275,14 +275,14 @@ static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
GetBitContext *gb = &slice->gb;
BitstreamContext *bc = &slice->bc;
const int *quants;
int flag = 0;
int last_dc;
int i, ret;
int cbp;
cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
cbp = bitstream_read_vlc(bc, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
for (i = 0; i < 16; i++)
memset(slice->block[i], 0, sizeof(**slice->block) * 64);
@ -290,9 +290,9 @@ static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
slice->block[i][0] = -0x800;
if (cbp) {
if (ctx->interlaced)
flag = get_bits1(gb);
flag = bitstream_read_bit(bc);
quants = hqx_quants[get_bits(gb, 4)];
quants = hqx_quants[bitstream_read(bc, 4)];
cbp |= cbp << 4; // alpha CBP
cbp |= cbp << 8; // chroma CBP
@ -301,7 +301,7 @@ static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
last_dc = 0;
if (cbp & (1 << i)) {
int vlc_index = ctx->dcb - 9;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@ -392,7 +392,7 @@ static int decode_slice_thread(AVCodecContext *avctx, void *arg,
return AVERROR_INVALIDDATA;
}
ret = init_get_bits8(&ctx->slice[slice_no].gb,
ret = bitstream_init8(&ctx->slice[slice_no].bc,
ctx->src + slice_off[slice_no],
slice_off[slice_no + 1] - slice_off[slice_no]);
if (ret < 0)

@ -25,7 +25,8 @@
#include "libavutil/frame.h"
#include "libavutil/mem.h"
#include "get_bits.h"
#include "bitstream.h"
#include "hqxdsp.h"
enum HQXACMode {
@ -55,7 +56,7 @@ typedef int (*mb_decode_func)(struct HQXContext *ctx,
int slice_no, int x, int y);
typedef struct HQXSlice {
GetBitContext gb;
BitstreamContext bc;
DECLARE_ALIGNED(16, int16_t, block)[16][64];
} HQXSlice;

Loading…
Cancel
Save