Search in sources :

Example 66 with EncodedImage

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

the class DownsampleUtilTest method whenImageWidthHeightAndRotation.

private void whenImageWidthHeightAndRotation(int width, int height, int rotationAngle) {
    mEncodedImage = new EncodedImage(CloseableReference.of(mock(PooledByteBuffer.class)));
    mEncodedImage.setWidth(width);
    mEncodedImage.setHeight(height);
    mEncodedImage.setRotationAngle(rotationAngle);
    mEncodedImage.setExifOrientation(ExifInterface.ORIENTATION_NORMAL);
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 67 with EncodedImage

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

the class StagingAreaTest method setUp.

@Before
public void setUp() {
    mStagingArea = StagingArea.getInstance();
    mCloseableReference = CloseableReference.of(mock(PooledByteBuffer.class));
    mCloseableReference2 = CloseableReference.of(mock(PooledByteBuffer.class));
    mEncodedImage = new EncodedImage(mCloseableReference);
    mSecondEncodedImage = new EncodedImage(mCloseableReference2);
    mCacheKey = new SimpleCacheKey("http://this.is/uri");
    mStagingArea.put(mCacheKey, mEncodedImage);
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 68 with EncodedImage

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

the class EncodedMemoryCacheProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mEncodedMemoryCacheProducer = new EncodedMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
    mPooledByteBuffer1 = mock(PooledByteBuffer.class);
    mPooledByteBuffer2 = mock(PooledByteBuffer.class);
    mFinalImageReference = CloseableReference.of(mPooledByteBuffer1);
    mIntermediateImageReference = CloseableReference.of(mPooledByteBuffer2);
    mFinalImageReferenceClone = mFinalImageReference.clone();
    mFinalEncodedImage = new EncodedImage(mFinalImageReference);
    mFinalEncodedImage.setImageFormat(new ImageFormat("jpeg", null));
    mFinalEncodedImage.setWidth(100);
    mFinalEncodedImage.setHeight(100);
    mImagePipelineConfig = mock(ImagePipelineConfig.class);
    mImagePipelineExperiments = mock(ImagePipelineExperiments.class);
    mFinalEncodedImageFormatUnknown = new EncodedImage(mFinalImageReference);
    mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
    mFinalEncodedImageClone = new EncodedImage(mFinalImageReferenceClone);
    List<CacheKey> list = new ArrayList<>();
    list.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(list);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mMemoryCache.cache(mCacheKey, mFinalImageReference)).thenReturn(mFinalImageReferenceClone);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getCallerContext()).thenReturn(mCallerContext);
    when(mProducerContext.getProducerListener()).thenReturn(mProducerListener);
    when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true);
    when(mProducerContext.getLowestPermittedRequestLevel()).thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
    when(mProducerContext.getImagePipelineConfig()).thenReturn(mImagePipelineConfig);
    when(mImagePipelineConfig.getExperiments()).thenReturn(mImagePipelineExperiments);
    when(mImagePipelineExperiments.isEncodedCacheEnabled()).thenReturn(true);
    setUpCacheEnabled(true);
}
Also used : ImagePipelineExperiments(com.facebook.imagepipeline.core.ImagePipelineExperiments) ImagePipelineConfig(com.facebook.imagepipeline.core.ImagePipelineConfig) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) ArrayList(java.util.ArrayList) 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) ImageFormat(com.facebook.imageformat.ImageFormat)

Example 69 with EncodedImage

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

the class EncodedMemoryCacheProducerTest method testEncodedMemoryCacheGetSuccessful.

@Test
public void testEncodedMemoryCacheGetSuccessful() {
    setupEncodedMemoryCacheGetSuccess();
    when(mProducerContext.getLowestPermittedRequestLevel()).thenReturn(ImageRequest.RequestLevel.ENCODED_MEMORY_CACHE);
    mEncodedMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.IS_LAST));
    EncodedImage encodedImage = argumentCaptor.getValue();
    Assert.assertSame(mFinalEncodedImage.getUnderlyingReferenceTestOnly(), encodedImage.getUnderlyingReferenceTestOnly());
    verify(mProducerListener).onProducerStart(mProducerContext, PRODUCER_NAME);
    Map<String, String> extraMap = ImmutableMap.of(EncodedMemoryCacheProducer.EXTRA_CACHED_VALUE_FOUND, "true");
    verify(mProducerListener).onProducerFinishWithSuccess(mProducerContext, PRODUCER_NAME, extraMap);
    verify(mProducerListener).onUltimateProducerReached(mProducerContext, PRODUCER_NAME, true);
    Assert.assertFalse(mFinalImageReference.isValid());
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 70 with EncodedImage

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

the class JobSchedulerTest method testClear.

@Test
public void testClear() throws Exception {
    EncodedImage encodedImage = fakeEncodedImage();
    mJobScheduler.updateJob(encodedImage, Consumer.IS_LAST);
    mJobScheduler.clearJob();
    assertEquals(null, mJobScheduler.mEncodedImage);
    encodedImage.close();
    assertNull(encodedImage.getByteBufferRef());
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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