mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Switch to hardware bitmap in reader only if device can handle it
Closes #1460
This commit is contained in:
parent
1909126921
commit
e6d96bd348
4 changed files with 39 additions and 32 deletions
|
@ -10,7 +10,6 @@ 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.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
|
||||||
|
@ -46,10 +45,7 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti
|
||||||
|
|
||||||
check(bitmap != null) { "Failed to decode image" }
|
check(bitmap != null) { "Failed to decode image" }
|
||||||
|
|
||||||
if (
|
if (options.bitmapConfig == Bitmap.Config.HARDWARE && ImageUtil.canUseHardwareBitmap(bitmap)) {
|
||||||
options.bitmapConfig == Bitmap.Config.HARDWARE &&
|
|
||||||
maxOf(bitmap.width, bitmap.height) <= GLUtil.maxTextureSize
|
|
||||||
) {
|
|
||||||
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
|
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
|
||||||
if (hwBitmap != null) {
|
if (hwBitmap != null) {
|
||||||
bitmap.recycle()
|
bitmap.recycle()
|
||||||
|
|
|
@ -295,11 +295,14 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||||
isVisible = true
|
isVisible = true
|
||||||
}
|
}
|
||||||
is BufferedSource -> {
|
is BufferedSource -> {
|
||||||
if (!isWebtoon || !ImageUtil.canUseCoilToDecode(data)) {
|
if (!isWebtoon) {
|
||||||
|
setHardwareConfig(ImageUtil.canUseHardwareBitmap(data))
|
||||||
setImage(ImageSource.inputStream(data.inputStream()))
|
setImage(ImageSource.inputStream(data.inputStream()))
|
||||||
isVisible = true
|
isVisible = true
|
||||||
} else {
|
return@apply
|
||||||
val request = ImageRequest.Builder(context)
|
}
|
||||||
|
|
||||||
|
ImageRequest.Builder(context)
|
||||||
.data(data)
|
.data(data)
|
||||||
.memoryCachePolicy(CachePolicy.DISABLED)
|
.memoryCachePolicy(CachePolicy.DISABLED)
|
||||||
.diskCachePolicy(CachePolicy.DISABLED)
|
.diskCachePolicy(CachePolicy.DISABLED)
|
||||||
|
@ -310,7 +313,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||||
isVisible = true
|
isVisible = true
|
||||||
},
|
},
|
||||||
onError = {
|
onError = {
|
||||||
this@ReaderPageImageView.onImageLoadError()
|
onImageLoadError()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.size(ViewSizeResolver(this@ReaderPageImageView))
|
.size(ViewSizeResolver(this@ReaderPageImageView))
|
||||||
|
@ -319,8 +322,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||||
.customDecoder(true)
|
.customDecoder(true)
|
||||||
.crossfade(false)
|
.crossfade(false)
|
||||||
.build()
|
.build()
|
||||||
context.imageLoader.enqueue(request)
|
.let(context.imageLoader::enqueue)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")
|
throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")
|
||||||
|
|
|
@ -310,9 +310,18 @@ object ImageUtil {
|
||||||
val bottomOffset = topOffset + splitHeight
|
val bottomOffset = topOffset + splitHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
fun canUseCoilToDecode(imageSource: BufferedSource): Boolean {
|
fun canUseHardwareBitmap(bitmap: Bitmap): Boolean {
|
||||||
val options = extractImageOptions(imageSource)
|
return canUseHardwareBitmap(bitmap.width, bitmap.height)
|
||||||
return maxOf(options.outWidth, options.outHeight) <= GLUtil.maxTextureSize
|
}
|
||||||
|
|
||||||
|
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-compose = { module = "io.coil-kt.coil3:coil-compose" }
|
||||||
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp" }
|
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"
|
image-decoder = "com.github.tachiyomiorg:image-decoder:41c059e540"
|
||||||
|
|
||||||
natural-comparator = "com.github.gpanther:java-nat-sort:natural-comparator-1.1"
|
natural-comparator = "com.github.gpanther:java-nat-sort:natural-comparator-1.1"
|
||||||
|
|
Loading…
Reference in a new issue