Java Code Examples for com.bumptech.glide.util.Util#getBitmapByteSize()

The following examples show how to use com.bumptech.glide.util.Util#getBitmapByteSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapPreFillRunner.java    From giffun with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to allocate {@link Bitmap}s and returns {@code true} if there are more
 * {@link Bitmap}s to allocate and {@code false} otherwise.
 */
private boolean allocate() {
    long start = clock.now();
    while (!toPrefill.isEmpty() && !isGcDetected(start)) {
        PreFillType toAllocate = toPrefill.remove();
        Bitmap bitmap = Bitmap.createBitmap(toAllocate.getWidth(), toAllocate.getHeight(),
                toAllocate.getConfig());

        // Don't over fill the memory cache to avoid evicting useful resources, but make sure it's not empty so
        // we use all available space.
        if (getFreeMemoryCacheBytes() >= Util.getBitmapByteSize(bitmap)) {
            memoryCache.put(new UniqueKey(), BitmapResource.obtain(bitmap, bitmapPool));
        } else {
            addToBitmapPool(toAllocate, bitmap);
        }

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "allocated [" + toAllocate.getWidth() + "x" + toAllocate.getHeight() + "] "
                    + toAllocate.getConfig() + " size: " + Util.getBitmapByteSize(bitmap));
        }
    }

    return !isCancelled && !toPrefill.isEmpty();
}
 
Example 2
Source File: SizeStrategy.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public Bitmap get(int width, int height, Bitmap.Config config) {
    final int size = Util.getBitmapByteSize(width, height, config);
    Key key = keyPool.get(size);

    Integer possibleSize = sortedSizes.ceilingKey(size);
    if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) {
        keyPool.offer(key);
        key = keyPool.get(possibleSize);
    }

    // Do a get even if we know we don't have a bitmap so that the key moves to the front in the lru pool
    final Bitmap result = groupedMap.get(key);
    if (result != null) {
        result.reconfigure(width, height, config);
        decrementBitmapOfSize(possibleSize);
    }

    return result;
}
 
Example 3
Source File: SizeConfigStrategy.java    From giffun with Apache License 2.0 5 votes vote down vote up
@Override
public void put(Bitmap bitmap) {
    int size = Util.getBitmapByteSize(bitmap);
    Key key = keyPool.get(size, bitmap.getConfig());

    groupedMap.put(key, bitmap);

    NavigableMap<Integer, Integer> sizes = getSizesForConfig(bitmap.getConfig());
    Integer current = sizes.get(key.size);
    sizes.put(key.size, current == null ? 1 : current + 1);
}
 
Example 4
Source File: SizeConfigStrategy.java    From giffun with Apache License 2.0 5 votes vote down vote up
@Override
public Bitmap get(int width, int height, Bitmap.Config config) {
    int size = Util.getBitmapByteSize(width, height, config);
    Key targetKey = keyPool.get(size, config);
    Key bestKey = findBestKey(targetKey, size, config);

    Bitmap result = groupedMap.get(bestKey);
    if (result != null) {
        // Decrement must be called before reconfigure.
        decrementBitmapOfSize(Util.getBitmapByteSize(result), result.getConfig());
        result.reconfigure(width, height,
                result.getConfig() != null ? result.getConfig() : Bitmap.Config.ARGB_8888);
    }
    return result;
}
 
Example 5
Source File: SizeConfigStrategy.java    From giffun with Apache License 2.0 5 votes vote down vote up
@Override
public Bitmap removeLast() {
    Bitmap removed = groupedMap.removeLast();
    if (removed != null) {
        int removedSize = Util.getBitmapByteSize(removed);
        decrementBitmapOfSize(removedSize, removed.getConfig());
    }
    return removed;
}
 
Example 6
Source File: ApplicationIconDecoder.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public Resource<Drawable> decode(ApplicationInfo source, int width, int height) throws IOException {
	Drawable icon = context.getPackageManager().getApplicationIcon(source);
	return new DrawableResource<Drawable>(icon) {
		@Override public int getSize() { // best effort
			if (drawable instanceof BitmapDrawable) {
				return Util.getBitmapByteSize(((BitmapDrawable)drawable).getBitmap());
			} else {
				return 1;
			}
		}
		@Override public void recycle() { /* not from our pool */ }
	};
}
 
Example 7
Source File: SizeStrategy.java    From giffun with Apache License 2.0 5 votes vote down vote up
@Override
public void put(Bitmap bitmap) {
    int size = Util.getBitmapByteSize(bitmap);
    final Key key = keyPool.get(size);

    groupedMap.put(key, bitmap);

    Integer current = sortedSizes.get(key.size);
    sortedSizes.put(key.size, current == null ? 1 : current + 1);
}
 
Example 8
Source File: SizeConfigStrategy.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public String logBitmap(int width, int height, Bitmap.Config config) {
    int size = Util.getBitmapByteSize(width, height, config);
    return getBitmapString(size, config);
}
 
Example 9
Source File: BitmapPaletteResource.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getSize() {
    return Util.getBitmapByteSize(bitmapPaletteWrapper.getBitmap());
}
 
Example 10
Source File: BitmapPaletteResource.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getSize() {
    return Util.getBitmapByteSize(bitmapPaletteWrapper.getBitmap());
}
 
Example 11
Source File: SizeStrategy.java    From giffun with Apache License 2.0 4 votes vote down vote up
private static String getBitmapString(Bitmap bitmap) {
    int size = Util.getBitmapByteSize(bitmap);
    return getBitmapString(size);
}
 
Example 12
Source File: SizeStrategy.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public int getSize(Bitmap bitmap) {
    return Util.getBitmapByteSize(bitmap);
}
 
Example 13
Source File: SizeStrategy.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public String logBitmap(int width, int height, Bitmap.Config config) {
    int size = Util.getBitmapByteSize(width, height, config);
    return getBitmapString(size);
}
 
Example 14
Source File: SizeConfigStrategy.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public int getSize(Bitmap bitmap) {
    return Util.getBitmapByteSize(bitmap);
}
 
Example 15
Source File: GifDrawableResource.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public int getSize() {
    return drawable.getData().length + Util.getBitmapByteSize(drawable.getFirstFrame());
}
 
Example 16
Source File: BitmapPaletteResource.java    From Orin with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getSize() {
    return Util.getBitmapByteSize(bitmapPaletteWrapper.getBitmap());
}
 
Example 17
Source File: BitmapPreFiller.java    From giffun with Apache License 2.0 4 votes vote down vote up
private static int getSizeInBytes(PreFillType size) {
    return Util.getBitmapByteSize(size.getWidth(), size.getHeight(), size.getConfig());
}
 
Example 18
Source File: BitmapPaletteResource.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getSize() {
    return Util.getBitmapByteSize(bitmapPaletteWrapper.getBitmap());
}
 
Example 19
Source File: BitmapDrawableResource.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public int getSize() {
    return Util.getBitmapByteSize(drawable.getBitmap());
}
 
Example 20
Source File: GlideBitmapDrawableResource.java    From giffun with Apache License 2.0 4 votes vote down vote up
@Override
public int getSize() {
    return Util.getBitmapByteSize(drawable.getBitmap());
}