Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance FrescoVitoRegionDecoder #2428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ public int getTitleId() {
}

private ImageDecoder createRegionDecoder() {
return new FrescoVitoRegionDecoder(Fresco.getImagePipelineFactory().getPlatformDecoder());
return new FrescoVitoRegionDecoder(Fresco.getImagePipelineFactory().getPlatformDecoder(), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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<Bitmap> decodedBitmapReference =
Expand All @@ -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;

Expand Down