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

Sail fails to decode some APNGs #184

Closed
qbnu opened this issue Dec 30, 2022 · 7 comments
Closed

Sail fails to decode some APNGs #184

qbnu opened this issue Dec 30, 2022 · 7 comments

Comments

@qbnu
Copy link

qbnu commented Dec 30, 2022

Sail fails to decode Animated PNG files which use a Color Type other than 6 and APNG_BLEND_OP_OVER. This is because png_private_blend_over only supports RGBA, and doesn't check the tRNS chunk. Even if the PNG doesn't have any transparency information, blend_source should be used instead (equivalent to blend_over assuming all pixels are opaque).

Examples from https://philip.html5.org/tests/apng/tests.html:
8-bit greyscale and alpha, with blending
1-bit palette and alpha, with blending

const char* filename = "038.png";
sail_image* image = NULL;
const sail_codec_info* codec_info = NULL;
void* state = NULL;
sail_codec_info_from_extension("png", &codec_info); // SAIL_OK
sail_start_loading_from_file(filename, codec_info, &state); // SAIL_OK
sail_load_next_frame(state, &image); // SAIL_OK
sail_load_next_frame(state, &image); // SAIL_ERROR_UNSUPPORTED_BIT_DEPTH

And here's a 16-bit grayscale+alpha APNG that will incorrectly be blended as if it's 8-bit RGBA:
grayanim16

@HappySeaFox
Copy link
Owner

HappySeaFox commented Dec 31, 2022

I agree there are some blending issues. I've just fixed a memory corruption issue (at least on MSVC 2019) on free() and allowed blending for BPP16-GRAYSCALE-ALPHA and BPP32-GRAYSCALE-ALPHA pixel formats. I will probably continue looking into it (sorry cannot guarantee).

Regarding the 8-bit greyscale and alpha, with blending image: it has three frames:

  1. The first frame is hidden.
  2. The second frame is black (gray component: 0, alpha: 255), blending mode: over.
  3. The 3rd frame consists of semi-transparent white pixels which will look like gray after blending with black pixels (gray component: 255, alpha: 128), blending mode: over.

https://philip.html5.org/tests/apng/tests.html specifies that the image should be rendered as This should be solid grey. but I have a question why 🤔 The second frame is black. The third (blended) frame is gray. I would expect flashing black and gray frames and this is what I see currently in the local fixed SAIL version.

@qbnu
Copy link
Author

qbnu commented Jan 1, 2023

If the image viewer respects num_plays in the acTL chunk then it should just play once and pause on the last frame.

@HappySeaFox
Copy link
Owner

HappySeaFox commented Jan 1, 2023

Oh, I see. This explains a lot. The next rc will have blending of grayscale frames and I'll add num_plays as a special property for those who are interested.

@HappySeaFox
Copy link
Owner

Did you install sail through vcpkg?

@qbnu
Copy link
Author

qbnu commented Jan 1, 2023

No, I built it from source.

@HappySeaFox
Copy link
Owner

You can try the latest master with blending of grayscale images.

@HappySeaFox
Copy link
Owner

Please reopen if needed

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