History

avcodec/proresenc_kostya: remove one LUT indirection for run/level to codebook mapping

This is following the same logic as proresenc_anatoliy.

Clément Bœsch committed 2 years ago

Commit c3573301 parent 3ba52f11 file · +14 −33Browse files

Unified · Split

libavcodec/proresenc_kostya.c+14−33
@@ -142,25 +142,6 @@ static const uint8_t prores_dc_codebook[4] = { · 141 unmodified lines
142 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0142 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0
143};143};
144 144
145static 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 */
159static 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
162static const uint8_t prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 };
163
164#define NUM_MB_LIMITS 4145#define NUM_MB_LIMITS 4
165static const int prores_mb_limits[NUM_MB_LIMITS] = {146static const int prores_mb_limits[NUM_MB_LIMITS] = {
166 1620, // up to 720x576147 1620, // up to 720x576
@@ -461,12 +442,12 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 294 unmodified lines
461 const uint8_t *scan, const int16_t *qmat)442 const uint8_t *scan, const int16_t *qmat)
462{443{
463 int idx, i;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 int max_coeffs, abs_level;448 int max_coeffs, abs_level;
466 449
467 max_coeffs = blocks_per_slice << 6;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 run = 0;451 run = 0;
471 452
472 for (i = 1; i < 64; i++) {453 for (i = 1; i < 64; i++) {
@@ -474,13 +455,13 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 1 unmodified line
474 level = blocks[idx] / qmat[scan[i]];455 level = blocks[idx] / qmat[scan[i]];
475 if (level) {456 if (level) {
476 abs_level = FFABS(level);457 abs_level = FFABS(level);
477 encode_vlc_codeword(pb, prores_ac_codebook[run_cb], run);458 encode_vlc_codeword(pb, ff_prores_run_to_cb[prev_run], run);
478 encode_vlc_codeword(pb, prores_ac_codebook[lev_cb],459 encode_vlc_codeword(pb, ff_prores_level_to_cb[prev_level],
479 abs_level - 1);460 abs_level - 1);
480 put_sbits(pb, 1, GET_SIGN(level));461 put_sbits(pb, 1, GET_SIGN(level));
481 462
482 run_cb = prores_run_to_cb_index[FFMIN(run, 15)];463 prev_run = FFMIN(run, 15);
483 lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)];464 prev_level = FFMIN(abs_level, 9);
484 run = 0;465 run = 0;
485 } else {466 } else {
486 run++;467 run++;
@@ -698,13 +679,13 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, · 211 unmodified lines
698 const uint8_t *scan, const int16_t *qmat)679 const uint8_t *scan, const int16_t *qmat)
699{680{
700 int idx, i;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 int max_coeffs, abs_level;685 int max_coeffs, abs_level;
703 int bits = 0;686 int bits = 0;
704 687
705 max_coeffs = blocks_per_slice << 6;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 run = 0;689 run = 0;
709 690
710 for (i = 1; i < 64; i++) {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 *error += FFABS(blocks[idx]) % qmat[scan[i]];694 *error += FFABS(blocks[idx]) % qmat[scan[i]];
714 if (level) {695 if (level) {
715 abs_level = FFABS(level);696 abs_level = FFABS(level);
716 bits += estimate_vlc(prores_ac_codebook[run_cb], run);697 bits += estimate_vlc(ff_prores_run_to_cb[prev_run], run);
717 bits += estimate_vlc(prores_ac_codebook[lev_cb],698 bits += estimate_vlc(ff_prores_level_to_cb[prev_level],
718 abs_level - 1) + 1;699 abs_level - 1) + 1;
719 700
720 run_cb = prores_run_to_cb_index[FFMIN(run, 15)];701 prev_run = FFMIN(run, 15);
721 lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)];702 prev_level = FFMIN(abs_level, 9);
722 run = 0;703 run = 0;
723 } else {704 } else {
724 run++;705 run++;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t