ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | Sun Jun 15 01:26:54 2025 +0200| [8a3566498e57d44e56c69f1f82b2ce58f5a79a83] | committer: Andreas Rheinhardt
avcodec/ituh263enc: Simplify creating LUT Only very few combinations (2x102) of 16384 correspond to valid codes; so just initialize all codes via memset and then set the few valid codes explicitly instead of initializing everything in the same way. Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8a3566498e57d44e56c69f1f82b2ce58f5a79a83 --- libavcodec/h263data.h | 4 ++++ libavcodec/ituh263enc.c | 54 ++++++++++++++++++++----------------------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/libavcodec/h263data.h b/libavcodec/h263data.h index 06554bdf0d..e733089e83 100644 --- a/libavcodec/h263data.h +++ b/libavcodec/h263data.h @@ -59,6 +59,10 @@ extern const uint16_t ff_inter_vlc[103][2]; extern const int8_t ff_inter_level[102]; extern const int8_t ff_inter_run[102]; +/* the following defines are valid for both ff_h263_rl_inter and ff_rl_intra_aic */ +#define H263_RL_NB_ELEMS 102 // does not include escape +#define H263_RL_NON_LAST_CODES 58 +#define H263_ESCAPE_CODE_LENGTH 7 extern RLTable ff_h263_rl_inter; extern RLTable ff_rl_intra_aic; diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index 903bb45fce..4ec851cab9 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -99,41 +99,31 @@ static uint8_t uni_h263_inter_rl_len [64*64*2*2]; static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab) { + const uint16_t (*table_vlc)[2] = rl->table_vlc; + const uint8_t *table_run = rl->table_run; + const uint8_t *table_level = rl->table_level; + av_assert0(MAX_LEVEL >= 64); av_assert0(MAX_RUN >= 63); - for (int slevel = -64; slevel < 64; slevel++) { - if (slevel == 0) continue; - for (int run = 0; run < 64; run++) { - for (int last = 0; last <= 1; last++) { - const int index = UNI_MPEG4_ENC_INDEX(last, run, slevel + 64); - int level = slevel < 0 ? -slevel : slevel; - int sign = slevel < 0 ? 1 : 0; - int bits, len, code; - - len_tab[index] = 100; - - /* ESC0 */ - code = get_rl_index(rl, last, run, level); - bits = rl->table_vlc[code][0]; - len = rl->table_vlc[code][1]; - bits = bits * 2 + sign; - len++; - - if (code != rl->n && len < len_tab[index]) - len_tab[index] = len; - - /* ESC */ - bits = rl->table_vlc[rl->n][0]; - len = rl->table_vlc[rl->n][1]; - bits = bits * 2 + last; len++; - bits = bits * 64 + run; len += 6; - bits = bits * 256 + (level & 0xff); len += 8; - - if (len < len_tab[index]) - len_tab[index] = len; - } - } + // Note: The LUT only covers level values for which the escape value + // is eight bits (not 8 + 5 + 6) + memset(len_tab, H263_ESCAPE_CODE_LENGTH + 1 + 6 + 8, + sizeof(uni_h263_intra_aic_rl_len)); + + len_tab += 64; // simplifies addressing + for (int i = 0; i < H263_RL_NB_ELEMS; ++i) { + int run = table_run[i]; + int level = table_level[i]; + int last = i >= H263_RL_NON_LAST_CODES; + int len = table_vlc[i][1]; + + len_tab[UNI_MPEG4_ENC_INDEX(last, run, level)] = + len_tab[UNI_MPEG4_ENC_INDEX(last, run, -level)] = len + 1 /* sign */; + } + for (int run = 0; run < MAX_RUN; ++run) { + len_tab[UNI_MPEG4_ENC_INDEX(0, run, 0)] = + len_tab[UNI_MPEG4_ENC_INDEX(1, run, 0)] = 0; // is this necessary? } } #endif _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".