Search in sources :

Example 1 with Postprocessor

use of com.facebook.imagepipeline.request.Postprocessor in project fresco by facebook.

the class PostprocessorProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, ProducerContext context) {
    final ProducerListener2 listener = context.getProducerListener();
    final Postprocessor postprocessor = context.getImageRequest().getPostprocessor();
    Preconditions.checkNotNull(postprocessor);
    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);
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) Postprocessor(com.facebook.imagepipeline.request.Postprocessor) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor)

Example 2 with Postprocessor

use of com.facebook.imagepipeline.request.Postprocessor in project fresco by facebook.

the class ImagePipelineUtilsImpl method createDecodedImageRequestBuilder.

@Nullable
protected ImageRequestBuilder createDecodedImageRequestBuilder(@Nullable ImageRequestBuilder imageRequestBuilder, DecodedImageOptions imageOptions) {
    if (imageRequestBuilder == null) {
        return null;
    }
    ResizeOptions resizeOptions = imageOptions.getResizeOptions();
    if (resizeOptions != null) {
        imageRequestBuilder.setResizeOptions(resizeOptions);
    }
    RotationOptions rotationOptions = imageOptions.getRotationOptions();
    if (rotationOptions != null) {
        imageRequestBuilder.setRotationOptions(rotationOptions);
    }
    ImageDecodeOptions imageDecodeOptions = mImageDecodeOptionsProvider.create(imageRequestBuilder, imageOptions);
    if (imageDecodeOptions != null) {
        imageRequestBuilder.setImageDecodeOptions(imageDecodeOptions);
    }
    imageRequestBuilder.setLocalThumbnailPreviewsEnabled(imageOptions.areLocalThumbnailPreviewsEnabled());
    Postprocessor postprocessor = imageOptions.getPostprocessor();
    if (postprocessor != null) {
        imageRequestBuilder.setPostprocessor(postprocessor);
    }
    if (imageOptions.isProgressiveDecodingEnabled() != null) {
        imageRequestBuilder.setProgressiveRenderingEnabled(imageOptions.isProgressiveDecodingEnabled());
    }
    return imageRequestBuilder;
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) Postprocessor(com.facebook.imagepipeline.request.Postprocessor) RotationOptions(com.facebook.imagepipeline.common.RotationOptions) ImageDecodeOptions(com.facebook.imagepipeline.common.ImageDecodeOptions) Nullable(javax.annotation.Nullable)

Example 3 with Postprocessor

use of com.facebook.imagepipeline.request.Postprocessor in project fresco by facebook.

the class PostprocessedBitmapMemoryCacheProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) {
    final ProducerListener2 listener = producerContext.getProducerListener();
    final ImageRequest imageRequest = producerContext.getImageRequest();
    final Object callerContext = producerContext.getCallerContext();
    // If there's no postprocessor or the postprocessor doesn't require caching, forward results.
    final Postprocessor postprocessor = imageRequest.getPostprocessor();
    if (postprocessor == null || postprocessor.getPostprocessorCacheKey() == null) {
        mInputProducer.produceResults(consumer, producerContext);
        return;
    }
    listener.onProducerStart(producerContext, getProducerName());
    final CacheKey cacheKey = mCacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, callerContext);
    final boolean isBitmapCacheEnabledForRead = producerContext.getImageRequest().isCacheEnabled(ImageRequest.CachesLocationsMasks.BITMAP_READ);
    CloseableReference<CloseableImage> cachedReference = isBitmapCacheEnabledForRead ? mMemoryCache.get(cacheKey) : null;
    if (cachedReference != null) {
        listener.onProducerFinishWithSuccess(producerContext, getProducerName(), listener.requiresExtraMap(producerContext, getProducerName()) ? ImmutableMap.of(VALUE_FOUND, "true") : null);
        listener.onUltimateProducerReached(producerContext, PRODUCER_NAME, true);
        producerContext.putOriginExtra("memory_bitmap", "postprocessed");
        consumer.onProgressUpdate(1.0f);
        consumer.onNewResult(cachedReference, Consumer.IS_LAST);
        cachedReference.close();
    } else {
        final boolean isRepeatedProcessor = postprocessor instanceof RepeatedPostprocessor;
        final boolean isBitmapCacheEnabledForWrite = producerContext.getImageRequest().isCacheEnabled(ImageRequest.CachesLocationsMasks.BITMAP_WRITE);
        Consumer<CloseableReference<CloseableImage>> cachedConsumer = new CachedPostprocessorConsumer(consumer, cacheKey, isRepeatedProcessor, mMemoryCache, isBitmapCacheEnabledForWrite);
        listener.onProducerFinishWithSuccess(producerContext, getProducerName(), listener.requiresExtraMap(producerContext, getProducerName()) ? ImmutableMap.of(VALUE_FOUND, "false") : null);
        mInputProducer.produceResults(cachedConsumer, producerContext);
    }
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableReference(com.facebook.common.references.CloseableReference) Postprocessor(com.facebook.imagepipeline.request.Postprocessor) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CacheKey(com.facebook.cache.common.CacheKey) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor)

Example 4 with Postprocessor

use of com.facebook.imagepipeline.request.Postprocessor in project fresco by facebook.

the class PipelineUtil method addOptionalFeatures.

/**
 * Utility method which adds optional configuration to ImageRequest
 *
 * @param imageRequestBuilder The Builder for ImageRequest
 * @param config The Config
 */
public static void addOptionalFeatures(ImageRequestBuilder imageRequestBuilder, Config config) {
    if (config.usePostprocessor) {
        final Postprocessor postprocessor;
        switch(config.postprocessorType) {
            case "use_slow_postprocessor":
                postprocessor = DelayPostprocessor.getMediumPostprocessor();
                break;
            case "use_fast_postprocessor":
                postprocessor = DelayPostprocessor.getFastPostprocessor();
                break;
            default:
                postprocessor = DelayPostprocessor.getMediumPostprocessor();
        }
        imageRequestBuilder.setPostprocessor(postprocessor);
    }
    if (config.rotateUsingMetaData) {
        imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
    } else {
        imageRequestBuilder.setRotationOptions(RotationOptions.forceRotation(config.forcedRotationAngle));
    }
}
Also used : Postprocessor(com.facebook.imagepipeline.request.Postprocessor) DelayPostprocessor(com.facebook.samples.scrollperf.postprocessor.DelayPostprocessor)

Example 5 with Postprocessor

use of com.facebook.imagepipeline.request.Postprocessor in project fresco by facebook.

the class DefaultCacheKeyFactory method getPostprocessedBitmapCacheKey.

@Override
public CacheKey getPostprocessedBitmapCacheKey(ImageRequest request, @Nullable Object callerContext) {
    final Postprocessor postprocessor = request.getPostprocessor();
    final CacheKey postprocessorCacheKey;
    final String postprocessorName;
    if (postprocessor != null) {
        postprocessorCacheKey = postprocessor.getPostprocessorCacheKey();
        postprocessorName = postprocessor.getClass().getName();
    } else {
        postprocessorCacheKey = null;
        postprocessorName = null;
    }
    BitmapMemoryCacheKey cacheKey = new BitmapMemoryCacheKey(getCacheKeySourceUri(request.getSourceUri()).toString(), request.getResizeOptions(), request.getRotationOptions(), request.getImageDecodeOptions(), postprocessorCacheKey, postprocessorName);
    cacheKey.setCallerContext(callerContext);
    return cacheKey;
}
Also used : Postprocessor(com.facebook.imagepipeline.request.Postprocessor) CacheKey(com.facebook.cache.common.CacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey)

Aggregations

Postprocessor (com.facebook.imagepipeline.request.Postprocessor)5 CacheKey (com.facebook.cache.common.CacheKey)2 CloseableReference (com.facebook.common.references.CloseableReference)2 RepeatedPostprocessor (com.facebook.imagepipeline.request.RepeatedPostprocessor)2 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)1 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)1 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)1 RotationOptions (com.facebook.imagepipeline.common.RotationOptions)1 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)1 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)1 DelayPostprocessor (com.facebook.samples.scrollperf.postprocessor.DelayPostprocessor)1 Nullable (javax.annotation.Nullable)1