28 #ifndef AVCODEC_DIRAC_ARITH_H 29 #define AVCODEC_DIRAC_ARITH_H 31 #include "libavutil/x86/asm.h" 32 #include "bytestream.h" 35 enum dirac_arith_contexts {
65 #define CTX_SB_F1 CTX_ZP_F5 67 #define CTX_PMODE_REF1 0 68 #define CTX_PMODE_REF2 1 69 #define CTX_GLOBAL_BLOCK 2 70 #define CTX_MV_F1 CTX_ZP_F2 72 #define CTX_DC_F1 CTX_ZP_F5 80 const uint8_t *bytestream;
81 const uint8_t *bytestream_end;
83 uint16_t contexts[DIRAC_CTX_COUNT];
86 extern const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT];
87 extern const uint16_t ff_dirac_prob[256];
88 extern int16_t ff_dirac_prob_branchless[256][2];
93 int shift = 14 - av_log2_16bit(c->range-1) + ((c->range-1)>>15);
99 while (c->range <= 0x4000) {
109 int counter = c->counter;
112 int new = bytestream_get_be16(&c->bytestream);
115 if (c->bytestream > c->bytestream_end) {
117 if (c->bytestream > c->bytestream_end+1)
120 c->bytestream = c->bytestream_end;
123 c->low +=
new << counter;
126 c->counter = counter;
129 static inline int dirac_get_arith_bit(
DiracArith *c,
int ctx)
131 int prob_zero = c->contexts[ctx];
132 int range_times_prob, bit;
133 unsigned low = c->low;
134 int range = c->range;
136 range_times_prob = (c->range * prob_zero) >> 16;
138 #if ARCH_X86 && HAVE_FAST_CMOV && HAVE_INLINE_ASM && HAVE_6REGS 139 low -= range_times_prob << 16;
140 range -= range_times_prob;
147 :
"+q"(bit),
"+r"(range),
"+r"(low)
148 :
"r"(c->low),
"r"(c->low>>16),
149 "r"(range_times_prob)
152 bit = (low >> 16) >= range_times_prob;
154 low -= range_times_prob << 16;
155 range -= range_times_prob;
157 range = range_times_prob;
161 c->contexts[ctx] += ff_dirac_prob_branchless[prob_zero>>8][bit];
170 static inline int dirac_get_arith_uint(
DiracArith *c,
int follow_ctx,
int data_ctx)
173 while (!dirac_get_arith_bit(c, follow_ctx)) {
174 if (ret >= 0x40000000) {
179 ret += dirac_get_arith_bit(c, data_ctx);
180 follow_ctx = ff_dirac_next_ctx[follow_ctx];
185 static inline int dirac_get_arith_int(
DiracArith *c,
int follow_ctx,
int data_ctx)
187 int ret = dirac_get_arith_uint(c, follow_ctx, data_ctx);
188 if (ret && dirac_get_arith_bit(c, data_ctx+1))
193 void ff_dirac_init_arith_tables(
void);
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
Definition: dirac_arith.h:75
bitstream reader API header.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
Definition: get_bits.h:56