Webtoon Split: Improve performance (#7947)

This commit is contained in:
AntsyLich 2022-09-04 21:16:20 +06:00 committed by GitHub
parent 6b2b21edfa
commit d55c854ebf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 17 deletions

View file

@ -1,15 +1,16 @@
package eu.kanade.tachiyomi.ui.reader.model package eu.kanade.tachiyomi.ui.reader.model
import eu.kanade.tachiyomi.util.system.ImageUtil import java.io.InputStream
class StencilPage( class StencilPage(
parent: ReaderPage, parent: ReaderPage,
val splitData: ImageUtil.SplitData, stencilStream: () -> InputStream,
) : ReaderPage(parent.index, parent.url, parent.imageUrl) { ) : ReaderPage(parent.index, parent.url, parent.imageUrl) {
override var chapter: ReaderChapter = parent.chapter override var chapter: ReaderChapter = parent.chapter
init { init {
stream = parent.stream status = READY
stream = stencilStream
} }
} }

View file

@ -28,6 +28,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
var currentChapter: ReaderChapter? = null var currentChapter: ReaderChapter? = null
fun onLongStripSplit(currentStrip: Any?, newStrips: List<StencilPage>) { fun onLongStripSplit(currentStrip: Any?, newStrips: List<StencilPage>) {
if (newStrips.isEmpty()) return
if (currentStrip is StencilPage) return if (currentStrip is StencilPage) return
val placeAtIndex = items.indexOf(currentStrip) + 1 val placeAtIndex = items.indexOf(currentStrip) + 1

View file

@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.ImageUtil.SplitData
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import rx.Observable import rx.Observable
import rx.Subscription import rx.Subscription
@ -286,27 +285,31 @@ class WebtoonPageHolder(
if (viewer.config.longStripSplit) { if (viewer.config.longStripSplit) {
if (page is StencilPage) { if (page is StencilPage) {
val splitData = (page as StencilPage).splitData return imageStream
return ImageUtil.splitStrip(imageStream, splitData)
} }
val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream) val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream)
if (isStripSplitNeeded) { if (isStripSplitNeeded) {
val splitData = onStripSplit(imageStream) onStripSplit(imageStream)?.let { return it }
splitData?.let { return ImageUtil.splitStrip(imageStream, it) }
} }
} }
return imageStream return imageStream
} }
private fun onStripSplit(imageStream: BufferedInputStream): SplitData? { private fun onStripSplit(imageStream: BufferedInputStream): InputStream? {
val page = page ?: return null val page = page ?: return null
val splitData = ImageUtil.getSplitDataForStream(imageStream).toMutableList() val streamFn = page.stream ?: return null
val toReturn = splitData.removeFirstOrNull() val splitData = ImageUtil.getSplitDataForStream(imageStream)
val newPages = splitData.map { StencilPage(page, it) } if (splitData.size == 1) return imageStream
viewer.onLongStripSplit(page, newPages) val newPages = splitData.map {
return toReturn StencilPage(page) { ImageUtil.splitStrip(it, streamFn) }
}.toMutableList()
return newPages.removeFirst().stream?.invoke()
.also {
// Doing this first and then returning InputStream
// results in various issues with splitting
viewer.onLongStripSplit(page, newPages)
}
} }
/** /**

View file

@ -268,8 +268,8 @@ object ImageUtil {
/** /**
* Split the imageStream according to the provided splitData * Split the imageStream according to the provided splitData
*/ */
fun splitStrip(imageStream: InputStream, splitData: SplitData): InputStream { fun splitStrip(splitData: SplitData, streamFn: () -> InputStream): InputStream {
val bitmapRegionDecoder = getBitmapRegionDecoder(imageStream) val bitmapRegionDecoder = getBitmapRegionDecoder(streamFn())
?: throw Exception("Failed to create new instance of BitmapRegionDecoder") ?: throw Exception("Failed to create new instance of BitmapRegionDecoder")
logcat { logcat {