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:
@@ -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 {
|
||||
|
||||
+17
@@ -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
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package tachiyomi.core.common.util.system
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class TallImageSplitCalculatorTest {
|
||||
|
||||
@Test
|
||||
fun `does not split when aspect ratio is tall but computed split count is one`() {
|
||||
assertFalse(
|
||||
TallImageSplitCalculator.shouldSplit(
|
||||
imageWidth = 1024,
|
||||
imageHeight = 4385,
|
||||
optimalImageHeight = 4386,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `splits when aspect ratio is tall and computed split count is greater than one`() {
|
||||
assertTrue(
|
||||
TallImageSplitCalculator.shouldSplit(
|
||||
imageWidth = 1024,
|
||||
imageHeight = 4385,
|
||||
optimalImageHeight = 4384,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `calculate part count rounds boundary correctly`() {
|
||||
assertEquals(1, TallImageSplitCalculator.calculatePartCount(imageHeight = 4384, optimalImageHeight = 4384))
|
||||
assertEquals(2, TallImageSplitCalculator.calculatePartCount(imageHeight = 4385, optimalImageHeight = 4384))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user