This is following the same logic as proresenc_anatoliy.
Unified · Split
| @@ -142,25 +142,6 @@ static const uint8_t prores_dc_codebook[4] = { · 141 unmodified lines | ||
| 142 | 142 | 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 |
| 143 | 143 | }; |
| 144 | 144 | |
| 145 | −static const uint8_t prores_ac_codebook[7] = { | |
| 146 | − 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 | |
| 147 | − 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 | |
| 148 | − 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0 | |
| 149 | − 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1 | |
| 150 | − 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1 | |
| 151 | − 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2 | |
| 152 | − 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2 | |
| 153 | −}; | |
| 154 | − | |
| 155 | −/** | |
| 156 | − * Lookup tables for adaptive switching between codebooks | |
| 157 | − * according with previous run/level value. | |
| 158 | − */ | |
| 159 | −static const uint8_t prores_run_to_cb_index[16] = | |
| 160 | − { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 }; | |
| 161 | − | |
| 162 | −static const uint8_t prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }; | |
| 163 | − | |
| 164 | 145 | #define NUM_MB_LIMITS 4 |
| 165 | 146 | static const int prores_mb_limits[NUM_MB_LIMITS] = { |
| 166 | 147 | 1620, // up to 720x576 |
| @@ -461,12 +442,12 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 294 unmodified lines | ||
| 461 | 442 | const uint8_t *scan, const int16_t *qmat) |
| 462 | 443 | { |
| 463 | 444 | int idx, i; |
| 464 | − int run, level, run_cb, lev_cb; | |
| 445 | + int prev_run = 4; | |
| 446 | + int prev_level = 2; | |
| 447 | + int run, level; | |
| 465 | 448 | int max_coeffs, abs_level; |
| 466 | 449 | |
| 467 | 450 | max_coeffs = blocks_per_slice << 6; |
| 468 | − run_cb = prores_run_to_cb_index[4]; | |
| 469 | − lev_cb = prores_lev_to_cb_index[2]; | |
| 470 | 451 | run = 0; |
| 471 | 452 | |
| 472 | 453 | for (i = 1; i < 64; i++) { |
| @@ -474,13 +455,13 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 1 unmodified line | ||
| 474 | 455 | level = blocks[idx] / qmat[scan[i]]; |
| 475 | 456 | if (level) { |
| 476 | 457 | abs_level = FFABS(level); |
| 477 | − encode_vlc_codeword(pb, prores_ac_codebook[run_cb], run); | |
| 478 | − encode_vlc_codeword(pb, prores_ac_codebook[lev_cb], | |
| 458 | + encode_vlc_codeword(pb, ff_prores_run_to_cb[prev_run], run); | |
| 459 | + encode_vlc_codeword(pb, ff_prores_level_to_cb[prev_level], | |
| 479 | 460 | abs_level - 1); |
| 480 | 461 | put_sbits(pb, 1, GET_SIGN(level)); |
| 481 | 462 | |
| 482 | − run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; | |
| 483 | − lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; | |
| 463 | + prev_run = FFMIN(run, 15); | |
| 464 | + prev_level = FFMIN(abs_level, 9); | |
| 484 | 465 | run = 0; |
| 485 | 466 | } else { |
| 486 | 467 | run++; |
| @@ -698,13 +679,13 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, · 211 unmodified lines | ||
| 698 | 679 | const uint8_t *scan, const int16_t *qmat) |
| 699 | 680 | { |
| 700 | 681 | int idx, i; |
| 701 | − int run, level, run_cb, lev_cb; | |
| 682 | + int prev_run = 4; | |
| 683 | + int prev_level = 2; | |
| 684 | + int run, level; | |
| 702 | 685 | int max_coeffs, abs_level; |
| 703 | 686 | int bits = 0; |
| 704 | 687 | |
| 705 | 688 | max_coeffs = blocks_per_slice << 6; |
| 706 | − run_cb = prores_run_to_cb_index[4]; | |
| 707 | − lev_cb = prores_lev_to_cb_index[2]; | |
| 708 | 689 | run = 0; |
| 709 | 690 | |
| 710 | 691 | for (i = 1; i < 64; i++) { |
| @@ -713,12 +694,12 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, · 2 unmodified lines | ||
| 713 | 694 | *error += FFABS(blocks[idx]) % qmat[scan[i]]; |
| 714 | 695 | if (level) { |
| 715 | 696 | abs_level = FFABS(level); |
| 716 | − bits += estimate_vlc(prores_ac_codebook[run_cb], run); | |
| 717 | − bits += estimate_vlc(prores_ac_codebook[lev_cb], | |
| 697 | + bits += estimate_vlc(ff_prores_run_to_cb[prev_run], run); | |
| 698 | + bits += estimate_vlc(ff_prores_level_to_cb[prev_level], | |
| 718 | 699 | abs_level - 1) + 1; |
| 719 | 700 | |
| 720 | − run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; | |
| 721 | − lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; | |
| 701 | + prev_run = FFMIN(run, 15); | |
| 702 | + prev_level = FFMIN(abs_level, 9); | |
| 722 | 703 | run = 0; |
| 723 | 704 | } else { |
| 724 | 705 | run++; |