refactor: Simplify code

This commit is contained in:
Ahmad Ansori Palembani 2024-05-31 05:46:18 +07:00
parent b4317f8f3b
commit e49e4f2895
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 21 additions and 12 deletions

View file

@ -225,11 +225,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
)
val useCoilPipeline = if (isWebtoon) {
when (data) {
is BitmapDrawable -> !ImageUtil.isMaxTextureSizeExceeded(data.bitmap)
is BufferedSource -> !ImageUtil.isMaxTextureSizeExceeded(data)
else -> false
}
!ImageUtil.isMaxTextureSizeExceeded(data)
} else {
false
}

View file

@ -783,12 +783,25 @@ object ImageUtil {
"image/jxl" to "jxl",
)
fun isMaxTextureSizeExceeded(bitmap: Bitmap): Boolean {
return maxOf(bitmap.width, bitmap.height) > GLUtil.maxTextureSize
}
fun isMaxTextureSizeExceeded(imageSource: BufferedSource): Boolean {
val opts = extractImageOptions(imageSource)
return maxOf(opts.outWidth, opts.outHeight) > GLUtil.maxTextureSize
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}")
}
return maxOf(width, height) > GLUtil.maxTextureSize
}
}