Switch to hardware bitmap in reader only if device can handle it
Closes #1460 (cherry picked from commit e6d96bd348ea5d18a005d6465222ad5f5123103e) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt
This commit is contained in:
parent
1a28c7fb35
commit
d286cf3267
@ -15,7 +15,6 @@ import coil3.request.bitmapConfig
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.util.storage.CbzCrypto
|
||||
import eu.kanade.tachiyomi.util.storage.CbzCrypto.getCoverStream
|
||||
import eu.kanade.tachiyomi.util.system.GLUtil
|
||||
import mihon.core.common.archive.archiveReader
|
||||
import okio.BufferedSource
|
||||
import tachiyomi.core.common.util.system.ImageUtil
|
||||
@ -71,7 +70,7 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti
|
||||
if (
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
options.bitmapConfig == Bitmap.Config.HARDWARE &&
|
||||
maxOf(bitmap.width, bitmap.height) <= GLUtil.maxTextureSize
|
||||
ImageUtil.canUseHardwareBitmap(bitmap)
|
||||
) {
|
||||
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
|
||||
if (hwBitmap != null) {
|
||||
|
@ -42,8 +42,6 @@ import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
||||
import eu.kanade.tachiyomi.util.view.isVisibleOnScreen
|
||||
import okio.BufferedSource
|
||||
import tachiyomi.core.common.util.system.ImageUtil
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
/**
|
||||
* A wrapper view for showing page image.
|
||||
@ -61,8 +59,6 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||
private val isWebtoon: Boolean = false,
|
||||
) : FrameLayout(context, attrs, defStyleAttrs, defStyleRes) {
|
||||
|
||||
private val alwaysUseSSIVToDecode by lazy { Injekt.get<BasePreferences>().alwaysUseSSIVToDecode().get() }
|
||||
|
||||
private var pageView: View? = null
|
||||
|
||||
private var config: Config? = null
|
||||
@ -300,32 +296,34 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||
isVisible = true
|
||||
}
|
||||
is BufferedSource -> {
|
||||
if (alwaysUseSSIVToDecode || !isWebtoon || !ImageUtil.canUseCoilToDecode(data)) {
|
||||
if (!isWebtoon) {
|
||||
setHardwareConfig(ImageUtil.canUseHardwareBitmap(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)
|
||||
return@apply
|
||||
}
|
||||
|
||||
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 = {
|
||||
onImageLoadError()
|
||||
},
|
||||
)
|
||||
.size(ViewSizeResolver(this@ReaderPageImageView))
|
||||
.precision(Precision.INEXACT)
|
||||
.cropBorders(config.cropBorders)
|
||||
.customDecoder(true)
|
||||
.crossfade(false)
|
||||
.build()
|
||||
.let(context.imageLoader::enqueue)
|
||||
}
|
||||
else -> {
|
||||
throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")
|
||||
|
@ -360,9 +360,18 @@ object ImageUtil {
|
||||
val bottomOffset = topOffset + splitHeight
|
||||
}
|
||||
|
||||
fun canUseCoilToDecode(imageSource: BufferedSource): Boolean {
|
||||
val options = extractImageOptions(imageSource)
|
||||
return maxOf(options.outWidth, options.outHeight) <= GLUtil.maxTextureSize
|
||||
fun canUseHardwareBitmap(bitmap: Bitmap): Boolean {
|
||||
return canUseHardwareBitmap(bitmap.width, bitmap.height)
|
||||
}
|
||||
|
||||
fun canUseHardwareBitmap(imageSource: BufferedSource): Boolean {
|
||||
return with(extractImageOptions(imageSource)) {
|
||||
canUseHardwareBitmap(outWidth, outHeight)
|
||||
}
|
||||
}
|
||||
|
||||
private fun canUseHardwareBitmap(width: Int, height: Int): Boolean {
|
||||
return maxOf(width, height) <= GLUtil.maxTextureSize
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ coil-gif = { module = "io.coil-kt.coil3:coil-gif" }
|
||||
coil-compose = { module = "io.coil-kt.coil3:coil-compose" }
|
||||
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp" }
|
||||
|
||||
subsamplingscaleimageview = "com.github.tachiyomiorg:subsampling-scale-image-view:b8e1b0ed2b"
|
||||
subsamplingscaleimageview = "com.github.tachiyomiorg:subsampling-scale-image-view:66e0db195d"
|
||||
image-decoder = "com.github.tachiyomiorg:image-decoder:41c059e540"
|
||||
|
||||
natural-comparator = "com.github.gpanther:java-nat-sort:natural-comparator-1.1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user