diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt index d921615bd..4754a6e26 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.app.RecoverableSecurityException import android.content.* +import android.graphics.BitmapFactory import android.media.MediaScannerConnection import android.net.Uri import android.os.Build @@ -31,6 +32,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import java.io.File import java.io.FileOutputStream +import java.io.IOException import java.io.OutputStream import java.io.SyncFailedException import java.util.* @@ -214,8 +216,8 @@ class MediaStoreImageProvider : ImageProvider() { // `mimeType` can be registered as null for file media URIs with unsupported media types (e.g. TIFF on old devices) // in that case we try to use the MIME type provided along the URI val mimeType: String? = cursor.getString(mimeTypeColumn) ?: fileMimeType - val width = cursor.getInt(widthColumn) - val height = cursor.getInt(heightColumn) + var width = cursor.getInt(widthColumn) + var height = cursor.getInt(heightColumn) val durationMillis = if (durationColumn != -1) cursor.getLong(durationColumn) else 0L if (mimeType == null) { @@ -238,6 +240,28 @@ class MediaStoreImageProvider : ImageProvider() { "contentId" to contentId, ) + if (MimeTypes.isHeic(mimeType)) { + // The reported size for some HEIC images is simply incorrect. + try { + StorageUtils.openInputStream(context, itemUri)?.use { input -> + val options = BitmapFactory.Options().apply { + inJustDecodeBounds = true + } + BitmapFactory.decodeStream(input, null, options) + val outWidth = options.outWidth + val outHeight = options.outHeight + if (outWidth > 0 && outHeight > 0) { + width = outWidth + height = outHeight + entryMap["width"] = width + entryMap["height"] = height + } + } + } catch (e: IOException) { + // ignore + } + } + if (MimeTypes.isRaw(mimeType) || (width <= 0 || height <= 0) && needSize(mimeType) || durationMillis == 0L && needDuration diff --git a/lib/ref/metadata/xmp.dart b/lib/ref/metadata/xmp.dart index 2d5ff418b..5a7ae5942 100644 --- a/lib/ref/metadata/xmp.dart +++ b/lib/ref/metadata/xmp.dart @@ -1,6 +1,7 @@ class XmpNamespaces { static const acdsee = 'http://ns.acdsee.com/iptc/1.0/'; static const adsmlat = 'http://adsml.org/xmlns/'; + static const appleDesktop = 'http://ns.apple.com/namespace/1.0/'; static const avm = 'http://www.communicatingastronomy.org/avm/1.0/'; static const camera = 'http://pix4d.com/camera/1.0/'; static const cc = 'http://creativecommons.org/ns#'; diff --git a/lib/view/src/xmp.dart b/lib/view/src/xmp.dart index 438a5d4fe..cbac7e646 100644 --- a/lib/view/src/xmp.dart +++ b/lib/view/src/xmp.dart @@ -7,6 +7,7 @@ class XmpNamespaceView { XmpNamespaces.adsmlat: 'AdsML', XmpNamespaces.exifAux: 'Exif Aux', XmpNamespaces.avm: 'Astronomy Visualization', + XmpNamespaces.appleDesktop: 'Apple Desktop', XmpNamespaces.camera: 'Pix4D Camera', XmpNamespaces.cc: 'Creative Commons', XmpNamespaces.crd: 'Camera Raw Defaults',