Hi!

Attached patch makes the output of the reference sample p0_03.j2k
bit-exact with opj_decompress and kdu_render and more similar to
jasper's output.

Please comment, Carl Eugen
From de80453a8decd95b4a71cea71b20ba0bd74485cb Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffm...@gmail.com>
Date: Sat, 25 Apr 2020 18:31:22 +0200
Subject: [PATCH] lavc/jpeg2000dec: Scale 4-7 bit output to 8 bits.

Makes p0_03.j2k output bitexact with opj_decompress and kdu_render
and more similar with the output of jasper.
---
 libavcodec/jpeg2000dec.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 460a4ad95c..8d7c729530 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1938,7 +1938,9 @@ static inline void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile
                         int val = lrintf(*datap) + (1 << (cbps - 1));                             \
                         /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */                  \
                         val  = av_clip(val, 0, (1 << cbps) - 1);                                  \
-                        *dst = val << (precision - cbps);                                         \
+                        *dst = val << ((precision < 8 ? 8 : precision) - cbps);                   \
+                        if (precision < 8)                                                        \
+                            *dst |= *dst >> (8 - precision);                                      \
                         datap++;                                                                  \
                         dst += pixelsize;                                                         \
                     }                                                                             \
@@ -1947,7 +1949,9 @@ static inline void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile
                         int val = *i_datap + (1 << (cbps - 1));                                   \
                         /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */                  \
                         val  = av_clip(val, 0, (1 << cbps) - 1);                                  \
-                        *dst = val << (precision - cbps);                                         \
+                        *dst = val << ((precision < 8 ? 8 : precision) - cbps);                   \
+                        if (precision < 8)                                                        \
+                            *dst |= *dst >> (8 - precision);                                      \
                         i_datap++;                                                                \
                         dst += pixelsize;                                                         \
                     }                                                                             \
@@ -1989,7 +1993,7 @@ static int jpeg2000_decode_tile(AVCodecContext *avctx, void *td,
     }
 
     if (s->precision <= 8) {
-        write_frame_8(s, tile, picture, 8);
+        write_frame_8(s, tile, picture, s->precision);
     } else {
         int precision = picture->format == AV_PIX_FMT_XYZ12 ||
                         picture->format == AV_PIX_FMT_RGB48 ||
-- 
2.24.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-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to