From 4fcb6cd5b3dbd7ecc58d3e3dcb7a3d8304e54a16 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Tue, 21 Oct 2014 19:31:46 -0700 Subject: Set minimum and default frame delays. Fixes #205. --- .../glide/gifdecoder/test/GifBytesTestUtil.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java') diff --git a/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java b/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java index e389deed..b6f3140e 100644 --- a/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java +++ b/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java @@ -10,6 +10,8 @@ public class GifBytesTestUtil { public static final int HEADER_LENGTH = 13; // Length in bytes. public static final int IMAGE_DESCRIPTOR_LENGTH = 10; + // Length in bytes. + public static final int GRAPHICS_CONTROL_EXTENSION_LENGTH = 8; public static int getColorTableLength(int numColors) { return 3 * numColors; @@ -104,6 +106,29 @@ public class GifBytesTestUtil { out.put((byte) 0); } + public static void writeGraphicsControlExtension(ByteBuffer out, int delayTime) { + verifyRemaining(out, GRAPHICS_CONTROL_EXTENSION_LENGTH); + verifyShortValues(delayTime); + + // Extension inducer (constant). + out.put((byte) 0x21); + // Graphic control label (constant). + out.put((byte) 0xF9); + // Block size (constant). + out.put((byte) 0x04); + // Packed (disposal method, user input, transparent color flag) + out.put((byte) 0x00); + + // Frame delay in 100ths of a second. + out.putShort((short) delayTime); + + // Transparent color index. + out.put((byte) 0x00); + + // Block terminator (constant). + out.put((byte) 0x00); + } + private static void verifyRemaining(ByteBuffer buffer, int expected) { if (buffer.remaining() < expected) { throw new IllegalArgumentException("Must have at least " + expected + " bytes to write"); -- cgit v1.2.3