Search in sources :

Example 11 with AnimatedDrawableBackend

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

the class ExperimentalBitmapAnimationDrawableFactory method createAnimationBackend.

private AnimationBackend createAnimationBackend(AnimatedImageResult animatedImageResult) {
    AnimatedDrawableBackend animatedDrawableBackend = createAnimatedDrawableBackend(animatedImageResult);
    BitmapFrameCache bitmapFrameCache = createBitmapFrameCache(animatedImageResult);
    BitmapAnimationBackend bitmapAnimationBackend = new BitmapAnimationBackend(mPlatformBitmapFactory, bitmapFrameCache, new AnimatedDrawableBackendAnimationInformation(animatedDrawableBackend), new AnimatedDrawableBackendFrameRenderer(bitmapFrameCache, animatedDrawableBackend));
    return AnimationBackendDelegateWithInactivityCheck.createForBackend(bitmapAnimationBackend, mMonotonicClock, mScheduledExecutorServiceForUiThread);
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) AnimatedDrawableBackendFrameRenderer(com.facebook.fresco.animation.bitmap.wrapper.AnimatedDrawableBackendFrameRenderer) AnimatedDrawableBackendAnimationInformation(com.facebook.fresco.animation.bitmap.wrapper.AnimatedDrawableBackendAnimationInformation) BitmapAnimationBackend(com.facebook.fresco.animation.bitmap.BitmapAnimationBackend) BitmapFrameCache(com.facebook.fresco.animation.bitmap.BitmapFrameCache)

Example 12 with AnimatedDrawableBackend

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

the class AnimatedDrawableFactoryImpl method create.

/**
   * Creates an {@link AnimatedDrawable} based on an {@link AnimatedImage}.
   *
   * @param animatedImageResult the result of the code
   * @param options additional options
   * @return a newly constructed {@link AnimatedDrawable}
   */
private AnimatedDrawable create(AnimatedImageResult animatedImageResult, AnimatedDrawableOptions options) {
    AnimatedImage animatedImage = animatedImageResult.getImage();
    Rect initialBounds = new Rect(0, 0, animatedImage.getWidth(), animatedImage.getHeight());
    AnimatedDrawableBackend animatedDrawableBackend = mAnimatedDrawableBackendProvider.get(animatedImageResult, initialBounds);
    return createAnimatedDrawable(options, animatedDrawableBackend);
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Rect(android.graphics.Rect) AnimatedImage(com.facebook.imagepipeline.animated.base.AnimatedImage) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage)

Example 13 with AnimatedDrawableBackend

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

the class AnimatedDrawableFactoryImplSupport method create.

/**
   * Creates an {@link AnimatedDrawable} based on an {@link AnimatedImage}.
   *
   * @param animatedImageResult the result of the code
   * @param options additional options
   * @return a newly constructed {@link AnimatedDrawable}
   */
private AnimatedDrawableSupport create(AnimatedImageResult animatedImageResult, AnimatedDrawableOptions options) {
    AnimatedImage animatedImage = animatedImageResult.getImage();
    Rect initialBounds = new Rect(0, 0, animatedImage.getWidth(), animatedImage.getHeight());
    AnimatedDrawableBackend animatedDrawableBackend = mAnimatedDrawableBackendProvider.get(animatedImageResult, initialBounds);
    return createAnimatedDrawable(options, animatedDrawableBackend);
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Rect(android.graphics.Rect) AnimatedImage(com.facebook.imagepipeline.animated.base.AnimatedImage) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage)

Example 14 with AnimatedDrawableBackend

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

the class AnimatedImageFactoryGifImplTest method createAnimatedDrawableBackendMock.

/**
 * Creates the mock for the AnimatedDrawableBackend with the number of frame
 *
 * @param frameCount The number of frame to mock
 */
private AnimatedDrawableBackend createAnimatedDrawableBackendMock(final int frameCount) {
    // For decoding preview frame, expect some calls.
    final AnimatedDrawableBackend mockAnimatedDrawableBackend = mock(AnimatedDrawableBackend.class);
    when(mockAnimatedDrawableBackend.getFrameCount()).thenReturn(frameCount);
    when(mockAnimatedDrawableBackend.getWidth()).thenReturn(50);
    when(mockAnimatedDrawableBackend.getHeight()).thenReturn(50);
    return mockAnimatedDrawableBackend;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)

Example 15 with AnimatedDrawableBackend

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

the class AnimatedImageFactoryWebPImplTest method testCreateWithPreviewBitmap.

private void testCreateWithPreviewBitmap(WebPImage mockWebPImage, PooledByteBuffer byteBuffer, Bitmap mockBitmap) throws Exception {
    // For decoding preview frame, expect some calls.
    final AnimatedDrawableBackend mockAnimatedDrawableBackend = createAnimatedDrawableBackendMock(1);
    when(mMockAnimatedDrawableBackendProvider.get(any(AnimatedImageResult.class), isNull(Rect.class))).thenReturn(mockAnimatedDrawableBackend);
    when(mMockBitmapFactory.createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG)).thenReturn(CloseableReference.of(mockBitmap, FAKE_BITMAP_RESOURCE_RELEASER));
    AnimatedImageCompositor mockCompositor = mock(AnimatedImageCompositor.class);
    PowerMockito.whenNew(AnimatedImageCompositor.class).withAnyArguments().thenReturn(mockCompositor);
    ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder().setDecodePreviewFrame(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.getPreviewBitmap());
    assertFalse(imageResult.hasDecodedFrame(0));
    // Should not have interacted with these.
    verify(mMockAnimatedDrawableBackendProvider).get(any(AnimatedImageResult.class), isNull(Rect.class));
    verifyNoMoreInteractions(mMockAnimatedDrawableBackendProvider);
    verify(mMockBitmapFactory).createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG);
    verifyNoMoreInteractions(mMockBitmapFactory);
    verify(mockCompositor).renderFrame(0, mockBitmap);
}
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)

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