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

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/proresenc_kostya.c+14−33
@@ -142,25 +142,6 @@ static const uint8_t prores_dc_codebook[4] = { · 141 unmodified lines
142142 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0
143143 };
144144
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−
164145 #define NUM_MB_LIMITS 4
165146 static const int prores_mb_limits[NUM_MB_LIMITS] = {
166147 1620, // up to 720x576
@@ -461,12 +442,12 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 294 unmodified lines
461442 const uint8_t *scan, const int16_t *qmat)
462443 {
463444 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;
465448 int max_coeffs, abs_level;
466449
467450 max_coeffs = blocks_per_slice << 6;
468− run_cb = prores_run_to_cb_index[4];
469− lev_cb = prores_lev_to_cb_index[2];
470451 run = 0;
471452
472453 for (i = 1; i < 64; i++) {
@@ -474,13 +455,13 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 1 unmodified line
474455 level = blocks[idx] / qmat[scan[i]];
475456 if (level) {
476457 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],
479460 abs_level - 1);
480461 put_sbits(pb, 1, GET_SIGN(level));
481462
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);
484465 run = 0;
485466 } else {
486467 run++;
@@ -698,13 +679,13 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, · 211 unmodified lines
698679 const uint8_t *scan, const int16_t *qmat)
699680 {
700681 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;
702685 int max_coeffs, abs_level;
703686 int bits = 0;
704687
705688 max_coeffs = blocks_per_slice << 6;
706− run_cb = prores_run_to_cb_index[4];
707− lev_cb = prores_lev_to_cb_index[2];
708689 run = 0;
709690
710691 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
713694 *error += FFABS(blocks[idx]) % qmat[scan[i]];
714695 if (level) {
715696 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],
718699 abs_level - 1) + 1;
719700
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);
722703 run = 0;
723704 } else {
724705 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