1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

avcodec/bonk: Simplify read_uint_max()

The max == 0 case can be removed too but i left it as 50% of the cases use it

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2022-11-06 10:34:39 +01:00
parent f4df49eb48
commit 9f00286c4c
No known key found for this signature in database
GPG Key ID: B18E8928B3948D64

View File

@ -132,7 +132,6 @@ static av_cold int bonk_init(AVCodecContext *avctx)
static unsigned read_uint_max(BonkContext *s, uint32_t max)
{
unsigned value = 0;
int i, bits;
if (max == 0)
return 0;
@ -140,15 +139,9 @@ static unsigned read_uint_max(BonkContext *s, uint32_t max)
if (max >> 31)
return 32;
bits = 32 - ff_clz(max);
for (i = 0; i < bits - 1; i++)
for (unsigned i = 1; i <= max - value; i+=i)
if (get_bits1(&s->gb))
value += 1 << i;
if ((value | (1 << (bits - 1))) <= max)
if (get_bits1(&s->gb))
value += 1 << (bits - 1);
value += i;
return value;
}