diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0288246..e3e653d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co ### Fixed - Fixed "currentTab was used multiple times" - Fixed a rare crash when invoking "Mark previous as read" action +- Fixed long strip images not loading in some old devices ### Improved - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt index 89d0b2e6e..bd6f419c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt @@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.animatorDurationScale import eu.kanade.tachiyomi.util.view.isVisibleOnScreen import okio.BufferedSource +import tachiyomi.core.common.util.system.ImageUtil /** * A wrapper view for showing page image. @@ -288,35 +289,42 @@ open class ReaderPageImageView @JvmOverloads constructor( }, ) - if (isWebtoon) { - val request = ImageRequest.Builder(context) - .data(data) - .memoryCachePolicy(CachePolicy.DISABLED) - .diskCachePolicy(CachePolicy.DISABLED) - .target( - onSuccess = { result -> - val image = result as BitmapImage - setImage(ImageSource.bitmap(image.bitmap)) - isVisible = true - }, - onError = { - this@ReaderPageImageView.onImageLoadError() - }, - ) - .size(ViewSizeResolver(this@ReaderPageImageView)) - .precision(Precision.INEXACT) - .cropBorders(config.cropBorders) - .customDecoder(true) - .crossfade(false) - .build() - context.imageLoader.enqueue(request) - } else { - when (data) { - is BitmapDrawable -> setImage(ImageSource.bitmap(data.bitmap)) - is BufferedSource -> setImage(ImageSource.inputStream(data.inputStream())) - else -> throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}") + when (data) { + is BitmapDrawable -> { + setImage(ImageSource.bitmap(data.bitmap)) + isVisible = true + } + is BufferedSource -> { + if (!isWebtoon || !ImageUtil.canUseCoilToDecode(data)) { + setImage(ImageSource.inputStream(data.inputStream())) + isVisible = true + } else { + val request = ImageRequest.Builder(context) + .data(data) + .memoryCachePolicy(CachePolicy.DISABLED) + .diskCachePolicy(CachePolicy.DISABLED) + .target( + onSuccess = { result -> + val image = result as BitmapImage + setImage(ImageSource.bitmap(image.bitmap)) + isVisible = true + }, + onError = { + this@ReaderPageImageView.onImageLoadError() + }, + ) + .size(ViewSizeResolver(this@ReaderPageImageView)) + .precision(Precision.INEXACT) + .cropBorders(config.cropBorders) + .customDecoder(true) + .crossfade(false) + .build() + context.imageLoader.enqueue(request) + } + } + else -> { + throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}") } - isVisible = true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/GLUtil.kt b/core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/GLUtil.kt similarity index 100% rename from app/src/main/java/eu/kanade/tachiyomi/util/system/GLUtil.kt rename to core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/GLUtil.kt diff --git a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt index 0f4bf2409..834c3ac63 100644 --- a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt +++ b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt @@ -22,6 +22,7 @@ import androidx.core.graphics.get import androidx.core.graphics.green import androidx.core.graphics.red import com.hippo.unifile.UniFile +import eu.kanade.tachiyomi.util.system.GLUtil import logcat.LogPriority import okio.Buffer import okio.BufferedSource @@ -309,6 +310,11 @@ object ImageUtil { val bottomOffset = topOffset + splitHeight } + fun canUseCoilToDecode(imageSource: BufferedSource): Boolean { + val options = extractImageOptions(imageSource) + return maxOf(options.outWidth, options.outHeight) <= GLUtil.maxTextureSize + } + /** * Algorithm for determining what background to accompany a comic/manga page */