52
52
import org .telegram .ui .Components .MotionBackgroundDrawable ;
53
53
import org .telegram .ui .Components .Point ;
54
54
import org .telegram .ui .Components .RLottieDrawable ;
55
- import org .telegram .ui .Components .Reactions .HwEmojis ;
56
55
import org .telegram .ui .Components .SlotsDrawable ;
57
56
import org .telegram .ui .Components .ThemePreviewDrawable ;
58
57
103
102
*/
104
103
public class ImageLoader {
105
104
105
+ private static final boolean DEBUG_MODE = false ;
106
+
106
107
private HashMap <String , Integer > bitmapUseCounts = new HashMap <>();
107
108
private LruCache <BitmapDrawable > smallImagesMemCache ;
108
109
private LruCache <BitmapDrawable > memCache ;
@@ -1822,7 +1823,9 @@ public static Bitmap getStrippedPhotoBitmap(byte[] photoBytes, String filter) {
1822
1823
data [164 ] = photoBytes [1 ];
1823
1824
data [166 ] = photoBytes [2 ];
1824
1825
1825
- Bitmap bitmap = BitmapFactory .decodeByteArray (data , 0 , len );
1826
+ BitmapFactory .Options options = new BitmapFactory .Options ();
1827
+ options .inPreferredConfig = SharedConfig .deviceIsHigh () ? Bitmap .Config .ARGB_8888 : Bitmap .Config .RGB_565 ;
1828
+ Bitmap bitmap = BitmapFactory .decodeByteArray (data , 0 , len , options );
1826
1829
if (bitmap != null && !TextUtils .isEmpty (filter ) && filter .contains ("b" )) {
1827
1830
Utilities .blurBitmap (bitmap , 3 , 1 , bitmap .getWidth (), bitmap .getHeight (), bitmap .getRowBytes ());
1828
1831
}
@@ -2060,15 +2063,15 @@ public ImageLoader() {
2060
2063
} else {
2061
2064
maxSize = 15 ;
2062
2065
}
2063
- int cacheSize = Math .min (maxSize , memoryClass / 7 ) * 1024 * 1024 ;
2066
+ int cacheSize = DEBUG_MODE ? 1 : Math .min (maxSize , memoryClass / 7 ) * 1024 * 1024 ;
2064
2067
2065
- int commonCacheSize = (int ) (cacheSize * 0.8f );
2066
- int smallImagesCacheSize = (int ) (cacheSize * 0.2f );
2068
+ int commonCacheSize = DEBUG_MODE ? 1 : (int ) (cacheSize * 0.8f );
2069
+ int smallImagesCacheSize = DEBUG_MODE ? 1 : (int ) (cacheSize * 0.2f );
2067
2070
2068
2071
memCache = new LruCache <BitmapDrawable >(commonCacheSize ) {
2069
2072
@ Override
2070
2073
protected int sizeOf (String key , BitmapDrawable value ) {
2071
- return value . getBitmap (). getByteCount ( );
2074
+ return sizeOfBitmapDrawable ( value );
2072
2075
}
2073
2076
2074
2077
@ Override
@@ -2090,7 +2093,7 @@ protected void entryRemoved(boolean evicted, String key, final BitmapDrawable ol
2090
2093
smallImagesMemCache = new LruCache <BitmapDrawable >(smallImagesCacheSize ) {
2091
2094
@ Override
2092
2095
protected int sizeOf (String key , BitmapDrawable value ) {
2093
- return value . getBitmap (). getByteCount ( );
2096
+ return sizeOfBitmapDrawable ( value );
2094
2097
}
2095
2098
2096
2099
@ Override
@@ -2109,18 +2112,18 @@ protected void entryRemoved(boolean evicted, String key, final BitmapDrawable ol
2109
2112
}
2110
2113
}
2111
2114
};
2112
- wallpaperMemCache = new LruCache <BitmapDrawable >(cacheSize / 4 ) {
2115
+ wallpaperMemCache = new LruCache <BitmapDrawable >(DEBUG_MODE ? 1 : cacheSize / 4 ) {
2113
2116
@ Override
2114
2117
protected int sizeOf (String key , BitmapDrawable value ) {
2115
- return value . getBitmap (). getByteCount ( );
2118
+ return sizeOfBitmapDrawable ( value );
2116
2119
}
2117
2120
};
2118
2121
2119
- lottieMemCache = new LruCache <BitmapDrawable >(512 * 512 * 2 * 4 * 5 ) {
2122
+ lottieMemCache = new LruCache <BitmapDrawable >(DEBUG_MODE ? 1 : 512 * 512 * 2 * 4 * 5 ) {
2120
2123
2121
2124
@ Override
2122
2125
protected int sizeOf (String key , BitmapDrawable value ) {
2123
- return value . getIntrinsicWidth () * value . getIntrinsicHeight () * 4 * 2 ;
2126
+ return sizeOfBitmapDrawable ( value ) ;
2124
2127
}
2125
2128
2126
2129
@ Override
@@ -2327,6 +2330,18 @@ public void onReceive(Context arg0, Intent intent) {
2327
2330
checkMediaPaths ();
2328
2331
}
2329
2332
2333
+ private int sizeOfBitmapDrawable (BitmapDrawable value ) {
2334
+ if (value instanceof AnimatedFileDrawable ) {
2335
+ AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable ) value ;
2336
+ int maxSize = animatedFileDrawable .getRenderingHeight () * animatedFileDrawable .getRenderingWidth () * 4 * 3 ;
2337
+ maxSize = Math .max (animatedFileDrawable .getIntrinsicHeight () * value .getIntrinsicWidth () * 4 * 3 , maxSize );
2338
+ return maxSize ;
2339
+ } if (value instanceof RLottieDrawable ) {
2340
+ return value .getIntrinsicWidth () * value .getIntrinsicHeight () * 4 * 2 ;
2341
+ }
2342
+ return value .getBitmap ().getByteCount ();
2343
+ }
2344
+
2330
2345
public void checkMediaPaths () {
2331
2346
checkMediaPaths (null );
2332
2347
}
0 commit comments