| 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.ALWAYS_ARGB_8888); |
| } |
| |
| 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; |
| } |
| } |