mirror of
https://github.com/immich-app/immich.git
synced 2025-06-23 15:30:51 -04:00
fix orientation for remote assets
This commit is contained in:
parent
4dbe2cc662
commit
ba499d9f54
@ -22,12 +22,8 @@ class Asset {
|
||||
durationInSeconds = remote.duration.toDuration()?.inSeconds ?? 0,
|
||||
type = remote.type.toAssetType(),
|
||||
fileName = remote.originalFileName,
|
||||
height = isFlipped(remote)
|
||||
? remote.exifInfo?.exifImageWidth?.toInt()
|
||||
: remote.exifInfo?.exifImageHeight?.toInt(),
|
||||
width = isFlipped(remote)
|
||||
? remote.exifInfo?.exifImageHeight?.toInt()
|
||||
: remote.exifInfo?.exifImageWidth?.toInt(),
|
||||
height = remote.exifInfo?.exifImageHeight?.toInt(),
|
||||
width = remote.exifInfo?.exifImageWidth?.toInt(),
|
||||
livePhotoVideoId = remote.livePhotoVideoId,
|
||||
ownerId = fastHash(remote.ownerId),
|
||||
exifInfo =
|
||||
@ -192,6 +188,14 @@ class Asset {
|
||||
@ignore
|
||||
set byteHash(List<int> hash) => checksum = base64.encode(hash);
|
||||
|
||||
@ignore
|
||||
int? get orientatedWidth =>
|
||||
exifInfo != null && exifInfo!.isFlipped ? height : width;
|
||||
|
||||
@ignore
|
||||
int? get orientatedHeight =>
|
||||
exifInfo != null && exifInfo!.isFlipped ? width : height;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
if (other is! Asset) return false;
|
||||
@ -511,21 +515,3 @@ extension AssetsHelper on IsarCollection<Asset> {
|
||||
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 =
|
||||
int.tryParse(response.exifInfo?.orientation ?? '0') ?? 0;
|
||||
return orientation != 0 &&
|
||||
(isRotated90CW(orientation) || isRotated270CW(orientation));
|
||||
}
|
||||
|
@ -47,7 +47,10 @@ class ExifInfo {
|
||||
String get focalLength => mm != null ? mm!.toStringAsFixed(1) : "";
|
||||
|
||||
@ignore
|
||||
bool get isFlipped => _isOrientationFlipped(orientation);
|
||||
bool? _isFlipped;
|
||||
|
||||
@ignore
|
||||
bool get isFlipped => _isFlipped ??= _isOrientationFlipped(orientation);
|
||||
|
||||
@ignore
|
||||
double? get latitude => lat;
|
||||
|
@ -13,6 +13,7 @@ import 'package:immich_mobile/services/asset.service.dart';
|
||||
import 'package:immich_mobile/widgets/asset_viewer/custom_video_player_controls.dart';
|
||||
import 'package:immich_mobile/widgets/common/delayed_loading_indicator.dart';
|
||||
import 'package:native_video_player/native_video_player.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
class NativeVideoViewerPage extends HookConsumerWidget {
|
||||
@ -63,7 +64,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||
|
||||
Future<VideoSource> createSource(Asset asset) async {
|
||||
if (asset.isLocal && asset.livePhotoVideoId == null) {
|
||||
final entity = await asset.local!.obtainForNewProperties();
|
||||
final entity = await AssetEntity.fromId(asset.localId!);
|
||||
final file = await entity?.file;
|
||||
if (entity == null || file == null) {
|
||||
throw Exception('No file found for the video');
|
||||
@ -79,13 +80,10 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||
} else {
|
||||
final assetWithExif =
|
||||
await ref.read(assetServiceProvider).loadExif(asset);
|
||||
final shouldFlip = assetWithExif.exifInfo?.isFlipped ?? false;
|
||||
width.value = (shouldFlip ? assetWithExif.height : assetWithExif.width)
|
||||
?.toDouble() ??
|
||||
width.value;
|
||||
height.value = (shouldFlip ? assetWithExif.width : assetWithExif.height)
|
||||
?.toDouble() ??
|
||||
height.value;
|
||||
|
||||
width.value = assetWithExif.orientatedWidth?.toDouble() ?? width.value;
|
||||
height.value =
|
||||
assetWithExif.orientatedHeight?.toDouble() ?? height.value;
|
||||
|
||||
// Use a network URL for the video player controller
|
||||
final serverEndpoint = Store.get(StoreKey.serverEndpoint);
|
||||
@ -132,7 +130,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||
}
|
||||
});
|
||||
|
||||
// When the custom video controls paus or plays
|
||||
// // When the custom video controls pause or play
|
||||
ref.listen(videoPlayerControlsProvider.select((value) => value.pause),
|
||||
(_, pause) {
|
||||
try {
|
||||
|
@ -15,8 +15,9 @@ class FileInfo extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final textColor = context.isDarkTheme ? Colors.white : Colors.black;
|
||||
|
||||
String resolution = asset.width != null && asset.height != null
|
||||
? "${asset.height} x ${asset.width} "
|
||||
String resolution =
|
||||
asset.orientatedHeight != null && asset.orientatedWidth != null
|
||||
? "${asset.orientatedHeight} x ${asset.orientatedWidth} "
|
||||
: "";
|
||||
String fileSize = asset.exifInfo?.fileSize != null
|
||||
? formatBytes(asset.exifInfo!.fileSize!)
|
||||
|
Loading…
x
Reference in New Issue
Block a user