com.facebook.imagepipeline.image.CloseableImage Java Examples

The following examples show how to use com.facebook.imagepipeline.image.CloseableImage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onNewResultImpl(
    CloseableReference<CloseableImage> newResult, boolean isLast) {
  if (!isLast) {
    return;
  }
  if (!mCloseableImageCopier.isCloseableImageCopyable(newResult)) {
    mConsumer.onNewResult(newResult, true);
    return;
  }

  synchronized (RepeatedPostprocessorConsumer.this) {
    mOriginalImageRef = newResult.clone();
  }
  maybeExecuteCopyAndPostprocessBitmap();
}
 
Example #2
Source File: ProducerSequenceFactory.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Bitmap cache get -> thread hand off -> multiplex -> bitmap cache
 *
 * @param inputProducer producer providing the input to the bitmap cache
 * @return bitmap cache get to bitmap cache sequence
 */
private Producer<CloseableReference<CloseableImage>> newBitmapCacheGetToBitmapCacheSequence(
    Producer<CloseableReference<CloseableImage>> inputProducer) {
  BitmapMemoryCacheProducer bitmapMemoryCacheProducer =
      mProducerFactory.newBitmapMemoryCacheProducer(inputProducer);
  BitmapMemoryCacheKeyMultiplexProducer bitmapKeyMultiplexProducer =
      mProducerFactory.newBitmapMemoryCacheKeyMultiplexProducer(bitmapMemoryCacheProducer);
  ThreadHandoffProducer<CloseableReference<CloseableImage>> threadHandoffProducer =
      mProducerFactory.newBackgroundThreadHandoffProducer(
          bitmapKeyMultiplexProducer, mThreadHandoffProducerQueue);
  if (mIsEncodedMemoryCacheProbingEnabled || mIsDiskCacheProbingEnabled) {
    BitmapMemoryCacheGetProducer bitmapMemoryCacheGetProducer =
        mProducerFactory.newBitmapMemoryCacheGetProducer(threadHandoffProducer);
    return mProducerFactory.newBitmapProbeProducer(bitmapMemoryCacheGetProducer);
  }
  return mProducerFactory.newBitmapMemoryCacheGetProducer(threadHandoffProducer);
}
 
Example #3
Source File: AnimatedSingleUsePostprocessorProducerTest.java    From fresco with MIT License 6 votes vote down vote up
@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();
}
 
Example #4
Source File: BitmapPrepareProducerTest.java    From fresco with MIT License 6 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  mImageReference = CloseableReference.of((CloseableImage) mCloseableStaticBitmap);
  when(mCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mBitmap);

  // 100 * 15 = 1500 (between MIN_BITMAP_SIZE_BYTES and MAX_BITMAP_SIZE_BYTES)
  when(mBitmap.getRowBytes()).thenReturn(100);
  when(mBitmap.getHeight()).thenReturn(15);

  doAnswer(
          new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
              Object[] args = invocation.getArguments();
              Consumer<CloseableReference<CloseableImage>> consumer =
                  (Consumer<CloseableReference<CloseableImage>>) args[0];
              consumer.onNewResult(mImageReference, 0);
              return null;
            }
          })
      .when(mInputProducer)
      .produceResults(any(Consumer.class), any(ProducerContext.class));
}
 
Example #5
Source File: ExperimentalBitmapAnimationDrawableFactory.java    From fresco with MIT License 6 votes vote down vote up
public ExperimentalBitmapAnimationDrawableFactory(
    AnimatedDrawableBackendProvider animatedDrawableBackendProvider,
    ScheduledExecutorService scheduledExecutorServiceForUiThread,
    ExecutorService executorServiceForFramePreparing,
    MonotonicClock monotonicClock,
    PlatformBitmapFactory platformBitmapFactory,
    CountingMemoryCache<CacheKey, CloseableImage> backingCache,
    Supplier<Integer> cachingStrategySupplier,
    Supplier<Integer> numberOfFramesToPrepareSupplier) {
  mAnimatedDrawableBackendProvider = animatedDrawableBackendProvider;
  mScheduledExecutorServiceForUiThread = scheduledExecutorServiceForUiThread;
  mExecutorServiceForFramePreparing = executorServiceForFramePreparing;
  mMonotonicClock = monotonicClock;
  mPlatformBitmapFactory = platformBitmapFactory;
  mBackingCache = backingCache;
  mCachingStrategySupplier = cachingStrategySupplier;
  mNumberOfFramesToPrepareSupplier = numberOfFramesToPrepareSupplier;
}
 
Example #6
Source File: PostprocessorProducer.java    From fresco with MIT License 6 votes vote down vote up
@Override
public void produceResults(
    final Consumer<CloseableReference<CloseableImage>> consumer, ProducerContext context) {
  final ProducerListener2 listener = context.getProducerListener();
  final Postprocessor postprocessor = context.getImageRequest().getPostprocessor();
  final PostprocessorConsumer basePostprocessorConsumer =
      new PostprocessorConsumer(consumer, listener, postprocessor, context);
  final Consumer<CloseableReference<CloseableImage>> postprocessorConsumer;
  if (postprocessor instanceof RepeatedPostprocessor) {
    postprocessorConsumer =
        new RepeatedPostprocessorConsumer(
            basePostprocessorConsumer, (RepeatedPostprocessor) postprocessor, context);
  } else {
    postprocessorConsumer = new SingleUsePostprocessorConsumer(basePostprocessorConsumer);
  }
  mInputProducer.produceResults(postprocessorConsumer, context);
}
 
Example #7
Source File: BaseBitmapDataSubscriber.java    From fresco with MIT License 6 votes vote down vote up
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (!dataSource.isFinished()) {
    return;
  }

  CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
  Bitmap bitmap = null;
  if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) {
    bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
  }

  try {
    onNewResultImpl(bitmap);
  } finally {
    CloseableReference.closeSafely(closeableImageRef);
  }
}
 
Example #8
Source File: FrescoControllerImpl.java    From fresco with MIT License 6 votes vote down vote up
@Nullable
private CloseableReference<CloseableImage> getCachedImage(@Nullable CacheKey cacheKey) {
  if (FrescoSystrace.isTracing()) {
    FrescoSystrace.beginSection("FrescoControllerImpl#getCachedImage");
  }
  try {
    CloseableReference<CloseableImage> cachedImageReference =
        mFrescoContext.getImagePipeline().getCachedImage(cacheKey);
    if (CloseableReference.isValid(cachedImageReference)) {
      return cachedImageReference;
    }
    return null;
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example #9
Source File: DefaultImageDecoder.java    From fresco with MIT License 6 votes vote down vote up
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  ImageFormat imageFormat = encodedImage.getImageFormat();
  if (imageFormat == DefaultImageFormats.JPEG) {
    return decodeJpeg(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == DefaultImageFormats.GIF) {
    return decodeGif(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == DefaultImageFormats.WEBP_ANIMATED) {
    return decodeAnimatedWebp(encodedImage, length, qualityInfo, options);
  } else if (imageFormat == ImageFormat.UNKNOWN) {
    throw new DecodeException("unknown image format", encodedImage);
  }
  return decodeStaticImage(encodedImage, options);
}
 
Example #10
Source File: CompositionPostProcessor.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
public CompositionPostProcessor(
  int width,
  int height,
  @Nullable JSONObject config,
  @Nonnull CloseableReference<CloseableImage> src,
  @Nonnull CacheKey srcCacheKey
) {
  super(config);

  InputConverter converter = new InputConverter(width, height);

  mWidth = width;
  mHeight = height;

  final PointF center = new PointF(0.5f, 0.5f);
  final Transform transform = new Transform(center, center, new Scale.WithMode(Scale.Mode.COVER), 0);

  mSrc = src.clone();
  mSrcCacheKey = srcCacheKey;
  mSrcTransform = converter.convertTransform(config, "srcTransform", transform);
  mDstTransform = converter.convertTransform(config, "dstTransform", transform);
  mResizeCanvasTo = converter.convertText(config, "resizeCanvasTo", null);
  mSwapImages = converter.convertBool(config, "swapImages", false);
}
 
Example #11
Source File: ProducerSequenceFactory.java    From fresco with MIT License 5 votes vote down vote up
/** swallow result producer -> inputProducer */
private synchronized Producer<Void> getDecodedImagePrefetchSequence(
    Producer<CloseableReference<CloseableImage>> inputProducer) {
  if (!mCloseableImagePrefetchSequences.containsKey(inputProducer)) {
    SwallowResultProducer<CloseableReference<CloseableImage>> swallowResultProducer =
        mProducerFactory.newSwallowResultProducer(inputProducer);
    mCloseableImagePrefetchSequences.put(inputProducer, swallowResultProducer);
  }
  return mCloseableImagePrefetchSequences.get(inputProducer);
}
 
Example #12
Source File: ProducerSequenceFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private Producer<CloseableReference<CloseableImage>> getBasicDecodedImageSequence(
    ImageRequest imageRequest) {
  Preconditions.checkNotNull(imageRequest);
  ImageRequest.RequestLevel lowestPermittedRequestLevel =
      imageRequest.getLowestPermittedRequestLevel();
  Preconditions.checkState(
      lowestPermittedRequestLevel.equals(ImageRequest.RequestLevel.FULL_FETCH) ||
          lowestPermittedRequestLevel.equals(
              ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE),
      "Only support bitmap memory cache or full fetch at present, request level is %s ",
      lowestPermittedRequestLevel);

  if (lowestPermittedRequestLevel.equals(ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE)) {
    return getBitmapCacheGetOnlySequence();
  }

  Uri uri = imageRequest.getSourceUri();
  if (UriUtil.isNetworkUri(uri)) {
    return getNetworkFetchSequence();
  } else if (UriUtil.isLocalFileUri(uri)) {
    if (MediaUtils.isVideo(MediaUtils.extractMime(uri.getPath()))) {
      return getLocalVideoFileFetchSequence();
    } else {
      return getLocalImageFileFetchSequence();
    }
  } else if (UriUtil.isLocalContentUri(uri)) {
    return getLocalContentUriFetchSequence();
  } else if (UriUtil.isLocalAssetUri(uri)) {
    return getLocalAssetFetchSequence();
  } else if (UriUtil.isLocalResourceUri(uri)) {
    return getLocalResourceFetchSequence();
  } else {
    throw new RuntimeException(
        "Unsupported image type! Uri is: " + uri.toString().substring(0, 30));
  }
}
 
Example #13
Source File: ImagePipelineFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public MemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> getBitmapMemoryCache() {
  if (mBitmapMemoryCache == null) {
    mBitmapMemoryCache =
        BitmapMemoryCacheFactory.get(
            getBitmapCountingMemoryCache(),
            mConfig.getImageCacheStatsTracker());
  }
  return mBitmapMemoryCache;
}
 
Example #14
Source File: DecodeProducer.java    From fresco with MIT License 5 votes vote down vote up
public NetworkImagesProgressiveDecoder(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext producerContext,
    final ProgressiveJpegParser progressiveJpegParser,
    final ProgressiveJpegConfig progressiveJpegConfig,
    final boolean decodeCancellationEnabled,
    final int maxBitmapSize) {
  super(consumer, producerContext, decodeCancellationEnabled, maxBitmapSize);
  mProgressiveJpegParser = Preconditions.checkNotNull(progressiveJpegParser);
  mProgressiveJpegConfig = Preconditions.checkNotNull(progressiveJpegConfig);
  mLastScheduledScanNumber = 0;
}
 
Example #15
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 5 votes vote down vote up
private void getFiles(
    PrintStream writer, CountingMemoryCacheInspector.DumpInfo<CacheKey, CloseableImage> dumpInfo)
    throws DumpException, IOException {
  writer.println("\nStoring all images in the memory cache into /sdcard/imagedumperfiles/ ...");

  File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/imagedumperfiles/");
  if (dir.exists() && dir.isDirectory()) {
    File[] files = dir.listFiles();
    if (files != null) {
      for (File file : files) {
        file.delete();
      }
    }
    if (!dir.delete()) {
      throw new DumpException("Failed to clear existing /sdcard/imagedumperfiles directory");
    }
  }
  if (!dir.mkdirs()) {
    throw new DumpException("Failed to create /sdcard/imagedumperfiles directory");
  }
  if (!dumpInfo.lruEntries.isEmpty()) {
    writer.println("LRU Entries:");
    storeEntries(dumpInfo.lruEntries, 1, writer, dir);
  }
  if (!dumpInfo.sharedEntries.isEmpty()) {
    writer.println("Shared Entries:");
    storeEntries(dumpInfo.sharedEntries, dumpInfo.lruEntries.size() + 1, writer, dir);
  }

  writer.println("Done!");
}
 
Example #16
Source File: ProducerFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public ProducerFactory(
    Context context,
    ByteArrayPool byteArrayPool,
    ImageDecoder imageDecoder,
    ProgressiveJpegConfig progressiveJpegConfig,
    ExecutorSupplier executorSupplier,
    PooledByteBufferFactory pooledByteBufferFactory,
    MemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> bitmapMemoryCache,
    MemoryCache<CacheKey, PooledByteBuffer, Void> encodedMemoryCache,
    BufferedDiskCache defaultBufferedDiskCache,
    BufferedDiskCache smallImageBufferedDiskCache,
    CacheKeyFactory cacheKeyFactory,
    CloseableImageCopier closeableImageCopier) {
  mContentResolver = context.getApplicationContext().getContentResolver();
  mResources = context.getApplicationContext().getResources();
  mAssetManager = context.getApplicationContext().getAssets();

  mByteArrayPool = byteArrayPool;
  mImageDecoder = imageDecoder;
  mProgressiveJpegConfig = progressiveJpegConfig;

  mExecutorSupplier = executorSupplier;
  mPooledByteBufferFactory = pooledByteBufferFactory;

  mBitmapMemoryCache = bitmapMemoryCache;
  mEncodedMemoryCache = encodedMemoryCache;
  mDefaultBufferedDiskCache = defaultBufferedDiskCache;
  mSmallImageBufferedDiskCache = smallImageBufferedDiskCache;
  mCacheKeyFactory = cacheKeyFactory;

  mCloseableImageCopier = closeableImageCopier;
}
 
Example #17
Source File: PipelineDraweeControllerFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public PipelineDraweeController newController(
    Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier,
    String id,
    Object callerContext) {
  return new PipelineDraweeController(
      mResources,
      mDeferredReleaser,
      mAnimatedDrawableFactory,
      mUiThreadExecutor,
      dataSourceSupplier,
      id,
      callerContext);
}
 
Example #18
Source File: DecodeProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
NetworkImagesProgressiveDecoder(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext producerContext,
    final ProgressiveJpegParser progressiveJpegParser,
    final ProgressiveJpegConfig progressiveJpegConfig) {
  super(consumer, producerContext);
  mProgressiveJpegParser = Preconditions.checkNotNull(progressiveJpegParser);
  mProgressiveJpegConfig = Preconditions.checkNotNull(progressiveJpegConfig);
  mLastDecodedScanNumber = 0;
}
 
Example #19
Source File: FrescoDrawable2.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Nullable
public Drawable setImage(
    @Nullable Drawable imageDrawable,
    @Nullable CloseableReference<CloseableImage> imageReference) {
  return super.setImage(imageDrawable, imageReference);
}
 
Example #20
Source File: AnimatedFrameCache.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Gets the image to be reused, or null if there is no such image.
 *
 * <p>The returned image is the least recently used image that has no more clients referencing it,
 * and it has not yet been evicted from the cache.
 *
 * <p>The client can freely modify the bitmap of the returned image and can cache it again without
 * any restrictions.
 */
@Nullable
public CloseableReference<CloseableImage> getForReuse() {
  while (true) {
    CacheKey key = popFirstFreeItemKey();
    if (key == null) {
      return null;
    }
    CloseableReference<CloseableImage> imageRef = mBackingCache.reuse(key);
    if (imageRef != null) {
      return imageRef;
    }
  }
}
 
Example #21
Source File: FrescoStateImpl.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void setMainFetchDatasource(
    @Nullable DataSource<CloseableReference<CloseableImage>> mainFetchDatasource) {
  if (mMainFetchDatasource != null) {
    mMainFetchDatasource.close();
  }
  mMainFetchDatasource = mainFetchDatasource;
}
 
Example #22
Source File: ProducerSequenceFactoryTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testLocalResourceFullFetch() {
  PowerMockito.when(mImageRequest.getSourceUriType()).thenReturn(SOURCE_TYPE_LOCAL_RESOURCE);
  Producer<CloseableReference<CloseableImage>> producer =
      mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest);
  assertSame(producer, mProducerSequenceFactory.mLocalResourceFetchSequence);
}
 
Example #23
Source File: AnimatedFrameCacheTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testReuse() {
  CloseableReference<CloseableImage> ret = mAnimatedFrameCache.cache(1, mFrame1);
  ret.close();
  CloseableReference<CloseableImage> free = mAnimatedFrameCache.getForReuse();
  assertNotNull(free);
}
 
Example #24
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private AbstractPostprocessorConsumer(
    Consumer<CloseableReference<CloseableImage>> consumer,
    ProducerListener listener,
    String requestId,
    Postprocessor postprocessor) {
  mConsumer = consumer;
  mListener = listener;
  mRequestId = requestId;
  mPostprocessor = postprocessor;
}
 
Example #25
Source File: ImagePipeline.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Returns a reference to the cached image
 *
 * @param cacheKey
 * @return a closeable reference or null if image was not present in cache
 */
@Nullable
public CloseableReference<CloseableImage> getCachedImage(@Nullable CacheKey cacheKey) {
  MemoryCache<CacheKey, CloseableImage> memoryCache = mBitmapMemoryCache;
  if (memoryCache == null || cacheKey == null) {
    return null;
  }
  CloseableReference<CloseableImage> closeableImage = memoryCache.get(cacheKey);
  if (closeableImage != null && !closeableImage.get().getQualityInfo().isOfFullQuality()) {
    closeableImage.close();
    return null;
  }
  return closeableImage;
}
 
Example #26
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public PostprocessorProducer(
    Producer<CloseableReference<CloseableImage>> nextProducer,
    CloseableImageCopier closeableImageCopier,
    Executor executor) {
  mNextProducer = Preconditions.checkNotNull(nextProducer);
  mCloseableImageCopier = Preconditions.checkNotNull(closeableImageCopier);
  mExecutor = Preconditions.checkNotNull(executor);
}
 
Example #27
Source File: BitmapMemoryCacheFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public static MemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> get(
  CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> bitmapCountingMemoryCache,
  final ImageCacheStatsTracker imageCacheStatsTracker) {

  ReferenceWrappingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> wrappingCache =
      new ReferenceWrappingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void>(
          bitmapCountingMemoryCache);

  imageCacheStatsTracker.registerBitmapMemoryCache(bitmapCountingMemoryCache);
  MemoryCacheTracker memoryCacheTracker = new MemoryCacheTracker() {
    @Override
    public void onCacheHit() {
      imageCacheStatsTracker.onBitmapCacheHit();
    }

    @Override
    public void onCacheMiss() {
      imageCacheStatsTracker.onBitmapCacheMiss();
    }

    @Override
    public void onCachePut() {
      imageCacheStatsTracker.onBitmapCachePut();
    }
  };

  return new InstrumentedMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void>(
      wrappingCache,
      memoryCacheTracker);
}
 
Example #28
Source File: FrescoDrawable2Impl.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void onNewResult(@Nonnull DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (dataSource != mDataSource || mImageRequest == null || mDrawableDataSubscriber == null) {
    return; // We don't care
  }
  mDrawableDataSubscriber.onNewResult(this, mImageRequest, dataSource);
}
 
Example #29
Source File: ProducerSequenceFactory.java    From fresco with MIT License 5 votes vote down vote up
/**
 * bitmap cache get -> background thread hand-off -> bitmap cache -> decode -> resize and rotate
 * -> (webp transcode) -> data fetch.
 */
private synchronized Producer<CloseableReference<CloseableImage>> getDataFetchSequence() {
  if (mDataFetchSequence == null) {
    Producer<EncodedImage> inputProducer = mProducerFactory.newDataFetchProducer();
    if (WebpSupportStatus.sIsWebpSupportRequired
        && (!mWebpSupportEnabled || WebpSupportStatus.sWebpBitmapFactory == null)) {
      inputProducer = mProducerFactory.newWebpTranscodeProducer(inputProducer);
    }
    inputProducer = mProducerFactory.newAddImageTransformMetaDataProducer(inputProducer);
    inputProducer =
        mProducerFactory.newResizeAndRotateProducer(inputProducer, true, mImageTranscoderFactory);
    mDataFetchSequence = newBitmapCacheGetToDecodeSequence(inputProducer);
  }
  return mDataFetchSequence;
}
 
Example #30
Source File: BitmapCountingMemoryCacheFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public static CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> get(
    Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier,
    MemoryTrimmableRegistry memoryTrimmableRegistry) {
  MemoryCacheIndex<BitmapMemoryCacheKey, CloseableImage, Void> memoryCacheIndex =
      new SimpleMemoryCacheIndex<BitmapMemoryCacheKey, CloseableImage>();

  CountingMemoryCache.ValueInfoCallback<CloseableImage> valueTypeDescriptor =
      new CountingMemoryCache.ValueInfoCallback<CloseableImage>() {
        @Override
        public long getSizeInBytes(CloseableImage value) {
          return value.getSizeInBytes();
        }
      };

  CountingMemoryCache.CacheTrimStrategy trimStrategy = new BitmapMemoryCacheTrimStrategy();

  CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> countingCache =
      new CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void>(
          memoryCacheIndex,
          valueTypeDescriptor,
          trimStrategy,
          bitmapMemoryCacheParamsSupplier);

   memoryTrimmableRegistry.registerMemoryTrimmable(countingCache);

  return countingCache;
}