Skip to content

Commit

Permalink
优化解码大图时的压缩倍率判断逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojieonly committed Nov 21, 2024
1 parent 2f4a4a9 commit aad975c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/src/main/java/com/hippo/lib/image/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
}
Expand Down Expand Up @@ -197,7 +197,7 @@ class Image private constructor(
updateBitmap()
mBitmap!!
} else {
if (mObtainedDrawable==null){
if (mObtainedDrawable == null) {
return
}
(mObtainedDrawable as BitmapDrawable).bitmap
Expand Down

0 comments on commit aad975c

Please sign in to comment.