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

animation artifacts #2

Open
bluesoho16 opened this issue Mar 29, 2017 · 3 comments
Open

animation artifacts #2

bluesoho16 opened this issue Mar 29, 2017 · 3 comments

Comments

@bluesoho16
Copy link

When animating with this APNG:
https://en.wikipedia.org/wiki/File:Animated_PNG_example_bouncing_beach_ball.png

Visible artifacts can be seen (dragging blue trail on bouncing ball). This is caused by not properly handling the "dispose_op" value (specifically, when "dispose_op" has value of "1":
https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk

Here is my fix:
PngAnimationComposer.java

    ...
    private PngFrameControl currentFrame;
    private PngFrameControl previousFrame;
    ...

    public void completeFrame(Argb8888Bitmap frameImage) {
        Bitmap frame = PngAndroid.toBitmap(frameImage);
        Paint paint = null;
        Drawable d;
        Bitmap previous=null;

        if(previousFrame != null) {
            if (1 == previousFrame.disposeOp) {
                canvas.drawColor(0, PorterDuff.Mode.CLEAR);
            }

            if (2 == previousFrame.disposeOp) {
                previous = Bitmap.createBitmap(canvasBitmap, currentFrame.xOffset, currentFrame.yOffset, currentFrame.width, currentFrame.height); // or could use from frames?
            }
        }
        if (0 == currentFrame.blendOp) {
            paint = srcModePaint;
        }

       ...
        previousFrame = currentFrame;
        currentFrame = null;
    }
@aellerton
Copy link
Owner

Excellent! I'll integrate that. Thank you!

@aellerton
Copy link
Owner

@bluesoho16 Can you please post the complete PngAnimationComposer.java or a PR?

Thanks!

@marcos-dogonahorse
Copy link

marcos-dogonahorse commented Apr 12, 2017

For everyone that is having problem with this bug, please look at #3

@bluesoho16 you should be careful with
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
because that would "clear" the whole screen which is not what it should be doing. It should be clearing only the region that the previous frame was drawn at

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

3 participants