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

Animated PNG is decoded incorrectly #2265

Closed
SludgePhD opened this issue Jun 23, 2024 · 3 comments
Closed

Animated PNG is decoded incorrectly #2265

SludgePhD opened this issue Jun 23, 2024 · 3 comments
Labels
kind: bug kind: incorrect This bug causes wrong image data

Comments

@SludgePhD
Copy link
Contributor

SludgePhD commented Jun 23, 2024

Expected

bonzi-book

This is how the animation should look (assuming your browser correctly implements APNG decoding; Firefox and Chromium-based browsers work fine in my tests).

Actual behaviour

Screencast_20240623_180709.webm

Using image to decode the animation and rendering the result to a window produces this flickering output instead. Other images work fine, so I don't think the bug is in my code.

Reproduction steps

The failing APNG is attached above.

@ripytide
Copy link
Member

ripytide commented Jun 25, 2024

I can reproduce the issue:

use std::io::Cursor;

use image::codecs::png::PngDecoder;
use image::AnimationDecoder;

fn main() {
    let png_decoder = PngDecoder::new(Cursor::new(std::fs::read("monkey.png").unwrap())).unwrap();

    let apng_decoder = png_decoder.apng().unwrap();

    let frames = apng_decoder.into_frames().collect_frames().unwrap();

    for (i, frame) in frames.into_iter().enumerate() {
        frame
            .buffer()
            .save_with_format(format!("frame-{i}.png"), image::ImageFormat::Png)
            .unwrap();
    }
}

It seems frames 2, 12 and 13 have missing sections (possibly via alpha=0) and all other frames seem fine.

@Shnatsel
Copy link
Contributor

At a glance this looks like an issue with compositing. Those frames do not change the the book, so that area is omitted from the frames. Other decoders fill in that area from the composited result of the previous frames, but apparently image does not.

We have correct compositing in the GIF decoder in image already. It even handles memory limits. We should generalize it to APNG and WebP animations too.

@MocA-Love
Copy link

MocA-Love commented Sep 14, 2024

I'm currently running into the same problem and will look into it.
I wonder if it's around DisposeOp since the hand is still in the middle.

a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug kind: incorrect This bug causes wrong image data
Projects
None yet
Development

No branches or pull requests

5 participants