use of com.bumptech.glide.gifdecoder.GifDecoder in project glide by bumptech.
the class ReEncodingGifResourceEncoder method encodeTransformedToStream.
private boolean encodeTransformedToStream(GifDrawable drawable, OutputStream os) {
Transformation<Bitmap> transformation = drawable.getFrameTransformation();
GifDecoder decoder = decodeHeaders(drawable.getBuffer());
AnimatedGifEncoder encoder = factory.buildEncoder();
if (!encoder.start(os)) {
return false;
}
for (int i = 0; i < decoder.getFrameCount(); i++) {
Bitmap currentFrame = decoder.getNextFrame();
Resource<Bitmap> transformedResource = getTransformedFrame(currentFrame, transformation, drawable);
try {
if (!encoder.addFrame(transformedResource.get())) {
return false;
}
int currentFrameIndex = decoder.getCurrentFrameIndex();
int delay = decoder.getDelay(currentFrameIndex);
encoder.setDelay(delay);
decoder.advance();
} finally {
transformedResource.recycle();
}
}
return encoder.finish();
}
use of com.bumptech.glide.gifdecoder.GifDecoder in project glide by bumptech.
the class ReEncodingGifResourceEncoder method decodeHeaders.
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;
}
use of com.bumptech.glide.gifdecoder.GifDecoder in project glide by bumptech.
the class ByteBufferGifDecoder method decode.
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);
}
use of com.bumptech.glide.gifdecoder.GifDecoder in project glide by bumptech.
the class ByteBufferGifDecoder method decode.
@Nullable
private GifDrawableResource decode(ByteBuffer byteBuffer, int width, int height, GifHeaderParser parser, Options options) {
long startTime = LogTime.getLogTime();
try {
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);
return new GifDrawableResource(gifDrawable);
} finally {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Decoded GIF from stream in " + LogTime.getElapsedMillis(startTime));
}
}
}
use of com.bumptech.glide.gifdecoder.GifDecoder in project glide by bumptech.
the class GifFrameResourceDecoderTest method setUp.
@Before
public void setUp() {
gifDecoder = mock(GifDecoder.class);
resourceDecoder = new GifFrameResourceDecoder(mock(BitmapPool.class));
options = new Options();
}
Aggregations