Search in sources :

Example 6 with BitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.

the class FitCenterTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    bitmapWidth = 100;
    bitmapHeight = 100;
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
    when(resource.get()).thenReturn(bitmap);
    BitmapPool pool = new BitmapPoolAdapter();
    context = RuntimeEnvironment.application;
    Glide.init(context, new GlideBuilder().setBitmapPool(pool));
    fitCenter = new FitCenter();
}
Also used : Bitmap(android.graphics.Bitmap) GlideBuilder(com.bumptech.glide.GlideBuilder) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Before(org.junit.Before)

Example 7 with BitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project Rocket by mozilla-tw.

the class BitmapDrawableTransformation method transform.

@Override
public Resource<BitmapDrawable> transform(Context context, Resource<BitmapDrawable> drawableResourceToTransform, int outWidth, int outHeight) {
    BitmapDrawable drawableToTransform = drawableResourceToTransform.get();
    Bitmap bitmapToTransform = drawableToTransform.getBitmap();
    BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
    BitmapResource bitmapResourceToTransform = BitmapResource.obtain(bitmapToTransform, bitmapPool);
    Resource<Bitmap> transformedBitmapResource = wrapped.transform(context, bitmapResourceToTransform, outWidth, outHeight);
    if (transformedBitmapResource.equals(bitmapResourceToTransform)) {
        return drawableResourceToTransform;
    } else {
        return LazyBitmapDrawableResource.obtain(context, transformedBitmapResource.get());
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool)

Example 8 with BitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.

the class DrawableToBitmapConverter method convert.

@Nullable
static Resource<Bitmap> convert(BitmapPool bitmapPool, Drawable drawable, int width, int height) {
    // Handle DrawableContainer or StateListDrawables that may contain one or more BitmapDrawables.
    drawable = drawable.getCurrent();
    Bitmap result = null;
    boolean isRecycleable = false;
    if (drawable instanceof BitmapDrawable) {
        result = ((BitmapDrawable) drawable).getBitmap();
    } else if (!(drawable instanceof Animatable)) {
        result = drawToBitmap(bitmapPool, drawable, width, height);
        // We created and drew to the Bitmap, so it's safe for us to recycle or re-use.
        isRecycleable = true;
    }
    BitmapPool toUse = isRecycleable ? bitmapPool : NO_RECYCLE_BITMAP_POOL;
    return BitmapResource.obtain(result, toUse);
}
Also used : Bitmap(android.graphics.Bitmap) Animatable(android.graphics.drawable.Animatable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Nullable(android.support.annotation.Nullable)

Example 9 with BitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.

the class GifDrawableTransformation method transform.

@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;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapResource(com.bumptech.glide.load.resource.bitmap.BitmapResource) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) NonNull(android.support.annotation.NonNull)

Example 10 with BitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool in project glide by bumptech.

the class DrawableTransformationTest method load_withColorDrawable_fixedSize_unitBitmapTransform_recyclesIntermediates.

@Test
public void load_withColorDrawable_fixedSize_unitBitmapTransform_recyclesIntermediates() throws ExecutionException, InterruptedException {
    Drawable colorDrawable = new ColorDrawable(Color.RED);
    int width = 100;
    int height = 200;
    GlideApp.with(context).load(colorDrawable).fitCenter().override(width, height).submit().get();
    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)

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