mirror of
https://github.com/null2264/yokai.git
synced 2025-07-16 22:06:54 +00:00
fix: Fixed some issues when reading/saving images
This commit is contained in:
parent
cb6677cc91
commit
73b395000f
3 changed files with 9 additions and 24 deletions
|
@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
|
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
@ -180,7 +181,7 @@ class DownloadManager(val context: Context) {
|
||||||
fun buildPageList(source: Source, manga: Manga, chapter: Chapter): List<Page> {
|
fun buildPageList(source: Source, manga: Manga, chapter: Chapter): List<Page> {
|
||||||
val chapterDir = provider.findChapterDir(chapter, manga, source)
|
val chapterDir = provider.findChapterDir(chapter, manga, source)
|
||||||
val files = chapterDir?.listFiles().orEmpty()
|
val files = chapterDir?.listFiles().orEmpty()
|
||||||
.filter { "image" in it.type.orEmpty() }
|
.filter { it.isFile && ImageUtil.isImage(it.name.orEmpty()) { it.openInputStream() } }
|
||||||
|
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
throw Exception(context.getString(MR.strings.no_pages_found))
|
throw Exception(context.getString(MR.strings.no_pages_found))
|
||||||
|
|
|
@ -536,14 +536,9 @@ class Downloader(
|
||||||
* @param file the file where the image is already downloaded.
|
* @param file the file where the image is already downloaded.
|
||||||
*/
|
*/
|
||||||
private fun getImageExtension(response: Response, file: UniFile): String {
|
private fun getImageExtension(response: Response, file: UniFile): String {
|
||||||
// Read content type if available.
|
val mime = response.body.contentType()?.let { ct -> if (ct.type == "image") "image/${ct.subtype}" else null }
|
||||||
val mime = response.body.contentType()?.let { ct -> "${ct.type}/${ct.subtype}" }
|
|
||||||
// Else guess from the uri.
|
|
||||||
?: context.contentResolver.getType(file.uri)
|
|
||||||
// Else read magic numbers.
|
|
||||||
?: ImageUtil.findImageType { file.openInputStream() }?.mime
|
|
||||||
|
|
||||||
return ImageUtil.getExtensionFromMimeType(mime)
|
return ImageUtil.getExtensionFromMimeType(mime) { file.openInputStream() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile): Boolean {
|
private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile): Boolean {
|
||||||
|
|
|
@ -45,12 +45,8 @@ import kotlin.math.roundToInt
|
||||||
object ImageUtil {
|
object ImageUtil {
|
||||||
|
|
||||||
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
|
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
|
||||||
val contentType = try {
|
val extension = name.substringAfterLast('.')
|
||||||
URLConnection.guessContentTypeFromName(name)
|
return ImageType.entries.any { it.extension == extension } || openStream?.let { findImageType(it) } != null
|
||||||
} catch (e: Exception) {
|
|
||||||
null
|
|
||||||
} ?: openStream?.let { findImageType(it)?.mime }
|
|
||||||
return contentType?.startsWith("image/") ?: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findImageType(openStream: () -> InputStream): ImageType? {
|
fun findImageType(openStream: () -> InputStream): ImageType? {
|
||||||
|
@ -88,10 +84,9 @@ object ImageUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExtensionFromMimeType(mime: String?): String {
|
fun getExtensionFromMimeType(mime: String?, openStream: () -> InputStream): String {
|
||||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(mime)
|
val type = mime?.let { ImageType.entries.find { it.mime == mime } } ?: findImageType(openStream)
|
||||||
?: SUPPLEMENTARY_MIMETYPE_MAPPING[mime]
|
return type?.extension ?: "jpg"
|
||||||
?: "jpg"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isAnimatedAndSupported(source: BufferedSource): Boolean {
|
fun isAnimatedAndSupported(source: BufferedSource): Boolean {
|
||||||
|
@ -780,12 +775,6 @@ object ImageUtil {
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
// Android doesn't include some mappings
|
|
||||||
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
|
||||||
// https://issuetracker.google.com/issues/182703810
|
|
||||||
"image/jxl" to "jxl",
|
|
||||||
)
|
|
||||||
|
|
||||||
fun isMaxTextureSizeExceeded(data: Any): Boolean {
|
fun isMaxTextureSizeExceeded(data: Any): Boolean {
|
||||||
val width: Int
|
val width: Int
|
||||||
val height: Int
|
val height: Int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue