use of com.facebook.imagepipeline.common.ImageDecodeOptions in project fresco by facebook.
the class ImagePipelineUtilsImplTest method testBuildImageRequest_whenRoundAsCircleWithAntiAliasingAndRoundingDisabled_thenDoNothing.
@Test
public void testBuildImageRequest_whenRoundAsCircleWithAntiAliasingAndRoundingDisabled_thenDoNothing() {
final ImageOptions imageOptions = ImageOptions.create().round(RoundingOptions.asCircle(true)).build();
ImageRequest imageRequest = mImagePipelineUtilsNoNativeRounding.buildImageRequest(URI, imageOptions);
assertThat(imageRequest).isNotNull();
assertThat(imageRequest.getSourceUri()).isEqualTo(URI);
ImageDecodeOptions imageDecodeOptions = imageRequest.getImageDecodeOptions();
assertThat(imageDecodeOptions).isEqualTo(ImageDecodeOptions.defaults());
}
use of com.facebook.imagepipeline.common.ImageDecodeOptions in project fresco by facebook.
the class ImagePipelineUtilsImplTest method testBuildImageRequest_whenRoundAsCircle_thenApplyRoundingParameters.
@Test
public void testBuildImageRequest_whenRoundAsCircle_thenApplyRoundingParameters() {
final ImageOptions imageOptions = ImageOptions.create().round(RoundingOptions.asCircle()).build();
ImageRequest imageRequest = mImagePipelineUtils.buildImageRequest(URI, imageOptions);
assertThat(imageRequest).isNotNull();
assertThat(imageRequest.getSourceUri()).isEqualTo(URI);
ImageDecodeOptions imageDecodeOptions = imageRequest.getImageDecodeOptions();
assertThat(imageDecodeOptions).isEqualTo(mRoundingDecodeOptions);
}
use of com.facebook.imagepipeline.common.ImageDecodeOptions 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);
}
use of com.facebook.imagepipeline.common.ImageDecodeOptions 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);
}
Aggregations