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

No colorspace information after opj_read_header #570

Closed
HGuillemet opened this issue Aug 26, 2015 · 9 comments
Closed

No colorspace information after opj_read_header #570

HGuillemet opened this issue Aug 26, 2015 · 9 comments

Comments

@HGuillemet
Copy link

image->color_space and image->icc_profile* are only filled in opj_decode() and not in opj_read_header(). This is problematic in situations where the color space must be know before decoding pixel data.

This should be easily fixable by moving from opj_jp2_decode() to opj_jp2_read_header() most of the code that copies color information from the jp2 struct to the image struct.

@lrosenth
Copy link

lrosenth commented Nov 1, 2015

Indeed, this is necessary. I have cases where I need the color space information before decoding the image.

@sebras
Copy link
Contributor

sebras commented Feb 21, 2019

I recently discovered the same. Only after calling opj_decode() is opj_image_t->color_space set. Others have been asking for the same.

Would you accept patches to try to move the colorspace detection code to some function called by opj_read_header()? Maybe there is a reason for why the colorspace is not available until after image decoding?

@mara004
Copy link

mara004 commented Mar 17, 2023

@ OpenJPEG developers: any comments on this issue?
PDFium's FPDFImageObj_GetImageMetadata() function is affected by this problem, too.

@rouault
Copy link
Collaborator

rouault commented Mar 17, 2023

attempt fix in #1463 . I'd appreciate if reporters could test that it actually fixes the issue (I'm not sure openjpeg test suite tests that)

@rouault
Copy link
Collaborator

rouault commented Mar 24, 2023

@mara004 Did you have a chance to test #1463 ?

@mara004
Copy link

mara004 commented Mar 25, 2023

@rouault Unfortunately no, as I'm not using openjpeg directly, but only through pdfium, which bundles openjpeg.
However, I think pdfium may benefit from the change once they update their copy of openjpeg.

Apart from that, could you add a test case to confirm your implementation works?

@sebras
Copy link
Contributor

sebras commented Mar 26, 2023

@rouault I did a little investigation. I think changed so that one can access normal colorspaces after calling opj_read_header(), but not ICC profiles (they still require a call to opj_decode()). So unfortunately I think you only adressed half the bug.

As I understand it file1.jp2 from your testsuite sets sRGB in its COLR box. And now after your commit I see that ->color_space is set to OPJ_CLRSPC_SRGB immediately after the call to opj_read_header(), i.e. no need to call opj_decode() to determine the colorspace.

As for ICC profiles relax.jp2 appears to set an ICC profile in its COLR box and after the call to opj_read_header() then ->icc_profile_len and ->icc_profile_buf are not set. However after I have called opj_decode() both will be populated and I can retrieve and analyze the colorspace.

rouault added a commit to rouault/openjpeg that referenced this issue Mar 26, 2023
@rouault
Copy link
Collaborator

rouault commented Mar 26, 2023

pull request amended to move ICC profile setting to image in read_header()

rouault added a commit that referenced this issue Mar 26, 2023
opj_jp2_read_header(): move setting color_space here instead in opj_jp2_decode()/get_tile() (fixes #570)
@sebras
Copy link
Contributor

sebras commented Mar 26, 2023

@rouault Thank you for fixing this! :)

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

5 participants