You've already forked FFmpeg
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:
@ -174,11 +174,8 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 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;
|
int luma_log2_weight_denom;
|
||||||
|
unsigned luma_weight_flags, chroma_weight_flags;
|
||||||
|
|
||||||
luma_log2_weight_denom = get_ue_golomb_long(gb);
|
luma_log2_weight_denom = get_ue_golomb_long(gb);
|
||||||
if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
|
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;
|
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++) {
|
for (i = 0; i < sh->nb_refs[L0]; i++) {
|
||||||
luma_weight_l0_flag[i] = get_bits1(gb);
|
unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
|
||||||
if (!luma_weight_l0_flag[i]) {
|
|
||||||
sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
|
if (luma_weight_flags & flag_bit) {
|
||||||
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]) {
|
|
||||||
int delta_luma_weight_l0 = get_se_golomb(gb);
|
int delta_luma_weight_l0 = get_se_golomb(gb);
|
||||||
if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
|
if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
|
sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
|
||||||
sh->luma_offset_l0[i] = get_se_golomb(gb);
|
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++) {
|
for (j = 0; j < 2; j++) {
|
||||||
int delta_chroma_weight_l0 = get_se_golomb(gb);
|
int delta_chroma_weight_l0 = get_se_golomb(gb);
|
||||||
int delta_chroma_offset_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) {
|
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++) {
|
for (i = 0; i < sh->nb_refs[L1]; i++) {
|
||||||
luma_weight_l1_flag[i] = get_bits1(gb);
|
unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
|
||||||
if (!luma_weight_l1_flag[i]) {
|
|
||||||
sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
|
if (luma_weight_flags & flag_bit) {
|
||||||
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]) {
|
|
||||||
int delta_luma_weight_l1 = get_se_golomb(gb);
|
int delta_luma_weight_l1 = get_se_golomb(gb);
|
||||||
if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
|
if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
|
sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
|
||||||
sh->luma_offset_l1[i] = get_se_golomb(gb);
|
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++) {
|
for (j = 0; j < 2; j++) {
|
||||||
int delta_chroma_weight_l1 = get_se_golomb(gb);
|
int delta_chroma_weight_l1 = get_se_golomb(gb);
|
||||||
int delta_chroma_offset_l1 = get_se_golomb(gb);
|
int delta_chroma_offset_l1 = get_se_golomb(gb);
|
||||||
|
Reference in New Issue
Block a user