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