mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix(manga): Compress custom cover to not exceed 4092px
This commit is contained in:
parent
349b9c181a
commit
1d200f426c
1 changed files with 33 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
||||||
package eu.kanade.tachiyomi.data.cache
|
package eu.kanade.tachiyomi.data.cache
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.os.Build
|
||||||
import android.text.format.Formatter
|
import android.text.format.Formatter
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
import coil3.imageLoader
|
import coil3.imageLoader
|
||||||
|
@ -171,8 +174,37 @@ class CoverCache(val context: Context) {
|
||||||
*/
|
*/
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun setCustomCoverToCache(manga: Manga, inputStream: InputStream) {
|
fun setCustomCoverToCache(manga: Manga, inputStream: InputStream) {
|
||||||
|
val maxTextureSize = 4096f
|
||||||
|
var bitmap = BitmapFactory.decodeStream(inputStream)
|
||||||
|
if (maxOf(bitmap.width, bitmap.height) > maxTextureSize) {
|
||||||
|
val widthRatio = bitmap.width / maxTextureSize
|
||||||
|
val heightRatio = bitmap.height / maxTextureSize
|
||||||
|
|
||||||
|
val targetWidth: Float
|
||||||
|
val targetHeight: Float
|
||||||
|
|
||||||
|
if (widthRatio >= heightRatio) {
|
||||||
|
targetWidth = maxTextureSize
|
||||||
|
targetHeight = (targetWidth / bitmap.width) * bitmap.height
|
||||||
|
} else {
|
||||||
|
targetHeight = maxTextureSize
|
||||||
|
targetWidth = (targetHeight / bitmap.height) * bitmap.width
|
||||||
|
}
|
||||||
|
|
||||||
|
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, targetWidth.toInt(), targetHeight.toInt(), true)
|
||||||
|
bitmap.recycle()
|
||||||
|
bitmap = scaledBitmap
|
||||||
|
}
|
||||||
getCustomCoverFile(manga).outputStream().use {
|
getCustomCoverFile(manga).outputStream().use {
|
||||||
inputStream.copyTo(it)
|
@Suppress("DEPRECATION")
|
||||||
|
bitmap.compress(
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||||
|
Bitmap.CompressFormat.WEBP_LOSSLESS
|
||||||
|
else
|
||||||
|
Bitmap.CompressFormat.WEBP,
|
||||||
|
100,
|
||||||
|
it
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue