Skip to content

animation artifacts #2

@bluesoho16

Description

@bluesoho16

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions