Fix app trying to split long strip when not needed (#3121)

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
Leodyver Semilla
2026-04-09 04:27:44 +08:00
committed by GitHub
parent 2a1859d7d7
commit cfc69d8d0b
4 changed files with 63 additions and 4 deletions
@@ -205,7 +205,11 @@ object ImageUtil {
*/
private fun isTallImage(imageSource: BufferedSource): Boolean {
val options = extractImageOptions(imageSource)
return (options.outHeight / options.outWidth) > 3
return TallImageSplitCalculator.shouldSplit(
imageWidth = options.outWidth,
imageHeight = options.outHeight,
optimalImageHeight = optimalImageHeight,
)
}
/**
@@ -226,7 +230,6 @@ object ImageUtil {
val options = extractImageOptions(imageSource).apply {
inJustDecodeBounds = false
}
val splitDataList = options.splitData
return try {
@@ -273,8 +276,7 @@ object ImageUtil {
val imageHeight = outHeight
val imageWidth = outWidth
// -1 so it doesn't try to split when imageHeight = optimalImageHeight
val partCount = (imageHeight - 1) / optimalImageHeight + 1
val partCount = TallImageSplitCalculator.calculatePartCount(imageHeight, optimalImageHeight)
val optimalSplitHeight = imageHeight / partCount
logcat {
@@ -0,0 +1,17 @@
package tachiyomi.core.common.util.system
internal object TallImageSplitCalculator {
fun calculatePartCount(imageHeight: Int, optimalImageHeight: Int): Int {
require(imageHeight > 0) { "imageHeight must be positive" }
require(optimalImageHeight > 0) { "optimalImageHeight must be positive" }
// -1 so it doesn't try to split when imageHeight = optimalImageHeight
return (imageHeight - 1) / optimalImageHeight + 1
}
fun shouldSplit(imageWidth: Int, imageHeight: Int, optimalImageHeight: Int): Boolean {
require(imageWidth > 0) { "imageWidth must be positive" }
return imageHeight > imageWidth * 3 &&
calculatePartCount(imageHeight, optimalImageHeight) > 1
}
}