From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH] avcodec/proresdata: Move data only used by ff_prores_ks_encoder to it Date: Fri, 29 Jul 2022 10:22:40 +0200 Message-ID: <DB6PR0101MB22143291782D1A0882DF6B638F999@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw) In this case, this allows to inline the initial run_cb and lev_cb values. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/proresdata.c | 27 ------------------ libavcodec/proresdata.h | 4 --- libavcodec/proresenc_kostya.c | 54 ++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/libavcodec/proresdata.c b/libavcodec/proresdata.c index 9849b5cc00..4787907c71 100644 --- a/libavcodec/proresdata.c +++ b/libavcodec/proresdata.c @@ -43,30 +43,3 @@ const uint8_t ff_prores_interlaced_scan[64] = { 30, 23, 31, 38, 45, 52, 60, 53, 46, 39, 47, 54, 61, 62, 55, 63 }; - - -const uint8_t ff_prores_dc_codebook[4] = { - 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 - 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 - 0x4D, // rice_order = 2, exp_golomb_order = 3, switch_bits = 1 - 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 -}; - -const uint8_t ff_prores_ac_codebook[7] = { - 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 - 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 - 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0 - 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1 - 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1 - 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2 - 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2 -}; - -/** - * Lookup tables for adaptive switching between codebooks - * according with previous run/level value. - */ -const uint8_t ff_prores_run_to_cb_index[16] = - { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 }; - -const uint8_t ff_prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }; diff --git a/libavcodec/proresdata.h b/libavcodec/proresdata.h index ee8278d5f4..d8c8786689 100644 --- a/libavcodec/proresdata.h +++ b/libavcodec/proresdata.h @@ -31,9 +31,5 @@ extern const uint8_t ff_prores_progressive_scan[64]; extern const uint8_t ff_prores_interlaced_scan[64]; #define FIRST_DC_CB 0xB8 // rice_order = 5, exp_golomb_order = 6, switch_bits = 0 -extern const uint8_t ff_prores_dc_codebook[4]; -extern const uint8_t ff_prores_ac_codebook[7]; -extern const uint8_t ff_prores_run_to_cb_index[16]; -extern const uint8_t ff_prores_lev_to_cb_index[10]; #endif /* AVCODEC_PRORESDATA_H */ diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 391072d470..60bb2286f8 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -135,6 +135,32 @@ static const uint8_t prores_quant_matrices[][64] = { }, }; +static const uint8_t prores_dc_codebook[4] = { + 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 + 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 + 0x4D, // rice_order = 2, exp_golomb_order = 3, switch_bits = 1 + 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 +}; + +static const uint8_t prores_ac_codebook[7] = { + 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 + 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 + 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0 + 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1 + 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1 + 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2 + 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2 +}; + +/** + * Lookup tables for adaptive switching between codebooks + * according with previous run/level value. + */ +static const uint8_t prores_run_to_cb_index[16] = + { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 }; + +static const uint8_t prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }; + #define NUM_MB_LIMITS 4 static const int prores_mb_limits[NUM_MB_LIMITS] = { 1620, // up to 720x576 @@ -423,7 +449,7 @@ static void encode_dcs(PutBitContext *pb, int16_t *blocks, new_sign = GET_SIGN(delta); delta = (delta ^ sign) - sign; code = MAKE_CODE(delta); - encode_vlc_codeword(pb, ff_prores_dc_codebook[codebook], code); + encode_vlc_codeword(pb, prores_dc_codebook[codebook], code); codebook = (code + (code & 1)) >> 1; codebook = FFMIN(codebook, 3); sign = new_sign; @@ -441,8 +467,8 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, int max_coeffs, abs_level; max_coeffs = blocks_per_slice << 6; - run_cb = ff_prores_run_to_cb_index[4]; - lev_cb = ff_prores_lev_to_cb_index[2]; + run_cb = prores_run_to_cb_index[4]; + lev_cb = prores_lev_to_cb_index[2]; run = 0; for (i = 1; i < 64; i++) { @@ -450,13 +476,13 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, level = blocks[idx] / qmat[scan[i]]; if (level) { abs_level = FFABS(level); - encode_vlc_codeword(pb, ff_prores_ac_codebook[run_cb], run); - encode_vlc_codeword(pb, ff_prores_ac_codebook[lev_cb], + encode_vlc_codeword(pb, prores_ac_codebook[run_cb], run); + encode_vlc_codeword(pb, prores_ac_codebook[lev_cb], abs_level - 1); put_sbits(pb, 1, GET_SIGN(level)); - run_cb = ff_prores_run_to_cb_index[FFMIN(run, 15)]; - lev_cb = ff_prores_lev_to_cb_index[FFMIN(abs_level, 9)]; + run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; + lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; run = 0; } else { run++; @@ -667,7 +693,7 @@ static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice, new_sign = GET_SIGN(delta); delta = (delta ^ sign) - sign; code = MAKE_CODE(delta); - bits += estimate_vlc(ff_prores_dc_codebook[codebook], code); + bits += estimate_vlc(prores_dc_codebook[codebook], code); codebook = (code + (code & 1)) >> 1; codebook = FFMIN(codebook, 3); sign = new_sign; @@ -687,8 +713,8 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, int bits = 0; max_coeffs = blocks_per_slice << 6; - run_cb = ff_prores_run_to_cb_index[4]; - lev_cb = ff_prores_lev_to_cb_index[2]; + run_cb = prores_run_to_cb_index[4]; + lev_cb = prores_lev_to_cb_index[2]; run = 0; for (i = 1; i < 64; i++) { @@ -697,12 +723,12 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, *error += FFABS(blocks[idx]) % qmat[scan[i]]; if (level) { abs_level = FFABS(level); - bits += estimate_vlc(ff_prores_ac_codebook[run_cb], run); - bits += estimate_vlc(ff_prores_ac_codebook[lev_cb], + bits += estimate_vlc(prores_ac_codebook[run_cb], run); + bits += estimate_vlc(prores_ac_codebook[lev_cb], abs_level - 1) + 1; - run_cb = ff_prores_run_to_cb_index[FFMIN(run, 15)]; - lev_cb = ff_prores_lev_to_cb_index[FFMIN(abs_level, 9)]; + run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; + lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; run = 0; } else { run++; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2022-07-29 8:23 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=DB6PR0101MB22143291782D1A0882DF6B638F999@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git