From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/jpeg2000: Simplify exp2fi for numbers used here Date: Sat, 17 Feb 2024 21:05:02 +0100 Message-ID: <GV1SPRMB0063AFB9D369C21EDE6DB4778F532@GV1SPRMB0063.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <GV1SPRMB006386A16563C97BA4D00D8E8F532@GV1SPRMB0063.EURP250.PROD.OUTLOOK.COM> The call to ff_exp2fi() here always uses arguments in the normal range, so that the branches in ff_exp2fi() are unnecessary. This is so because JPEG2000 itself only supports up to 128 bits per component per pixel (we only support far less); furthermore, expn is always 0..31 for the decoder and also sane for the encoder, so that the difference between these two values is always in the normal range of -126..128. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/jpeg2000.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index 0aa984bc53..d6ffb02319 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -32,7 +32,6 @@ #include "libavutil/mem.h" #include "libavutil/thread.h" #include "avcodec.h" -#include "internal.h" #include "jpeg2000.h" #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n)) @@ -201,6 +200,17 @@ void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, // static const uint8_t lut_gain[2][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 2 } }; (unused) +/** + * 2^(x) for integer x in the range -126..128. + * @return correctly rounded float + */ +static av_always_inline float exp2fi(int x) +{ + av_assert2(-126 <= x && x <= 128); + /* Normal range */ + return av_int2float((x+127) << 23); +} + static void init_band_stepsize(AVCodecContext *avctx, Jpeg2000Band *band, Jpeg2000CodingStyle *codsty, @@ -230,7 +240,7 @@ static void init_band_stepsize(AVCodecContext *avctx, * R_b = R_I + log2 (gain_b ) * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */ gain = cbps; - band->f_stepsize = ff_exp2fi(gain - qntsty->expn[gbandno]); + band->f_stepsize = exp2fi(gain - qntsty->expn[gbandno]); band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0; break; default: @@ -391,7 +401,7 @@ static int init_band(AVCodecContext *avctx, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int bandno, int gbandno, int reslevelno, - int cbps, int dx, int dy) + const int cbps, int dx, int dy) { Jpeg2000Band *band = reslevel->band + bandno; uint8_t log2_band_prec_width, log2_band_prec_height; @@ -466,7 +476,7 @@ static int init_band(AVCodecContext *avctx, int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, - int cbps, int dx, int dy, + const int cbps, int dx, int dy, AVCodecContext *avctx) { int reslevelno, bandno, gbandno = 0, ret, i, j; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-02-17 20:03 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-17 19:54 [FFmpeg-devel] [PATCH 1/4] avcodec/jpeg2000dec, j2kenc: Constify where appropriate Andreas Rheinhardt 2024-02-17 20:05 ` [FFmpeg-devel] [PATCH 2/4] avcodec/jpeg2000dec: Avoid using GetByteContext.buffer directly Andreas Rheinhardt 2024-02-19 14:00 ` Tomas Härdin 2024-02-17 20:05 ` Andreas Rheinhardt [this message] 2024-02-19 14:09 ` [FFmpeg-devel] [PATCH 3/4] avcodec/jpeg2000: Simplify exp2fi for numbers used here Tomas Härdin 2024-02-19 14:14 ` Andreas Rheinhardt 2024-02-19 14:51 ` Tomas Härdin 2024-02-17 20:05 ` [FFmpeg-devel] [PATCH 4/4] avcodec/internal: Move ff_exp2fi() to aacsbr.c Andreas Rheinhardt 2024-02-19 11:30 ` [FFmpeg-devel] [PATCH 1/4] avcodec/jpeg2000dec, j2kenc: Constify where appropriate Andreas Rheinhardt 2024-02-19 13:58 ` Tomas Härdin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=GV1SPRMB0063AFB9D369C21EDE6DB4778F532@GV1SPRMB0063.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git