public GifDrawableLoadProvider(Context context, BitmapPool bitmapPool) { decoder = new GifResourceDecoder(context, bitmapPool); cacheDecoder = new FileToStreamDecoder<GifDrawable>(decoder); encoder = new GifResourceEncoder(bitmapPool); sourceEncoder = new StreamEncoder(); }
@Override public GifDrawableResource decode(InputStream source, int width, int height) { byte[] data = inputStreamToBytes(source); 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); } }
private GifDrawableResource 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(); GifDrawable gifDrawable = new GifDrawable(context, provider, bitmapPool, unitTransformation, width, height, header, data, firstFrame); return new GifDrawableResource(gifDrawable); }