From d94e2667b7f3b907a127f93c8075f864071a52df Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sun, 23 Feb 2025 23:21:00 +0100 Subject: [PATCH 1/9] avcodec/proresdec: Don't use LONG_BITSTREAM_READER Using LONG_BITSTREAM_READER means that every get_bits() call uses an AV_RB64() to ensure that cache always contains 32 valid bits (as opposed to the ordinary 25 guaranteed by reading 32 bits); yet this is unnecessary when unpacking alpha. So only use these 64bit reads where necessary. Signed-off-by: Andreas Rheinhardt --- libavcodec/proresdec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/proresdec.c b/libavcodec/proresdec.c index 6a256107b4..b2517bd5a4 100644 --- a/libavcodec/proresdec.c +++ b/libavcodec/proresdec.c @@ -26,8 +26,6 @@ //#define DEBUG -#define LONG_BITSTREAM_READER - #include "config_components.h" #include "libavutil/internal.h" @@ -428,7 +426,7 @@ static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, cons unsigned int rice_order, exp_order, switch_bits; \ unsigned int q, buf, bits; \ \ - UPDATE_CACHE(re, gb); \ + UPDATE_CACHE_32(re, gb); /* We really need 32 bits */ \ buf = GET_CACHE(re, gb); \ \ /* number of bits to switch between rice and exp golomb */ \ @@ -440,7 +438,7 @@ static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, cons \ if (q > switch_bits) { /* exp golomb */ \ bits = exp_order - switch_bits + (q<<1); \ - if (bits > FFMIN(MIN_CACHE_BITS, 31)) \ + if (bits > 31) \ return AVERROR_INVALIDDATA; \ val = SHOW_UBITS(re, gb, bits) - (1 << exp_order) + \ ((switch_bits + 1) << rice_order); \ @@ -502,7 +500,7 @@ static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContex int log2_block_count = av_log2(blocks_per_slice); OPEN_READER(re, gb); - UPDATE_CACHE(re, gb); \ + UPDATE_CACHE_32(re, gb); run = 4; level = 2; -- 2.45.2