From 35bb2e786f8fa23f58c2bbeaacedaa91c8a44c25 Mon Sep 17 00:00:00 2001 From: "Hannes R. Brunsch" <51321855+Yagnap@users.noreply.github.com> Date: Thu, 3 Oct 2024 03:02:38 +0000 Subject: [PATCH] fix(mobile): respect orientation on displaying asset dimensions (#13129) * fix(mobile): respect orientation on displaying asset dimensions * lint --------- Co-authored-by: Alex --- mobile/lib/entities/asset.entity.dart | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/mobile/lib/entities/asset.entity.dart b/mobile/lib/entities/asset.entity.dart index df902ca995e9b..8e2d9c84d5d1e 100644 --- a/mobile/lib/entities/asset.entity.dart +++ b/mobile/lib/entities/asset.entity.dart @@ -22,8 +22,12 @@ class Asset { durationInSeconds = remote.duration.toDuration()?.inSeconds ?? 0, type = remote.type.toAssetType(), fileName = remote.originalFileName, - height = remote.exifInfo?.exifImageHeight?.toInt(), - width = remote.exifInfo?.exifImageWidth?.toInt(), + height = isFlipped(remote) + ? remote.exifInfo?.exifImageWidth?.toInt() + : remote.exifInfo?.exifImageHeight?.toInt(), + width = isFlipped(remote) + ? remote.exifInfo?.exifImageHeight?.toInt() + : remote.exifInfo?.exifImageWidth?.toInt(), livePhotoVideoId = remote.livePhotoVideoId, ownerId = fastHash(remote.ownerId), exifInfo = @@ -507,3 +511,20 @@ extension AssetsHelper on IsarCollection { return where().anyOf(ids, (q, String e) => q.localIdEqualTo(e)); } } + +/// Returns `true` if this [int] is flipped 90° clockwise +bool isRotated90CW(int orientation) { + return [7, 8, -90].contains(orientation); +} + +/// Returns `true` if this [int] is flipped 270° clockwise +bool isRotated270CW(int orientation) { + return [5, 6, 90].contains(orientation); +} + +/// Returns `true` if this [Asset] is flipped 90° or 270° clockwise +bool isFlipped(AssetResponseDto response) { + final int orientation = response.exifInfo?.orientation?.toInt() ?? 0; + return orientation != 0 && + (isRotated90CW(orientation) || isRotated270CW(orientation)); +}