mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Separate isHardwareThresholdExceeded from isMaxTextureSizeExceeded
This commit is contained in:
parent
23db3244ce
commit
332f3f7ee6
3 changed files with 23 additions and 9 deletions
|
@ -50,7 +50,7 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti
|
||||||
if (
|
if (
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||||
options.bitmapConfig == Bitmap.Config.HARDWARE &&
|
options.bitmapConfig == Bitmap.Config.HARDWARE &&
|
||||||
!ImageUtil.isMaxTextureSizeExceeded(bitmap)
|
!ImageUtil.isHardwareThresholdExceeded(bitmap)
|
||||||
) {
|
) {
|
||||||
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
|
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
|
||||||
if (hwBitmap != null) {
|
if (hwBitmap != null) {
|
||||||
|
|
|
@ -234,7 +234,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||||
is BufferedSource -> {
|
is BufferedSource -> {
|
||||||
// SSIV doesn't tile bitmaps, so if the image exceeded max texture size it won't load regardless.
|
// SSIV doesn't tile bitmaps, so if the image exceeded max texture size it won't load regardless.
|
||||||
if (!isWebtoon || ImageUtil.isMaxTextureSizeExceeded(data)) {
|
if (!isWebtoon || ImageUtil.isMaxTextureSizeExceeded(data)) {
|
||||||
setHardwareConfig(!ImageUtil.isMaxTextureSizeExceeded(data))
|
setHardwareConfig(!ImageUtil.isHardwareThresholdExceeded(data))
|
||||||
setImage(ImageSource.inputStream(data.inputStream()))
|
setImage(ImageSource.inputStream(data.inputStream()))
|
||||||
isVisible = true
|
isVisible = true
|
||||||
return@apply
|
return@apply
|
||||||
|
|
|
@ -776,20 +776,34 @@ object ImageUtil {
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isMaxTextureSizeExceeded(source: BufferedSource): Boolean =
|
fun isHardwareThresholdExceeded(source: BufferedSource): Boolean = extractImageOptions(source).let { opts ->
|
||||||
extractImageOptions(source).let { opts -> isMaxTextureSizeExceeded(opts.outWidth, opts.outHeight) }
|
isHardwareThresholdExceeded(opts.outWidth, opts.outHeight)
|
||||||
|
}
|
||||||
|
|
||||||
fun isMaxTextureSizeExceeded(drawable: BitmapDrawable): Boolean =
|
fun isHardwareThresholdExceeded(drawable: BitmapDrawable): Boolean =
|
||||||
isMaxTextureSizeExceeded(drawable.bitmap)
|
isHardwareThresholdExceeded(drawable.bitmap)
|
||||||
|
|
||||||
fun isMaxTextureSizeExceeded(bitmap: Bitmap): Boolean =
|
fun isHardwareThresholdExceeded(bitmap: Bitmap): Boolean =
|
||||||
isMaxTextureSizeExceeded(bitmap.width, bitmap.height)
|
isHardwareThresholdExceeded(bitmap.width, bitmap.height)
|
||||||
|
|
||||||
var hardwareBitmapThreshold: Int = GLUtil.SAFE_TEXTURE_LIMIT
|
var hardwareBitmapThreshold: Int = GLUtil.SAFE_TEXTURE_LIMIT
|
||||||
|
|
||||||
private fun isMaxTextureSizeExceeded(width: Int, height: Int): Boolean {
|
private fun isHardwareThresholdExceeded(width: Int, height: Int): Boolean {
|
||||||
if (minOf(width, height) <= 0) return false
|
if (minOf(width, height) <= 0) return false
|
||||||
|
|
||||||
return maxOf(width, height) > hardwareBitmapThreshold
|
return maxOf(width, height) > hardwareBitmapThreshold
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isMaxTextureSizeExceeded(source: BufferedSource): Boolean = extractImageOptions(source).let { opts ->
|
||||||
|
isMaxTextureSizeExceeded(opts.outWidth, opts.outHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isMaxTextureSizeExceeded(bitmap: Bitmap): Boolean =
|
||||||
|
isMaxTextureSizeExceeded(bitmap.width, bitmap.height)
|
||||||
|
|
||||||
|
private fun isMaxTextureSizeExceeded(width: Int, height: Int): Boolean {
|
||||||
|
if (minOf(width, height) <= 0) return false
|
||||||
|
|
||||||
|
return maxOf(width, height) > GLUtil.DEVICE_TEXTURE_LIMIT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue