@Override public int getSize() { return Util.getBitmapByteSize(bitmap); }
@Override public int getSize() { return Util.getBitmapByteSize(bitmap); }
/** * Returns the allocated byte size of the given bitmap. * * @see #getBitmapByteSize(android.graphics.Bitmap) * @deprecated Use {@link #getBitmapByteSize(android.graphics.Bitmap)} instead. Scheduled to be * removed in Glide 4.0. */ @Deprecated public static int getSize(@NonNull Bitmap bitmap) { return getBitmapByteSize(bitmap); }
private static String getBitmapString(Bitmap bitmap) { int size = Util.getBitmapByteSize(bitmap); return getBitmapString(size); }
@Override public String logBitmap(Bitmap bitmap) { int size = Util.getBitmapByteSize(bitmap); return getBitmapString(size, bitmap.getConfig()); }
@Override public String logBitmap(int width, int height, Bitmap.Config config) { int size = Util.getBitmapByteSize(width, height, config); return getBitmapString(size, config); }
@Override public String logBitmap(int width, int height, Bitmap.Config config) { int size = Util.getBitmapByteSize(width, height, config); return getBitmapString(size); }
@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); }
@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); }
@Override @Nullable public Bitmap removeLast() { Bitmap removed = groupedMap.removeLast(); if (removed != null) { int removedSize = Util.getBitmapByteSize(removed); decrementBitmapOfSize(removedSize, removed); } return removed; }
@Override @Nullable public Bitmap removeLast() { Bitmap removed = groupedMap.removeLast(); if (removed != null) { final int removedSize = Util.getBitmapByteSize(removed); decrementBitmapOfSize(removedSize); } return removed; }
private int getFrameSize() { return Util.getBitmapByteSize(getCurrentFrame().getWidth(), getCurrentFrame().getHeight(), getCurrentFrame().getConfig()); }
@Test public void testReturnsCorrectBitmapSizeForDifferentDimensions() { int width = 100; int height = 100; Bitmap.Config config = Bitmap.Config.ARGB_8888; int initialSize = Util.getBitmapByteSize(width, height, config); int sizeOne = Util.getBitmapByteSize(width * 2, height, config); int sizeTwo = Util.getBitmapByteSize(width, height * 2, config); assertEquals(4 * width * height, initialSize); assertEquals(2 * initialSize, sizeOne); assertEquals(2 * initialSize, sizeTwo); }
@Test public void getBitmapByteSize_withRGBA_F16_returnsCorrectSize() { int width = 100; int height = 200; assertThat(Util.getBitmapByteSize(width, height, Bitmap.Config.RGBA_F16)) .isEqualTo(width * height * 8); } }
@Test public void testReturnsLargestSizeForNullConfig() { int width = 999; int height = 41324; int size = Util.getBitmapByteSize(width, height, null); assertEquals(width * height * 4, size); }
@Test public void testReturnsCorrectBitmapSizeForAlpha8Bitmap() { int width = 110; int height = 43; int size = Util.getBitmapByteSize(width, height, Bitmap.Config.ALPHA_8); assertEquals(width * height, size); }
@Test public void testReturnsCorrectBitmapSizeForRgb565() { int width = 34; int height = 1444; int size = Util.getBitmapByteSize(width, height, Bitmap.Config.RGB_565); assertEquals(width * height * 2, size); }
@Test public void testReturnsCorrectBitmapSizeForARGB4444() { int width = 4454; int height = 1235; int size = Util.getBitmapByteSize(width, height, Bitmap.Config.ARGB_4444); assertEquals(width * height * 2, size); }
@Test public void testReturnsCorrectBitmapSizeForARGB8888() { int width = 943; int height = 3584; int size = Util.getBitmapByteSize(width, height, Bitmap.Config.ARGB_8888); assertEquals(width * height * 4, size); }
@Test public void testReturnsSizeFromGifDecoderAndCurrentFrame() { int decoderByteSize = 123456; when(gifDecoder.getByteSize()).thenReturn(decoderByteSize); assertThat(loader.getSize()).isEqualTo(decoderByteSize + Util.getBitmapByteSize(firstFrame)); }