forked from avluis/Hentoid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
befd892
commit aca96cf
Showing
17 changed files
with
285 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-keep public class com.bumptech.glide.integration.webp.WebpImage { *; } | ||
-keep public class com.bumptech.glide.integration.webp.WebpFrame { *; } | ||
-keep public class com.bumptech.glide.integration.webp.WebpBitmapFactory { *; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/FileHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package me.devsaki.hentoid.customssiv; | ||
|
||
/** | ||
* Generic file-related utility class | ||
*/ | ||
public class FileHelper { | ||
|
||
private FileHelper() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
public static final int FILE_IO_BUFFER_SIZE = 32 * 1024; | ||
|
||
|
||
/** | ||
* Return the position of the given sequence in the given data array | ||
* | ||
* @param data Data where to find the sequence | ||
* @param initialPos Initial position to start from | ||
* @param sequence Sequence to look for | ||
* @param limit Limit not to cross (in bytes counted from the initial position); 0 for unlimited | ||
* @return Position of the sequence in the data array; -1 if not found within the given initial position and limit | ||
*/ | ||
static int findSequencePosition(byte[] data, int initialPos, byte[] sequence, int limit) { | ||
int remainingBytes; | ||
int iSequence = 0; | ||
|
||
if (initialPos < 0 || initialPos > data.length) return -1; | ||
|
||
remainingBytes = (limit > 0) ? Math.min(data.length - initialPos, limit) : data.length; | ||
|
||
for (int i = initialPos; i < remainingBytes; i++) { | ||
if (sequence[iSequence] == data[i]) iSequence++; | ||
else if (iSequence > 0) iSequence = 0; | ||
|
||
if (sequence.length == iSequence) return i - sequence.length; | ||
} | ||
|
||
// Target sequence not found | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/ImageHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package me.devsaki.hentoid.customssiv; | ||
|
||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* Generic utility class | ||
*/ | ||
public final class ImageHelper { | ||
|
||
private static final Charset CHARSET_LATIN_1 = StandardCharsets.ISO_8859_1; | ||
|
||
public static final String MIME_IMAGE_GENERIC = "image/*"; | ||
public static final String MIME_IMAGE_WEBP = "image/webp"; | ||
public static final String MIME_IMAGE_JPEG = "image/jpeg"; | ||
public static final String MIME_IMAGE_GIF = "image/gif"; | ||
public static final String MIME_IMAGE_PNG = "image/png"; | ||
public static final String MIME_IMAGE_APNG = "image/apng"; | ||
|
||
|
||
private ImageHelper() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
|
||
/** | ||
* Determine the MIME-type of the given binary data if it's a picture | ||
* | ||
* @param binary Picture binary data to determine the MIME-type for | ||
* @return MIME-type of the given binary data; empty string if not supported | ||
*/ | ||
public static String getMimeTypeFromPictureBinary(byte[] binary) { | ||
if (binary.length < 12) return ""; | ||
|
||
// In Java, byte type is signed ! | ||
// => Converting all raw values to byte to be sure they are evaluated as expected | ||
if ((byte) 0xFF == binary[0] && (byte) 0xD8 == binary[1] && (byte) 0xFF == binary[2]) | ||
return MIME_IMAGE_JPEG; | ||
else if ((byte) 0x89 == binary[0] && (byte) 0x50 == binary[1] && (byte) 0x4E == binary[2]) { | ||
// Detect animated PNG : To be recognized as APNG an 'acTL' chunk must appear in the stream before any 'IDAT' chunks | ||
int acTlPos = FileHelper.findSequencePosition(binary, 0, "acTL".getBytes(CHARSET_LATIN_1), (int) (binary.length * 0.2)); | ||
if (acTlPos > -1) { | ||
long idatPos = FileHelper.findSequencePosition(binary, acTlPos, "IDAT".getBytes(CHARSET_LATIN_1), (int) (binary.length * 0.1)); | ||
if (idatPos > -1) return MIME_IMAGE_APNG; | ||
} | ||
return MIME_IMAGE_PNG; | ||
} else if ((byte) 0x47 == binary[0] && (byte) 0x49 == binary[1] && (byte) 0x46 == binary[2]) | ||
return MIME_IMAGE_GIF; | ||
else if ((byte) 0x52 == binary[0] && (byte) 0x49 == binary[1] && (byte) 0x46 == binary[2] && (byte) 0x46 == binary[3] | ||
&& (byte) 0x57 == binary[8] && (byte) 0x45 == binary[9] && (byte) 0x42 == binary[10] && (byte) 0x50 == binary[11]) | ||
return MIME_IMAGE_WEBP; | ||
else if ((byte) 0x42 == binary[0] && (byte) 0x4D == binary[1]) return "image/bmp"; | ||
else return MIME_IMAGE_GENERIC; | ||
} | ||
|
||
// If format is supported by Android, true if animated (animated GIF, APNG, animated WEBP); false if not | ||
// TODO complete doc | ||
public static boolean isImageAnimated(byte[] binary) { | ||
if (binary.length < 400) return false; | ||
|
||
switch (getMimeTypeFromPictureBinary(binary)) { | ||
case MIME_IMAGE_APNG: | ||
return true; | ||
case MIME_IMAGE_GIF: | ||
return FileHelper.findSequencePosition(binary, 0, "NETSCAPE".getBytes(CHARSET_LATIN_1), 400) > -1; | ||
case MIME_IMAGE_WEBP: | ||
return FileHelper.findSequencePosition(binary, 0, "ANIM".getBytes(CHARSET_LATIN_1), 400) > -1; | ||
default: | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.