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);
}
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;
}
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);
}
}
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));
}
}
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;
}
Aggregations