From 1821fd56faa447251c32cf1b2b61f6f16ac16ae9 Mon Sep 17 00:00:00 2001 From: Yithis Date: Tue, 29 Oct 2019 16:18:22 +0100 Subject: [PATCH] Enhance FrescoVitoRegionDecoder --- .../vito/FrescoVitoLithoRegionDecodeFragment.java | 2 +- .../fresco/vito/core/FrescoVitoRegionDecoder.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/vito/FrescoVitoLithoRegionDecodeFragment.java b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/vito/FrescoVitoLithoRegionDecodeFragment.java index 915f65ed0e..c90f6df5f6 100644 --- a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/vito/FrescoVitoLithoRegionDecodeFragment.java +++ b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/vito/FrescoVitoLithoRegionDecodeFragment.java @@ -151,6 +151,6 @@ public int getTitleId() { } private ImageDecoder createRegionDecoder() { - return new FrescoVitoRegionDecoder(Fresco.getImagePipelineFactory().getPlatformDecoder()); + return new FrescoVitoRegionDecoder(Fresco.getImagePipelineFactory().getPlatformDecoder(), null); } } diff --git a/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoRegionDecoder.java b/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoRegionDecoder.java index 9113fb550d..3bd4b7ccb8 100644 --- a/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoRegionDecoder.java +++ b/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoRegionDecoder.java @@ -13,7 +13,9 @@ import android.graphics.RectF; import android.os.Build; import com.facebook.common.references.CloseableReference; +import com.facebook.imageformat.DefaultImageFormats; import com.facebook.imagepipeline.common.ImageDecodeOptions; +import com.facebook.imagepipeline.decoder.DefaultImageDecoder; import com.facebook.imagepipeline.decoder.ImageDecoder; import com.facebook.imagepipeline.image.CloseableImage; import com.facebook.imagepipeline.image.CloseableStaticBitmap; @@ -31,9 +33,11 @@ public class FrescoVitoRegionDecoder implements ImageDecoder { private final PlatformDecoder mPlatformDecoder; + private final @Nullable DefaultImageDecoder mImageDecoder; - public FrescoVitoRegionDecoder(PlatformDecoder platformDecoder) { + public FrescoVitoRegionDecoder(PlatformDecoder platformDecoder, @Nullable DefaultImageDecoder imageDecoder) { mPlatformDecoder = platformDecoder; + mImageDecoder = imageDecoder; } /** @@ -49,6 +53,11 @@ public FrescoVitoRegionDecoder(PlatformDecoder platformDecoder) { public CloseableImage decode( EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) { + if (encodedImage.getImageFormat() != DefaultImageFormats.JPEG && + mImageDecoder != null) { + return mImageDecoder.decode(encodedImage, length, qualityInfo, options); + } + Rect regionToDecode = computeRegionToDecode(encodedImage, options); CloseableReference decodedBitmapReference = @@ -69,7 +78,7 @@ public CloseableImage decode( private @Nullable Rect computeRegionToDecode( EncodedImage encodedImage, ImageDecodeOptions options) { if (!(options instanceof FrescoVitoImageDecodeOptions)) { - return null; + return null; //this value means that we will decode full image. } FrescoVitoImageDecodeOptions frescoVitoOptions = (FrescoVitoImageDecodeOptions) options;