1package com.bumptech.glide.load.resource.bitmap; 2 3import android.graphics.Bitmap; 4import android.os.ParcelFileDescriptor; 5 6import com.bumptech.glide.load.DecodeFormat; 7import com.bumptech.glide.load.ResourceDecoder; 8import com.bumptech.glide.load.engine.Resource; 9import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 10 11import java.io.IOException; 12 13public class FileDescriptorBitmapDecoder implements ResourceDecoder<ParcelFileDescriptor, Bitmap> { 14 private final VideoBitmapDecoder bitmapDecoder; 15 private final BitmapPool bitmapPool; 16 private DecodeFormat decodeFormat; 17 18 public FileDescriptorBitmapDecoder(BitmapPool bitmapPool) { 19 this(new VideoBitmapDecoder(), bitmapPool, DecodeFormat.ALWAYS_ARGB_8888); 20 } 21 22 public FileDescriptorBitmapDecoder(VideoBitmapDecoder bitmapDecoder, BitmapPool bitmapPool, 23 DecodeFormat decodeFormat) { 24 this.bitmapDecoder = bitmapDecoder; 25 this.bitmapPool = bitmapPool; 26 this.decodeFormat = decodeFormat; 27 } 28 29 @Override 30 public Resource<Bitmap> decode(ParcelFileDescriptor source, int width, int height) throws IOException { 31 Bitmap bitmap = bitmapDecoder.decode(source, bitmapPool, width, height, decodeFormat); 32 if (bitmap == null) { 33 return null; 34 } else { 35 return new BitmapResource(bitmap, bitmapPool); 36 } 37 } 38 39 @Override 40 public String getId() { 41 return "FileDescriptorBitmapDecoder.com.bumptech.glide.load.data.bitmap"; 42 } 43} 44