Search in sources :

Example 41 with CloseableReference

use of com.facebook.common.references.CloseableReference in project fresco by facebook.

the class AnimatedImageFactoryImpl method decodeAllFrames.

private List<CloseableReference<Bitmap>> decodeAllFrames(AnimatedImage image, Bitmap.Config bitmapConfig) {
    AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
    AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
    final List<CloseableReference<Bitmap>> bitmaps = new ArrayList<>(drawableBackend.getFrameCount());
    AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {

        @Override
        public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
        // Don't care.
        }

        @Override
        @Nullable
        public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
            return CloseableReference.cloneOrNull(bitmaps.get(frameNumber));
        }
    });
    for (int i = 0; i < drawableBackend.getFrameCount(); i++) {
        CloseableReference<Bitmap> bitmap = createBitmap(drawableBackend.getWidth(), drawableBackend.getHeight(), bitmapConfig);
        animatedImageCompositor.renderFrame(i, bitmap.get());
        bitmaps.add(bitmap);
    }
    return bitmaps;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableReference(com.facebook.common.references.CloseableReference) ArrayList(java.util.ArrayList) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) SuppressLint(android.annotation.SuppressLint) Nullable(javax.annotation.Nullable)

Example 42 with CloseableReference

use of com.facebook.common.references.CloseableReference in project fresco by facebook.

the class AnimatedImageFactoryImpl method createPreviewBitmap.

private CloseableReference<Bitmap> createPreviewBitmap(AnimatedImage image, Bitmap.Config bitmapConfig, int frameForPreview) {
    CloseableReference<Bitmap> bitmap = createBitmap(image.getWidth(), image.getHeight(), bitmapConfig);
    AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
    AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
    AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {

        @Override
        public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
        // Don't care.
        }

        @Override
        @Nullable
        public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
            return null;
        }
    });
    animatedImageCompositor.renderFrame(frameForPreview, bitmap.get());
    return bitmap;
}
Also used : AnimatedDrawableBackend(com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) AnimatedImageResult(com.facebook.imagepipeline.animated.base.AnimatedImageResult) CloseableReference(com.facebook.common.references.CloseableReference) AnimatedImageCompositor(com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor) SuppressLint(android.annotation.SuppressLint) Nullable(javax.annotation.Nullable)

Example 43 with CloseableReference

use of com.facebook.common.references.CloseableReference in project fresco by facebook.

the class AnimatedRepeatedPostprocessorProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mTestExecutorService = new TestExecutorService(new FakeClock());
    mPostprocessorProducer = new PostprocessorProducer(mInputProducer, mPlatformBitmapFactory, mTestExecutorService);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, /* isPrefetch */
    false, /* isIntermediateResultExpected */
    Priority.MEDIUM, mConfig);
    when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
    mResults = new ArrayList<>();
    when(mPostprocessor.getName()).thenReturn(POSTPROCESSOR_NAME);
    when(mProducerListener.requiresExtraMap(mProducerContext, POSTPROCESSOR_NAME)).thenReturn(true);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mResults.add(((CloseableReference<CloseableImage>) invocation.getArguments()[0]).clone());
            return null;
        }
    }).when(mConsumer).onNewResult(any(CloseableReference.class), anyInt());
    mInOrder = inOrder(mPostprocessor, mProducerListener, mConsumer);
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) CloseableReference(com.facebook.common.references.CloseableReference)

Example 44 with CloseableReference

use of com.facebook.common.references.CloseableReference in project fresco by facebook.

the class AnimatedSingleUsePostprocessorProducerTest method testNonStaticBitmapIsPassedOn.

@Test
public void testNonStaticBitmapIsPassedOn() {
    SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
    CloseableAnimatedImage sourceCloseableAnimatedImage = mock(CloseableAnimatedImage.class);
    CloseableReference<CloseableImage> sourceCloseableImageRef = CloseableReference.<CloseableImage>of(sourceCloseableAnimatedImage);
    postprocessorConsumer.onNewResult(sourceCloseableImageRef, Consumer.IS_LAST);
    sourceCloseableImageRef.close();
    mTestExecutorService.runUntilIdle();
    mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.IS_LAST));
    mInOrder.verifyNoMoreInteractions();
    assertEquals(1, mResults.size());
    CloseableReference<CloseableImage> res0 = mResults.get(0);
    assertTrue(CloseableReference.isValid(res0));
    assertSame(sourceCloseableAnimatedImage, res0.get());
    res0.close();
    verify(sourceCloseableAnimatedImage).close();
}
Also used : CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) SingleUsePostprocessorConsumer(com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)

Example 45 with CloseableReference

use of com.facebook.common.references.CloseableReference in project fresco by facebook.

the class RemoveImageTransformMetaDataProducerTest method testOnNewResult.

@Test
public void testOnNewResult() {
    when(mEncodedImage.getByteBufferRef()).thenReturn(mIntermediateResult);
    when(mEncodedImage.isValid()).thenReturn(true);
    mRemoveMetaDataConsumer.onNewResult(mEncodedImage, Consumer.NO_FLAGS);
    ArgumentCaptor<CloseableReference> argumentCaptor = ArgumentCaptor.forClass(CloseableReference.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.NO_FLAGS));
    CloseableReference intermediateResult = argumentCaptor.getValue();
    assertEquals(mIntermediateResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly(), intermediateResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
    when(mEncodedImage.getByteBufferRef()).thenReturn(mFinalResult);
    mRemoveMetaDataConsumer.onNewResult(mEncodedImage, Consumer.IS_LAST);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.NO_FLAGS));
    CloseableReference finalResult = argumentCaptor.getValue();
    assertEquals(mFinalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly(), finalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference)

Aggregations

CloseableReference (com.facebook.common.references.CloseableReference)50 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)24 Bitmap (android.graphics.Bitmap)17 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)16 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)14 DataSource (com.facebook.datasource.DataSource)9 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)8 Uri (android.net.Uri)7 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)7 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)5 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)5 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)5 Nullable (javax.annotation.Nullable)5 Test (org.junit.Test)5 SuppressLint (android.annotation.SuppressLint)4 CacheKey (com.facebook.cache.common.CacheKey)3 MemoryTrimType (com.facebook.common.memory.MemoryTrimType)3 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)3 CloseableBitmap (com.facebook.imagepipeline.image.CloseableBitmap)3 FakeClock (com.facebook.imagepipeline.testing.FakeClock)3