Previously, the VP8X chunk dimensions were incorrectly set based on the last frame encountered, which could result in canvas dimensions being too small when frames of varying sizes were present.
The code has been updated to track the maximum width and height across all frames, ensuring that the VP8X chunk accurately reflects the overall canvas size.
The library failed to correctly detect and set the alpha flag in the VP8X chunk for animated WebP files where ALPH chunks were nested within ANMF chunks.
A new function, _get_sub_chunks_from_anmf, has been introduced to recursively examine sub-chunks within ANMF chunks while preventing excessive recursion through a depth limit.
This ensures that the alpha flag is properly set when transparency data is present in any frame of the animation.
Testing
Verified the correctness of canvas size detection and alpha channel handling by running the included tests with various animated WebP files.
Confirmed that the changes do not introduce any regressions for non-animated WebP files.
Description
This pull request addresses two key issues related to handling animated WebP files in the Piexif library:
Canvas Size Detection:
VP8X
chunk dimensions were incorrectly set based on the last frame encountered, which could result in canvas dimensions being too small when frames of varying sizes were present.VP8X
chunk accurately reflects the overall canvas size.Alpha Channel Detection for Animated Frames:
VP8X
chunk for animated WebP files whereALPH
chunks were nested withinANMF
chunks._get_sub_chunks_from_anmf
, has been introduced to recursively examine sub-chunks withinANMF
chunks while preventing excessive recursion through a depth limit.Testing