mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
HEIC support
This commit is contained in:
parent
b4a667e0ee
commit
400abd33e4
6 changed files with 53 additions and 40 deletions
|
@ -7,4 +7,5 @@ const _supportedFormatMimes = [
|
|||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/webp",
|
||||
"image/heic",
|
||||
];
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'dart:async';
|
|||
import 'package:exifdart/exifdart_io.dart';
|
||||
import 'package:exifdart/exifdart_memory.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:image_size_getter/image_size_getter.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api.dart';
|
||||
|
@ -42,17 +41,10 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
response: response,
|
||||
message: "Failed communicating with server: ${response.statusCode}");
|
||||
}
|
||||
final resolution =
|
||||
await AsyncImageSizeGetter.getSize(AsyncMemoryInput(response.body));
|
||||
final exif = await readExifFromBytes(response.body);
|
||||
return {
|
||||
if (exif != null) "exif": exif,
|
||||
if (resolution.width > 0 && resolution.height > 0)
|
||||
"resolution": {
|
||||
"width": resolution.width,
|
||||
"height": resolution.height,
|
||||
},
|
||||
};
|
||||
return itf.MetadataLoader.loadMetadata(
|
||||
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
||||
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -72,18 +64,11 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
_getFileTask.cancel();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> _onGetFile(FileInfo f) async {
|
||||
final resolution =
|
||||
await AsyncImageSizeGetter.getSize(AsyncFileInput(f.file));
|
||||
final exif = await readExifFromFile(f.file);
|
||||
return {
|
||||
if (exif != null) "exif": exif,
|
||||
if (resolution.width > 0 && resolution.height > 0)
|
||||
"resolution": {
|
||||
"width": resolution.width,
|
||||
"height": resolution.height,
|
||||
},
|
||||
};
|
||||
Future<Map<String, dynamic>> _onGetFile(FileInfo f) {
|
||||
return itf.MetadataLoader.loadMetadata(
|
||||
exifdartReaderBuilder: () => FileReader(f.file),
|
||||
imageSizeGetterInputBuilder: () => AsyncFileInput(f.file),
|
||||
);
|
||||
}
|
||||
|
||||
final _getFileTask = CancelableGetFile(DefaultCacheManager().store);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import 'package:exifdart/exifdart.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:image_size_getter/image_size_getter.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
|
||||
|
@ -18,4 +21,36 @@ abstract class MetadataLoader {
|
|||
Future<Map<String, dynamic>> loadFile(Account account, File file);
|
||||
|
||||
void cancel();
|
||||
|
||||
@protected
|
||||
static Future<Map<String, dynamic>> loadMetadata({
|
||||
AbstractBlobReader Function() exifdartReaderBuilder,
|
||||
AsyncImageInput Function() imageSizeGetterInputBuilder,
|
||||
}) async {
|
||||
final metadata = await readMetadata(exifdartReaderBuilder());
|
||||
int imageWidth, imageHeight;
|
||||
if (metadata.imageWidth == null || metadata.imageHeight == null) {
|
||||
final resolution =
|
||||
await AsyncImageSizeGetter.getSize(imageSizeGetterInputBuilder());
|
||||
imageWidth = resolution.width;
|
||||
imageHeight = resolution.height;
|
||||
} else {
|
||||
if (metadata.rotateAngleCcw != null &&
|
||||
metadata.rotateAngleCcw % 180 != 0) {
|
||||
imageWidth = metadata.imageHeight;
|
||||
imageHeight = metadata.imageWidth;
|
||||
} else {
|
||||
imageWidth = metadata.imageWidth;
|
||||
imageHeight = metadata.imageHeight;
|
||||
}
|
||||
}
|
||||
return {
|
||||
if (metadata.exif != null) "exif": metadata.exif,
|
||||
if (imageWidth > 0 && imageHeight > 0)
|
||||
"resolution": {
|
||||
"width": imageWidth,
|
||||
"height": imageHeight,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:exifdart/exifdart_memory.dart';
|
||||
import 'package:image_size_getter/image_size_getter.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api.dart';
|
||||
|
@ -27,17 +26,10 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
response: response,
|
||||
message: "Failed communicating with server: ${response.statusCode}");
|
||||
}
|
||||
final resolution =
|
||||
await AsyncImageSizeGetter.getSize(AsyncMemoryInput(response.body));
|
||||
final exif = await readExifFromBytes(response.body);
|
||||
return {
|
||||
if (exif != null) "exif": exif,
|
||||
if (resolution.width > 0 && resolution.height > 0)
|
||||
"resolution": {
|
||||
"width": resolution.width,
|
||||
"height": resolution.height,
|
||||
},
|
||||
};
|
||||
return itf.MetadataLoader.loadMetadata(
|
||||
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
||||
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -110,11 +110,11 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "1.0.0"
|
||||
resolved-ref: "6d52c90f5e48dd1a2eeefb04b43d90b993387568"
|
||||
ref: "1.1.0"
|
||||
resolved-ref: "3b5712b23252e695c4767eb1be044af18668570d"
|
||||
url: "https://gitlab.com/nkming2/exifdart.git"
|
||||
source: git
|
||||
version: "1.0.0"
|
||||
version: "1.1.0"
|
||||
ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -36,7 +36,7 @@ dependencies:
|
|||
exifdart:
|
||||
git:
|
||||
url: https://gitlab.com/nkming2/exifdart.git
|
||||
ref: 1.0.0
|
||||
ref: 1.1.0
|
||||
flutter_bloc: ^7.0.0
|
||||
flutter_staggered_grid_view: ^0.3.3
|
||||
google_maps_flutter: ^2.0.3
|
||||
|
|
Loading…
Reference in a new issue