Search in sources :

Example 1 with PooledByteBuffer

use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.

the class AnimatedImageFactoryImpl method decodeGif.

/**
   * Decodes a GIF into a CloseableImage.
   * @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
   * @param options the options for the decode
   * @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
   * @return a {@link CloseableImage} for the GIF image
   */
public CloseableImage decodeGif(final EncodedImage encodedImage, final ImageDecodeOptions options, final Bitmap.Config bitmapConfig) {
    if (sGifAnimatedImageDecoder == null) {
        throw new UnsupportedOperationException("To encode animated gif please add the dependency " + "to the animated-gif module");
    }
    final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
    Preconditions.checkNotNull(bytesRef);
    try {
        final PooledByteBuffer input = bytesRef.get();
        AnimatedImage gifImage = sGifAnimatedImageDecoder.decode(input.getNativePtr(), input.size());
        return getCloseableImage(options, gifImage, bitmapConfig);
    } finally {
        CloseableReference.closeSafely(bytesRef);
    }
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) AnimatedImage(com.facebook.imagepipeline.animated.base.AnimatedImage) CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage)

Example 2 with PooledByteBuffer

use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.

the class LocalContentUriThumbnailFetchProducerTest method testFetchLocalContentUri.

@Test
public void testFetchLocalContentUri() throws Exception {
    mockResizeOptions(512, 384);
    PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
    when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class))).thenReturn(pooledByteBuffer);
    produceResultsAndRunUntilIdle();
    assertConsumerReceivesImage();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with PooledByteBuffer

use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.

the class LocalFileFetchProducerTest method testFetchLocalFile.

@Test
public void testFetchLocalFile() throws Exception {
    PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
    when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class), eq(INPUT_STREAM_LENGTH))).thenReturn(pooledByteBuffer);
    mLocalFileFetchProducer.produceResults(mConsumer, mProducerContext);
    mExecutor.runUntilIdle();
    assertEquals(2, mCapturedEncodedImage.getByteBufferRef().getUnderlyingReferenceTestOnly().getRefCountTestOnly());
    assertSame(pooledByteBuffer, mCapturedEncodedImage.getByteBufferRef().get());
    verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
    verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, null);
}
Also used : InputStream(java.io.InputStream) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer)

Example 4 with PooledByteBuffer

use of com.facebook.common.memory.PooledByteBuffer 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)

Example 5 with PooledByteBuffer

use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.

the class KitKatPurgeableDecoderTest method setUp.

@Before
public void setUp() {
    mFlexByteArrayPool = mock(FlexByteArrayPool.class);
    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.decodeByteArray(any(byte[].class), anyInt(), anyInt(), 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));
    when(mFlexByteArrayPool.get(Integer.valueOf(LENGTH))).thenReturn(mDecodeBufRef);
    mockStatic(Bitmaps.class);
    mKitKatPurgeableDecoder = new KitKatPurgeableDecoder(mFlexByteArrayPool);
}
Also used : BitmapCounter(com.facebook.imagepipeline.memory.BitmapCounter) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) FlexByteArrayPool(com.facebook.imagepipeline.memory.FlexByteArrayPool) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Before(org.junit.Before)

Aggregations

PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)33 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)14 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)7 Bitmap (android.graphics.Bitmap)6 InputStream (java.io.InputStream)6 BitmapFactory (android.graphics.BitmapFactory)3 TargetApi (android.annotation.TargetApi)2 AnimatedImage (com.facebook.imagepipeline.animated.base.AnimatedImage)2 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)2 BitmapCounter (com.facebook.imagepipeline.memory.BitmapCounter)2 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Before (org.junit.Before)2 Rect (android.graphics.Rect)1 ExifInterface (android.media.ExifInterface)1 Uri (android.net.Uri)1 BinaryResource (com.facebook.binaryresource.BinaryResource)1 CacheKey (com.facebook.cache.common.CacheKey)1 PooledByteBufferInputStream (com.facebook.common.memory.PooledByteBufferInputStream)1 PooledByteBufferOutputStream (com.facebook.common.memory.PooledByteBufferOutputStream)1