diff --git a/CHANGELOG.md b/CHANGELOG.md index 606d1e5e6..f2db3764b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co ### Improved - Show informative error when trying to add unapproved titles to list on MAL ([@MajorTanya](https://github.com/MajorTanya)) ([#3155](https://github.com/mihonapp/mihon/pull/3155)) +### Fixed +- Fix app trying to split long strip when not needed ([@leodyversemilla07](https://github.com/leodyversemilla07)) ([#3121](https://github.com/mihonapp/mihon/pull/3121)) + ## [v0.19.7] - 2026-03-23 Same as v0.19.6 diff --git a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt index a8cee59e5..ec08d66d2 100644 --- a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt +++ b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt @@ -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 { diff --git a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/TallImageSplitCalculator.kt b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/TallImageSplitCalculator.kt new file mode 100644 index 000000000..9613812ae --- /dev/null +++ b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/TallImageSplitCalculator.kt @@ -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 + } +} diff --git a/core/common/src/test/java/tachiyomi/core/common/util/system/TallImageSplitCalculatorTest.kt b/core/common/src/test/java/tachiyomi/core/common/util/system/TallImageSplitCalculatorTest.kt new file mode 100644 index 000000000..dd3f7a560 --- /dev/null +++ b/core/common/src/test/java/tachiyomi/core/common/util/system/TallImageSplitCalculatorTest.kt @@ -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)) + } +}