mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Cleanup logic of onStripSplit
in WebtoonPageHolder (#7955)
* Cleanup logic of `onStripSplit` in WebtoonPageHolder * Update app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
parent
0c7b1bda7f
commit
6b91f65457
2 changed files with 17 additions and 17 deletions
|
@ -289,25 +289,24 @@ class WebtoonPageHolder(
|
|||
}
|
||||
val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream)
|
||||
if (isStripSplitNeeded) {
|
||||
onStripSplit(imageStream)?.let { return it }
|
||||
return onStripSplit(imageStream)
|
||||
}
|
||||
}
|
||||
|
||||
return imageStream
|
||||
}
|
||||
|
||||
private fun onStripSplit(imageStream: BufferedInputStream): InputStream? {
|
||||
val page = page ?: return null
|
||||
val streamFn = page.stream ?: return null
|
||||
private fun onStripSplit(imageStream: BufferedInputStream): InputStream {
|
||||
// If we have reached this point [page] and its stream shouldn't be null
|
||||
val page = page!!
|
||||
val stream = page.stream!!
|
||||
val splitData = ImageUtil.getSplitDataForStream(imageStream)
|
||||
if (splitData.size == 1) return imageStream
|
||||
val newPages = splitData.map {
|
||||
StencilPage(page) { ImageUtil.splitStrip(it, streamFn) }
|
||||
StencilPage(page) { ImageUtil.splitStrip(it, stream) }
|
||||
}.toMutableList()
|
||||
return newPages.removeFirst().stream?.invoke()
|
||||
return newPages.removeFirst().stream!!()
|
||||
.also {
|
||||
// Doing this first and then returning InputStream
|
||||
// results in various issues with splitting
|
||||
// Running [onLongStripSplit] first results in issues with splitting
|
||||
viewer.onLongStripSplit(page, newPages)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -261,7 +261,7 @@ object ImageUtil {
|
|||
|
||||
val options = extractImageOptions(imageStream)
|
||||
val imageHeightIsBiggerThanWidth = options.outHeight > options.outWidth
|
||||
val imageHeightBiggerThanScreenHeight = options.outHeight > getDisplayMaxHeightInPx
|
||||
val imageHeightBiggerThanScreenHeight = options.outHeight > optimalImageHeight
|
||||
return imageHeightIsBiggerThanWidth && imageHeightBiggerThanScreenHeight
|
||||
}
|
||||
|
||||
|
@ -300,9 +300,8 @@ object ImageUtil {
|
|||
val imageHeight = outHeight
|
||||
val imageWidth = outWidth
|
||||
|
||||
val splitHeight = getDisplayMaxHeightInPx * 2
|
||||
// -1 so it doesn't try to split when imageHeight = splitHeight
|
||||
val partCount = (imageHeight - 1) / splitHeight + 1
|
||||
// -1 so it doesn't try to split when imageHeight = optimalImageHeight
|
||||
val partCount = (imageHeight - 1) / optimalImageHeight + 1
|
||||
val optimalSplitHeight = imageHeight / partCount
|
||||
|
||||
logcat {
|
||||
|
@ -316,15 +315,15 @@ object ImageUtil {
|
|||
if (isNotEmpty() && imageHeight <= last().bottomOffset) break
|
||||
|
||||
val topOffset = index * optimalSplitHeight
|
||||
var outputImageHeight = min(optimalSplitHeight, imageHeight - topOffset)
|
||||
var splitHeight = min(optimalSplitHeight, imageHeight - topOffset)
|
||||
|
||||
val remainingHeight = imageHeight - (topOffset + outputImageHeight)
|
||||
val remainingHeight = imageHeight - (topOffset + splitHeight)
|
||||
// If remaining height is smaller or equal to 1/10th of
|
||||
// optimal split height then include it in current page
|
||||
if (remainingHeight <= (optimalSplitHeight / 10)) {
|
||||
outputImageHeight += remainingHeight
|
||||
splitHeight += remainingHeight
|
||||
}
|
||||
add(SplitData(index, topOffset, outputImageHeight, imageWidth))
|
||||
add(SplitData(index, topOffset, splitHeight, imageWidth))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -578,6 +577,8 @@ object ImageUtil {
|
|||
}
|
||||
}
|
||||
|
||||
private val optimalImageHeight = getDisplayMaxHeightInPx * 2
|
||||
|
||||
// Android doesn't include some mappings
|
||||
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
||||
// https://issuetracker.google.com/issues/182703810
|
||||
|
|
Loading…
Reference in a new issue