Search in sources :

Example 1 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateWithDecodeAlFrames.

@Test
public void testCreateWithDecodeAlFrames() 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.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(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) 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 2 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class AnimatedImageFactoryWebPImplTest method testCreateDefaults.

@Test
public void testCreateDefaults() {
    WebPImage mockWebPImage = mock(WebPImage.class);
    // Expect a call to WebPImage.create
    TrivialPooledByteBuffer byteBuffer = createByteBuffer();
    when(mWebPImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size())).thenReturn(mockWebPImage);
    EncodedImage encodedImage = new EncodedImage(CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
    encodedImage.setImageFormat(ImageFormat.UNKNOWN);
    CloseableAnimatedImage closeableImage = (CloseableAnimatedImage) mAnimatedImageFactory.decodeWebP(encodedImage, ImageDecodeOptions.defaults(), DEFAULT_BITMAP_CONFIG);
    // Verify we got the right result
    AnimatedImageResult imageResult = closeableImage.getImageResult();
    assertSame(mockWebPImage, imageResult.getImage());
    assertNull(imageResult.getPreviewBitmap());
    assertFalse(imageResult.hasDecodedFrame(0));
    // Should not have interacted with these.
    verifyZeroInteractions(mMockAnimatedDrawableBackendProvider);
    verifyZeroInteractions(mMockBitmapFactory);
}
Also used : 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) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 3 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class PooledByteBufferInputStreamTest method setup.

@Before
public void setup() {
    PooledByteBuffer buffer = new TrivialPooledByteBuffer(BYTES);
    mStream = new PooledByteBufferInputStream(buffer);
}
Also used : TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) Before(org.junit.Before)

Example 4 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class ArtDecoderTest method setUp.

@Before
public void setUp() throws Exception {
    final Random random = new Random();
    random.setSeed(RANDOM_SEED);
    mEncodedBytes = new byte[ENCODED_BYTES_LENGTH];
    random.nextBytes(mEncodedBytes);
    mPooledByteBuffer = new TrivialPooledByteBuffer(mEncodedBytes);
    mBitmapPool = mock(BitmapPool.class);
    mArtDecoder = new ArtDecoder(mBitmapPool, 1, new Pools.SynchronizedPool(1));
    mByteBufferRef = CloseableReference.of(mPooledByteBuffer);
    mEncodedImage = new EncodedImage(mByteBufferRef);
    mEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
    mBitmap = MockBitmapFactory.create();
    doReturn(mBitmap).when(mBitmapPool).get(MockBitmapFactory.DEFAULT_BITMAP_SIZE);
    mBitmapFactoryDefaultAnswer = new Answer<Bitmap>() {

        @Override
        public Bitmap answer(InvocationOnMock invocation) throws Throwable {
            final BitmapFactory.Options options = (BitmapFactory.Options) invocation.getArguments()[2];
            options.outWidth = MockBitmapFactory.DEFAULT_BITMAP_WIDTH;
            options.outHeight = MockBitmapFactory.DEFAULT_BITMAP_HEIGHT;
            verifyBitmapFactoryOptions(options);
            return options.inJustDecodeBounds ? null : mBitmap;
        }
    };
    whenBitmapFactoryDecodeStream().thenAnswer(mBitmapFactoryDefaultAnswer);
    ByteBuffer buf = mArtDecoder.mDecodeBuffers.acquire();
    mTempStorage = buf.array();
    mArtDecoder.mDecodeBuffers.release(buf);
}
Also used : BitmapPool(com.facebook.imagepipeline.memory.BitmapPool) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) ByteBuffer(java.nio.ByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) Bitmap(android.graphics.Bitmap) Random(java.util.Random) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) MockBitmapFactory(com.facebook.imagepipeline.testing.MockBitmapFactory) BitmapFactory(android.graphics.BitmapFactory) Before(org.junit.Before)

Example 5 with TrivialPooledByteBuffer

use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.

the class GingerbreadPurgeableDecoderTest method setUp.

@Before
public void setUp() {
    mBitmap = MockBitmapFactory.create();
    mBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_SIZE);
    mockStatic(BitmapCounterProvider.class);
    when(BitmapCounterProvider.get()).thenReturn(mBitmapCounter);
    mockStatic(BitmapFactory.class);
    when(BitmapFactory.decodeFileDescriptor(any(FileDescriptor.class), any(Rect.class), any(BitmapFactory.Options.class))).thenReturn(mBitmap);
    mInputBuf = new byte[LENGTH];
    PooledByteBuffer input = new TrivialPooledByteBuffer(mInputBuf, POINTER);
    mByteBufferRef = CloseableReference.of(input);
    mEncodedImage = new EncodedImage(mByteBufferRef);
    mDecodeBuf = new byte[LENGTH + 2];
    mDecodeBufRef = CloseableReference.of(mDecodeBuf, mock(ResourceReleaser.class));
    mockStatic(Bitmaps.class);
    mGingerbreadPurgeableDecoder = new GingerbreadPurgeableDecoder();
}
Also used : BitmapCounter(com.facebook.imagepipeline.memory.BitmapCounter) Rect(android.graphics.Rect) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) FileDescriptor(java.io.FileDescriptor) Before(org.junit.Before)

Aggregations

TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)23 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)9 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)8 Test (org.junit.Test)8 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)6 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)6 Bitmap (android.graphics.Bitmap)5 Rect (android.graphics.Rect)5 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)4 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)4 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)4 Before (org.junit.Before)4 GifImage (com.facebook.animated.gif.GifImage)3 WebPImage (com.facebook.animated.webp.WebPImage)3 BitmapCounter (com.facebook.imagepipeline.memory.BitmapCounter)2 BitmapFactory (android.graphics.BitmapFactory)1 UiThreadImmediateExecutorService (com.facebook.common.executors.UiThreadImmediateExecutorService)1 BitmapPool (com.facebook.imagepipeline.memory.BitmapPool)1 FlexByteArrayPool (com.facebook.imagepipeline.memory.FlexByteArrayPool)1