Change devenv.com command line.
[libvpx.git] / vp8 / decoder / arm / detokenizearm_sjl.c
blobe9917c175b592936a23aa86069d3bec187499304
1 /*
2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 #include "type_aliases.h"
13 #include "blockd.h"
14 #include "onyxd_int.h"
15 #include "vpx_mem/vpx_mem.h"
16 #include "vpx_ports/mem.h"
18 #define BR_COUNT 8
19 #define BOOL_DATA UINT8
21 #define OCB_X PREV_COEF_CONTEXTS * ENTROPY_NODES
22 //ALIGN16 UINT16 onyx_coef_bands_x[16] = { 0, 1*OCB_X, 2*OCB_X, 3*OCB_X, 6*OCB_X, 4*OCB_X, 5*OCB_X, 6*OCB_X, 6*OCB_X, 6*OCB_X, 6*OCB_X, 6*OCB_X, 6*OCB_X, 6*OCB_X, 6*OCB_X, 7*OCB_X};
23 DECLARE_ALIGNED(16, UINT8, vp8_coef_bands_x[16]) = { 0, 1 * OCB_X, 2 * OCB_X, 3 * OCB_X, 6 * OCB_X, 4 * OCB_X, 5 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 6 * OCB_X, 7 * OCB_X};
25 #define EOB_CONTEXT_NODE 0
26 #define ZERO_CONTEXT_NODE 1
27 #define ONE_CONTEXT_NODE 2
28 #define LOW_VAL_CONTEXT_NODE 3
29 #define TWO_CONTEXT_NODE 4
30 #define THREE_CONTEXT_NODE 5
31 #define HIGH_LOW_CONTEXT_NODE 6
32 #define CAT_ONE_CONTEXT_NODE 7
33 #define CAT_THREEFOUR_CONTEXT_NODE 8
34 #define CAT_THREE_CONTEXT_NODE 9
35 #define CAT_FIVE_CONTEXT_NODE 10
40 DECLARE_ALIGNED(16, static const TOKENEXTRABITS, vp8d_token_extra_bits2[MAX_ENTROPY_TOKENS]) =
42 { 0, -1, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //ZERO_TOKEN
43 { 1, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //ONE_TOKEN
44 { 2, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //TWO_TOKEN
45 { 3, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //THREE_TOKEN
46 { 4, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //FOUR_TOKEN
47 { 5, 0, { 159, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY1
48 { 7, 1, { 145, 165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY2
49 { 11, 2, { 140, 148, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY3
50 { 19, 3, { 135, 140, 155, 176, 0, 0, 0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY4
51 { 35, 4, { 130, 134, 141, 157, 180, 0, 0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY5
52 { 67, 10, { 129, 130, 133, 140, 153, 177, 196, 230, 243, 254, 254, 0 } }, //DCT_VAL_CATEGORY6
53 { 0, -1, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, // EOB TOKEN
57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 DECLARE_ALIGNED(16, const UINT8, vp8_block2context_leftabove[25*3]) =
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, //end of vp8_block2context
63 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 1, 1, 0, 0, 1, 1, 0, //end of vp8_block2left
64 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0 //end of vp8_block2above
68 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72 void vp8_reset_mb_tokens_context(MACROBLOCKD *x)
74 ENTROPY_CONTEXT **const A = x->above_context;
75 ENTROPY_CONTEXT(* const L)[4] = x->left_context;
77 ENTROPY_CONTEXT *a;
78 ENTROPY_CONTEXT *l;
79 int i;
81 for (i = 0; i < 24; i++)
84 a = A[ vp8_block2context[i] ] + vp8_block2above[i];
85 l = L[ vp8_block2context[i] ] + vp8_block2left[i];
87 *a = *l = 0;
90 if (x->mbmi.mode != B_PRED && x->mbmi.mode != SPLITMV)
92 a = A[Y2CONTEXT] + vp8_block2above[24];
93 l = L[Y2CONTEXT] + vp8_block2left[24];
94 *a = *l = 0;
100 #define ONYXBLOCK2CONTEXT_OFFSET 0
101 #define ONYXBLOCK2LEFT_OFFSET 25
102 #define ONYXBLOCK2ABOVE_OFFSET 50
104 DECLARE_ALIGNED(16, const static unsigned char, norm[128]) =
106 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
107 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
109 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
113 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 void init_detokenizer(VP8D_COMP *dx)
118 const VP8_COMMON *const oc = & dx->common;
119 MACROBLOCKD *x = & dx->mb;
121 dx->detoken.norm_ptr = (unsigned char *)norm;
122 dx->detoken.vp8_coef_tree_ptr = (vp8_tree_index *)vp8_coef_tree;
123 dx->detoken.ptr_onyxblock2context_leftabove = (UINT8 *)vp8_block2context_leftabove;
124 dx->detoken.ptr_onyx_coef_bands_x = vp8_coef_bands_x;
125 dx->detoken.scan = (int *)vp8_default_zig_zag1d;
126 dx->detoken.teb_base_ptr = (TOKENEXTRABITS *)vp8d_token_extra_bits2;
128 dx->detoken.qcoeff_start_ptr = &x->qcoeff[0];
131 dx->detoken.coef_probs[0] = (unsigned char *)(oc->fc.coef_probs [0] [ 0 ] [0]);
132 dx->detoken.coef_probs[1] = (unsigned char *)(oc->fc.coef_probs [1] [ 0 ] [0]);
133 dx->detoken.coef_probs[2] = (unsigned char *)(oc->fc.coef_probs [2] [ 0 ] [0]);
134 dx->detoken.coef_probs[3] = (unsigned char *)(oc->fc.coef_probs [3] [ 0 ] [0]);
139 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 //shift = norm[range]; \
145 // shift = norm_ptr[range]; \
147 #define NORMALIZE \
148 /*if(range < 0x80)*/ \
150 shift = detoken->norm_ptr[range]; \
151 range <<= shift; \
152 value <<= shift; \
153 count -= shift; \
154 if(count <= 0) \
156 count += BR_COUNT ; \
157 value |= (*bufptr) << (BR_COUNT-count); \
158 bufptr++; \
161 #if 1
162 #define DECODE_AND_APPLYSIGN(value_to_sign) \
163 split = (range + 1) >> 1; \
164 if ( (value >> 24) < split ) \
166 range = split; \
167 v= value_to_sign; \
169 else \
171 range = range-split; \
172 value = value-(split<<24); \
173 v = -value_to_sign; \
175 range +=range; \
176 value +=value; \
177 if (!--count) \
179 count = BR_COUNT; \
180 value |= *bufptr; \
181 bufptr++; \
184 #define DECODE_AND_BRANCH_IF_ZERO(probability,branch) \
186 split = 1 + ((( probability*(range-1) ) )>> 8); \
187 if ( (value >> 24) < split ) \
189 range = split; \
190 NORMALIZE \
191 goto branch; \
193 value -= (split<<24); \
194 range = range - split; \
195 NORMALIZE \
198 #define DECODE_AND_LOOP_IF_ZERO(probability,branch) \
200 split = 1 + ((( probability*(range-1) ) ) >> 8); \
201 if ( (value >> 24) < split ) \
203 range = split; \
204 NORMALIZE \
205 Prob = coef_probs; \
206 ++c; \
207 Prob += vp8_coef_bands_x[c]; \
208 goto branch; \
210 value -= (split<<24); \
211 range = range - split; \
212 NORMALIZE \
215 #define DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) \
216 DECODE_AND_APPLYSIGN(val) \
217 Prob = coef_probs + (ENTROPY_NODES*2); \
218 if(c < 15){\
219 qcoeff_ptr [ scan[c] ] = (INT16) v; \
220 ++c; \
221 goto DO_WHILE; }\
222 qcoeff_ptr [ scan[15] ] = (INT16) v; \
223 goto BLOCK_FINISHED;
226 #define DECODE_EXTRABIT_AND_ADJUST_VAL(t,bits_count)\
227 split = 1 + (((range-1) * vp8d_token_extra_bits2[t].Probs[bits_count]) >> 8); \
228 if(value >= (split<<24))\
230 range = range-split;\
231 value = value-(split<<24);\
232 val += ((UINT16)1<<bits_count);\
234 else\
236 range = split;\
238 NORMALIZE
239 #endif
241 #if 0
242 int vp8_decode_mb_tokens(VP8D_COMP *dx, MACROBLOCKD *x)
244 ENTROPY_CONTEXT **const A = x->above_context;
245 ENTROPY_CONTEXT(* const L)[4] = x->left_context;
246 const VP8_COMMON *const oc = & dx->common;
248 BOOL_DECODER *bc = x->current_bc;
250 ENTROPY_CONTEXT *a;
251 ENTROPY_CONTEXT *l;
252 int i;
254 int eobtotal = 0;
256 register int count;
258 BOOL_DATA *bufptr;
259 register unsigned int range;
260 register unsigned int value;
261 const int *scan;
262 register unsigned int shift;
263 UINT32 split;
264 INT16 *qcoeff_ptr;
266 UINT8 *coef_probs;
267 int type;
268 int stop;
269 INT16 val, bits_count;
270 INT16 c;
271 INT16 t;
272 INT16 v;
273 vp8_prob *Prob;
275 //int *scan;
276 type = 3;
277 i = 0;
278 stop = 16;
280 if (x->mbmi.mode != B_PRED && x->mbmi.mode != SPLITMV)
282 i = 24;
283 stop = 24;
284 type = 1;
285 qcoeff_ptr = &x->qcoeff[24*16];
286 scan = vp8_default_zig_zag1d;
287 eobtotal -= 16;
289 else
291 scan = vp8_default_zig_zag1d;
292 qcoeff_ptr = &x->qcoeff[0];
295 count = bc->count;
296 range = bc->range;
297 value = bc->value;
298 bufptr = &bc->buffer[bc->pos];
301 coef_probs = (unsigned char *)(oc->fc.coef_probs [type] [ 0 ] [0]);
303 BLOCK_LOOP:
304 a = A[ vp8_block2context[i] ] + vp8_block2above[i];
305 l = L[ vp8_block2context[i] ] + vp8_block2left[i];
306 c = (INT16)(!type);
308 VP8_COMBINEENTROPYCONTEXTS(t, *a, *l);
309 Prob = coef_probs;
310 Prob += t * ENTROPY_NODES;
312 DO_WHILE:
313 Prob += vp8_coef_bands_x[c];
314 DECODE_AND_BRANCH_IF_ZERO(Prob[EOB_CONTEXT_NODE], BLOCK_FINISHED);
316 CHECK_0_:
317 DECODE_AND_LOOP_IF_ZERO(Prob[ZERO_CONTEXT_NODE], CHECK_0_);
318 DECODE_AND_BRANCH_IF_ZERO(Prob[ONE_CONTEXT_NODE], ONE_CONTEXT_NODE_0_);
319 DECODE_AND_BRANCH_IF_ZERO(Prob[LOW_VAL_CONTEXT_NODE], LOW_VAL_CONTEXT_NODE_0_);
320 DECODE_AND_BRANCH_IF_ZERO(Prob[HIGH_LOW_CONTEXT_NODE], HIGH_LOW_CONTEXT_NODE_0_);
321 DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_THREEFOUR_CONTEXT_NODE], CAT_THREEFOUR_CONTEXT_NODE_0_);
322 DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_FIVE_CONTEXT_NODE], CAT_FIVE_CONTEXT_NODE_0_);
323 val = vp8d_token_extra_bits2[DCT_VAL_CATEGORY6].min_val;
324 bits_count = vp8d_token_extra_bits2[DCT_VAL_CATEGORY6].Length;
328 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY6, bits_count);
329 bits_count -- ;
331 while (bits_count >= 0);
333 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
335 CAT_FIVE_CONTEXT_NODE_0_:
336 val = vp8d_token_extra_bits2[DCT_VAL_CATEGORY5].min_val;
337 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 4);
338 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 3);
339 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 2);
340 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 1);
341 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 0);
342 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
344 CAT_THREEFOUR_CONTEXT_NODE_0_:
345 DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_THREE_CONTEXT_NODE], CAT_THREE_CONTEXT_NODE_0_);
346 val = vp8d_token_extra_bits2[DCT_VAL_CATEGORY4].min_val;
347 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 3);
348 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 2);
349 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 1);
350 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 0);
351 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
353 CAT_THREE_CONTEXT_NODE_0_:
354 val = vp8d_token_extra_bits2[DCT_VAL_CATEGORY3].min_val;
355 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 2);
356 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 1);
357 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 0);
358 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
360 HIGH_LOW_CONTEXT_NODE_0_:
361 DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_ONE_CONTEXT_NODE], CAT_ONE_CONTEXT_NODE_0_);
363 val = vp8d_token_extra_bits2[DCT_VAL_CATEGORY2].min_val;
364 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 1);
365 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 0);
366 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
368 CAT_ONE_CONTEXT_NODE_0_:
369 val = vp8d_token_extra_bits2[DCT_VAL_CATEGORY1].min_val;
370 DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY1, 0);
371 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
373 LOW_VAL_CONTEXT_NODE_0_:
374 DECODE_AND_BRANCH_IF_ZERO(Prob[TWO_CONTEXT_NODE], TWO_CONTEXT_NODE_0_);
375 DECODE_AND_BRANCH_IF_ZERO(Prob[THREE_CONTEXT_NODE], THREE_CONTEXT_NODE_0_);
376 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(4);
378 THREE_CONTEXT_NODE_0_:
379 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(3);
381 TWO_CONTEXT_NODE_0_:
382 DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(2);
384 ONE_CONTEXT_NODE_0_:
385 DECODE_AND_APPLYSIGN(1);
386 Prob = coef_probs + ENTROPY_NODES;
388 if (c < 15)
390 qcoeff_ptr [ scan[c] ] = (INT16) v;
391 ++c;
392 goto DO_WHILE;
395 qcoeff_ptr [ scan[15] ] = (INT16) v;
396 BLOCK_FINISHED:
397 t = ((x->Block[i].eob = c) != !type); // any nonzero data?
398 eobtotal += x->Block[i].eob;
399 *a = *l = t;
400 qcoeff_ptr += 16;
402 i++;
404 if (i < stop)
405 goto BLOCK_LOOP;
407 if (i == 25)
409 scan = vp8_default_zig_zag1d;//x->scan_order1d;
410 type = 0;
411 i = 0;
412 stop = 16;
413 coef_probs = (unsigned char *)(oc->fc.coef_probs [type] [ 0 ] [0]);
414 qcoeff_ptr = &x->qcoeff[0];
415 goto BLOCK_LOOP;
418 if (i == 16)
420 type = 2;
421 coef_probs = (unsigned char *)(oc->fc.coef_probs [type] [ 0 ] [0]);
422 stop = 24;
423 goto BLOCK_LOOP;
426 bc->count = count;
427 bc->value = value;
428 bc->range = range;
429 bc->pos = bufptr - bc->buffer;
430 return eobtotal;
433 //#endif
434 #else
436 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
437 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
438 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
439 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442 #if 0
443 //uses relative offsets
445 const vp8_tree_index vp8_coef_tree_x[ 22] = /* corresponding _CONTEXT_NODEs */
447 -DCT_EOB_TOKEN, 1, /* 0 = EOB */
448 -ZERO_TOKEN, 1, /* 1 = ZERO */
449 -ONE_TOKEN, 1, /* 2 = ONE */
450 2, 5, /* 3 = LOW_VAL */
451 -TWO_TOKEN, 1, /* 4 = TWO */
452 -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */
453 2, 3, /* 6 = HIGH_LOW */
454 -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */
455 2, 3, /* 8 = CAT_THREEFOUR */
456 -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */
457 -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */
459 #endif
461 #define _SCALEDOWN 8 //16 //8
463 int vp8_decode_mb_tokens_v5(DETOK *detoken, int type);
465 int vp8_decode_mb_tokens_v5_c(DETOK *detoken, int type)
467 BOOL_DECODER *bc = detoken->current_bc;
469 ENTROPY_CONTEXT *a;
470 ENTROPY_CONTEXT *l;
471 int i;
473 register int count;
475 BOOL_DATA *bufptr;
476 register unsigned int range;
477 register unsigned int value;
478 register unsigned int shift;
479 UINT32 split;
480 INT16 *qcoeff_ptr;
482 UINT8 *coef_probs;
483 // int type;
484 int stop;
485 INT16 c;
486 INT16 t;
487 INT16 v;
488 vp8_prob *Prob;
492 // type = 3;
493 i = 0;
494 stop = 16;
495 qcoeff_ptr = detoken->qcoeff_start_ptr;
497 // if( detoken->mode != B_PRED && detoken->mode != SPLITMV)
498 if (type == 1)
500 i += 24;
501 stop += 8; //24;
502 // type = 1;
503 qcoeff_ptr += 24 * 16;
504 // eobtotal-=16;
507 count = bc->count;
508 range = bc->range;
509 value = bc->value;
510 bufptr = &bc->buffer[bc->pos];
513 coef_probs = detoken->coef_probs[type]; //(unsigned char *)( oc->fc.coef_probs [type] [ 0 ] [0]);
515 BLOCK_LOOP:
516 a = detoken->A[ detoken->ptr_onyxblock2context_leftabove[i] ];
517 l = detoken->L[ detoken->ptr_onyxblock2context_leftabove[i] ];
518 c = !type;
519 a += detoken->ptr_onyxblock2context_leftabove[i + ONYXBLOCK2ABOVE_OFFSET];
520 l += detoken->ptr_onyxblock2context_leftabove[i + ONYXBLOCK2LEFT_OFFSET];
522 //#define ONYX_COMBINEENTROPYCONTEXTS( Dest, A, B) \
523 //Dest = ((A)!=0) + ((B)!=0);
525 VP8_COMBINEENTROPYCONTEXTS(t, *a, *l);
527 Prob = coef_probs;
528 Prob += t * ENTROPY_NODES;
529 t = 0;
535 // onyx_tree_index * onyx_coef_tree_ptr = onyx_coef_tree_x;
537 Prob += detoken->ptr_onyx_coef_bands_x[c];
539 GET_TOKEN_START:
543 split = 1 + (((range - 1) * (Prob[t>>1])) >> 8);
545 if (value >> 24 >= split)
547 range = range - split;
548 value = value - (split << 24);
549 t += 1;
551 //used to eliminate else branch
552 split = range;
555 range = split;
557 t = detoken->vp8_coef_tree_ptr[ t ];
559 NORMALIZE
562 while (t > 0) ;
564 GET_TOKEN_STOP:
566 if (t == -DCT_EOB_TOKEN)
568 break;
571 v = -t;
573 if (v > FOUR_TOKEN)
575 INT16 bits_count;
576 TOKENEXTRABITS *teb_ptr;
578 // teb_ptr = &onyxd_token_extra_bits2[t];
579 // teb_ptr = &onyxd_token_extra_bits2[v];
580 teb_ptr = &detoken->teb_base_ptr[v];
583 v = teb_ptr->min_val;
584 bits_count = teb_ptr->Length;
588 split = 1 + (((range - 1) * teb_ptr->Probs[bits_count]) >> _SCALEDOWN);
590 if ((value >> 24) >= split)
592 range = range - split;
593 value = value - (split << 24);
594 v += ((UINT16)1 << bits_count);
596 //used to eliminate else branch
597 split = range;
600 range = split;
602 NORMALIZE
604 bits_count -- ;
606 while (bits_count >= 0);
609 Prob = coef_probs;
611 if (t)
613 split = 1 + (((range - 1) * vp8_prob_half) >> 8);
615 if ((value >> 24) >= split)
617 range = range - split;
618 value = value - (split << 24);
619 v = (v ^ -1) + 1; /* negate w/out conditionals */
621 //used to eliminate else branch
622 split = range;
625 range = split;
627 NORMALIZE
628 Prob += ENTROPY_NODES;
630 if (t < -ONE_TOKEN)
631 Prob += ENTROPY_NODES;
633 t = -2;
636 //if t is zero, we will skip the eob table check
637 t += 2;
638 qcoeff_ptr [detoken->scan [c] ] = (INT16) v;
641 while (++c < 16);
643 if (t != -DCT_EOB_TOKEN)
645 --c;
648 t = ((detoken->eob[i] = c) != !type); // any nonzero data?
649 // eobtotal += detoken->eob[i];
650 *a = *l = t;
651 qcoeff_ptr += 16;
653 i++;
655 if (i < stop)
656 goto BLOCK_LOOP;
658 if (i == 25)
660 type = 0;
661 i = 0;
662 stop = 16;
663 // coef_probs = (unsigned char *)(oc->fc.coef_probs [type] [ 0 ] [0]);
664 coef_probs = detoken->coef_probs[type]; //(unsigned char *)( oc->fc.coef_probs [type] [ 0 ] [0]);
665 qcoeff_ptr = detoken->qcoeff_start_ptr;
666 goto BLOCK_LOOP;
669 if (i == 16)
671 type = 2;
672 // coef_probs =(unsigned char *)( oc->fc.coef_probs [type] [ 0 ] [0]);
673 coef_probs = detoken->coef_probs[type]; //(unsigned char *)( oc->fc.coef_probs [type] [ 0 ] [0]);
674 stop = 24;
675 goto BLOCK_LOOP;
678 bc->count = count;
679 bc->value = value;
680 bc->range = range;
681 bc->pos = bufptr - bc->buffer;
682 return 0;
684 //#if 0
685 int vp8_decode_mb_tokens(VP8D_COMP *dx, MACROBLOCKD *x)
687 // const ONYX_COMMON * const oc = & dx->common;
688 int eobtotal = 0;
689 int i, type;
691 dx->detoken.norm_ptr = norm;
692 dx->detoken.onyx_coef_tree_ptr = onyx_coef_tree;
693 dx->detoken.ptr_onyxblock2context_leftabove = ONYXBLOCK2CONTEXT_LEFTABOVE;
694 dx->detoken.ptr_onyx_coef_bands_x = onyx_coef_bands_x;
695 dx->detoken.scan = default_zig_zag1d;
696 dx->detoken.teb_base_ptr = onyxd_token_extra_bits2;
698 dx->detoken.qcoeff_start_ptr = &x->qcoeff[0];
700 dx->detoken.A = x->above_context;
701 dx->detoken.L = x->left_context;
703 dx->detoken.coef_probs[0] = (unsigned char *)( oc->fc.coef_probs [0] [ 0 ] [0]);
704 dx->detoken.coef_probs[1] = (unsigned char *)( oc->fc.coef_probs [1] [ 0 ] [0]);
705 dx->detoken.coef_probs[2] = (unsigned char *)( oc->fc.coef_probs [2] [ 0 ] [0]);
706 dx->detoken.coef_probs[3] = (unsigned char *)( oc->fc.coef_probs [3] [ 0 ] [0]);
709 dx->detoken.current_bc = x->current_bc;
710 dx->detoken.A = x->above_context;
711 dx->detoken.L = x->left_context;
713 type = 3;
715 if (x->mbmi.mode != B_PRED && x->mbmi.mode != SPLITMV)
717 type = 1;
718 eobtotal -= 16;
721 vp8_decode_mb_tokens_v5(&dx->detoken, type);
723 for (i = 0; i < 25; i++)
725 x->Block[i].eob = dx->detoken.eob[i];
726 eobtotal += dx->detoken.eob[i];
729 return eobtotal;
731 #endif