24 #define LUT_SIZE (1 << LUT_BITS)
25 #define RSIZE_BITS (CHAR_BIT*sizeof(residual))
27 #define CONVERT_TO_RESIDUE(a, b) \
28 (((residual)(a)) << (RSIZE_BITS - (b)))
30 #define INIT_RESIDUE(N) \
32 av_unused int32_t N ## _bits = 0
34 #define SET_RESIDUE(N, I, B) \
35 N = CONVERT_TO_RESIDUE(I, B); \
38 #define APPEND_RESIDUE(N, M) \
39 N |= M >> (N ## _bits); \
40 N ## _bits += (M ## _bits)
50 for (b = 1; b <= bytes; b++) {
51 future[0] = &lut_ctx[buf[
b]];
56 if ((c_idx + 1) > coeffs)
60 if (res_bits && l->
sign) {
63 for (i = 0; i < (res_bits >> 1) - 1; i++) {
67 dst[c_idx++] = l->
sign * (coeff - 1);
76 l = future[l->
need_s ? 3 : !res_bits ? 2 : res_bits & 1];
86 int16_t *dst = (int16_t *)_dst;
90 for (b = 1; b <= bytes; b++) {
91 future[0] = &lut_ctx[buf[
b]];
96 if ((c_idx + 1) > coeffs)
99 if (res_bits && l->
sign) {
102 for (i = 0; i < (res_bits >> 1) - 1; i++) {
106 dst[c_idx++] = l->
sign * (coeff - 1);
111 dst[c_idx + i] = l->
ready[i];
116 l = future[l->
need_s ? 3 : !res_bits ? 2 : res_bits & 1];
126 int bits_start, bits_tot =
bits, need_sign = 0;
128 #define READ_BIT(N) (((N) >> (N ## _count--)) & 1)
171 for (idx = 0; idx <
LUT_SIZE; idx++) {
173 int symbol_end_loc = -1;
181 const int cond = even ? (i & 1) : !(i & 1);
182 if (((res >> (
RSIZE_BITS - i - 1)) & 1) && cond) {
183 symbol_end_loc = i + 2;
188 if (symbol_end_loc < 0 || symbol_end_loc > LUT_BITS) {
199 code = idx >> ((LUT_BITS - 1) - (symbol_end_loc - 1));
200 code &= ((1 <<
LUT_BITS) - 1) >> (LUT_BITS - symbol_end_loc);
213 for (idx = 0; idx <
LUT_SIZE; idx++) {
int ff_dirac_golomb_read_32bit(DiracGolombLUT *lut_ctx, const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
static void search_for_golomb(DiracGolombLUT *l, residual r, int bits)
int ff_dirac_golomb_read_16bit(DiracGolombLUT *lut_ctx, const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
#define SET_RESIDUE(N, I, B)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
av_cold int ff_dirac_golomb_reader_init(DiracGolombLUT **lut_ctx)
static void generate_offset_lut(DiracGolombLUT *lut, int off)
av_cold void ff_dirac_golomb_reader_end(DiracGolombLUT **lut_ctx)
static av_always_inline int even(uint64_t layout)
#define CONVERT_TO_RESIDUE(a, b)
#define APPEND_RESIDUE(N, M)
static const int16_t coeffs[]
static const double coeff[2][5]
static void generate_parity_lut(DiracGolombLUT *lut, int even)