openjpeg icon indicating copy to clipboard operation
openjpeg copied to clipboard

`opj_compress` sometimes loses data when encoding in lossless mode

Open nico opened this issue 11 months ago • 1 comments

Repro:

  1. Download this input file: ref.zip It contains ref.bmp.

It looks like so (in png form, for github's preview):

Image

  1. Download osx-arm64 version from https://github.com/uclouvain/openjpeg/releases/tag/v2.5.3, fix up the rpath with install_name_tool -add_rpath "@loader_path/../lib" ~/Downloads/openjpeg-v2.5.3-osx-arm64/bin/opj_compress

  2. Compress ref.bmp losslessly like so: ~/Downloads/openjpeg-v2.5.3-osx-arm64/bin/opj_compress -i ref.bmp -o openjpeg-lossless-rgba-u8-prog0-tile3x2-res5.jp2 -n 5 -t 39,53 -C "opj_compress -n 5 -t 39,53"

  3. Uncompress it again (or look at it in Preview.app): ~/Downloads/openjpeg-v2.5.3-osx-arm64/bin/opj_decompress -i openjpeg-lossless-rgba-u8-prog0-tile3x2-res5.jp2 -o out.png

The output looks like so:

Image

Note the two white stripes at the far right. (This is a true effect in the color channels, not an alpha handling effect.)

This is probably related to the rightmost tiles being just 2 pixels wide. Since we have 4 decompositions, the LL band and the first decomposition after it are empty, which might confuse something.

nico avatar Feb 02 '25 02:02 nico

Jasper does not have this problem: % .../jasper-build/src/app/jasper --input ref.bmp --output jasper-tile3x2-res5.jp2 -O tilewidth=39 -O tileheight=53 -O numrlvls=5 also produces a jp2 file that has a 0x4 LL layer in tile 3 and has several empty subbands after this, but it decodes fine in all viewers.

Jasper's output attached: jasper-tile3x2-res5.zip

nico avatar Feb 03 '25 15:02 nico