Search in sources :

Example 16 with AnimatedDrawableBackend

use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateWithDecodeAlFrames.

private void testCreateWithDecodeAlFrames(WebPImage mockWebPImage, PooledByteBuffer byteBuffer, Bitmap mockBitmap1, Bitmap mockBitmap2) throws Exception {
    // For decoding preview frame, expect some calls.
    final AnimatedDrawableBackend mockAnimatedDrawableBackend = createAnimatedDrawableBackendMock(2);
    when(mMockAnimatedDrawableBackendProvider.get(any(AnimatedImageResult.class), isNull(Rect.class))).thenReturn(mockAnimatedDrawableBackend);
    when(mMockBitmapFactory.createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG)).thenReturn(CloseableReference.of(mockBitmap1, FAKE_BITMAP_RESOURCE_RELEASER)).thenReturn(CloseableReference.of(mockBitmap2, FAKE_BITMAP_RESOURCE_RELEASER));
    AnimatedImageCompositor mockCompositor = mock(AnimatedImageCompositor.class);
    PowerMockito.whenNew(AnimatedImageCompositor.class).withAnyArguments().thenReturn(mockCompositor);
    ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder().setDecodePreviewFrame(true).setDecodeAllFrames(true).build();
    EncodedImage encodedImage = new EncodedImage(CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
    encodedImage.setImageFormat(ImageFormat.UNKNOWN);
    CloseableAnimatedImage closeableImage = (CloseableAnimatedImage) mAnimatedImageFactory.decodeWebP(encodedImage, imageDecodeOptions, DEFAULT_BITMAP_CONFIG);
    // Verify we got the right result
    AnimatedImageResult imageResult = closeableImage.getImageResult();
    assertSame(mockWebPImage, imageResult.getImage());
    assertNotNull(imageResult.getDecodedFrame(0));
    assertNotNull(imageResult.getDecodedFrame(1));
    assertNotNull(imageResult.getPreviewBitmap());
    // Should not have interacted with these.
    verify(mMockAnimatedDrawableBackendProvider).get(any(AnimatedImageResult.class), isNull(Rect.class));
    verifyNoMoreInteractions(mMockAnimatedDrawableBackendProvider);
    verify(mMockBitmapFactory, times(2)).createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG);
    verifyNoMoreInteractions(mMockBitmapFactory);
    verify(mockCompositor).renderFrame(0, mockBitmap1);
    verify(mockCompositor).renderFrame(1, mockBitmap2);
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Rect(android.graphics.Rect) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 17 with AnimatedDrawableBackend

use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.

the class AnimatedImageFactoryImpl method decodeAllFrames.

private List<CloseableReference<Bitmap>> decodeAllFrames(AnimatedImage image, Bitmap.Config bitmapConfig) {
    AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
    AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
    final List<CloseableReference<Bitmap>> bitmaps = new ArrayList<>(drawableBackend.getFrameCount());
    AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {

        @Override
        public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
        // Don't care.
        }

        @Override
        @Nullable
        public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
            return CloseableReference.cloneOrNull(bitmaps.get(frameNumber));
        }
    });
    for (int i = 0; i < drawableBackend.getFrameCount(); i++) {
        CloseableReference<Bitmap> bitmap = createBitmap(drawableBackend.getWidth(), drawableBackend.getHeight(), bitmapConfig);
        animatedImageCompositor.renderFrame(i, bitmap.get());
        bitmaps.add(bitmap);
    }
    return bitmaps;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableReference(com.facebook.common.references.CloseableReference) ArrayList(java.util.ArrayList) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) SuppressLint(android.annotation.SuppressLint) Nullable(javax.annotation.Nullable)

Example 18 with AnimatedDrawableBackend

use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.

the class AnimatedImageFactoryImpl method createPreviewBitmap.

private CloseableReference<Bitmap> createPreviewBitmap(AnimatedImage image, Bitmap.Config bitmapConfig, int frameForPreview) {
    CloseableReference<Bitmap> bitmap = createBitmap(image.getWidth(), image.getHeight(), bitmapConfig);
    AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
    AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
    AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {

        @Override
        public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
        // Don't care.
        }

        @Override
        @Nullable
        public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
            return null;
        }
    });
    animatedImageCompositor.renderFrame(frameForPreview, bitmap.get());
    return bitmap;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableReference(com.facebook.common.references.CloseableReference) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) SuppressLint(android.annotation.SuppressLint) Nullable(javax.annotation.Nullable)

Aggregations

AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)18 Rect (android.graphics.Rect)11 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)11 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)11 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)10 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)8 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)8 Bitmap (android.graphics.Bitmap)6 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)4 Test (org.junit.Test)4 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)4 AnimatedImage (com.facebook.imagepipeline.animated.base.AnimatedImage)3 SuppressLint (android.annotation.SuppressLint)2 GifImage (com.facebook.animated.gif.GifImage)2 WebPImage (com.facebook.animated.webp.WebPImage)2 CloseableReference (com.facebook.common.references.CloseableReference)2 BitmapAnimationBackend (com.facebook.fresco.animation.bitmap.BitmapAnimationBackend)2 BitmapFrameCache (com.facebook.fresco.animation.bitmap.BitmapFrameCache)2 AnimatedDrawableBackendAnimationInformation (com.facebook.fresco.animation.bitmap.wrapper.AnimatedDrawableBackendAnimationInformation)2 AnimatedDrawableBackendFrameRenderer (com.facebook.fresco.animation.bitmap.wrapper.AnimatedDrawableBackendFrameRenderer)2