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

Possible bug reading JP2 as grayscale when should be in color #1464

Closed
fmw42 opened this issue Apr 15, 2023 · 3 comments
Closed

Possible bug reading JP2 as grayscale when should be in color #1464

fmw42 opened this issue Apr 15, 2023 · 3 comments

Comments

@fmw42
Copy link

fmw42 commented Apr 15, 2023

Operating system

MacOS

Operating system, version and so on

Monterey

Description

The attached image seems to be coded improperly or there is a bug. Can you identify which?

Exiftool says:

 0 ImageHeight                     : 10000
    4 ImageWidth                      : 10000
    8 NumberOfComponents              : 4

but it also says

    3 ColorSpace                      : Grayscale

NumberOfComponents I interpret as having 4 channels, RGBI or RGBA, but then it says colorspace is grayscale. So I am confused about this file.

Steps to Reproduce

See above

Images

http://www.fmwconcepts.com/misc_tests/dop10rgbi_32_280_5652_1_nw_2021.jp2.zip

Original from first file at https://www.opengeodata.nrw.de/produkte/geobasis/lusat/dop/dop_jp2_f10/, but there are a lot of files there that likely have the same issue.

Most tools that I have used (such as GIMP and Photoshop and GraphicConverter) seem to read the file open it as grayscale (with or without) an alpha channel. I believe that is wrong. It should be an RGB with IR channel or perhaps alpha channel, not sure which.

Are these tools reading it with old JP2 software? Or is this a miscoding on the creator of the files? Or is this a bug in OpenJpeg code for JP2?

@rouault
Copy link
Collaborator

rouault commented Apr 15, 2023

The issue is that the value of the EnumCS of the colr box is 17=GreyScale. It should rather be 16=sRGB

    <JP2Box name="colr" box_offset="66" box_length="15" data_offset="74" data_length="7">
      <BinaryContent>01000000000011</BinaryContent>
      <DecodedContent>
        <Field name="METH" type="uint8" description="Enumerated Colourspace">1</Field>
        <Field name="PREC" type="uint8">0</Field>
        <Field name="APPROX" type="uint8">0</Field>
        <Field name="EnumCS" type="uint32" description="greyscale">17</Field>
      </DecodedContent>
    </JP2Box>

@rouault rouault closed this as completed Apr 15, 2023
@rouault
Copy link
Collaborator

rouault commented Apr 15, 2023

by the way recent versions of Kakadu also complain about that file: "Looks like the file contains an illegal channel definitions (cdef) box; trying to fix the problem so that content can still be rendered."

@fmw42
Copy link
Author

fmw42 commented Apr 15, 2023

Agreed. It likely needs to be coded as RGB not grayscale. Also the 4th channel is coded as alpha and I think it might be an IR channel. The files are likely miscoded or they were created under an earlier definition of the format, though I suspect the former is the issue.

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

2 participants