private GifTextureResource decode(byte[] data, int width, int height, GifHeaderParser parser, GifDecoder decoder) { final GifHeader header = parser.parseHeader(); if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) { // If we couldn't decode the GIF, we will end up with a frame count of 0. return null; } Bitmap firstFrame = decodeFirstFrame(decoder, header, data); if (firstFrame == null) { return null; } Transformation<Bitmap> unitTransformation = UnitTransformation.get(); GifTexture gifDrawable = new GifTexture(context, provider, bitmapPool, unitTransformation, width, height, header, data, firstFrame); return new GifTextureResource(gifDrawable); }
private GifDecoder decodeHeaders(ByteBuffer data) { GifHeaderParser parser = factory.buildParser(); parser.setData(data); GifHeader header = parser.parseHeader(); GifDecoder decoder = factory.buildDecoder(provider); decoder.setData(header, data); decoder.advance(); return decoder; }
@Override public GifDrawableResource decode(ByteBuffer source, int width, int height, Options options) { final GifHeaderParser parser = parserPool.obtain(source); try { return decode(source, width, height, parser); } finally { parserPool.release(parser); } }
private GifDrawableResource decode(ByteBuffer byteBuffer, int width, int height, GifHeaderParser parser) { long startTime = LogTime.getLogTime(); final GifHeader header = parser.parseHeader(); if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) { // If we couldn't decode the GIF, we will end up with a frame count of 0. return null; } int sampleSize = getSampleSize(header, width, height); GifDecoder gifDecoder = gifDecoderFactory.build(provider, header, byteBuffer, sampleSize); gifDecoder.advance(); Bitmap firstFrame = gifDecoder.getNextFrame(); if (firstFrame == null) { return null; } Transformation<Bitmap> unitTransformation = UnitTransformation.get(); GifDrawable gifDrawable = new GifDrawable(context, gifDecoder, bitmapPool, unitTransformation, width, height, firstFrame); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Decoded GIF from stream in " + LogTime.getElapsedMillis(startTime)); } return new GifDrawableResource(gifDrawable); }
@Override public GifDrawableResource decode(ByteBuffer source, int width, int height, Options options) { final GifHeaderParser parser = parserPool.obtain(source); try { return decode(source, width, height, parser, options); } finally { parserPool.release(parser); } }
private GifDrawableResource decode( ByteBuffer byteBuffer, int width, int height, GifHeaderParser parser, Options options) { long startTime = LogTime.getLogTime(); final GifHeader header = parser.parseHeader(); if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) { // If we couldn't decode the GIF, we will end up with a frame count of 0. return null; } Bitmap.Config config = options.get(GifOptions.DECODE_FORMAT) == DecodeFormat.PREFER_RGB_565 ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888; int sampleSize = getSampleSize(header, width, height); GifDecoder gifDecoder = gifDecoderFactory.build(provider, header, byteBuffer, sampleSize); gifDecoder.setDefaultBitmapConfig(config); gifDecoder.advance(); Bitmap firstFrame = gifDecoder.getNextFrame(); if (firstFrame == null) { return null; } Transformation<Bitmap> unitTransformation = UnitTransformation.get(); GifDrawable gifDrawable = new GifDrawable(context, gifDecoder, unitTransformation, width, height, firstFrame); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Decoded GIF from stream in " + LogTime.getElapsedMillis(startTime)); } return new GifDrawableResource(gifDrawable); }
@Override public GifDataResource decode(InputStream source, int width, int height) throws IOException { byte[] data = inputStreamToBytes(source); GifHeader header = new GifHeaderParser(data).parseHeader(); String id = getGifId(data); return new GifDataResource(new GifData(context, bitmapPool, id, header, data)); }
public GifTextureResource decode(byte[] data, int width, int height) { final GifHeaderParser parser = parserPool.obtain(data); final GifDecoder decoder = decoderPool.obtain(provider); try { return decode(data, width, height, parser, decoder); } finally { parserPool.release(parser); decoderPool.release(decoder); } }
public GifHeaderParser buildParser() { return new GifHeaderParser(); }
public synchronized void release(GifHeaderParser parser) { parser.clear(); pool.offer(parser); }
GifHeaderParser buildParser() { return new GifHeaderParser(); }
synchronized void release(GifHeaderParser parser) { parser.clear(); pool.offer(parser); }