refactor: Separate isHardwareThresholdExceeded from isMaxTextureSizeExceeded

This commit is contained in:
Ahmad Ansori Palembani 2024-12-05 14:49:14 +07:00
parent 23db3244ce
commit 332f3f7ee6
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
3 changed files with 23 additions and 9 deletions

View file

@ -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) {

View file

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

View file

@ -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
}
} }