@SuppressWarnings("unused") public VideoBitmapDecoder(Context context) { this(Glide.get(context).getBitmapPool()); }
/** * @deprecated Use {@link #obtain(Resources, Resource)} instead, it can be unsafe to extract * {@link Bitmap}s from their wrapped {@link Resource}. */ @Deprecated public static LazyBitmapDrawableResource obtain(Context context, Bitmap bitmap) { return (LazyBitmapDrawableResource) obtain( context.getResources(), BitmapResource.obtain(bitmap, Glide.get(context).getBitmapPool())); }
GifFrameLoader( Glide glide, GifDecoder gifDecoder, int width, int height, Transformation<Bitmap> transformation, Bitmap firstFrame) { this( glide.getBitmapPool(), Glide.with(glide.getContext()), gifDecoder, null /*handler*/, getRequestBuilder(Glide.with(glide.getContext()), width, height), transformation, firstFrame); }
@NonNull @Override public final Resource<Bitmap> transform( @NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) { if (!Util.isValidDimensions(outWidth, outHeight)) { throw new IllegalArgumentException( "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight + " less than or equal to zero and not Target.SIZE_ORIGINAL"); } BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Bitmap toTransform = resource.get(); int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth; int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight; Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight); final Resource<Bitmap> result; if (toTransform.equals(transformed)) { result = resource; } else { result = BitmapResource.obtain(transformed, bitmapPool); } return result; }
@NonNull @Override public Resource<Drawable> transform(@NonNull Context context, @NonNull Resource<Drawable> resource, int outWidth, int outHeight) { BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Drawable drawable = resource.get(); Resource<Bitmap> bitmapResourceToTransform = DrawableToBitmapConverter.convert(bitmapPool, drawable, outWidth, outHeight); if (bitmapResourceToTransform == null) { if (isRequired) { throw new IllegalArgumentException("Unable to convert " + drawable + " to a Bitmap"); } else { return resource; } } Resource<Bitmap> transformedBitmapResource = wrapped.transform(context, bitmapResourceToTransform, outWidth, outHeight); if (transformedBitmapResource.equals(bitmapResourceToTransform)) { transformedBitmapResource.recycle(); return resource; } else { return newDrawableResource(context, transformedBitmapResource); } }
@NonNull @Override public final Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) { if (!Util.isValidDimensions(outWidth, outHeight)) { throw new IllegalArgumentException( "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight + " less than or equal to zero and not Target.SIZE_ORIGINAL"); } BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); Bitmap toTransform = resource.get(); int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth; int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight; Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight); final Resource<Bitmap> result; if (toTransform.equals(transformed)) { result = resource; } else { result = BitmapResource.obtain(transformed, bitmapPool); } return result; }
@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; }
@SuppressWarnings("unused") public ByteBufferGifDecoder(Context context) { this(context, Glide.get(context).getRegistry().getImageHeaderParsers(), Glide.get(context).getBitmapPool(), Glide.get(context).getArrayPool()); }
@NonNull private GifFrameLoader createGifFrameLoader(Handler handler) { Glide glide = getGlideSingleton(); GifFrameLoader result = new GifFrameLoader( glide.getBitmapPool(), requestManager, gifDecoder, handler, requestBuilder, transformation, firstFrame); result.subscribe(callback); return result; }
@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(); }
@Test public void loadWideGamutImage_withArgb888OfSufficientSizeInPool_usesArgb8888Bitmap() { Bitmap wideGamut = Bitmap.createBitmap(100, 50, Bitmap.Config.RGBA_F16); byte[] data = asPng(wideGamut); Bitmap argb8888 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Glide.init(context, new GlideBuilder() .setBitmapPool(new LruBitmapPool(wideGamut.getAllocationByteCount() * 5))); Glide.get(context).getBitmapPool().put(argb8888); Bitmap result = concurrency.get( Glide.with(context) .asBitmap() .load(data) .submit()); assertThat(result).isSameAs(argb8888); }
@Test public void load_withWideGamutImage_bitmapInPoolWithSizeAndConfig_usesBitmapFromPool() { int bitmapDimension = 1000; Glide.init( context, new GlideBuilder() .setBitmapPool(new LruBitmapPool(bitmapDimension * bitmapDimension * 8 * 4))); Bitmap expected = Bitmap.createBitmap(bitmapDimension, bitmapDimension, Bitmap.Config.RGBA_F16); Glide.get(context) .getBitmapPool() .put(expected); Bitmap bitmap = concurrency.get( Glide.with(context) .asBitmap() .load(ResourceIds.raw.webkit_logo_p3) .submit()); assertThat(bitmap).isSameAs(expected); }
@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); } @Test
@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); } }
private GifDrawableTransformation[] toGifTransformations(Transformation<Bitmap>[] bitmapTransformations) { GifDrawableTransformation[] transformations = new GifDrawableTransformation[bitmapTransformations.length]; for (int i = 0; i < bitmapTransformations.length; i++) { transformations[i] = new GifDrawableTransformation(bitmapTransformations[i], glide.getBitmapPool()); } return transformations; }
/** * @param maskId If you change the mask file, please also rename the mask file, or Glide will get * the cache with the old mask. Because getId() return the same values if using the * same make file name. If you have a good idea please tell us, thanks. */ public MaskTransformation(Context context, int maskId) { this(context, Glide.get(context).getBitmapPool(), maskId); }
@Test public void testRoundedCorners_usePool() throws ExecutionException, InterruptedException { canonicalBitmap = canonicalBitmap.scale(0.1f); Bitmap redRect = createRect( Color.RED, canonicalBitmap.getWidth(), canonicalBitmap.getHeight(), Bitmap.Config.ARGB_8888); Glide.get(context).getBitmapPool().put(redRect); Bitmap roundedRect = bitmapRegressionTester.test( GlideApp.with(context) .asBitmap() .load(canonicalBitmap.getBitmap()) .override(canonicalBitmap.getWidth(), canonicalBitmap.getHeight()) .transform(new RoundedCorners(5))); assertThat(roundedRect).isEqualTo(redRect); }
public GifFrameLoader(Context context, FrameCallback callback, GifDecoder gifDecoder, int width, int height) { this(callback, gifDecoder, null, getRequestBuilder(context, gifDecoder, width, height, Glide.get(context).getBitmapPool())); }
private void refresh() { final BitmapPool pool = glide.getBitmapPool(); final String total = getSizeString(pool.getMaxSize()); final String memCacheCurrent = getSizeString(memoryCache.getCurrentSize()); final String memCacheMax = getSizeString(memoryCache.getMaxSize()); poolSizeLabel.setText(total); memCacheCurrentLabel.setText(memCacheCurrent); memCacheMaxLabel.setText(memCacheMax); }
BitmapRequestBuilder(LoadProvider<ModelType, ImageVideoWrapper, Bitmap, TranscodeType> loadProvider, Class<TranscodeType> transcodeClass, GenericRequestBuilder<ModelType, ?, ?, ?> other) { super(loadProvider, transcodeClass, other); this.bitmapPool = other.glide.getBitmapPool(); this.decodeFormat = other.glide.getDecodeFormat(); imageDecoder = new StreamBitmapDecoder(bitmapPool, decodeFormat); videoDecoder = new FileDescriptorBitmapDecoder(bitmapPool, decodeFormat); }