1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package com.bumptech.glide.load.resource.bitmap;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.ParcelFileDescriptor;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.DecodeFormat;
import java.io.IOException;
/**
* An {@link com.bumptech.glide.load.ResourceDecoder} for decoding {@link android.graphics.Bitmap}s from
* {@link android.os.ParcelFileDescriptor} data.
*/
public class FileDescriptorBitmapDecoder implements ResourceDecoder<ParcelFileDescriptor, Bitmap> {
private final VideoBitmapDecoder bitmapDecoder;
private final BitmapPool bitmapPool;
private DecodeFormat decodeFormat;
public FileDescriptorBitmapDecoder(Context context) {
this(Glide.get(context).getBitmapPool(), DecodeFormat.DEFAULT);
}
public FileDescriptorBitmapDecoder(Context context, DecodeFormat decodeFormat) {
this(Glide.get(context).getBitmapPool(), decodeFormat);
}
public FileDescriptorBitmapDecoder(BitmapPool bitmapPool, DecodeFormat decodeFormat) {
this(new VideoBitmapDecoder(), bitmapPool, decodeFormat);
}
public FileDescriptorBitmapDecoder(VideoBitmapDecoder bitmapDecoder, BitmapPool bitmapPool,
DecodeFormat decodeFormat) {
this.bitmapDecoder = bitmapDecoder;
this.bitmapPool = bitmapPool;
this.decodeFormat = decodeFormat;
}
@Override
public Resource<Bitmap> decode(ParcelFileDescriptor source, int width, int height) throws IOException {
Bitmap bitmap = bitmapDecoder.decode(source, bitmapPool, width, height, decodeFormat);
return BitmapResource.obtain(bitmap, bitmapPool);
}
@Override
public String getId() {
return "FileDescriptorBitmapDecoder.com.bumptech.glide.load.data.bitmap";
}
}
|