[FFmpeg-devel] [PATCH 2/2] libavcodec/jpeg2000dec.c: ROI marker support
Carl Eugen Hoyos
ceffmpeg at gmail.com
Mon Apr 20 23:43:01 EEST 2020
Am Mo., 20. Apr. 2020 um 21:38 Uhr schrieb <gautamramk at gmail.com>:
>
> From: Gautam Ramakrishnan <gautamramk at gmail.com>
>
> This patch adds support for decoding images
> with a Region of Interest. Allows decoding
> samples such as p0_03.j2k. This patch should
> fix ticket #4681.
The following inlined poc makes FFmpeg's output for this
sample bit-exact with kdu_render and opj_decompress.
jasper's output file looks ugly.
Carl Eugen
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index af6dcee228..5380596c04 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1921,7 +1921,9 @@ static inline void tile_codeblocks
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;
\
}
\
@@ -1930,7 +1932,9 @@ static inline void tile_codeblocks
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;
\
}
\
@@ -1972,7 +1976,7 @@ static int jpeg2000_decode_tile
}
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 ||
More information about the ffmpeg-devel
mailing list