Search in sources :

Example 6 with PooledByteBuffer

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

the class JobSchedulerTest method fakeEncodedImage.

private EncodedImage fakeEncodedImage() {
    PooledByteBuffer buf = mock(PooledByteBuffer.class);
    CloseableReference<PooledByteBuffer> ref = CloseableReference.of(buf);
    return new EncodedImage(ref);
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 7 with PooledByteBuffer

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

the class LocalAssetFetchProducerTest method testFetchAssetResource.

@Test
public void testFetchAssetResource() throws Exception {
    PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
    when(mAssetManager.open(eq(TEST_FILENAME), eq(AssetManager.ACCESS_STREAMING))).thenReturn(new ByteArrayInputStream(new byte[TEST_DATA_LENGTH]));
    when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class), eq(TEST_DATA_LENGTH))).thenReturn(pooledByteBuffer);
    mLocalAssetFetchProducer.produceResults(mConsumer, mProducerContext);
    mExecutor.runUntilIdle();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer)

Example 8 with PooledByteBuffer

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

the class LocalContentUriFetchProducerTest method testFetchLocalContentUri.

@Test
public void testFetchLocalContentUri() throws Exception {
    PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
    when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class))).thenReturn(pooledByteBuffer);
    when(mContentResolver.openInputStream(mContentUri)).thenReturn(mock(InputStream.class));
    mLocalContentUriFetchProducer.produceResults(mConsumer, mProducerContext);
    mExecutor.runUntilIdle();
}
Also used : InputStream(java.io.InputStream) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer)

Example 9 with PooledByteBuffer

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

the class DecodeProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mProgressiveJpegConfig = new SimpleProgressiveJpegConfig(new SimpleProgressiveJpegConfig.DynamicValueConfig() {

        public List<Integer> getScansToDecode() {
            return Arrays.asList(PREVIEW_SCAN, GOOD_ENOUGH_SCAN);
        }

        public int getGoodEnoughScanNumber() {
            return GOOD_ENOUGH_SCAN;
        }
    });
    PowerMockito.mockStatic(ProgressiveJpegParser.class);
    PowerMockito.whenNew(ProgressiveJpegParser.class).withAnyArguments().thenReturn(mProgressiveJpegParser);
    PowerMockito.mockStatic(JobScheduler.class);
    PowerMockito.whenNew(JobScheduler.class).withAnyArguments().thenReturn(mJobScheduler);
    mDecodeProducer = new DecodeProducer(mByteArrayPool, mExecutor, mImageDecoder, mProgressiveJpegConfig, false, /* Set downsampleEnabled to false */
    false, /* Set resizeAndRotateForNetwork to false */
    false, /* We don't cancel when the request is cancelled */
    mInputProducer);
    PooledByteBuffer pooledByteBuffer = mockPooledByteBuffer(IMAGE_SIZE);
    mByteBufferRef = CloseableReference.of(pooledByteBuffer);
    mEncodedImage = new EncodedImage(mByteBufferRef);
}
Also used : SimpleProgressiveJpegConfig(com.facebook.imagepipeline.decoder.SimpleProgressiveJpegConfig) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 10 with PooledByteBuffer

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

the class EncodedImageTest method testIsJpegCompleteAt_notComplete.

@Test
public void testIsJpegCompleteAt_notComplete() {
    byte[] encodedBytes = new byte[ENCODED_BYTES_LENGTH];
    encodedBytes[ENCODED_BYTES_LENGTH - 2] = 0;
    encodedBytes[ENCODED_BYTES_LENGTH - 1] = 0;
    PooledByteBuffer buf = new TrivialPooledByteBuffer(encodedBytes);
    EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
    encodedImage.setImageFormat(DefaultImageFormats.JPEG);
    assertFalse(encodedImage.isCompleteAt(ENCODED_BYTES_LENGTH));
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

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