use of com.facebook.animated.giflite.decoder.GifMetadataDecoder in project fresco by facebook.
the class GifDecoder method decode.
@Override
public CloseableImage decode(final EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) {
InputStream is = encodedImage.getInputStream();
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GifMetadataDecoder decoder = GifMetadataDecoder.create(is, out);
if (out.size() > 0) {
// let's use the fixed gif version if exists
is.close();
is = new ByteArrayInputStream(out.toByteArray());
}
is.reset();
Movie movie = Movie.decodeStream(is);
MovieDrawer drawer = new MovieDrawer(movie);
MovieFrame[] frames = new MovieFrame[decoder.getFrameCount()];
int currTime = 0;
for (int frameNumber = 0, N = frames.length; frameNumber < N; frameNumber++) {
int frameDuration = decoder.getFrameDurationMs(frameNumber);
currTime += frameDuration;
frames[frameNumber] = new MovieFrame(drawer, currTime, frameDuration, movie.width(), movie.height(), translateFrameDisposal(decoder.getFrameDisposal(frameNumber)));
}
return new CloseableAnimatedImage(AnimatedImageResult.forAnimatedImage(new MovieAnimatedImage(frames, encodedImage.getSize(), movie.duration(), decoder.getLoopCount())), false);
} catch (IOException e) {
throw new RuntimeException("Error while decoding gif", e);
} finally {
try {
is.close();
} catch (IOException ignored) {
}
}
}
use of com.facebook.animated.giflite.decoder.GifMetadataDecoder in project fresco by facebook.
the class GifAnimationBackend method create.
public static GifAnimationBackend create(String filePath) throws IOException {
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(filePath));
is.mark(Integer.MAX_VALUE);
GifMetadataDecoder decoder = GifMetadataDecoder.create(is, null);
is.reset();
Movie movie = Movie.decodeStream(is);
return new GifAnimationBackend(decoder, movie);
} finally {
closeSilently(is);
}
}
Aggregations