use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class DrawableTransformationTest method load_withColorDrawable_fixedSize_nonUnitRequiredTransform_returnsBitmapDrawable.
/**
* Transformations that produce a different output color/shape/image etc will end up returning
* a {@link Bitmap} based on the original {@link Drawable} but with the transformation applied.
*/
@Test
public void load_withColorDrawable_fixedSize_nonUnitRequiredTransform_returnsBitmapDrawable() throws ExecutionException, InterruptedException {
Drawable colorDrawable = new ColorDrawable(Color.RED);
Drawable result = Glide.with(context).load(colorDrawable).apply(new RequestOptions().circleCrop()).submit(100, 100).get();
Bitmap redSquare = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
Canvas canvas = new Canvas(redSquare);
canvas.drawColor(Color.RED);
BitmapPool bitmapPool = mock(BitmapPool.class);
when(bitmapPool.get(100, 100, Bitmap.Config.ARGB_8888)).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
Bitmap expected = TransformationUtils.circleCrop(bitmapPool, redSquare, 100, 100);
assertThat(result).isInstanceOf(BitmapDrawable.class);
Bitmap bitmap = ((BitmapDrawable) result).getBitmap();
assertThat(bitmap.getWidth()).isEqualTo(100);
assertThat(bitmap.getHeight()).isEqualTo(100);
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
assertThat(bitmap.getPixel(x, y)).isEqualTo(expected.getPixel(x, y));
}
}
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class DrawableTransformationTest method load_withColorDrawable_fixedSize_functionalBitmapTransform_doesNotRecycleOutput.
@Test
public void load_withColorDrawable_fixedSize_functionalBitmapTransform_doesNotRecycleOutput() throws ExecutionException, InterruptedException {
Drawable colorDrawable = new ColorDrawable(Color.RED);
int width = 100;
int height = 200;
Drawable result = GlideApp.with(context).load(colorDrawable).circleCrop().override(width, height).submit().get();
BitmapSubject.assertThat(result).isNotRecycled();
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
// Make sure we didn't put the same Bitmap twice.
Bitmap first = bitmapPool.get(width, height, Config.ARGB_8888);
Bitmap second = bitmapPool.get(width, height, Config.ARGB_8888);
assertThat(first).isNotSameAs(second);
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class WideGamutTest method load_withSmallerWideGamutInPool_decodesBitmap.
@Test
public void load_withSmallerWideGamutInPool_decodesBitmap() {
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toPut = Bitmap.createBitmap(300, 298, Config.RGBA_F16);
bitmapPool.put(toPut);
// Add a second Bitmap to account for the InputStream decode.
bitmapPool.put(Bitmap.createBitmap(toPut));
Bitmap wideGamut = Bitmap.createBitmap(300, 300, Config.RGBA_F16);
byte[] data = asPng(wideGamut);
Bitmap bitmap = concurrency.get(Glide.with(context).asBitmap().load(data).submit());
assertThat(bitmap).isNotNull();
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class DownsamplerEmulatorTest method buildDownsampler.
private static Downsampler buildDownsampler() {
List<ImageHeaderParser> parsers = Collections.<ImageHeaderParser>singletonList(new DefaultImageHeaderParser());
DisplayMetrics displayMetrics = new DisplayMetrics();
// XHDPI.
displayMetrics.densityDpi = 320;
BitmapPool bitmapPool = new BitmapPoolAdapter();
ArrayPool arrayPool = new LruArrayPool();
return new Downsampler(parsers, displayMetrics, bitmapPool, arrayPool);
}
use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.
the class BitmapTransformationTest method testReturnsNewResourceWhenBitmapTransformed.
@Test
public void testReturnsNewResourceWhenBitmapTransformed() {
final Bitmap transformed = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444);
BitmapTransformation transformation = new BitmapTransformation() {
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
}
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap bitmap, int outWidth, int outHeight) {
return transformed;
}
};
Resource<Bitmap> resource = mockResource(1, 2);
assertNotSame(resource, transformation.transform(context, resource, 100, 100));
}
Aggregations