Commit 3e579a60 authored by Sarah Parker's avatar Sarah Parker

Remove global motion from compressed header

This requires making a temporary copy of the functions in
binary_codes_writer/reader to take in the aom_write_bit_buffer type.

Change-Id: Idb60b29cff69b45224535c6e6a4079a34a2c6871
parent 49c335f4
...@@ -53,6 +53,15 @@ uint16_t aom_read_primitive_quniform_(aom_reader *r, ...@@ -53,6 +53,15 @@ uint16_t aom_read_primitive_quniform_(aom_reader *r,
return v < m ? v : (v << 1) - m + aom_read_bit(r, ACCT_STR_NAME); return v < m ? v : (v << 1) - m + aom_read_bit(r, ACCT_STR_NAME);
} }
static uint16_t aom_rb_read_primitive_quniform(struct aom_read_bit_buffer *rb,
uint16_t n) {
if (n <= 1) return 0;
const int l = get_msb(n - 1) + 1;
const int m = (1 << l) - n;
const int v = aom_rb_read_literal(rb, l - 1);
return v < m ? v : (v << 1) - m + aom_rb_read_bit(rb);
}
uint16_t aom_read_primitive_refbilevel_(aom_reader *r, uint16_t n, uint16_t p, uint16_t aom_read_primitive_refbilevel_(aom_reader *r, uint16_t n, uint16_t p,
uint16_t ref ACCT_STR_PARAM) { uint16_t ref ACCT_STR_PARAM) {
if (n <= 1) return 0; if (n <= 1) return 0;
...@@ -101,15 +110,42 @@ uint16_t aom_read_primitive_subexpfin_(aom_reader *r, uint16_t n, ...@@ -101,15 +110,42 @@ uint16_t aom_read_primitive_subexpfin_(aom_reader *r, uint16_t n,
return v; return v;
} }
// Decode finite subexponential code that for a symbol v in [0, n-1] with static uint16_t aom_rb_read_primitive_subexpfin(struct aom_read_bit_buffer *rb,
// parameter k uint16_t n, uint16_t k) {
// based on a reference ref also in [0, n-1]. int i = 0;
int mk = 0;
uint16_t v;
while (1) {
int b = (i ? k + i - 1 : k);
int a = (1 << b);
if (n <= mk + 3 * a) {
v = aom_rb_read_primitive_quniform(rb, n - mk) + mk;
break;
} else {
if (aom_rb_read_bit(rb)) {
i = i + 1;
mk += a;
} else {
v = aom_rb_read_literal(rb, b) + mk;
break;
}
}
}
return v;
}
uint16_t aom_read_primitive_refsubexpfin_(aom_reader *r, uint16_t n, uint16_t k, uint16_t aom_read_primitive_refsubexpfin_(aom_reader *r, uint16_t n, uint16_t k,
uint16_t ref ACCT_STR_PARAM) { uint16_t ref ACCT_STR_PARAM) {
return inv_recenter_finite_nonneg( return inv_recenter_finite_nonneg(
n, ref, aom_read_primitive_subexpfin(r, n, k, ACCT_STR_NAME)); n, ref, aom_read_primitive_subexpfin(r, n, k, ACCT_STR_NAME));
} }
static uint16_t aom_rb_read_primitive_refsubexpfin(
struct aom_read_bit_buffer *rb, uint16_t n, uint16_t k, uint16_t ref) {
return inv_recenter_finite_nonneg(n, ref,
aom_rb_read_primitive_subexpfin(rb, n, k));
}
// Decode finite subexponential code that for a symbol v in [-(n-1), n-1] with // Decode finite subexponential code that for a symbol v in [-(n-1), n-1] with
// parameter k based on a reference ref also in [-(n-1), n-1]. // parameter k based on a reference ref also in [-(n-1), n-1].
int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n, int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n,
...@@ -120,3 +156,10 @@ int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n, ...@@ -120,3 +156,10 @@ int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n,
return aom_read_primitive_refsubexpfin(r, scaled_n, k, ref, ACCT_STR_NAME) - return aom_read_primitive_refsubexpfin(r, scaled_n, k, ref, ACCT_STR_NAME) -
n + 1; n + 1;
} }
int16_t aom_rb_read_signed_primitive_refsubexpfin(
struct aom_read_bit_buffer *rb, uint16_t n, uint16_t k, int16_t ref) {
ref += n - 1;
const uint16_t scaled_n = (n << 1) - 1;
return aom_rb_read_primitive_refsubexpfin(rb, scaled_n, k, ref) - n + 1;
}
...@@ -17,9 +17,11 @@ extern "C" { ...@@ -17,9 +17,11 @@ extern "C" {
#endif #endif
#include <assert.h> #include <assert.h>
#include "./aom_config.h" #include "./aom_config.h"
#include "aom/aom_integer.h" #include "aom/aom_integer.h"
#include "aom_dsp/bitreader.h" #include "aom_dsp/bitreader.h"
#include "aom_dsp/bitreader_buffer.h"
#define aom_read_primitive_symmetric(r, n, ACCT_STR_NAME) \ #define aom_read_primitive_symmetric(r, n, ACCT_STR_NAME) \
aom_read_primitive_symmetric_(r, n ACCT_STR_ARG(ACCT_STR_NAME)) aom_read_primitive_symmetric_(r, n ACCT_STR_ARG(ACCT_STR_NAME))
...@@ -47,6 +49,9 @@ uint16_t aom_read_primitive_refsubexpfin_(aom_reader *r, uint16_t n, uint16_t k, ...@@ -47,6 +49,9 @@ uint16_t aom_read_primitive_refsubexpfin_(aom_reader *r, uint16_t n, uint16_t k,
int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n, int16_t aom_read_signed_primitive_refsubexpfin_(aom_reader *r, uint16_t n,
uint16_t k, uint16_t k,
int16_t ref ACCT_STR_PARAM); int16_t ref ACCT_STR_PARAM);
int16_t aom_rb_read_signed_primitive_refsubexpfin(
struct aom_read_bit_buffer *rb, uint16_t n, uint16_t k, int16_t ref);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
*/ */
#include "aom_dsp/bitwriter.h" #include "aom_dsp/bitwriter.h"
#include "aom_dsp/binary_codes_writer.h"
#include "av1/common/common.h" #include "av1/common/common.h"
...@@ -68,6 +69,19 @@ void aom_write_primitive_quniform(aom_writer *w, uint16_t n, uint16_t v) { ...@@ -68,6 +69,19 @@ void aom_write_primitive_quniform(aom_writer *w, uint16_t n, uint16_t v) {
} }
} }
static void aom_wb_write_primitive_quniform(struct aom_write_bit_buffer *wb,
uint16_t n, uint16_t v) {
if (n <= 1) return;
const int l = get_msb(n - 1) + 1;
const int m = (1 << l) - n;
if (v < m) {
aom_wb_write_literal(wb, v, l - 1);
} else {
aom_wb_write_literal(wb, m + ((v - m) >> 1), l - 1);
aom_wb_write_bit(wb, (v - m) & 1);
}
}
int aom_count_primitive_quniform(uint16_t n, uint16_t v) { int aom_count_primitive_quniform(uint16_t n, uint16_t v) {
if (n <= 1) return 0; if (n <= 1) return 0;
const int l = get_msb(n - 1) + 1; const int l = get_msb(n - 1) + 1;
...@@ -155,6 +169,31 @@ void aom_write_primitive_subexpfin(aom_writer *w, uint16_t n, uint16_t k, ...@@ -155,6 +169,31 @@ void aom_write_primitive_subexpfin(aom_writer *w, uint16_t n, uint16_t k,
} }
} }
static void aom_wb_write_primitive_subexpfin(struct aom_write_bit_buffer *wb,
uint16_t n, uint16_t k,
uint16_t v) {
int i = 0;
int mk = 0;
while (1) {
int b = (i ? k + i - 1 : k);
int a = (1 << b);
if (n <= mk + 3 * a) {
aom_wb_write_primitive_quniform(wb, n - mk, v - mk);
break;
} else {
int t = (v >= mk + a);
aom_wb_write_bit(wb, t);
if (t) {
i = i + 1;
mk += a;
} else {
aom_wb_write_literal(wb, v - mk, b);
break;
}
}
}
}
int aom_count_primitive_subexpfin(uint16_t n, uint16_t k, uint16_t v) { int aom_count_primitive_subexpfin(uint16_t n, uint16_t k, uint16_t v) {
int count = 0; int count = 0;
int i = 0; int i = 0;
...@@ -184,19 +223,34 @@ int aom_count_primitive_subexpfin(uint16_t n, uint16_t k, uint16_t v) { ...@@ -184,19 +223,34 @@ int aom_count_primitive_subexpfin(uint16_t n, uint16_t k, uint16_t v) {
// based on a reference ref also in [0, n-1]. // based on a reference ref also in [0, n-1].
// Recenters symbol around r first and then uses a finite subexponential code. // Recenters symbol around r first and then uses a finite subexponential code.
void aom_write_primitive_refsubexpfin(aom_writer *w, uint16_t n, uint16_t k, void aom_write_primitive_refsubexpfin(aom_writer *w, uint16_t n, uint16_t k,
int16_t ref, int16_t v) { uint16_t ref, uint16_t v) {
aom_write_primitive_subexpfin(w, n, k, recenter_finite_nonneg(n, ref, v)); aom_write_primitive_subexpfin(w, n, k, recenter_finite_nonneg(n, ref, v));
} }
static void aom_wb_write_primitive_refsubexpfin(struct aom_write_bit_buffer *wb,
uint16_t n, uint16_t k,
uint16_t ref, uint16_t v) {
aom_wb_write_primitive_subexpfin(wb, n, k, recenter_finite_nonneg(n, ref, v));
}
void aom_write_signed_primitive_refsubexpfin(aom_writer *w, uint16_t n, void aom_write_signed_primitive_refsubexpfin(aom_writer *w, uint16_t n,
uint16_t k, uint16_t ref, uint16_t k, int16_t ref,
uint16_t v) { int16_t v) {
ref += n - 1; ref += n - 1;
v += n - 1; v += n - 1;
const uint16_t scaled_n = (n << 1) - 1; const uint16_t scaled_n = (n << 1) - 1;
aom_write_primitive_refsubexpfin(w, scaled_n, k, ref, v); aom_write_primitive_refsubexpfin(w, scaled_n, k, ref, v);
} }
void aom_wb_write_signed_primitive_refsubexpfin(struct aom_write_bit_buffer *wb,
uint16_t n, uint16_t k,
int16_t ref, int16_t v) {
ref += n - 1;
v += n - 1;
const uint16_t scaled_n = (n << 1) - 1;
aom_wb_write_primitive_refsubexpfin(wb, scaled_n, k, ref, v);
}
int aom_count_primitive_refsubexpfin(uint16_t n, uint16_t k, uint16_t ref, int aom_count_primitive_refsubexpfin(uint16_t n, uint16_t k, uint16_t ref,
uint16_t v) { uint16_t v) {
return aom_count_primitive_subexpfin(n, k, recenter_finite_nonneg(n, ref, v)); return aom_count_primitive_subexpfin(n, k, recenter_finite_nonneg(n, ref, v));
......
...@@ -20,6 +20,7 @@ extern "C" { ...@@ -20,6 +20,7 @@ extern "C" {
#include "./aom_config.h" #include "./aom_config.h"
#include "aom/aom_integer.h" #include "aom/aom_integer.h"
#include "aom_dsp/bitwriter.h" #include "aom_dsp/bitwriter.h"
#include "aom_dsp/bitwriter_buffer.h"
// Codes a symbol v in [-2^mag_bits, 2^mag_bits] // Codes a symbol v in [-2^mag_bits, 2^mag_bits]
// mag_bits is number of bits for magnitude. The alphabet is of size // mag_bits is number of bits for magnitude. The alphabet is of size
...@@ -53,6 +54,10 @@ void aom_write_signed_primitive_refsubexpfin(aom_writer *w, uint16_t n, ...@@ -53,6 +54,10 @@ void aom_write_signed_primitive_refsubexpfin(aom_writer *w, uint16_t n,
uint16_t k, int16_t ref, uint16_t k, int16_t ref,
int16_t v); int16_t v);
void aom_wb_write_signed_primitive_refsubexpfin(struct aom_write_bit_buffer *wb,
uint16_t n, uint16_t k,
int16_t ref, int16_t v);
// Functions that counts bits for the above primitives // Functions that counts bits for the above primitives
int aom_count_primitive_symmetric(int16_t v, unsigned int mag_bits); int aom_count_primitive_symmetric(int16_t v, unsigned int mag_bits);
int aom_count_primitive_quniform(uint16_t n, uint16_t v); int aom_count_primitive_quniform(uint16_t n, uint16_t v);
......
This diff is collapsed.
This diff is collapsed.
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