Opened 10 years ago

Closed 5 years ago

#4681 closed defect (fixed)

Reference sample p0_03.j2k (ROI) shows artefacts

Reported by: Carl Eugen Hoyos Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: j2k
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

$ ffmpeg -i p0_03.j2k out.bmp
ffmpeg version N-73193-gf4be604 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 45.101 / 56. 45.101
  libavformat    56. 38.102 / 56. 38.102
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 18.100 /  5. 18.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
[jpeg2000 @ 0x31400a0] unsupported marker 0xFF63 at pos 0x57
[jpeg2000 @ 0x31400a0] unsupported marker 0xFF5E at pos 0x136
Input #0, j2k_pipe, from 'p0_03.j2k':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: jpeg2000 (JPEG 2000 codestream restriction 1), gray(4 bpc), 256x256, 25 tbr, 25 tbn, 25 tbc
Output #0, image2, to 'out.bmp':
  Metadata:
    encoder         : Lavf56.38.102
    Stream #0:0: Video: bmp, gray(4 bpc), 256x256, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.45.101 bmp
Stream mapping:
  Stream #0:0 -> #0:0 (jpeg2000 (native) -> bmp (native))
Press [q] to stop, [?] for help
[jpeg2000 @ 0x3147100] unsupported marker 0xFF63 at pos 0x57
[jpeg2000 @ 0x3147100] unsupported marker 0xFF5E at pos 0x136
frame=    1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A
video:65kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Attachments (1)

p0_03.j2k (12.5 KB ) - added by Carl Eugen Hoyos 10 years ago.

Download all attachments as: .zip

Change History (3)

by Carl Eugen Hoyos, 10 years ago

Attachment: p0_03.j2k added

comment:1 by Michael Niedermayer, 10 years ago

Summary: Reference sample p0_03.j2k shows artefactsReference sample p0_03.j2k (ROI) shows artefacts

comment:2 by Carl Eugen Hoyos, 5 years ago

Resolution: fixed
Status: newclosed

Fixed by Gautam Ramakrishnan in e58766ba12bc86f54af1d8078cbe02f45b1686aa

The following change makes decoding bit-exact with kdu_render and opj_decompress:

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 ||

Note: See TracTickets for help on using tickets.