Skip to content

Commit

Permalink
MPF: mpf dependent image decoding in viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Dec 20, 2023
1 parent 8c5cfc4 commit ae5c2f7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ImageByteStreamHandler(private val context: Context, private val arguments

if (isVideo(mimeType)) {
streamVideoByGlide(uri, mimeType, sizeBytes)
} else if (!canDecodeWithFlutter(mimeType, rotationDegrees, isFlipped)) {
} else if (!canDecodeWithFlutter(mimeType, pageId, rotationDegrees, isFlipped)) {
// decode exotic format on platform side, then encode it in portable format for Flutter
streamImageByGlide(uri, pageId, mimeType, sizeBytes, rotationDegrees, isFlipped)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class MultiPageImageGlideModule : LibraryGlideModule() {
}

class MultiPageImage(val context: Context, val uri: Uri, val mimeType: String, val pageId: Int?) {
override fun toString(): String = "MultiPageImage#${hashCode()}{uri=$uri, mimeType=$mimeType, pageId=$pageId}"

companion object {
fun isSupported(mimeType: String) = MimeTypes.isHeic(mimeType) || mimeType == MimeTypes.JPEG
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class MpEntry(val flags: Int, val format: Int, val type: Int, val size: Long, va
else -> false
}

override fun toString(): String = "MpEntry#${hashCode()}{flags=$flags, format=$format, type=$type, size=$size, dataOffset=$dataOffset, dep1=$dep1, dep2=$dep2}"

companion object {
const val FLAG_REPRESENTATIVE = 1 shl 2
const val FLAG_DEPENDENT_CHILD = 1 shl 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ object MimeTypes {
else -> false
}

// as of Flutter v1.22.0, with additional custom handling for SVG
fun canDecodeWithFlutter(mimeType: String, rotationDegrees: Int?, isFlipped: Boolean?) = when (mimeType) {
JPEG, GIF, WEBP, BMP, WBMP, ICO, SVG -> true
// as of Flutter v3.16.4, with additional custom handling for SVG
fun canDecodeWithFlutter(mimeType: String, pageId: Int?, rotationDegrees: Int?, isFlipped: Boolean?) = when (mimeType) {
GIF, WEBP, BMP, WBMP, ICO, SVG -> true
JPEG -> (pageId ?: 0) == 0
PNG -> (rotationDegrees ?: 0) == 0 && !(isFlipped ?: false)
else -> false
}
Expand Down

0 comments on commit ae5c2f7

Please sign in to comment.