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);
}
}
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();
}
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);
}
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();
}
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);
}
Aggregations