From b66f06d9dc6529d128c5e4ebf06bcc8b324adddf Mon Sep 17 00:00:00 2001 From: len Date: Thu, 2 Feb 2017 23:44:25 +0100 Subject: [PATCH] Use the first 3 bytes for jpeg --- .../main/java/eu/kanade/tachiyomi/util/DiskUtil.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt index 7c47e0d3bf..cf289506b3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt @@ -19,10 +19,10 @@ object DiskUtil { return contentType?.startsWith("image/") ?: false } - fun findImageMime(openStream: (() -> InputStream)): String? { + fun findImageMime(openStream: () -> InputStream): String? { try { openStream().buffered().use { - val bytes = ByteArray(11) + val bytes = ByteArray(8) it.mark(bytes.size) val length = it.read(bytes, 0, bytes.size) it.reset() @@ -35,13 +35,7 @@ object DiskUtil { && bytes[6] == 0x1A.toByte() && bytes[7] == 0x0A.toByte()) { return "image/png" } else if (bytes[0] == 0xFF.toByte() && bytes[1] == 0xD8.toByte() && bytes[2] == 0xFF.toByte()) { - if (bytes[3] == 0xE0.toByte() || bytes[3] == 0xE1.toByte() && bytes[6] == 'E'.toByte() - && bytes[7] == 'x'.toByte() && bytes[8] == 'i'.toByte() - && bytes[9] == 'f'.toByte() && bytes[10] == 0.toByte()) { - return "image/jpeg" - } else if (bytes[3] == 0xEE.toByte()) { - return "image/jpg" - } + return "image/jpeg" } else if (bytes[0] == 'W'.toByte() && bytes[1] == 'E'.toByte() && bytes[2] == 'B'.toByte() && bytes[3] == 'P'.toByte()) { return "image/webp" }