blob: b8bdb5ba1a4368d55777e364c9c2e9b15de3156c (
plain)
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
53
54
55
56
|
package com.bumptech.glide.load.resource.bitmap;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import java.io.InputStream;
//TODO(actually fill out this stub)
public class StreamBitmapDecoder implements ResourceDecoder<InputStream, Bitmap> {
private static final String ID = "StreamBitmapDecoder.com.bumptech.glide.load.resource.bitmap";
private final Downsampler downsampler;
private BitmapPool bitmapPool;
private DecodeFormat decodeFormat;
private String id;
public StreamBitmapDecoder(Context context) {
this(Glide.get(context).getBitmapPool());
}
public StreamBitmapDecoder(BitmapPool bitmapPool) {
this(Downsampler.AT_LEAST, bitmapPool, DecodeFormat.PREFER_RGB_565);
}
public StreamBitmapDecoder(Downsampler downsampler, BitmapPool bitmapPool, DecodeFormat decodeFormat) {
this.downsampler = downsampler;
this.bitmapPool = bitmapPool;
this.decodeFormat = decodeFormat;
}
@Override
public Resource<Bitmap> decode(InputStream source, int width, int height) {
Bitmap bitmap = downsampler.decode(source, bitmapPool, width, height, decodeFormat);
if (bitmap == null) {
return null;
} else {
return new BitmapResource(bitmap, bitmapPool);
}
}
@Override
public String getId() {
if (id == null) {
id = new StringBuilder()
.append(ID)
.append(downsampler.getId())
.append(decodeFormat.name())
.toString();
}
return id;
}
}
|