Fix long strip images not loading in some old devices

Fixes #1398
This commit is contained in:
AntsyLich
2024-10-31 18:25:34 +06:00
parent f508d10ad1
commit 06efc3b25c
4 changed files with 43 additions and 28 deletions

View File

@ -0,0 +1,47 @@
package eu.kanade.tachiyomi.util.system
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext
import kotlin.math.max
object GLUtil {
val maxTextureSize: Int by lazy {
// Get EGL Display
val egl = EGLContext.getEGL() as EGL10
val display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)
// Initialise
val version = IntArray(2)
egl.eglInitialize(display, version)
// Query total number of configurations
val totalConfigurations = IntArray(1)
egl.eglGetConfigs(display, null, 0, totalConfigurations)
// Query actual list configurations
val configurationsList = arrayOfNulls<EGLConfig>(totalConfigurations[0])
egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations)
val textureSize = IntArray(1)
var maximumTextureSize = 0
// Iterate through all the configurations to located the maximum texture size
for (i in 0..<totalConfigurations[0]) {
// Only need to check for width since opengl textures are always squared
egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize)
// Keep track of the maximum texture size
if (maximumTextureSize < textureSize[0]) maximumTextureSize = textureSize[0]
}
// Release
egl.eglTerminate(display)
// Return largest texture size found, or default
max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION)
}
}
// Safe minimum default size
private const val IMAGE_MAX_BITMAP_DIMENSION = 2048

View File

@ -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
*/