Skip to content

Commit

Permalink
avif_integration: Add support for RGB565 Bitmaps
Browse files Browse the repository at this point in the history
Some low-RAM devices tend to use this format. Honor the existing
Downsampler.PREFER_RGB_565 flag in the AVIF integration.

PiperOrigin-RevId: 478018960
  • Loading branch information
vigneshvg authored and glide-copybara-robot committed Sep 30, 2022
1 parent 8a279ef commit 098c1a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion integration/avif/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

dependencies {
implementation project(':library')
implementation 'org.aomedia.avif.android:avif:0.9.3.a319893'
implementation 'org.aomedia.avif.android:avif:0.10.1.2e8fe11'
implementation "com.google.guava:guava:${GUAVA_VERSION}"

annotationProcessor project(':annotation:compiler')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.bumptech.glide.integration.avif;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.util.Log;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.bitmap.Downsampler;
import com.bumptech.glide.util.Preconditions;
import java.nio.ByteBuffer;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -46,11 +49,13 @@ public Resource<Bitmap> decode(ByteBuffer source, int width, int height, Options
}
return null;
}
Bitmap bitmap =
bitmapPool.get(
info.width,
info.height,
(info.depth == 8) ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGBA_F16);
Bitmap.Config config;
if (options.get(Downsampler.DECODE_FORMAT) == DecodeFormat.PREFER_RGB_565) {
config = Config.RGB_565;
} else {
config = (info.depth == 8) ? Config.ARGB_8888 : Config.RGBA_F16;
}
Bitmap bitmap = bitmapPool.get(info.width, info.height, config);
if (!AvifDecoder.decode(sourceCopy, sourceCopy.remaining(), bitmap)) {
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "Failed to decode ByteBuffer as Avif.");
Expand Down

0 comments on commit 098c1a4

Please sign in to comment.