From aad975ce099dddd06d47abc3e70324a3e210b0d3 Mon Sep 17 00:00:00 2001 From: xiaojie Date: Thu, 21 Nov 2024 15:50:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=A3=E7=A0=81=E5=A4=A7?= =?UTF-8?q?=E5=9B=BE=E6=97=B6=E7=9A=84=E5=8E=8B=E7=BC=A9=E5=80=8D=E7=8E=87?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hippo/lib/image/Image.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/hippo/lib/image/Image.kt b/app/src/main/java/com/hippo/lib/image/Image.kt index f2ec6c650..89e0f4f83 100644 --- a/app/src/main/java/com/hippo/lib/image/Image.kt +++ b/app/src/main/java/com/hippo/lib/image/Image.kt @@ -38,6 +38,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics import com.hippo.ehviewer.EhApplication import java.io.FileInputStream import java.nio.channels.FileChannel +import kotlin.math.max import kotlin.math.min class Image private constructor( @@ -53,9 +54,9 @@ class Image private constructor( init { mObtainedDrawable = null source?.let { - var simpleSize: Int? = null - if (source.available() > 8388608) { - simpleSize = source.available() / 8388608 + var simpleSize = 1 + if (source.available() > 10485760) { + simpleSize = source.available() / 10485760 + 1 } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { val src = ImageDecoder.createSource( @@ -71,13 +72,12 @@ class Image private constructor( if (hardware) ALLOCATOR_DEFAULT else ALLOCATOR_SOFTWARE // Sadly we must use software memory since we need copy it to tile buffer, fuck glgallery // Idk it will cause how much performance regression - + val screenSize = min( + info.size.width / (2 * screenWidth), + info.size.height / (2 * screenHeight) + ).coerceAtLeast(1) decoder.setTargetSampleSize( - simpleSize - ?: min( - info.size.width / (2 * screenWidth), - info.size.height / (2 * screenHeight) - ).coerceAtLeast(1) + max(screenSize, simpleSize) ) // Don't } @@ -197,7 +197,7 @@ class Image private constructor( updateBitmap() mBitmap!! } else { - if (mObtainedDrawable==null){ + if (mObtainedDrawable == null) { return } (mObtainedDrawable as BitmapDrawable).bitmap