mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 14:51:49 +01: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
@ -289,25 +289,24 @@ class WebtoonPageHolder(
|
|||||||
}
|
}
|
||||||
val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream)
|
val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream)
|
||||||
if (isStripSplitNeeded) {
|
if (isStripSplitNeeded) {
|
||||||
onStripSplit(imageStream)?.let { return it }
|
return onStripSplit(imageStream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageStream
|
return imageStream
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onStripSplit(imageStream: BufferedInputStream): InputStream? {
|
private fun onStripSplit(imageStream: BufferedInputStream): InputStream {
|
||||||
val page = page ?: return null
|
// If we have reached this point [page] and its stream shouldn't be null
|
||||||
val streamFn = page.stream ?: return null
|
val page = page!!
|
||||||
|
val stream = page.stream!!
|
||||||
val splitData = ImageUtil.getSplitDataForStream(imageStream)
|
val splitData = ImageUtil.getSplitDataForStream(imageStream)
|
||||||
if (splitData.size == 1) return imageStream
|
|
||||||
val newPages = splitData.map {
|
val newPages = splitData.map {
|
||||||
StencilPage(page) { ImageUtil.splitStrip(it, streamFn) }
|
StencilPage(page) { ImageUtil.splitStrip(it, stream) }
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
return newPages.removeFirst().stream?.invoke()
|
return newPages.removeFirst().stream!!()
|
||||||
.also {
|
.also {
|
||||||
// Doing this first and then returning InputStream
|
// Running [onLongStripSplit] first results in issues with splitting
|
||||||
// results in various issues with splitting
|
|
||||||
viewer.onLongStripSplit(page, newPages)
|
viewer.onLongStripSplit(page, newPages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ object ImageUtil {
|
|||||||
|
|
||||||
val options = extractImageOptions(imageStream)
|
val options = extractImageOptions(imageStream)
|
||||||
val imageHeightIsBiggerThanWidth = options.outHeight > options.outWidth
|
val imageHeightIsBiggerThanWidth = options.outHeight > options.outWidth
|
||||||
val imageHeightBiggerThanScreenHeight = options.outHeight > getDisplayMaxHeightInPx
|
val imageHeightBiggerThanScreenHeight = options.outHeight > optimalImageHeight
|
||||||
return imageHeightIsBiggerThanWidth && imageHeightBiggerThanScreenHeight
|
return imageHeightIsBiggerThanWidth && imageHeightBiggerThanScreenHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,9 +300,8 @@ object ImageUtil {
|
|||||||
val imageHeight = outHeight
|
val imageHeight = outHeight
|
||||||
val imageWidth = outWidth
|
val imageWidth = outWidth
|
||||||
|
|
||||||
val splitHeight = getDisplayMaxHeightInPx * 2
|
// -1 so it doesn't try to split when imageHeight = optimalImageHeight
|
||||||
// -1 so it doesn't try to split when imageHeight = splitHeight
|
val partCount = (imageHeight - 1) / optimalImageHeight + 1
|
||||||
val partCount = (imageHeight - 1) / splitHeight + 1
|
|
||||||
val optimalSplitHeight = imageHeight / partCount
|
val optimalSplitHeight = imageHeight / partCount
|
||||||
|
|
||||||
logcat {
|
logcat {
|
||||||
@ -316,15 +315,15 @@ object ImageUtil {
|
|||||||
if (isNotEmpty() && imageHeight <= last().bottomOffset) break
|
if (isNotEmpty() && imageHeight <= last().bottomOffset) break
|
||||||
|
|
||||||
val topOffset = index * optimalSplitHeight
|
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
|
// If remaining height is smaller or equal to 1/10th of
|
||||||
// optimal split height then include it in current page
|
// optimal split height then include it in current page
|
||||||
if (remainingHeight <= (optimalSplitHeight / 10)) {
|
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
|
// Android doesn't include some mappings
|
||||||
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
||||||
// https://issuetracker.google.com/issues/182703810
|
// https://issuetracker.google.com/issues/182703810
|
||||||
|
Loading…
Reference in New Issue
Block a user