Skip to content

Commit 098c1a4

Browse files
vigneshvgglide-copybara-robot
authored andcommittedSep 30, 2022
avif_integration: Add support for RGB565 Bitmaps
Some low-RAM devices tend to use this format. Honor the existing Downsampler.PREFER_RGB_565 flag in the AVIF integration. PiperOrigin-RevId: 478018960
1 parent 8a279ef commit 098c1a4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎integration/avif/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
dependencies {
44
implementation project(':library')
5-
implementation 'org.aomedia.avif.android:avif:0.9.3.a319893'
5+
implementation 'org.aomedia.avif.android:avif:0.10.1.2e8fe11'
66
implementation "com.google.guava:guava:${GUAVA_VERSION}"
77

88
annotationProcessor project(':annotation:compiler')

‎integration/avif/src/main/java/com/bumptech/glide/integration/avif/AvifByteBufferBitmapDecoder.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.bumptech.glide.integration.avif;
22

33
import android.graphics.Bitmap;
4+
import android.graphics.Bitmap.Config;
45
import android.util.Log;
6+
import com.bumptech.glide.load.DecodeFormat;
57
import com.bumptech.glide.load.Options;
68
import com.bumptech.glide.load.ResourceDecoder;
79
import com.bumptech.glide.load.engine.Resource;
810
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
911
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
12+
import com.bumptech.glide.load.resource.bitmap.Downsampler;
1013
import com.bumptech.glide.util.Preconditions;
1114
import java.nio.ByteBuffer;
1215
import javax.annotation.Nullable;
@@ -46,11 +49,13 @@ public Resource<Bitmap> decode(ByteBuffer source, int width, int height, Options
4649
}
4750
return null;
4851
}
49-
Bitmap bitmap =
50-
bitmapPool.get(
51-
info.width,
52-
info.height,
53-
(info.depth == 8) ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGBA_F16);
52+
Bitmap.Config config;
53+
if (options.get(Downsampler.DECODE_FORMAT) == DecodeFormat.PREFER_RGB_565) {
54+
config = Config.RGB_565;
55+
} else {
56+
config = (info.depth == 8) ? Config.ARGB_8888 : Config.RGBA_F16;
57+
}
58+
Bitmap bitmap = bitmapPool.get(info.width, info.height, config);
5459
if (!AvifDecoder.decode(sourceCopy, sourceCopy.remaining(), bitmap)) {
5560
if (Log.isLoggable(TAG, Log.ERROR)) {
5661
Log.e(TAG, "Failed to decode ByteBuffer as Avif.");

0 commit comments

Comments
 (0)
Please sign in to comment.