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

Fix "restore to previous" #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/main/java/com/madgag/gif/fmsware/GifDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class GifDecoder {
protected Rectangle lastRect; // last image rect
protected BufferedImage image; // current frame
protected BufferedImage lastImage; // previous frame
protected BufferedImage restorePrevImage; // for restore to previous

protected byte[] block = new byte[256]; // current data block
protected int blockSize = 0; // block size
Expand Down Expand Up @@ -162,13 +163,7 @@ protected void setPixels() {
// fill in starting image contents based on last image's dispose code
if (lastDispose > 0) {
if (lastDispose == 3) {
// use image before last
int n = frameCount - 2;
if (n > 0) {
lastImage = getFrame(n - 1);
} else {
lastImage = null;
}
lastImage = restorePrevImage;
}

if (lastImage != null) {
Expand All @@ -194,6 +189,15 @@ protected void setPixels() {
}
}

// copy before drawing for restore to previous
if (dispose == 3) {
if (restorePrevImage == null) {
restorePrevImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
}
int[] restore = ((DataBufferInt) restorePrevImage.getRaster().getDataBuffer()).getData();
System.arraycopy(dest, 0, restore, 0, width * height);
}

// copy each source line to the appropriate place in the destination
int pass = 1;
int inc = 8;
Expand Down