Search in sources :

Example 6 with WebPImage

use of com.facebook.animated.webp.WebPImage in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateDefaultsUsingByteBuffer.

@Test
public void testCreateDefaultsUsingByteBuffer() {
    WebPImage mockWebPImage = mock(WebPImage.class);
    // Expect a call to WebPImage.createFromByteBuffer
    TrivialBufferPooledByteBuffer byteBuffer = createDirectByteBuffer();
    when(mWebPImageMock.decodeFromByteBuffer(eq(byteBuffer.getByteBuffer()), any(ImageDecodeOptions.class))).thenReturn(mockWebPImage);
    testCreateDefaults(mockWebPImage, byteBuffer);
}
Also used : TrivialBufferPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialBufferPooledByteBuffer) WebPImage(com.facebook.animated.webp.WebPImage) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 7 with WebPImage

use of com.facebook.animated.webp.WebPImage in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateWithPreviewBitmapUsingByteBuffer.

@Test
public void testCreateWithPreviewBitmapUsingByteBuffer() throws Exception {
    WebPImage mockWebPImage = mock(WebPImage.class);
    Bitmap mockBitmap = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
    // Expect a call to WebPImage.createFromByteBuffer
    TrivialBufferPooledByteBuffer byteBuffer = createDirectByteBuffer();
    when(mWebPImageMock.decodeFromByteBuffer(eq(byteBuffer.getByteBuffer()), any(ImageDecodeOptions.class))).thenReturn(mockWebPImage);
    when(mockWebPImage.getWidth()).thenReturn(50);
    when(mockWebPImage.getHeight()).thenReturn(50);
    testCreateWithPreviewBitmap(mockWebPImage, byteBuffer, mockBitmap);
}
Also used : Bitmap(android.graphics.Bitmap) TrivialBufferPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialBufferPooledByteBuffer) WebPImage(com.facebook.animated.webp.WebPImage) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 8 with WebPImage

use of com.facebook.animated.webp.WebPImage in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateWithDecodeAlFramesUsingPointer.

@Test
public void testCreateWithDecodeAlFramesUsingPointer() throws Exception {
    WebPImage mockWebPImage = mock(WebPImage.class);
    Bitmap mockBitmap1 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
    Bitmap mockBitmap2 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
    // Expect a call to WebPImage.createFromByteBuffer
    TrivialPooledByteBuffer byteBuffer = createByteBuffer();
    when(mWebPImageMock.decodeFromNativeMemory(eq(byteBuffer.getNativePtr()), eq(byteBuffer.size()), any(ImageDecodeOptions.class))).thenReturn(mockWebPImage);
    when(mockWebPImage.getWidth()).thenReturn(50);
    when(mockWebPImage.getHeight()).thenReturn(50);
    testCreateWithDecodeAlFrames(mockWebPImage, byteBuffer, mockBitmap1, mockBitmap2);
}
Also used : Bitmap(android.graphics.Bitmap) WebPImage(com.facebook.animated.webp.WebPImage) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 9 with WebPImage

use of com.facebook.animated.webp.WebPImage in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateWithPreviewBitmap.

@Test
public void testCreateWithPreviewBitmap() throws Exception {
    WebPImage mockWebPImage = mock(WebPImage.class);
    Bitmap mockBitmap = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
    // Expect a call to WebPImage.create
    TrivialPooledByteBuffer byteBuffer = createByteBuffer();
    when(mWebPImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size())).thenReturn(mockWebPImage);
    when(mockWebPImage.getWidth()).thenReturn(50);
    when(mockWebPImage.getHeight()).thenReturn(50);
    // 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) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) WebPImage(com.facebook.animated.webp.WebPImage) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 10 with WebPImage

use of com.facebook.animated.webp.WebPImage in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateWithDecodeAlFramesUsingByteBuffer.

@Test
public void testCreateWithDecodeAlFramesUsingByteBuffer() throws Exception {
    WebPImage mockWebPImage = mock(WebPImage.class);
    Bitmap mockBitmap1 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
    Bitmap mockBitmap2 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
    // Expect a call to WebPImage.createFromByteBuffer
    TrivialBufferPooledByteBuffer byteBuffer = createDirectByteBuffer();
    when(mWebPImageMock.decodeFromByteBuffer(eq(byteBuffer.getByteBuffer()), any(ImageDecodeOptions.class))).thenReturn(mockWebPImage);
    when(mockWebPImage.getWidth()).thenReturn(50);
    when(mockWebPImage.getHeight()).thenReturn(50);
    testCreateWithDecodeAlFrames(mockWebPImage, byteBuffer, mockBitmap1, mockBitmap2);
}
Also used : Bitmap(android.graphics.Bitmap) TrivialBufferPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialBufferPooledByteBuffer) WebPImage(com.facebook.animated.webp.WebPImage) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Aggregations

WebPImage (com.facebook.animated.webp.WebPImage)10 Test (org.junit.Test)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)8 Bitmap (android.graphics.Bitmap)6 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)6 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)3 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)3 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)3 TrivialBufferPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialBufferPooledByteBuffer)3 Rect (android.graphics.Rect)2 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)2 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1