Skip to content

Commit

Permalink
avif: Use the correct bucket for GlideModule
Browse files Browse the repository at this point in the history
Instead of prepending to the default prepend_all bucket, prepend
the Avif integration decoders to the Bitmap bucket. Also add a
configuration for decoding into a BitmapDrawable.

This prevents some incorrect interactions with the Downsampler
when dealing with the animated drawables (if the Avif integration
is in the prepend_all bucket, it prevents GIF animations from
playing back since they are returned as a BitmapDrawable as
explained in issue #5051).

Fixes #5051
  • Loading branch information
vigneshvg authored and sjudd committed Nov 9, 2023
1 parent c06a85d commit 3bbc390
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import androidx.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.resource.bitmap.BitmapDrawableDecoder;
import com.bumptech.glide.module.LibraryGlideModule;
import java.io.InputStream;
import java.nio.ByteBuffer;
Expand All @@ -21,10 +23,21 @@ public void registerComponents(
// the integration will be preferred for Avif images.
AvifByteBufferBitmapDecoder byteBufferBitmapDecoder =
new AvifByteBufferBitmapDecoder(glide.getBitmapPool());
registry.prepend(ByteBuffer.class, Bitmap.class, byteBufferBitmapDecoder);
registry.prepend(
Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, byteBufferBitmapDecoder);
registry.prepend(
Registry.BUCKET_BITMAP_DRAWABLE,
ByteBuffer.class,
BitmapDrawable.class,
new BitmapDrawableDecoder<>(context.getResources(), byteBufferBitmapDecoder));
AvifStreamBitmapDecoder streamBitmapDecoder =
new AvifStreamBitmapDecoder(
registry.getImageHeaderParsers(), byteBufferBitmapDecoder, glide.getArrayPool());
registry.prepend(InputStream.class, Bitmap.class, streamBitmapDecoder);
registry.prepend(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, streamBitmapDecoder);
registry.prepend(
Registry.BUCKET_BITMAP_DRAWABLE,
InputStream.class,
BitmapDrawable.class,
new BitmapDrawableDecoder<>(context.getResources(), streamBitmapDecoder));
}
}

0 comments on commit 3bbc390

Please sign in to comment.