Search in sources :

Example 11 with BitmapPool

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));
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) RequestOptions(com.bumptech.glide.request.RequestOptions) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Test(org.junit.Test)

Example 12 with BitmapPool

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);
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Test(org.junit.Test)

Example 13 with BitmapPool

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();
}
Also used : Bitmap(android.graphics.Bitmap) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) Test(org.junit.Test)

Example 14 with BitmapPool

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);
}
Also used : LruArrayPool(com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool) ArrayPool(com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool) LruArrayPool(com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) ImageHeaderParser(com.bumptech.glide.load.ImageHeaderParser) DisplayMetrics(android.util.DisplayMetrics) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)

Example 15 with BitmapPool

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));
}
Also used : Bitmap(android.graphics.Bitmap) NonNull(android.support.annotation.NonNull) MessageDigest(java.security.MessageDigest) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Test(org.junit.Test)

Aggregations

BitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)17 Bitmap (android.graphics.Bitmap)15 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Test (org.junit.Test)6 Drawable (android.graphics.drawable.Drawable)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 NonNull (android.support.annotation.NonNull)4 GlideBuilder (com.bumptech.glide.GlideBuilder)3 BitmapPoolAdapter (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter)3 Before (org.junit.Before)2 Context (android.content.Context)1 Canvas (android.graphics.Canvas)1 Animatable (android.graphics.drawable.Animatable)1 Nullable (android.support.annotation.Nullable)1 DisplayMetrics (android.util.DisplayMetrics)1 NonNull (androidx.annotation.NonNull)1 ImageHeaderParser (com.bumptech.glide.load.ImageHeaderParser)1 ArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool)1 LruArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool)1 LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)1