Skip to content
Snippets Groups Projects
Commit 6fad5abc authored by Alexandra Hájková's avatar Alexandra Hájková Committed by Diego Biurrun
Browse files

lagarith: Convert to the new bitstream reader

parent c3defda0
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.h" #include "bitstream.h"
#include "mathops.h" #include "mathops.h"
#include "huffyuvdsp.h" #include "huffyuvdsp.h"
#include "lagarithrac.h" #include "lagarithrac.h"
...@@ -101,7 +101,7 @@ static uint8_t lag_calc_zero_run(int8_t x) ...@@ -101,7 +101,7 @@ static uint8_t lag_calc_zero_run(int8_t x)
return (x << 1) ^ (x >> 7); return (x << 1) ^ (x >> 7);
} }
static int lag_decode_prob(GetBitContext *gb, uint32_t *value) static int lag_decode_prob(BitstreamContext *bc, uint32_t *value)
{ {
static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 }; static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21 };
int i; int i;
...@@ -114,7 +114,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value) ...@@ -114,7 +114,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
if (prevbit && bit) if (prevbit && bit)
break; break;
prevbit = bit; prevbit = bit;
bit = get_bits1(gb); bit = bitstream_read_bit(bc);
if (bit && !prevbit) if (bit && !prevbit)
bits += series[i]; bits += series[i];
} }
...@@ -127,7 +127,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value) ...@@ -127,7 +127,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
return 0; return 0;
} }
val = get_bits_long(gb, bits); val = bitstream_read(bc, bits);
val |= 1 << bits; val |= 1 << bits;
*value = val - 1; *value = val - 1;
...@@ -135,7 +135,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value) ...@@ -135,7 +135,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
return 0; return 0;
} }
static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) static int lag_read_prob_header(lag_rac *rac, BitstreamContext *bc)
{ {
int i, j, scale_factor; int i, j, scale_factor;
unsigned prob, cumulative_target; unsigned prob, cumulative_target;
...@@ -146,7 +146,7 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) ...@@ -146,7 +146,7 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb)
rac->prob[257] = UINT_MAX; rac->prob[257] = UINT_MAX;
/* Read probabilities from bitstream */ /* Read probabilities from bitstream */
for (i = 1; i < 257; i++) { for (i = 1; i < 257; i++) {
if (lag_decode_prob(gb, &rac->prob[i]) < 0) { if (lag_decode_prob(bc, &rac->prob[i]) < 0) {
av_log(rac->avctx, AV_LOG_ERROR, "Invalid probability encountered.\n"); av_log(rac->avctx, AV_LOG_ERROR, "Invalid probability encountered.\n");
return -1; return -1;
} }
...@@ -156,7 +156,7 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb) ...@@ -156,7 +156,7 @@ static int lag_read_prob_header(lag_rac *rac, GetBitContext *gb)
} }
cumul_prob += rac->prob[i]; cumul_prob += rac->prob[i];
if (!rac->prob[i]) { if (!rac->prob[i]) {
if (lag_decode_prob(gb, &prob)) { if (lag_decode_prob(bc, &prob)) {
av_log(rac->avctx, AV_LOG_ERROR, "Invalid probability run encountered.\n"); av_log(rac->avctx, AV_LOG_ERROR, "Invalid probability run encountered.\n");
return -1; return -1;
} }
...@@ -422,7 +422,7 @@ static int lag_decode_arith_plane(LagarithContext *l, uint8_t *dst, ...@@ -422,7 +422,7 @@ static int lag_decode_arith_plane(LagarithContext *l, uint8_t *dst,
uint32_t length; uint32_t length;
uint32_t offset = 1; uint32_t offset = 1;
int esc_count = src[0]; int esc_count = src[0];
GetBitContext gb; BitstreamContext bc;
lag_rac rac; lag_rac rac;
const uint8_t *src_end = src + src_size; const uint8_t *src_end = src + src_size;
...@@ -436,12 +436,12 @@ static int lag_decode_arith_plane(LagarithContext *l, uint8_t *dst, ...@@ -436,12 +436,12 @@ static int lag_decode_arith_plane(LagarithContext *l, uint8_t *dst,
offset += 4; offset += 4;
} }
init_get_bits(&gb, src + offset, src_size * 8); bitstream_init(&bc, src + offset, src_size * 8);
if (lag_read_prob_header(&rac, &gb) < 0) if (lag_read_prob_header(&rac, &bc) < 0)
return -1; return -1;
ff_lag_rac_init(&rac, &gb, length - stride); ff_lag_rac_init(&rac, &bc, length - stride);
for (i = 0; i < height; i++) for (i = 0; i < height; i++)
read += lag_decode_line(l, &rac, dst + (i * stride), width, read += lag_decode_line(l, &rac, dst + (i * stride), width,
......
...@@ -27,20 +27,20 @@ ...@@ -27,20 +27,20 @@
* @author David Conrad * @author David Conrad
*/ */
#include "get_bits.h" #include "bitstream.h"
#include "lagarithrac.h" #include "lagarithrac.h"
void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length) void ff_lag_rac_init(lag_rac *l, BitstreamContext *bc, int length)
{ {
int i, j, left; int i, j, left;
/* According to reference decoder "1st byte is garbage", /* According to reference decoder "1st byte is garbage",
* however, it gets skipped by the call to align_get_bits() * however, it gets skipped by the call to bitstream_align()
*/ */
align_get_bits(gb); bitstream_align(bc);
left = get_bits_left(gb) >> 3; left = bitstream_bits_left(bc) >> 3;
l->bytestream_start = l->bytestream_start =
l->bytestream = gb->buffer + get_bits_count(gb) / 8; l->bytestream = bc->buffer + bitstream_tell(bc) / 8;
l->bytestream_end = l->bytestream_start + FFMIN(length, left); l->bytestream_end = l->bytestream_start + FFMIN(length, left);
l->range = 0x80; l->range = 0x80;
......
...@@ -31,10 +31,12 @@ ...@@ -31,10 +31,12 @@
#define AVCODEC_LAGARITHRAC_H #define AVCODEC_LAGARITHRAC_H
#include <stdint.h> #include <stdint.h>
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.h" #include "bitstream.h"
typedef struct lag_rac { typedef struct lag_rac {
AVCodecContext *avctx; AVCodecContext *avctx;
...@@ -51,7 +53,7 @@ typedef struct lag_rac { ...@@ -51,7 +53,7 @@ typedef struct lag_rac {
uint8_t range_hash[256]; /**< Hash table mapping upper byte to approximate symbol. */ uint8_t range_hash[256]; /**< Hash table mapping upper byte to approximate symbol. */
} lag_rac; } lag_rac;
void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length); void ff_lag_rac_init(lag_rac *l, BitstreamContext *bc, int length);
/* TODO: Optimize */ /* TODO: Optimize */
static inline void lag_rac_refill(lag_rac *l) static inline void lag_rac_refill(lag_rac *l)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment