You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Jasper does not write cdef box for output with opacity #392
The attached file is a jp2 with rgb and a channels. (I made it in Photoshop and saved it using its "Save a Copy…" feature, which under the hood seems to use kakadu.) Its cdef says that component 0 is color 1 (red), 1 is 2 (blue), 2 is 3 (green), and 3 is alpha associated with the entire image.
If I re-encode this image using jasper, e.g. with build/src/app/jasper --input Tests/LibGfx/test-inputs/jpeg2000/kakadu-lossless-rgba-u8-prog1-layers1-res6-mct.jp2 --output jasper-tile3x2-res5.jp2 -O tilewidth=39 -O tileheight=53 -O numrlvls=5, it doesn't write a cdef box.
I believe this is incorrect.
T.800, I.5.3.6 Channel Definition box: "If the JP2 Header box does not contain a Component Mapping box, then a reader shall map component i to channel i, for all components in the codestream."
T.800 Table 1.18 maps 1 to R, 2 to G, 3 to B, and 4 to nothing. (The spec text probably means "map component i to channel i + 1".) That is, per spec, the last component, alpha, should be ignored if there's no cdef box.
And indeed, Preview.app at least displays jasper's output as if it didn't contain an alpha channel.
changed the title [-]Jasper does not write cdef box for output with opactiy[/-][+]Jasper does not write cdef box for output with opacity[/+]on Mar 2, 2025
@nico: I am sorry that it took so long to address this issue. I looked at the code more carefully, and as far as I can tell your "hack" as you call it appears to be a very reasonable (i.e., non-hacky) fix. It seems that JasPer was being too strict about when a CDEF box is generated. I think that a CDEF box should only be omitted in a very specific circumstance but using ">= 3" instead of "== 3" was causing the CDEF box to be omitted in many other cases as well. Anyways, I have adopted your fix and made a similar correction for the other color spaces as well, since it would appear that the same problem also exists for YCBCR and GRAY color spaces. I have made a new release of JasPer (4.2.9) that includes this fix. So, you might want to switch to it, if this issue is a significant one for you.
Activity
nico commentedon Feb 3, 2025
Here's a hack; a real fix probably would want to check if the fourth component is opacity.
With this, jasper produces a jp2 with a cdef box that looks right, and its output does show up with transparency in Preview.app.
Tests/LibGfx: Replace test image for SerenityOS#25678 with better one
nico commentedon Feb 3, 2025
(OpenJPEG's
opj_encodedoes write this cdef box with a similar invocation, fwiw.)Tests/LibGfx: Replace test image for #25678 with better one
Tests/LibGfx: Add tests for JPEG2000 code block style
Tests/LibGfx: Add tests for JPEG2000 code block style
Tests/LibGfx: Add tests for JPEG2000 code block style
[-]Jasper does not write cdef box for output with opactiy[/-][+]Jasper does not write cdef box for output with opacity[/+]mdadams commentedon Mar 5, 2026
@nico: I am sorry that it took so long to address this issue. I looked at the code more carefully, and as far as I can tell your "hack" as you call it appears to be a very reasonable (i.e., non-hacky) fix. It seems that JasPer was being too strict about when a CDEF box is generated. I think that a CDEF box should only be omitted in a very specific circumstance but using ">= 3" instead of "== 3" was causing the CDEF box to be omitted in many other cases as well. Anyways, I have adopted your fix and made a similar correction for the other color spaces as well, since it would appear that the same problem also exists for YCBCR and GRAY color spaces. I have made a new release of JasPer (4.2.9) that includes this fix. So, you might want to switch to it, if this issue is a significant one for you.
Fixes jasper-software#392.
nico commentedon Apr 24, 2026
Thanks for the fix!