Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opj_compress sometimes loses data when encoding in lossless mode #1575

Open
nico opened this issue Feb 2, 2025 · 1 comment
Open

opj_compress sometimes loses data when encoding in lossless mode #1575

nico opened this issue Feb 2, 2025 · 1 comment

Comments

@nico
Copy link

nico commented Feb 2, 2025

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
Copy link
Author

nico commented Feb 3, 2025

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 added a commit to nico/serenity that referenced this issue Feb 3, 2025
The test image added in SerenityOS#25678 had wonky borders, due to
uclouvain/openjpeg#1575. Recreate it using jasper instead of
openjpeg, which doesn't have this problem.

jasper does have the problem that it doesn't write a cdef box,
which I think is invalid, so I built jasper with this local hack
to work around that:
jasper-software/jasper#392 (comment)

Image created using

    build/src/app/jasper --input \
        Tests/LibGfx/test-inputs/jpeg2000/kakadu-lossless-*.jp2 \
        --output jasper-tile3x2-res5.jp2 \
        -O tilewidth=39 -O tileheight=53 -O numrlvls=5

I verified that the new image still triggers the crash without the
code change in SerenityOS#25678.
nico added a commit to SerenityOS/serenity that referenced this issue Feb 4, 2025
The test image added in #25678 had wonky borders, due to
uclouvain/openjpeg#1575. Recreate it using jasper instead of
openjpeg, which doesn't have this problem.

jasper does have the problem that it doesn't write a cdef box,
which I think is invalid, so I built jasper with this local hack
to work around that:
jasper-software/jasper#392 (comment)

Image created using

    build/src/app/jasper --input \
        Tests/LibGfx/test-inputs/jpeg2000/kakadu-lossless-*.jp2 \
        --output jasper-tile3x2-res5.jp2 \
        -O tilewidth=39 -O tileheight=53 -O numrlvls=5

I verified that the new image still triggers the crash without the
code change in #25678.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant