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

Apng with region clearing #3

Closed
marcos-dogonahorse opened this issue Apr 12, 2017 · 1 comment
Closed

Apng with region clearing #3

marcos-dogonahorse opened this issue Apr 12, 2017 · 1 comment

Comments

@marcos-dogonahorse
Copy link

marcos-dogonahorse commented Apr 12, 2017

hi Aellerton,

I notice a bug while working with your wrapper around japng. It seems in the latest code, you clear the whole screen every time the FrameController return a 1 in the disposeOP ( PngAnimationComposer.java -> function completeFrame(Argb8888Bitmap frameImage) )

The problem with that is that there are images that depend on the previous screen being only partly clear. These reduces the png file size and is completely supported by the APNG standers ( https://developer.mozilla.org/en-US/docs/Mozilla/Tech/APNG#.27fcTL.27:_The_Frame_Control_Chunk
)

The solution to that problem is that you always only clear the region of the next frame.

so this should be the new switch statement in that function:

switch (currentFrame.disposeOp) {
            case 1: // APNG_DISPOSE_OP_BACKGROUND
                Rect region = new Rect(currentFrame.xOffset, currentFrame.yOffset, currentFrame.xOffset + currentFrame.width, currentFrame.yOffset + currentFrame.height);
                canvas.drawRect(region, clearModePaint);
                break;
            case 2: // APNG_DISPOSE_OP_PREVIOUS
                //System.out.println(String.format("Frame %d restore previous (full=%s, x=%d y=%d w=%d h=%d) previous=%s", currentFrame.sequenceNumber,
                //        isFull, currentFrame.xOffset, currentFrame.yOffset, currentFrame.width, currentFrame.height, previous));

                // Put the original section back
                if (null != previous) {
                    //paint = new Paint();
                    //paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
                    paint = srcModePaint;
                    canvas.drawBitmap(previous, currentFrame.xOffset, currentFrame.yOffset, paint);

                    //System.out.println("  Restored previous "+previous.getWidth()+" x "+previous.getHeight());
                    previous.recycle();
                } else {
                    System.out.println("  Huh, no previous?");
                }
                break;

            case 0: // APNG_DISPOSE_OP_NONE
            default: // Default should never happen
                // do nothing
                //System.out.println("Frame "+currentFrame.sequenceNumber+" do nothing dispose");
                break;

        }

clearModePaint is just a paint that i store from the constructor
this.clearModePaint = new Paint(); this.clearModePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

Here is an sample image that you can see the problem in:
12338-img-l-1491582573446 w400

Thank you again for the wrapper 👍

@aellerton
Copy link
Owner

aellerton commented Apr 13, 2017 via email

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