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
import eu.kanade.tachiyomi.util.system.ImageUtil
import java.io.InputStream
class StencilPage(
parent: ReaderPage,
val splitData: ImageUtil.SplitData,
stencilStream: () -> InputStream,
) : ReaderPage(parent.index, parent.url, parent.imageUrl) {
override var chapter: ReaderChapter = parent.chapter
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
fun onLongStripSplit(currentStrip: Any?, newStrips: List<StencilPage>) {
if (newStrips.isEmpty()) return
if (currentStrip is StencilPage) return
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.webview.WebViewActivity
import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.ImageUtil.SplitData
import eu.kanade.tachiyomi.util.system.dpToPx
import rx.Observable
import rx.Subscription
@ -286,27 +285,31 @@ class WebtoonPageHolder(
if (viewer.config.longStripSplit) {
if (page is StencilPage) {
val splitData = (page as StencilPage).splitData
return ImageUtil.splitStrip(imageStream, splitData)
return imageStream
}
val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream)
if (isStripSplitNeeded) {
val splitData = onStripSplit(imageStream)
splitData?.let { return ImageUtil.splitStrip(imageStream, it) }
onStripSplit(imageStream)?.let { return it }
}
}
return imageStream
}
private fun onStripSplit(imageStream: BufferedInputStream): SplitData? {
private fun onStripSplit(imageStream: BufferedInputStream): InputStream? {
val page = page ?: return null
val splitData = ImageUtil.getSplitDataForStream(imageStream).toMutableList()
val toReturn = splitData.removeFirstOrNull()
val newPages = splitData.map { StencilPage(page, it) }
val streamFn = page.stream ?: return null
val splitData = ImageUtil.getSplitDataForStream(imageStream)
if (splitData.size == 1) return imageStream
val newPages = splitData.map {
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)
return toReturn
}
}
/**

View file

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