use of com.bumptech.glide.gifdecoder.GifHeader in project glide by bumptech.
the class ByteBufferGifDecoderTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
gifHeader = Mockito.spy(new GifHeader());
when(parser.parseHeader()).thenReturn(gifHeader);
when(parserPool.obtain(isA(ByteBuffer.class))).thenReturn(parser);
when(decoderFactory.build(isA(GifDecoder.BitmapProvider.class), eq(gifHeader), isA(ByteBuffer.class), anyInt())).thenReturn(gifDecoder);
List<ImageHeaderParser> parsers = new ArrayList<ImageHeaderParser>();
parsers.add(new DefaultImageHeaderParser());
options = new Options();
decoder = new ByteBufferGifDecoder(RuntimeEnvironment.application, parsers, bitmapPool, new LruArrayPool(ARRAY_POOL_SIZE_BYTES), parserPool, decoderFactory);
}
use of com.bumptech.glide.gifdecoder.GifHeader in project glide by bumptech.
the class ReEncodingGifResourceEncoderTest method testSetsDataOnParserBeforeParsingHeader.
@Test
public void testSetsDataOnParserBeforeParsingHeader() {
ByteBuffer data = ByteBuffer.allocate(1);
when(gifDrawable.getBuffer()).thenReturn(data);
GifHeader header = mock(GifHeader.class);
when(parser.parseHeader()).thenReturn(header);
encoder.encode(resource, file, options);
InOrder order = inOrder(parser, decoder);
order.verify(parser).setData(eq(data));
order.verify(parser).parseHeader();
order.verify(decoder).setData(header, data);
}
use of com.bumptech.glide.gifdecoder.GifHeader 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.GifHeader 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);
}
Aggregations