comparison vp56.h @ 11921:f2007d7c3f1d libavcodec

Native VP8 decoder. Patch by David Conrad <lessen42 gmail com> and myself.
author rbultje
date Tue, 22 Jun 2010 19:24:09 +0000
parents 7d04a6cec75f
children 934968bd410d
comparison
equal deleted inserted replaced
11920:7d04a6cec75f 11921:f2007d7c3f1d
235 c->code_word |= *c->buffer++; 235 c->code_word |= *c->buffer++;
236 } 236 }
237 return bit; 237 return bit;
238 } 238 }
239 239
240 // rounding is different than vp56_rac_get, is vp56_rac_get wrong?
241 static inline int vp8_rac_get(VP56RangeCoder *c)
242 {
243 return vp56_rac_get_prob(c, 128);
244 }
245
240 static inline int vp56_rac_gets(VP56RangeCoder *c, int bits) 246 static inline int vp56_rac_gets(VP56RangeCoder *c, int bits)
241 { 247 {
242 int value = 0; 248 int value = 0;
243 249
244 while (bits--) { 250 while (bits--) {
246 } 252 }
247 253
248 return value; 254 return value;
249 } 255 }
250 256
257 static inline int vp8_rac_get_uint(VP56RangeCoder *c, int bits)
258 {
259 int value = 0;
260
261 while (bits--) {
262 value = (value << 1) | vp8_rac_get(c);
263 }
264
265 return value;
266 }
267
268 // fixme: add 1 bit to all the calls to this?
269 static inline int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
270 {
271 int v;
272
273 if (!vp8_rac_get(c))
274 return 0;
275
276 v = vp8_rac_get_uint(c, bits);
277
278 if (vp8_rac_get(c))
279 v = -v;
280
281 return v;
282 }
283
284 // P(7)
251 static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits) 285 static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
252 { 286 {
253 int v = vp56_rac_gets(c, 7) << 1; 287 int v = vp56_rac_gets(c, 7) << 1;
288 return v + !v;
289 }
290
291 static inline int vp8_rac_get_nn(VP56RangeCoder *c)
292 {
293 int v = vp8_rac_get_uint(c, 7) << 1;
254 return v + !v; 294 return v + !v;
255 } 295 }
256 296
257 static inline int vp56_rac_get_tree(VP56RangeCoder *c, 297 static inline int vp56_rac_get_tree(VP56RangeCoder *c,
258 const VP56Tree *tree, 298 const VP56Tree *tree,
265 tree++; 305 tree++;
266 } 306 }
267 return -tree->val; 307 return -tree->val;
268 } 308 }
269 309
310 /**
311 * This is identical to vp8_rac_get_tree except for the possibility of starting
312 * on a node other than the root node, needed for coeff decode where this is
313 * used to save a bit after a 0 token (by disallowing EOB to immediately follow.)
314 */
315 static inline int vp8_rac_get_tree_with_offset(VP56RangeCoder *c, const int8_t (*tree)[2],
316 const uint8_t *probs, int i)
317 {
318 do {
319 i = tree[i][vp56_rac_get_prob(c, probs[i])];
320 } while (i > 0);
321
322 return -i;
323 }
324
325 // how probabilities are associated with decisions is different I think
326 // well, the new scheme fits in the old but this way has one fewer branches per decision
327 static inline int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2],
328 const uint8_t *probs)
329 {
330 return vp8_rac_get_tree_with_offset(c, tree, probs, 0);
331 }
332
333 // DCTextra
334 static inline int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob)
335 {
336 int v = 0;
337
338 do {
339 v = (v<<1) + vp56_rac_get_prob(c, *prob++);
340 } while (*prob);
341
342 return v;
343 }
344
270 #endif /* AVCODEC_VP56_H */ 345 #endif /* AVCODEC_VP56_H */