aboutsummaryrefslogtreecommitdiff
path: root/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
diff options
context:
space:
mode:
authorSam Judd <judds@google.com>2014-10-21 19:31:46 -0700
committerSam Judd <judds@google.com>2014-10-21 19:31:46 -0700
commit4fcb6cd5b3dbd7ecc58d3e3dcb7a3d8304e54a16 (patch)
tree4b4fca82227416189be4f66af5b9c01d420eb5de /third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
parent39f12e09c7273b13604184e523846c1ef18ff311 (diff)
downloadglide-4fcb6cd5b3dbd7ecc58d3e3dcb7a3d8304e54a16.tar.gz
Set minimum and default frame delays.
Fixes #205.
Diffstat (limited to 'third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java')
-rw-r--r--third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
index 286a5602..126a799c 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
@@ -16,6 +16,11 @@ import static com.bumptech.glide.gifdecoder.GifDecoder.STATUS_FORMAT_ERROR;
public class GifHeaderParser {
public static final String TAG = "GifHeaderParser";
+ // The minimum frame delay in hundredths of a second.
+ static final int MIN_FRAME_DELAY = 3;
+ // The default frame delay in hundredths of a second for GIFs with frame delays less than the minimum.
+ static final int DEFAULT_FRAME_DELAY = 10;
+
private static final int MAX_BLOCK_SIZE = 256;
// Raw data read working array.
private final byte[] block = new byte[MAX_BLOCK_SIZE];
@@ -147,7 +152,12 @@ public class GifHeaderParser {
}
header.currentFrame.transparency = (packed & 1) != 0;
// Delay in milliseconds.
- header.currentFrame.delay = readShort() * 10;
+ int delayInHundredthsOfASecond = readShort();
+ // TODO: consider allowing -1 to indicate show forever.
+ if (delayInHundredthsOfASecond < MIN_FRAME_DELAY) {
+ delayInHundredthsOfASecond = DEFAULT_FRAME_DELAY;
+ }
+ header.currentFrame.delay = delayInHundredthsOfASecond * 10;
// Transparent color index
header.currentFrame.transIndex = read();
// Block terminator