mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Switch to hardware bitmap in reader only if device can handle it
This commit is contained in:
parent
fbe2d8c701
commit
01fcd7d122
4 changed files with 50 additions and 56 deletions
|
@ -50,7 +50,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.isMaxTextureSizeExceeded(bitmap)
|
||||
) {
|
||||
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
|
||||
if (hwBitmap != null) {
|
||||
|
|
|
@ -18,6 +18,7 @@ import androidx.annotation.CallSuper
|
|||
import androidx.annotation.StyleRes
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.core.view.isVisible
|
||||
import coil3.BitmapImage
|
||||
import coil3.asDrawable
|
||||
import coil3.dispose
|
||||
import coil3.imageLoader
|
||||
|
@ -225,20 +226,26 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
|||
},
|
||||
)
|
||||
|
||||
val useCoilPipeline = if (isWebtoon) {
|
||||
try { !ImageUtil.isMaxTextureSizeExceeded(data) } catch (_: IllegalStateException) { false }
|
||||
} else {
|
||||
false
|
||||
when (data) {
|
||||
is BitmapDrawable -> {
|
||||
setImage(ImageSource.bitmap(data.bitmap))
|
||||
isVisible = true
|
||||
}
|
||||
is BufferedSource -> {
|
||||
if (!isWebtoon || !ImageUtil.isMaxTextureSizeExceeded(data)) {
|
||||
setHardwareConfig(!ImageUtil.isMaxTextureSizeExceeded(data))
|
||||
setImage(ImageSource.inputStream(data.inputStream()))
|
||||
isVisible = true
|
||||
return@apply
|
||||
}
|
||||
|
||||
if (useCoilPipeline) {
|
||||
val request = ImageRequest.Builder(context)
|
||||
ImageRequest.Builder(context)
|
||||
.data(data)
|
||||
.memoryCachePolicy(CachePolicy.DISABLED)
|
||||
.diskCachePolicy(CachePolicy.DISABLED)
|
||||
.target(
|
||||
onSuccess = { result ->
|
||||
val image = result.asDrawable(context.resources) as BitmapDrawable
|
||||
val image = result as BitmapImage
|
||||
setImage(ImageSource.bitmap(image.bitmap))
|
||||
isVisible = true
|
||||
},
|
||||
|
@ -252,14 +259,11 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
|||
.customDecoder(true)
|
||||
.crossfade(false)
|
||||
.build()
|
||||
context.imageLoader.enqueue(request)
|
||||
} else {
|
||||
when (data) {
|
||||
is BitmapDrawable -> setImage(ImageSource.bitmap(data.bitmap))
|
||||
is BufferedSource -> setImage(ImageSource.inputStream(data.inputStream()))
|
||||
else -> throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")
|
||||
.let(context.imageLoader::enqueue)
|
||||
}
|
||||
else -> {
|
||||
throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")
|
||||
}
|
||||
isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -776,27 +776,17 @@ object ImageUtil {
|
|||
return options
|
||||
}
|
||||
|
||||
fun isMaxTextureSizeExceeded(data: Any): Boolean {
|
||||
val width: Int
|
||||
val height: Int
|
||||
when (data) {
|
||||
is BufferedSource -> {
|
||||
val opts = extractImageOptions(data)
|
||||
width = opts.outWidth
|
||||
height = opts.outHeight
|
||||
}
|
||||
is BitmapDrawable -> {
|
||||
width = data.bitmap.width
|
||||
height = data.bitmap.height
|
||||
}
|
||||
is Bitmap -> {
|
||||
width = data.width
|
||||
height = data.height
|
||||
}
|
||||
else -> throw IllegalArgumentException("Not implemented for class ${data::class.simpleName}")
|
||||
}
|
||||
fun isMaxTextureSizeExceeded(source: BufferedSource): Boolean =
|
||||
extractImageOptions(source).let { opts -> isMaxTextureSizeExceeded(opts.outWidth, opts.outHeight) }
|
||||
|
||||
if (minOf(width, height) <= 0) throw IllegalStateException("Invalid bitmap size")
|
||||
fun isMaxTextureSizeExceeded(drawable: BitmapDrawable): Boolean =
|
||||
isMaxTextureSizeExceeded(drawable.bitmap)
|
||||
|
||||
fun isMaxTextureSizeExceeded(bitmap: Bitmap): Boolean =
|
||||
isMaxTextureSizeExceeded(data.width, data.height)
|
||||
|
||||
private fun isMaxTextureSizeExceeded(width: Int, height: Int): Boolean {
|
||||
if (minOf(width, height) <= 0) return false
|
||||
|
||||
return maxOf(width, height) > GLUtil.maxTextureSize
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ sqldelight-android-driver = { module = "app.cash.sqldelight:android-driver", ver
|
|||
sqldelight-android-paging = { module = "app.cash.sqldelight:androidx-paging3-extensions", version.ref = "sqldelight" }
|
||||
sqldelight-dialects-sql = { module = "app.cash.sqldelight:sqlite-3-38-dialect", version.ref = "sqldelight" }
|
||||
|
||||
subsamplingscaleimageview = { module = "com.github.null2264:subsampling-scale-image-view", version = "338caedb5f" }
|
||||
subsamplingscaleimageview = { module = "com.github.null2264:subsampling-scale-image-view", version = "f7b674ebdd" }
|
||||
shizuku-api = { module = "dev.rikka.shizuku:api", version.ref = "shizuku" }
|
||||
shizuku-provider = { module = "dev.rikka.shizuku:provider", version.ref = "shizuku" }
|
||||
taptargetview = { module = "com.getkeepsafe.taptargetview:taptargetview", version = "1.13.3" }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue