Fix some issues when reading/saving images (#993)
* Fix unsupported mime type error when saving images Avoid using platform mime type map to get extensions as it may not have all mime types we support. * Fix jxl images downloading/reading (cherry picked from commit daa47e049327c4d8b1fe4724ed1b84897d81fcf2) # Conflicts: # core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt
This commit is contained in:
@@ -14,7 +14,6 @@ import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Build
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.graphics.alpha
|
||||
import androidx.core.graphics.applyCanvas
|
||||
@@ -32,7 +31,6 @@ import tachiyomi.decoder.Format
|
||||
import tachiyomi.decoder.ImageDecoder
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.net.URLConnection
|
||||
import java.security.SecureRandom
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
@@ -47,12 +45,8 @@ object ImageUtil {
|
||||
if (File(name).extension.equals("cbi", ignoreCase = true)) return true
|
||||
// SY <--
|
||||
|
||||
val contentType = try {
|
||||
URLConnection.guessContentTypeFromName(name)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
} ?: openStream?.let { findImageType(it)?.mime }
|
||||
return contentType?.startsWith("image/") ?: false
|
||||
val extension = name.substringAfterLast('.')
|
||||
return ImageType.entries.any { it.extension == extension } || openStream?.let { findImageType(it) } != null
|
||||
}
|
||||
|
||||
fun findImageType(openStream: () -> InputStream): ImageType? {
|
||||
@@ -76,10 +70,9 @@ object ImageUtil {
|
||||
}
|
||||
}
|
||||
|
||||
fun getExtensionFromMimeType(mime: String?): String {
|
||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(mime)
|
||||
?: SUPPLEMENTARY_MIMETYPE_MAPPING[mime]
|
||||
?: "jpg"
|
||||
fun getExtensionFromMimeType(mime: String?, openStream: () -> InputStream): String {
|
||||
val type = mime?.let { ImageType.entries.find { it.mime == mime } } ?: findImageType(openStream)
|
||||
return type?.extension ?: "jpg"
|
||||
}
|
||||
|
||||
fun isAnimatedAndSupported(source: BufferedSource): Boolean {
|
||||
@@ -623,12 +616,6 @@ object ImageUtil {
|
||||
|
||||
private val optimalImageHeight = getDisplayMaxHeightInPx * 2
|
||||
|
||||
// Android doesn't include some mappings
|
||||
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
||||
// https://issuetracker.google.com/issues/182703810
|
||||
"image/jxl" to "jxl",
|
||||
)
|
||||
|
||||
fun mergeBitmaps(
|
||||
imageBitmap: Bitmap,
|
||||
imageBitmap2: Bitmap,
|
||||
|
||||
Reference in New Issue
Block a user