Search in sources :

Example 1 with GifHeader

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);
}
Also used : Options(com.bumptech.glide.load.Options) LruArrayPool(com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool) DefaultImageHeaderParser(com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser) ArrayList(java.util.ArrayList) GifHeader(com.bumptech.glide.gifdecoder.GifHeader) ByteBuffer(java.nio.ByteBuffer) DefaultImageHeaderParser(com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser) ImageHeaderParser(com.bumptech.glide.load.ImageHeaderParser) Before(org.junit.Before)

Example 2 with GifHeader

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);
}
Also used : InOrder(org.mockito.InOrder) GifHeader(com.bumptech.glide.gifdecoder.GifHeader) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with GifHeader

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;
}
Also used : GifDecoder(com.bumptech.glide.gifdecoder.GifDecoder) StandardGifDecoder(com.bumptech.glide.gifdecoder.StandardGifDecoder) GifHeaderParser(com.bumptech.glide.gifdecoder.GifHeaderParser) GifHeader(com.bumptech.glide.gifdecoder.GifHeader)

Example 4 with GifHeader

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);
}
Also used : StandardGifDecoder(com.bumptech.glide.gifdecoder.StandardGifDecoder) GifDecoder(com.bumptech.glide.gifdecoder.GifDecoder) Bitmap(android.graphics.Bitmap) GifHeader(com.bumptech.glide.gifdecoder.GifHeader)

Aggregations

GifHeader (com.bumptech.glide.gifdecoder.GifHeader)4 GifDecoder (com.bumptech.glide.gifdecoder.GifDecoder)2 StandardGifDecoder (com.bumptech.glide.gifdecoder.StandardGifDecoder)2 ByteBuffer (java.nio.ByteBuffer)2 Bitmap (android.graphics.Bitmap)1 GifHeaderParser (com.bumptech.glide.gifdecoder.GifHeaderParser)1 ImageHeaderParser (com.bumptech.glide.load.ImageHeaderParser)1 Options (com.bumptech.glide.load.Options)1 LruArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool)1 DefaultImageHeaderParser (com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1