|
1 | 1 | package com.bumptech.glide.integration.avif;
|
2 | 2 |
|
3 | 3 | import android.graphics.Bitmap;
|
| 4 | +import android.graphics.Bitmap.Config; |
4 | 5 | import android.util.Log;
|
| 6 | +import com.bumptech.glide.load.DecodeFormat; |
5 | 7 | import com.bumptech.glide.load.Options;
|
6 | 8 | import com.bumptech.glide.load.ResourceDecoder;
|
7 | 9 | import com.bumptech.glide.load.engine.Resource;
|
8 | 10 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
9 | 11 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
| 12 | +import com.bumptech.glide.load.resource.bitmap.Downsampler; |
10 | 13 | import com.bumptech.glide.util.Preconditions;
|
11 | 14 | import java.nio.ByteBuffer;
|
12 | 15 | import javax.annotation.Nullable;
|
@@ -46,11 +49,13 @@ public Resource<Bitmap> decode(ByteBuffer source, int width, int height, Options
|
46 | 49 | }
|
47 | 50 | return null;
|
48 | 51 | }
|
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); |
54 | 59 | if (!AvifDecoder.decode(sourceCopy, sourceCopy.remaining(), bitmap)) {
|
55 | 60 | if (Log.isLoggable(TAG, Log.ERROR)) {
|
56 | 61 | Log.e(TAG, "Failed to decode ByteBuffer as Avif.");
|
|
0 commit comments