com.bumptech.glide.gifdecoder.GifHeaderParser Java Examples

The following examples show how to use com.bumptech.glide.gifdecoder.GifHeaderParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GifResourceDecoder.java    From giffun with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: GifResourceEncoder.java    From giffun with Apache License 2.0 5 votes vote down vote up
private GifDecoder decodeHeaders(byte[] 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;
}
 
Example #3
Source File: GifResourceDecoder.java    From giffun with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: DefaultDataSource.java    From GIFCompressor with Apache License 2.0 5 votes vote down vote up
private void ensureGifHeader() {
    if (mGifHeader != null) return;
    GifHeaderParser parser = new GifHeaderParser();
    parser.setData(getInputStreamData());
    mGifHeader = parser.parseHeader();
    parser.clear();
    if (mGifHeader.getStatus() != GifDecoder.STATUS_OK) {
        throw new RuntimeException("Illegal status: " + mGifHeader.getStatus());
    }
}
 
Example #5
Source File: GifResourceEncoder.java    From giffun with Apache License 2.0 4 votes vote down vote up
public GifHeaderParser buildParser() {
    return new GifHeaderParser();
}
 
Example #6
Source File: GifResourceDecoder.java    From giffun with Apache License 2.0 4 votes vote down vote up
public synchronized void release(GifHeaderParser parser) {
    parser.clear();
    pool.offer(parser);
}