Set producer context extras in the bitmap producer
@@ -13,7 +13,10 @@ import com.facebook.common.references.CloseableReference;
import com.facebook.imagepipeline.cache.CacheKeyFactory;
import com.facebook.imagepipeline.cache.MemoryCache;
import com.facebook.imagepipeline.image.CloseableImage;
+import com.facebook.imagepipeline.image.HasImageMetadata;
+import com.facebook.imagepipeline.image.OriginalEncodedImageInfo;
import com.facebook.imagepipeline.image.QualityInfo;
+import com.facebook.imagepipeline.producers.ProducerContext.ExtraKeys;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.systrace.FrescoSystrace;
@@ -53,6 +56,7 @@ public class BitmapMemoryCacheProducer implements Producer<CloseableReference<Cl
CloseableReference<CloseableImage> cachedReference = mMemoryCache.get(cacheKey);
if (cachedReference != null) {
+ maybeSetExtrasFromCloseableImage(cachedReference.get(), producerContext);
boolean isFinal = cachedReference.get().getQualityInfo().isOfFullQuality();
if (isFinal) {
listener.onProducerFinishWithSuccess(
@@ -179,4 +183,16 @@ public class BitmapMemoryCacheProducer implements Producer<CloseableReference<Cl
protected String getProducerName() {
return PRODUCER_NAME;
}
+
+ private static void maybeSetExtrasFromCloseableImage(
+ HasImageMetadata imageWithMeta, ProducerContext producerContext) {
+ final OriginalEncodedImageInfo info = imageWithMeta.getOriginalEncodedImageInfo();
+ if (info == null) {
+ return;
+ }
+
+ producerContext.setExtra(ExtraKeys.ENCODED_WIDTH, info.getWidth());
+ producerContext.setExtra(ExtraKeys.ENCODED_HEIGHT, info.getHeight());
+ producerContext.setExtra(ExtraKeys.ENCODED_SIZE, info.getSize());
+ }
}
