-/*
- * This function unpacks a single token (which should be in the range 0..31)
- * and returns a zero run (number of zero coefficients in current DCT matrix
- * before next non-zero coefficient), the next DCT coefficient, and the
- * number of consecutive, non-EOB'd DCT blocks to EOB.
- */
-static void unpack_token(GetBitContext *gb, int token, int *zero_run,
- DCTELEM *coeff, int *eob_run)
-{
- int sign;
-
- *zero_run = 0;
- *eob_run = 0;
- *coeff = 0;
-
- debug_token(" vp3 token %d: ", token);
- switch (token) {
-
- case 0:
- debug_token("DCT_EOB_TOKEN, EOB next block\n");
- *eob_run = 1;
- break;
-
- case 1:
- debug_token("DCT_EOB_PAIR_TOKEN, EOB next 2 blocks\n");
- *eob_run = 2;
- break;
-
- case 2:
- debug_token("DCT_EOB_TRIPLE_TOKEN, EOB next 3 blocks\n");
- *eob_run = 3;
- break;
-
- case 3:
- debug_token("DCT_REPEAT_RUN_TOKEN, ");
- *eob_run = get_bits(gb, 2) + 4;
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 4:
- debug_token("DCT_REPEAT_RUN2_TOKEN, ");
- *eob_run = get_bits(gb, 3) + 8;
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 5:
- debug_token("DCT_REPEAT_RUN3_TOKEN, ");
- *eob_run = get_bits(gb, 4) + 16;
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 6:
- debug_token("DCT_REPEAT_RUN4_TOKEN, ");
- *eob_run = get_bits(gb, 12);
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 7:
- debug_token("DCT_SHORT_ZRL_TOKEN, ");
- /* note that this token actually indicates that (3 extra bits) + 1 0s
- * should be output; this case specifies a run of (3 EBs) 0s and a
- * coefficient of 0. */
- *zero_run = get_bits(gb, 3);
- *coeff = 0;
- debug_token("skip the next %d positions in output matrix\n", *zero_run + 1);
- break;
-
- case 8:
- debug_token("DCT_ZRL_TOKEN, ");
- /* note that this token actually indicates that (6 extra bits) + 1 0s
- * should be output; this case specifies a run of (6 EBs) 0s and a
- * coefficient of 0. */
- *zero_run = get_bits(gb, 6);
- *coeff = 0;
- debug_token("skip the next %d positions in output matrix\n", *zero_run + 1);
- break;
-
- case 9:
- debug_token("ONE_TOKEN, output 1\n");
- *coeff = 1;
- break;
-
- case 10:
- debug_token("MINUS_ONE_TOKEN, output -1\n");
- *coeff = -1;
- break;
-
- case 11:
- debug_token("TWO_TOKEN, output 2\n");
- *coeff = 2;
- break;
-
- case 12:
- debug_token("MINUS_TWO_TOKEN, output -2\n");
- *coeff = -2;
- break;
-
- case 13:
- case 14:
- case 15:
- case 16:
- debug_token("LOW_VAL_TOKENS, ");
- if (get_bits(gb, 1))
- *coeff = -(3 + (token - 13));
- else
- *coeff = 3 + (token - 13);
- debug_token("output %d\n", *coeff);
- break;
-
- case 17:
- debug_token("DCT_VAL_CATEGORY3, ");
- sign = get_bits(gb, 1);
- *coeff = 7 + get_bits(gb, 1);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 18:
- debug_token("DCT_VAL_CATEGORY4, ");
- sign = get_bits(gb, 1);
- *coeff = 9 + get_bits(gb, 2);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 19:
- debug_token("DCT_VAL_CATEGORY5, ");
- sign = get_bits(gb, 1);
- *coeff = 13 + get_bits(gb, 3);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 20:
- debug_token("DCT_VAL_CATEGORY6, ");
- sign = get_bits(gb, 1);
- *coeff = 21 + get_bits(gb, 4);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 21:
- debug_token("DCT_VAL_CATEGORY7, ");
- sign = get_bits(gb, 1);
- *coeff = 37 + get_bits(gb, 5);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 22:
- debug_token("DCT_VAL_CATEGORY8, ");
- sign = get_bits(gb, 1);
- *coeff = 69 + get_bits(gb, 9);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- debug_token("DCT_RUN_CATEGORY1, ");
- *zero_run = token - 22;
- if (get_bits(gb, 1))
- *coeff = -1;
- else
- *coeff = 1;
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 28:
- debug_token("DCT_RUN_CATEGORY1B, ");
- if (get_bits(gb, 1))
- *coeff = -1;
- else
- *coeff = 1;
- *zero_run = 6 + get_bits(gb, 2);
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 29:
- debug_token("DCT_RUN_CATEGORY1C, ");
- if (get_bits(gb, 1))
- *coeff = -1;
- else
- *coeff = 1;
- *zero_run = 10 + get_bits(gb, 3);
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 30:
- debug_token("DCT_RUN_CATEGORY2, ");
- sign = get_bits(gb, 1);
- *coeff = 2 + get_bits(gb, 1);
- if (sign)
- *coeff = -(*coeff);
- *zero_run = 1;
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 31:
- debug_token("DCT_RUN_CATEGORY2, ");
- sign = get_bits(gb, 1);
- *coeff = 2 + get_bits(gb, 1);
- if (sign)
- *coeff = -(*coeff);
- *zero_run = 2 + get_bits(gb, 1);
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- default:
- av_log(NULL, AV_LOG_ERROR, " vp3: help! Got a bad token: %d > 31\n", token);
- break;
-
- }
-}
-