@NonNull Resource<Bitmap> buildFrameResource(@NonNull Bitmap bitmap, @NonNull BitmapPool bitmapPool) { return new BitmapResource(bitmap, bitmapPool); } }
/** * Returns a new {@link BitmapResource} wrapping the given {@link Bitmap} if the Bitmap is * non-null or null if the given Bitmap is null. * * @param bitmap A Bitmap. * @param bitmapPool A non-null {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool}. */ @Nullable public static BitmapResource obtain(@Nullable Bitmap bitmap, @NonNull BitmapPool bitmapPool) { if (bitmap == null) { return null; } else { return new BitmapResource(bitmap, bitmapPool); } }
@Override public boolean encode(@NonNull Resource<BitmapDrawable> data, @NonNull File file, @NonNull Options options) { return encoder.encode(new BitmapResource(data.get().getBitmap(), bitmapPool), file, options); }
@Test(expected = NullPointerException.class) public void testThrowsIfBitmapPoolIsNull() { new BitmapResource(Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565), null); }
@Test(expected = NullPointerException.class) public void testThrowsIfBitmapAndBitmapPoolAreNull() { new BitmapResource(null, null); }
@Test(expected = NullPointerException.class) public void testThrowsIfBitmapIsNull() { new BitmapResource(null, mock(BitmapPool.class)); }
@NonNull @Override public Resource<GifDrawable> transform( @NonNull Context context, @NonNull Resource<GifDrawable> resource, int outWidth, int outHeight) { GifDrawable drawable = resource.get(); // The drawable needs to be initialized with the correct width and height in order for a view // displaying it to end up with the right dimensions. Since our transformations may arbitrarily // modify the dimensions of our GIF, here we create a stand in for a frame and pass it to the // transformation to see what the final transformed dimensions will be so that our drawable can // report the correct intrinsic width and height. BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Bitmap firstFrame = drawable.getFirstFrame(); Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool); Resource<Bitmap> transformed = wrapped.transform(context, bitmapResource, outWidth, outHeight); if (!bitmapResource.equals(transformed)) { bitmapResource.recycle(); } Bitmap transformedFrame = transformed.get(); drawable.setFrameTransformation(wrapped, transformedFrame); return resource; }
public Resource<Bitmap> buildFrameResource(Bitmap bitmap, BitmapPool bitmapPool) { return new BitmapResource(bitmap, bitmapPool); } }
/** * Returns a new {@link BitmapResource} wrapping the given {@link Bitmap} if the Bitmap is non-null or null if the * given Bitmap is null. * * @param bitmap A Bitmap. * @param bitmapPool A non-null {@link BitmapPool}. */ public static BitmapResource obtain(Bitmap bitmap, BitmapPool bitmapPool) { if (bitmap == null) { return null; } else { return new BitmapResource(bitmap, bitmapPool); } }
@Override public Resource<GifDrawable> transform(Resource<GifDrawable> resource, int outWidth, int outHeight) { GifDrawable drawable = resource.get(); // The drawable needs to be initialized with the correct width and height in order for a view displaying it // to end up with the right dimensions. Since our transformations may arbitrarily modify the dimensions of // our gif, here we create a stand in for a frame and pass it to the transformation to see what the final // transformed dimensions will be so that our drawable can report the correct intrinsic width and height. Bitmap firstFrame = resource.get().getFirstFrame(); Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool); Resource<Bitmap> transformed = wrapped.transform(bitmapResource, outWidth, outHeight); Bitmap transformedFrame = transformed.get(); if (!transformedFrame.equals(firstFrame)) { return new GifDrawableResource(new GifDrawable(drawable, transformedFrame, wrapped)); } else { return resource; } }
private GifBitmapWrapper decodeGifWrapper(InputStream bis, int width, int height) throws IOException { GifBitmapWrapper result = null; Resource<GifDrawable> gifResource = gifDecoder.decode(bis, width, height); if (gifResource != null) { GifDrawable drawable = gifResource.get(); // We can more efficiently hold Bitmaps in memory, so for static GIFs, try to return Bitmaps // instead. Returning a Bitmap incurs the cost of allocating the GifDrawable as well as the normal // Bitmap allocation, but since we can encode the Bitmap out as a JPEG, future decodes will be // efficient. if (drawable.getFrameCount() > 1) { result = new GifBitmapWrapper(null /*bitmapResource*/, gifResource); } else { Resource<Bitmap> bitmapResource = new BitmapResource(drawable.getFirstFrame(), bitmapPool); result = new GifBitmapWrapper(bitmapResource, null /*gifResource*/); } } return result; }
/** * Returns a new {@link BitmapResource} wrapping the given {@link Bitmap} if the Bitmap is * non-null or null if the given Bitmap is null. * * @param bitmap A Bitmap. * @param bitmapPool A non-null {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool}. */ @Nullable public static BitmapResource obtain(@Nullable Bitmap bitmap, BitmapPool bitmapPool) { if (bitmap == null) { return null; } else { return new BitmapResource(bitmap, bitmapPool); } }
@Override public boolean encode(Resource<BitmapDrawable> data, File file, Options options) { return encoder.encode(new BitmapResource(data.get().getBitmap(), bitmapPool), file, options); }
public Resource<Bitmap> decode(Bitmap source, int width, int height, Options options) { if (this.mBitmapPool == null) { this.mBitmapPool = Glide.get(context).getBitmapPool(); } return new BitmapResource(source, this.mBitmapPool); }