From 1485b06278f38dcda5ff83f17e0a3446949809b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <g...@haerdin.se>
Date: Mon, 23 May 2022 11:20:57 +0200
Subject: [PATCH 8/8] libavcodec/jpeg2000: Call av_codec_is_encoder() only once
 in init_prec()

---
 libavcodec/jpeg2000.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 0aa984bc53..0d4b18b38d 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -278,7 +278,7 @@ static int init_prec(AVCodecContext *avctx,
                      int log2_band_prec_height)
 {
     Jpeg2000Prec *prec = band->prec + precno;
-    int nb_codeblocks, cblkno;
+    int nb_codeblocks, cblkno, is_enc;
 
     prec->decoded_layers = 0;
 
@@ -336,6 +336,9 @@ static int init_prec(AVCodecContext *avctx,
     prec->cblk = av_calloc(nb_codeblocks, sizeof(*prec->cblk));
     if (!prec->cblk)
         return AVERROR(ENOMEM);
+
+    is_enc = av_codec_is_encoder(avctx->codec);
+
     for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
         Jpeg2000Cblk *cblk = prec->cblk + cblkno;
         int Cx0, Cy0;
@@ -375,7 +378,7 @@ static int init_prec(AVCodecContext *avctx,
         cblk->lblock    = 3;
         cblk->length    = 0;
         cblk->npasses   = 0;
-        if (av_codec_is_encoder(avctx->codec)) {
+        if (is_enc) {
             cblk->layers = av_calloc(codsty->nlayers, sizeof(*cblk->layers));
             if (!cblk->layers)
                 return AVERROR(ENOMEM);
-- 
2.30.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to