Search in sources :

Example 61 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class BranchOnSeparateImagesProducerTest method testFirstProducerReturnsNull.

@Test
public void testFirstProducerReturnsNull() {
    mFirstProducerConsumer.onNewResult(null, Consumer.IS_LAST);
    verify(mConsumer, never()).onNewResult(isNull(EncodedImage.class), anyInt());
    EncodedImage finalEncodedImage = new EncodedImage(mIntermediateResult.getByteBufferRef());
    mSecondProducerConsumer.onNewResult(finalEncodedImage, Consumer.IS_LAST);
    verify(mConsumer).onNewResult(finalEncodedImage, Consumer.IS_LAST);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test)

Example 62 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class BranchOnSeparateImagesProducerTest method testFirstProducerResultNotGoodEnoughThumbnailsNotAllowed.

@Test
public void testFirstProducerResultNotGoodEnoughThumbnailsNotAllowed() {
    when(mImageRequest.getLocalThumbnailPreviewsEnabled()).thenReturn(false);
    EncodedImage firstProducerEncodedImage = new EncodedImage(mFirstProducerFinalResult.getByteBufferRef());
    firstProducerEncodedImage.setRotationAngle(-1);
    firstProducerEncodedImage.setWidth(WIDTH / 2);
    firstProducerEncodedImage.setHeight(HEIGHT / 2);
    mFirstProducerConsumer.onNewResult(firstProducerEncodedImage, Consumer.IS_LAST);
    verify(mConsumer, never()).onNewResult(firstProducerEncodedImage, Consumer.NO_FLAGS);
    EncodedImage intermediateEncodedImage = new EncodedImage(mIntermediateResult.getByteBufferRef());
    intermediateEncodedImage.setRotationAngle(-1);
    intermediateEncodedImage.setWidth(WIDTH / 2);
    intermediateEncodedImage.setHeight(HEIGHT / 2);
    mSecondProducerConsumer.onNewResult(intermediateEncodedImage, Consumer.NO_FLAGS);
    verify(mConsumer).onNewResult(intermediateEncodedImage, Consumer.NO_FLAGS);
    EncodedImage secondProducerEncodedImage = new EncodedImage(mFirstProducerFinalResult.getByteBufferRef());
    secondProducerEncodedImage.setRotationAngle(-1);
    secondProducerEncodedImage.setWidth(WIDTH / 2);
    secondProducerEncodedImage.setHeight(HEIGHT / 2);
    mSecondProducerConsumer.onNewResult(secondProducerEncodedImage, Consumer.IS_LAST);
    verify(mConsumer).onNewResult(secondProducerEncodedImage, Consumer.IS_LAST);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test)

Example 63 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class DecodeProducerTest method testNewResult_Intermediate_pJPEG.

@Test
public void testNewResult_Intermediate_pJPEG() {
    setupNetworkUri();
    Consumer<EncodedImage> consumer = produceResults();
    InOrder inOrder = inOrder(mJobScheduler, mProgressiveJpegParser);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    // preview scan; schedule
    when(mJobScheduler.updateJob(mEncodedImage, Consumer.NO_FLAGS)).thenReturn(true);
    when(mProgressiveJpegParser.parseMoreData(any(EncodedImage.class))).thenReturn(true);
    when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(PREVIEW_SCAN);
    consumer.onNewResult(mEncodedImage, Consumer.NO_FLAGS);
    inOrder.verify(mJobScheduler).updateJob(mEncodedImage, Consumer.NO_FLAGS);
    inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
    inOrder.verify(mJobScheduler).scheduleJob();
    assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), mByteBufferRef.getUnderlyingReferenceTestOnly());
    // no data parsed; ignore
    PooledByteBuffer pooledByteBuffer2 = mockPooledByteBuffer(210);
    CloseableReference<PooledByteBuffer> ref2 = CloseableReference.of(pooledByteBuffer2);
    EncodedImage encodedImage2 = mockEncodedJpeg(ref2);
    when(mJobScheduler.updateJob(encodedImage2, Consumer.NO_FLAGS)).thenReturn(true);
    when(mProgressiveJpegParser.parseMoreData(encodedImage2)).thenReturn(false);
    when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(PREVIEW_SCAN);
    consumer.onNewResult(encodedImage2, Consumer.NO_FLAGS);
    inOrder.verify(mJobScheduler).updateJob(encodedImage2, Consumer.NO_FLAGS);
    inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
    inOrder.verify(mJobScheduler, never()).scheduleJob();
    assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref2.getUnderlyingReferenceTestOnly());
    // same scan; ignore
    PooledByteBuffer pooledByteBuffer3 = mockPooledByteBuffer(220);
    CloseableReference<PooledByteBuffer> ref3 = CloseableReference.of(pooledByteBuffer3);
    EncodedImage encodedImage3 = mockEncodedJpeg(ref3);
    when(mJobScheduler.updateJob(encodedImage3, Consumer.NO_FLAGS)).thenReturn(true);
    when(mProgressiveJpegParser.parseMoreData(encodedImage3)).thenReturn(true);
    when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(PREVIEW_SCAN);
    consumer.onNewResult(encodedImage3, Consumer.NO_FLAGS);
    inOrder.verify(mJobScheduler).updateJob(encodedImage3, Consumer.NO_FLAGS);
    inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
    inOrder.verify(mJobScheduler, never()).scheduleJob();
    assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref3.getUnderlyingReferenceTestOnly());
    // scan not for decode; ignore
    PooledByteBuffer pooledByteBuffer4 = mockPooledByteBuffer(300);
    CloseableReference<PooledByteBuffer> ref4 = CloseableReference.of(pooledByteBuffer4);
    EncodedImage encodedImage4 = mockEncodedJpeg(ref4);
    when(mJobScheduler.updateJob(encodedImage4, Consumer.NO_FLAGS)).thenReturn(true);
    when(mProgressiveJpegParser.parseMoreData(encodedImage4)).thenReturn(true);
    when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(IGNORED_SCAN);
    consumer.onNewResult(encodedImage4, Consumer.NO_FLAGS);
    inOrder.verify(mJobScheduler).updateJob(encodedImage4, Consumer.NO_FLAGS);
    inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
    inOrder.verify(mJobScheduler, never()).scheduleJob();
    assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref4.getUnderlyingReferenceTestOnly());
    // good-enough scan; schedule
    PooledByteBuffer pooledByteBuffer5 = mockPooledByteBuffer(500);
    CloseableReference<PooledByteBuffer> ref5 = CloseableReference.of(pooledByteBuffer5);
    EncodedImage encodedImage5 = mockEncodedJpeg(ref5);
    when(mJobScheduler.updateJob(encodedImage5, Consumer.NO_FLAGS)).thenReturn(true);
    when(mProgressiveJpegParser.parseMoreData(encodedImage5)).thenReturn(true);
    when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(GOOD_ENOUGH_SCAN);
    consumer.onNewResult(encodedImage5, Consumer.NO_FLAGS);
    inOrder.verify(mJobScheduler).updateJob(encodedImage5, Consumer.NO_FLAGS);
    inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
    inOrder.verify(mJobScheduler).scheduleJob();
    assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref5.getUnderlyingReferenceTestOnly());
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 64 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class DecodeProducerTest method mockEncodedJpeg.

private static EncodedImage mockEncodedJpeg(CloseableReference<PooledByteBuffer> ref) {
    final EncodedImage encodedImage = new EncodedImage(ref);
    encodedImage.setImageFormat(DefaultImageFormats.JPEG);
    encodedImage.setWidth(IMAGE_WIDTH);
    encodedImage.setHeight(IMAGE_HEIGHT);
    return encodedImage;
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 65 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class DiskCacheReadProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mDiskCacheReadProducer = new DiskCacheReadProducer(mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory, mInputProducer);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    mIntermediatePooledByteBuffer = mock(PooledByteBuffer.class);
    mFinalPooledByteBuffer = mock(PooledByteBuffer.class);
    mIntermediateImageReference = CloseableReference.of(mIntermediatePooledByteBuffer);
    mFinalImageReference = CloseableReference.of(mFinalPooledByteBuffer);
    mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
    mFinalEncodedImage = new EncodedImage(mFinalImageReference);
    mIsCancelled = ArgumentCaptor.forClass(AtomicBoolean.class);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM, mConfig);
    mLowestLevelProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM, mConfig);
    when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)108 Test (org.junit.Test)32 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)20 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)12 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)12 CacheKey (com.facebook.cache.common.CacheKey)11 Rect (android.graphics.Rect)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 InputStream (java.io.InputStream)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)8 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)8 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)8 Before (org.junit.Before)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)7 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6