aboutsummaryrefslogtreecommitdiff
path: root/third_party/gif_decoder/src/main/java/com/bumptech/glide
diff options
context:
space:
mode:
authorSam Judd <judds@google.com>2014-10-25 16:27:02 -0700
committerSam Judd <judds@google.com>2014-10-26 11:40:01 -0700
commit78a850159e64118073a66d1ae430133214d08a7a (patch)
tree22cc7a66ea0de8b016ab9d5973ce0aec9691b425 /third_party/gif_decoder/src/main/java/com/bumptech/glide
parent9acc6b7c656833022a6b0839c303d0fb49750831 (diff)
downloadglide-78a850159e64118073a66d1ae430133214d08a7a.tar.gz
Synchronize gif decoder getNextFrame.
This does not make GifDecoder thread safe in that it doesn't guarantee that a decoder will decode a particular frame, but should keep state consistent and prevent crashes from concurrent writes to buffers. Fixes #212.
Diffstat (limited to 'third_party/gif_decoder/src/main/java/com/bumptech/glide')
-rw-r--r--third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java36
1 files changed, 18 insertions, 18 deletions
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
index 161c9321..f5c05a15 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
@@ -248,7 +248,7 @@ public class GifDecoder {
*
* @return Bitmap representation of frame.
*/
- public Bitmap getNextFrame() {
+ public synchronized Bitmap getNextFrame() {
if (header.frameCount <= 0 || framePointer < 0) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "unable to decode frame, frameCount=" + header.frameCount + " framePointer=" + framePointer);
@@ -263,23 +263,28 @@ public class GifDecoder {
}
status = STATUS_OK;
- GifFrame frame = header.frames.get(framePointer);
+ GifFrame currentFrame = header.frames.get(framePointer);
+ GifFrame previousFrame = null;
+ int previousIndex = framePointer - 1;
+ if (previousIndex >= 0) {
+ previousFrame = header.frames.get(previousIndex);
+ }
// Set the appropriate color table.
- if (frame.lct == null) {
+ if (currentFrame.lct == null) {
act = header.gct;
} else {
- act = frame.lct;
- if (header.bgIndex == frame.transIndex) {
+ act = currentFrame.lct;
+ if (header.bgIndex == currentFrame.transIndex) {
header.bgColor = 0;
}
}
int save = 0;
- if (frame.transparency) {
- save = act[frame.transIndex];
+ if (currentFrame.transparency) {
+ save = act[currentFrame.transIndex];
// Set transparent color if specified.
- act[frame.transIndex] = 0;
+ act[currentFrame.transIndex] = 0;
}
if (act == null) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
@@ -291,11 +296,11 @@ public class GifDecoder {
}
// Transfer pixel data to image.
- Bitmap result = setPixels(framePointer);
+ Bitmap result = setPixels(currentFrame, previousFrame);
// Reset the transparent pixel in the color table
- if (frame.transparency) {
- act[frame.transIndex] = save;
+ if (currentFrame.transparency) {
+ act[currentFrame.transIndex] = save;
}
return result;
@@ -416,13 +421,8 @@ public class GifDecoder {
/**
* Creates new frame image from current data (and previous frames as specified by their disposition codes).
*/
- private Bitmap setPixels(int frameIndex) {
- GifFrame currentFrame = header.frames.get(frameIndex);
- GifFrame previousFrame = null;
- int previousIndex = frameIndex - 1;
- if (previousIndex >= 0) {
- previousFrame = header.frames.get(previousIndex);
- }
+ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) {
+
int width = header.width;
int height = header.height;