Skip to content

Commit

Permalink
Merge pull request #1093 from TWiStErRob/gif_dispose
Browse files Browse the repository at this point in the history
Fill only the area that was modified by the previous GIF frame
  • Loading branch information
sjudd committed Mar 25, 2016
2 parents 2fc89a9 + e15172e commit 258cc10
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
* Reads frame data from a GIF image source and decodes it into individual frames
Expand Down Expand Up @@ -434,7 +433,15 @@ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) {
c = 0;
}
}
Arrays.fill(dest, c);
// The area used by the graphic must be restored to the background color.
int topLeft = previousFrame.iy * width + previousFrame.ix;
int bottomLeft = topLeft + previousFrame.ih * width;
for (int left = topLeft; left < bottomLeft; left += width) {
int right = left + previousFrame.iw;
for (int pointer = left; pointer < right; pointer++) {
dest[pointer] = c;
}
}
} else if (previousFrame.dispose == DISPOSAL_PREVIOUS && previousImage != null) {
// Start with the previous frame
previousImage.getPixels(dest, 0, width, 0, 0, width, height);
Expand Down

0 comments on commit 258cc10

Please sign in to comment.