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:
@@ -18,6 +18,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
### Improved
|
### 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))
|
- 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
|
## [v0.19.7] - 2026-03-23
|
||||||
Same as v0.19.6
|
Same as v0.19.6
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,11 @@ object ImageUtil {
|
|||||||
*/
|
*/
|
||||||
private fun isTallImage(imageSource: BufferedSource): Boolean {
|
private fun isTallImage(imageSource: BufferedSource): Boolean {
|
||||||
val options = extractImageOptions(imageSource)
|
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 {
|
val options = extractImageOptions(imageSource).apply {
|
||||||
inJustDecodeBounds = false
|
inJustDecodeBounds = false
|
||||||
}
|
}
|
||||||
|
|
||||||
val splitDataList = options.splitData
|
val splitDataList = options.splitData
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
@@ -273,8 +276,7 @@ object ImageUtil {
|
|||||||
val imageHeight = outHeight
|
val imageHeight = outHeight
|
||||||
val imageWidth = outWidth
|
val imageWidth = outWidth
|
||||||
|
|
||||||
// -1 so it doesn't try to split when imageHeight = optimalImageHeight
|
val partCount = TallImageSplitCalculator.calculatePartCount(imageHeight, optimalImageHeight)
|
||||||
val partCount = (imageHeight - 1) / optimalImageHeight + 1
|
|
||||||
val optimalSplitHeight = imageHeight / partCount
|
val optimalSplitHeight = imageHeight / partCount
|
||||||
|
|
||||||
logcat {
|
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