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

png support for 1, 2 or 4 bit depths? #508

Open
webisu opened this issue Sep 18, 2024 · 4 comments · May be fixed by #526
Open

png support for 1, 2 or 4 bit depths? #508

webisu opened this issue Sep 18, 2024 · 4 comments · May be fixed by #526
Assignees
Labels
enhancement New feature or request

Comments

@webisu
Copy link

webisu commented Sep 18, 2024

Does g2c support png-encoded grib files with bit depths of 1, 2 or 4?

@DusanJovic-NOAA
Copy link
Contributor

DusanJovic-NOAA commented Oct 2, 2024

As far as I can tell, no. The reason is that in png decoding routine, if the image is encoded with less than 8 bits per pixel, this line:

174     bytes = bit_depth / 8;
175     clen = (*width) * bytes;
176     for (j = 0; j < *height; j++)

for bit_depth less than 8 (ie. 1, 2 or 4) will incorrectly set bytes to 0, and then clen will be 0, which is incorrect.

Instead, to support bit depths < 8, I think this should be changed to either bytes = (width * nbits) / 8 or to  bytes = (width * nbits) / 8 + 1 depending on whether width * bits is divisible by 8 or not.
And probably the loop that copies data from png arrays to g2c arrays needs to be changed as well.

I can try to update the code if we need to support this feature.

@DusanJovic-NOAA
Copy link
Contributor

Are there sample files encoded with 1, 2 and 4 bit depths? Is this needed for production?

@webisu
Copy link
Author

webisu commented Oct 3, 2024 via email

@DusanJovic-NOAA
Copy link
Contributor

See changes in #526

@edwardhartnett edwardhartnett added the enhancement New feature or request label Oct 10, 2024
@edwardhartnett edwardhartnett linked a pull request Oct 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To do
Development

Successfully merging a pull request may close this issue.

3 participants