- 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.
This commit is contained in:
Raikuha 2024-11-04 02:10:24 -03:00 committed by GitHub
parent 2f4bb7cadb
commit 200cc60f5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,10 +10,13 @@ import coil3.decode.ImageSource
import coil3.fetch.SourceFetchResult import coil3.fetch.SourceFetchResult
import coil3.request.Options import coil3.request.Options
import coil3.request.bitmapConfig import coil3.request.bitmapConfig
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.GLUtil
import okio.BufferedSource import okio.BufferedSource
import tachiyomi.core.common.util.system.ImageUtil import tachiyomi.core.common.util.system.ImageUtil
import tachiyomi.decoder.ImageDecoder 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. * 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) ImageDecoder.newInstance(it.inputStream(), options.cropBorders, displayProfile)
} }
val fallbackForLongStrips by lazy { Injekt.get<BasePreferences>().fallbackForLongStrips().get() }
check(decoder != null && decoder.width > 0 && decoder.height > 0) { "Failed to initialize decoder" } check(decoder != null && decoder.width > 0 && decoder.height > 0) { "Failed to initialize decoder" }
val srcWidth = decoder.width val srcWidth = decoder.width
@ -50,10 +55,15 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti
options.bitmapConfig == Bitmap.Config.HARDWARE && options.bitmapConfig == Bitmap.Config.HARDWARE &&
maxOf(bitmap.width, bitmap.height) <= GLUtil.maxTextureSize maxOf(bitmap.width, bitmap.height) <= GLUtil.maxTextureSize
) { ) {
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false) if (
if (hwBitmap != null) { bitmap.height*1.1 <= GLUtil.maxTextureSize &&
bitmap.recycle() bitmap.width < 1100 || !fallbackForLongStrips
bitmap = hwBitmap ) {
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
if (hwBitmap != null) {
bitmap.recycle()
bitmap = hwBitmap
}
} }
} }