From 591df8abccba95031a670b1ef761fb522b0c0517 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 3 Jul 2022 22:33:15 -0400 Subject: [PATCH] Add MIME type mapping for image/jxl (fixes #7117) --- .../eu/kanade/tachiyomi/data/download/Downloader.kt | 3 +-- .../eu/kanade/tachiyomi/util/system/ImageUtil.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 9ad7f9355..7711a1cba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.data.download import android.content.Context -import android.webkit.MimeTypeMap import com.hippo.unifile.UniFile import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay @@ -478,7 +477,7 @@ class Downloader( // Else read magic numbers. ?: ImageUtil.findImageType { file.openInputStream() }?.mime - return MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) ?: "jpg" + return ImageUtil.getExtensionFromMimeType(mime) } private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt index c1d4edfce..2d9bec718 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt @@ -11,6 +11,7 @@ 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 @@ -65,6 +66,12 @@ object ImageUtil { return null } + fun getExtensionFromMimeType(mime: String?): String { + return MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) + ?: SUPPLEMENTARY_MIMETYPE_MAPPING[mime] + ?: "jpg" + } + fun isAnimatedAndSupported(stream: InputStream): Boolean { try { val type = getImageType(stream) ?: return false @@ -514,4 +521,10 @@ object ImageUtil { if (resetAfterExtraction) imageStream.reset() return options } + + // Android doesn't include some mappings + private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf( + // https://issuetracker.google.com/issues/182703810 + "image/jxl" to "jxl", + ) }