Search in sources :

Example 6 with CloseableImage

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

the class BaseFrescoStethoPlugin method storeEntries.

private void storeEntries(List<CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage>> entries, int i, PrintStream writer, File directory) throws IOException {
    String filename;
    for (CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage> entry : entries) {
        CloseableImage closeableImage = entry.value.get();
        if (closeableImage instanceof CloseableBitmap) {
            CloseableBitmap closeableBitmap = (CloseableBitmap) closeableImage;
            filename = "tmp" + i + ".png";
            writer.println(formatStrLocaleSafe("Storing image %d as %s. Key: %s", i, filename, entry.key));
            storeImage(closeableBitmap.getUnderlyingBitmap(), new File(directory, filename), Bitmap.CompressFormat.PNG, 100);
        } else {
            writer.println(formatStrLocaleSafe("Image %d has unrecognized type %s. Key: %s", i, closeableImage, entry.key));
        }
        i++;
    }
}
Also used : CloseableImage(com.facebook.imagepipeline.image.CloseableImage) File(java.io.File) CacheKey(com.facebook.cache.common.CacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) CountingMemoryCacheInspector(com.facebook.imagepipeline.cache.CountingMemoryCacheInspector) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap)

Example 7 with CloseableImage

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

the class PipelineDraweeController method createDrawable.

@Override
protected Drawable createDrawable(CloseableReference<CloseableImage> image) {
    Preconditions.checkState(CloseableReference.isValid(image));
    CloseableImage closeableImage = image.get();
    maybeUpdateDebugOverlay(closeableImage);
    if (mDrawableFactories != null) {
        for (DrawableFactory factory : mDrawableFactories) {
            if (factory.supportsImageType(closeableImage)) {
                Drawable drawable = factory.createDrawable(closeableImage);
                if (drawable != null) {
                    return drawable;
                }
            }
        }
    }
    Drawable defaultDrawable = mDefaultDrawableFactory.createDrawable(closeableImage);
    if (defaultDrawable != null) {
        return defaultDrawable;
    }
    throw new UnsupportedOperationException("Unrecognized image class: " + closeableImage);
}
Also used : Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) OrientedDrawable(com.facebook.drawee.drawable.OrientedDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DebugControllerOverlayDrawable(com.facebook.drawee.debug.DebugControllerOverlayDrawable) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) AnimatedDrawableFactory(com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory)

Example 8 with CloseableImage

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

the class AnimatedFrameCacheTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    MemoryCacheParams params = new MemoryCacheParams(4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
    when(mMemoryCacheParamsSupplier.get()).thenReturn(params);
    CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = BitmapCountingMemoryCacheFactory.get(mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, mPlatformBitmapFactory, true);
    mCacheKey = new SimpleCacheKey("key");
    mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
    mFrame1 = CloseableReference.of(mock(CloseableImage.class));
    mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
Also used : MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CacheKey(com.facebook.cache.common.CacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 9 with CloseableImage

use of com.facebook.imagepipeline.image.CloseableImage 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, true);
    sourceCloseableImageRef.close();
    mTestExecutorService.runUntilIdle();
    mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(true));
    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 10 with CloseableImage

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

the class FrescoFrameCache method onFrameRendered.

@Override
public synchronized void onFrameRendered(int frameNumber, CloseableReference<Bitmap> bitmapReference, @BitmapAnimationBackend.FrameType int frameType) {
    Preconditions.checkNotNull(bitmapReference);
    CloseableReference<CloseableImage> closableReference = null;
    try {
        // The given CloseableStaticBitmap will be cached and then released by the resource releaser
        // of the closeable reference
        CloseableImage closeableImage = new CloseableStaticBitmap(bitmapReference, ImmutableQualityInfo.FULL_QUALITY, 0);
        closableReference = CloseableReference.of(closeableImage);
        CloseableReference.closeSafely(mLastCachedItem);
        mLastCachedItem = mAnimatedFrameCache.cache(frameNumber, closableReference);
    } finally {
        CloseableReference.closeSafely(closableReference);
    }
}
Also used : CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap)

Aggregations

CloseableImage (com.facebook.imagepipeline.image.CloseableImage)19 CacheKey (com.facebook.cache.common.CacheKey)7 CloseableReference (com.facebook.common.references.CloseableReference)7 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)4 Bitmap (android.graphics.Bitmap)3 BitmapMemoryCacheKey (com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)2 CountingMemoryCacheInspector (com.facebook.imagepipeline.cache.CountingMemoryCacheInspector)2 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)2 CloseableBitmap (com.facebook.imagepipeline.image.CloseableBitmap)2 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)2 SingleUsePostprocessorConsumer (com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)2 IOException (java.io.IOException)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1