Commit bc1ac158 authored by Nathan E. Egge's avatar Nathan E. Egge Committed by Alex Converse

Refactor bitreader and bitwriter wrapper.

Move code for reading and writing literals and reading trees to use
just the aom_read_bit() and aom_write_bit() function calls.

Change-Id: Id2bced5f0125a5558030a813c51c3d79e5701873
parent de383d08
......@@ -45,15 +45,25 @@ static INLINE int aom_read(aom_reader *r, int prob) {
return aom_dk_read(r, prob);
}
static INLINE int aom_read_bit(aom_reader *r) { return aom_dk_read_bit(r); }
static INLINE int aom_read_bit(aom_reader *r) {
return aom_read(r, 128); // aom_prob_half
}
static INLINE int aom_read_literal(aom_reader *r, int bits) {
return aom_dk_read_literal(r, bits);
int literal = 0, bit;
for (bit = bits - 1; bit >= 0; bit--) literal |= aom_read_bit(r) << bit;
return literal;
}
static INLINE int aom_read_tree(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs) {
return aom_dk_read_tree(r, tree, probs);
aom_tree_index i = 0;
while ((i = tree[i + aom_read(r, probs[i >> 1])]) > 0) continue;
return -i;
}
#ifdef __cplusplus
......
......@@ -32,11 +32,13 @@ static INLINE void aom_write(aom_writer *br, int bit, int probability) {
}
static INLINE void aom_write_bit(aom_writer *w, int bit) {
aom_dk_write_bit(w, bit);
aom_write(w, bit, 128); // aom_prob_half
}
static INLINE void aom_write_literal(aom_writer *w, int data, int bits) {
aom_dk_write_literal(w, data, bits);
int bit;
for (bit = bits - 1; bit >= 0; bit--) aom_write_bit(w, 1 & (data >> bit));
}
#ifdef __cplusplus
......
......@@ -19,6 +19,10 @@
#include "aom_mem/aom_mem.h"
#include "aom_util/endian_inl.h"
static INLINE int aom_dk_read_bit(struct aom_dk_reader *r) {
return aom_dk_read(r, 128); // aom_prob_half
}
int aom_dk_reader_init(struct aom_dk_reader *r, const uint8_t *buffer,
size_t size, aom_decrypt_cb decrypt_cb,
void *decrypt_state) {
......
......@@ -108,28 +108,6 @@ static INLINE int aom_dk_read(struct aom_dk_reader *r, int prob) {
return bit;
}
static INLINE int aom_dk_read_bit(struct aom_dk_reader *r) {
return aom_dk_read(r, 128); // aom_prob_half
}
static INLINE int aom_dk_read_literal(struct aom_dk_reader *r, int bits) {
int literal = 0, bit;
for (bit = bits - 1; bit >= 0; bit--) literal |= aom_dk_read_bit(r) << bit;
return literal;
}
static INLINE int aom_dk_read_tree(struct aom_dk_reader *r,
const aom_tree_index *tree,
const aom_prob *probs) {
aom_tree_index i = 0;
while ((i = tree[i + aom_dk_read(r, probs[i >> 1])]) > 0) continue;
return -i;
}
#ifdef __cplusplus
} // extern "C"
#endif
......
......@@ -13,6 +13,10 @@
#include "./dkboolwriter.h"
static INLINE void aom_dk_write_bit(aom_dk_writer *w, int bit) {
aom_dk_write(w, bit, 128); // aom_prob_half
}
void aom_dk_start_encode(aom_dk_writer *br, uint8_t *source) {
br->lowvalue = 0;
br->range = 255;
......
......@@ -79,16 +79,6 @@ static INLINE void aom_dk_write(aom_dk_writer *br, int bit, int probability) {
br->range = range;
}
static INLINE void aom_dk_write_bit(aom_dk_writer *w, int bit) {
aom_dk_write(w, bit, 128); // aom_prob_half
}
static INLINE void aom_dk_write_literal(aom_dk_writer *w, int data, int bits) {
int bit;
for (bit = bits - 1; bit >= 0; bit--) aom_dk_write_bit(w, 1 & (data >> bit));
}
#ifdef __cplusplus
} // extern "C"
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment