#976 mpf: apply rotation when decoding sub pages

This commit is contained in:
Thibault Deckers 2024-04-16 19:58:45 +02:00
parent e777c35b1e
commit e9d2e3c42e
4 changed files with 11 additions and 6 deletions

View file

@ -146,7 +146,7 @@ class ThumbnailFetcher internal constructor(
return try {
var bitmap = target.get()
if (needRotationAfterGlide(mimeType)) {
if (needRotationAfterGlide(mimeType, pageId)) {
bitmap = applyExifOrientation(context, bitmap, rotationDegrees, isFlipped)
}
bitmap

View file

@ -145,7 +145,7 @@ class ImageByteStreamHandler(private val context: Context, private val arguments
.submit()
try {
var bitmap = withContext(Dispatchers.IO) { target.get() }
if (needRotationAfterGlide(mimeType)) {
if (needRotationAfterGlide(mimeType, pageId)) {
bitmap = applyExifOrientation(context, bitmap, rotationDegrees, isFlipped)
}
if (bitmap != null) {

View file

@ -334,7 +334,7 @@ abstract class ImageProvider {
.load(model)
.submit(targetWidthPx, targetHeightPx)
var bitmap = withContext(Dispatchers.IO) { target.get() }
if (MimeTypes.needRotationAfterGlide(sourceMimeType)) {
if (MimeTypes.needRotationAfterGlide(sourceMimeType, pageId)) {
bitmap = BitmapUtils.applyExifOrientation(activity, bitmap, sourceEntry.rotationDegrees, sourceEntry.isFlipped)
}
bitmap ?: throw Exception("failed to get image for mimeType=$sourceMimeType uri=$sourceUri page=$pageId")

View file

@ -2,6 +2,7 @@ package deckers.thibault.aves.utils
import android.webkit.MimeTypeMap
import androidx.exifinterface.media.ExifInterface
import deckers.thibault.aves.decoder.MultiPageImage
object MimeTypes {
const val ANY = "*/*"
@ -137,10 +138,14 @@ object MimeTypes {
// but we need to rotate the decoded bitmap for the other formats
// maybe related to ExifInterface version used by Glide:
// https://github.com/bumptech/glide/blob/master/gradle.properties#L21
fun needRotationAfterGlide(mimeType: String) = when (mimeType) {
fun needRotationAfterGlide(mimeType: String, pageId: Int?): Boolean {
return if (pageId != null && MultiPageImage.isSupported(mimeType)) {
true
} else when (mimeType) {
DNG, HEIC, HEIF, PNG, WEBP -> true
else -> false
}
}
// Thumbnails obtained from the Media Store are automatically rotated
// according to EXIF orientation when decoding images of known formats