1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/hevc/hevcdec: Use bitfield instead of array of flags

It is simpler, avoids several loops and also makes GCC no longer
emit bogus -Wstringop-overflow= warnings.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-03-30 14:35:04 +02:00
parent ffa56f73a9
commit 0ce8868878

View File

@ -174,11 +174,8 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
{
int i = 0;
int j = 0;
uint8_t luma_weight_l0_flag[16];
uint8_t chroma_weight_l0_flag[16];
uint8_t luma_weight_l1_flag[16];
uint8_t chroma_weight_l1_flag[16];
int luma_log2_weight_denom;
unsigned luma_weight_flags, chroma_weight_flags;
luma_log2_weight_denom = get_ue_golomb_long(gb);
if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
@ -195,29 +192,22 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
}
luma_weight_flags = get_bits(gb, sh->nb_refs[L0]);
chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
for (i = 0; i < sh->nb_refs[L0]; i++) {
luma_weight_l0_flag[i] = get_bits1(gb);
if (!luma_weight_l0_flag[i]) {
sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
sh->luma_offset_l0[i] = 0;
}
}
if (sps->chroma_format_idc != 0) {
for (i = 0; i < sh->nb_refs[L0]; i++)
chroma_weight_l0_flag[i] = get_bits1(gb);
} else {
for (i = 0; i < sh->nb_refs[L0]; i++)
chroma_weight_l0_flag[i] = 0;
}
for (i = 0; i < sh->nb_refs[L0]; i++) {
if (luma_weight_l0_flag[i]) {
unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
if (luma_weight_flags & flag_bit) {
int delta_luma_weight_l0 = get_se_golomb(gb);
if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
return AVERROR_INVALIDDATA;
sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
sh->luma_offset_l0[i] = get_se_golomb(gb);
} else {
sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
sh->luma_offset_l0[i] = 0;
}
if (chroma_weight_l0_flag[i]) {
if (chroma_weight_flags & flag_bit) {
for (j = 0; j < 2; j++) {
int delta_chroma_weight_l0 = get_se_golomb(gb);
int delta_chroma_offset_l0 = get_se_golomb(gb);
@ -239,29 +229,22 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
}
}
if (sh->slice_type == HEVC_SLICE_B) {
luma_weight_flags = get_bits(gb, sh->nb_refs[L1]);
chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0;
for (i = 0; i < sh->nb_refs[L1]; i++) {
luma_weight_l1_flag[i] = get_bits1(gb);
if (!luma_weight_l1_flag[i]) {
sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
sh->luma_offset_l1[i] = 0;
}
}
if (sps->chroma_format_idc != 0) {
for (i = 0; i < sh->nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = get_bits1(gb);
} else {
for (i = 0; i < sh->nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = 0;
}
for (i = 0; i < sh->nb_refs[L1]; i++) {
if (luma_weight_l1_flag[i]) {
unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
if (luma_weight_flags & flag_bit) {
int delta_luma_weight_l1 = get_se_golomb(gb);
if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
return AVERROR_INVALIDDATA;
sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
sh->luma_offset_l1[i] = get_se_golomb(gb);
} else {
sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
sh->luma_offset_l1[i] = 0;
}
if (chroma_weight_l1_flag[i]) {
if (chroma_weight_flags & flag_bit) {
for (j = 0; j < 2; j++) {
int delta_chroma_weight_l1 = get_se_golomb(gb);
int delta_chroma_offset_l1 = get_se_golomb(gb);