From 200cc60f5e688780be8529f2f2c54104963ad92f Mon Sep 17 00:00:00 2001 From: Raikuha <65867276+Raikuha@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:10:24 -0300 Subject: [PATCH] - Add an option to only skip hwBitmap when it could cause empty textures Debugging shows images may have bigger dimensions than expected. To avoid exceeding maxTextureSize, a second optional check is added, controlled by a toggle under Advanced Settings. --- .../data/coil/TachiyomiImageDecoder.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt b/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt index 6403f760b..f6ba675ae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt @@ -10,10 +10,13 @@ import coil3.decode.ImageSource import coil3.fetch.SourceFetchResult import coil3.request.Options import coil3.request.bitmapConfig +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.util.system.GLUtil import okio.BufferedSource import tachiyomi.core.common.util.system.ImageUtil import tachiyomi.decoder.ImageDecoder +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get /** * A [Decoder] that uses built-in [ImageDecoder] to decode images that is not supported by the system. @@ -25,6 +28,8 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti ImageDecoder.newInstance(it.inputStream(), options.cropBorders, displayProfile) } + val fallbackForLongStrips by lazy { Injekt.get().fallbackForLongStrips().get() } + check(decoder != null && decoder.width > 0 && decoder.height > 0) { "Failed to initialize decoder" } val srcWidth = decoder.width @@ -50,10 +55,15 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti options.bitmapConfig == Bitmap.Config.HARDWARE && maxOf(bitmap.width, bitmap.height) <= GLUtil.maxTextureSize ) { - val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false) - if (hwBitmap != null) { - bitmap.recycle() - bitmap = hwBitmap + if ( + bitmap.height*1.1 <= GLUtil.maxTextureSize && + bitmap.width < 1100 || !fallbackForLongStrips + ) { + val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false) + if (hwBitmap != null) { + bitmap.recycle() + bitmap = hwBitmap + } } }