mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +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/jpeg",
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/webp",
|
"image/webp",
|
||||||
|
"image/heic",
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,7 +3,6 @@ import 'dart:async';
|
||||||
import 'package:exifdart/exifdart_io.dart';
|
import 'package:exifdart/exifdart_io.dart';
|
||||||
import 'package:exifdart/exifdart_memory.dart';
|
import 'package:exifdart/exifdart_memory.dart';
|
||||||
import 'package:flutter_cache_manager/flutter_cache_manager.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:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/api/api.dart';
|
import 'package:nc_photos/api/api.dart';
|
||||||
|
@ -42,17 +41,10 @@ class MetadataLoader implements itf.MetadataLoader {
|
||||||
response: response,
|
response: response,
|
||||||
message: "Failed communicating with server: ${response.statusCode}");
|
message: "Failed communicating with server: ${response.statusCode}");
|
||||||
}
|
}
|
||||||
final resolution =
|
return itf.MetadataLoader.loadMetadata(
|
||||||
await AsyncImageSizeGetter.getSize(AsyncMemoryInput(response.body));
|
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
||||||
final exif = await readExifFromBytes(response.body);
|
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
||||||
return {
|
);
|
||||||
if (exif != null) "exif": exif,
|
|
||||||
if (resolution.width > 0 && resolution.height > 0)
|
|
||||||
"resolution": {
|
|
||||||
"width": resolution.width,
|
|
||||||
"height": resolution.height,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -72,18 +64,11 @@ class MetadataLoader implements itf.MetadataLoader {
|
||||||
_getFileTask.cancel();
|
_getFileTask.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> _onGetFile(FileInfo f) async {
|
Future<Map<String, dynamic>> _onGetFile(FileInfo f) {
|
||||||
final resolution =
|
return itf.MetadataLoader.loadMetadata(
|
||||||
await AsyncImageSizeGetter.getSize(AsyncFileInput(f.file));
|
exifdartReaderBuilder: () => FileReader(f.file),
|
||||||
final exif = await readExifFromFile(f.file);
|
imageSizeGetterInputBuilder: () => AsyncFileInput(f.file),
|
||||||
return {
|
);
|
||||||
if (exif != null) "exif": exif,
|
|
||||||
if (resolution.width > 0 && resolution.height > 0)
|
|
||||||
"resolution": {
|
|
||||||
"width": resolution.width,
|
|
||||||
"height": resolution.height,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final _getFileTask = CancelableGetFile(DefaultCacheManager().store);
|
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/account.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
|
|
||||||
|
@ -18,4 +21,36 @@ abstract class MetadataLoader {
|
||||||
Future<Map<String, dynamic>> loadFile(Account account, File file);
|
Future<Map<String, dynamic>> loadFile(Account account, File file);
|
||||||
|
|
||||||
void cancel();
|
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 'dart:io';
|
||||||
|
|
||||||
import 'package:exifdart/exifdart_memory.dart';
|
import 'package:exifdart/exifdart_memory.dart';
|
||||||
import 'package:image_size_getter/image_size_getter.dart';
|
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/api/api.dart';
|
import 'package:nc_photos/api/api.dart';
|
||||||
|
@ -27,17 +26,10 @@ class MetadataLoader implements itf.MetadataLoader {
|
||||||
response: response,
|
response: response,
|
||||||
message: "Failed communicating with server: ${response.statusCode}");
|
message: "Failed communicating with server: ${response.statusCode}");
|
||||||
}
|
}
|
||||||
final resolution =
|
return itf.MetadataLoader.loadMetadata(
|
||||||
await AsyncImageSizeGetter.getSize(AsyncMemoryInput(response.body));
|
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
||||||
final exif = await readExifFromBytes(response.body);
|
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
||||||
return {
|
);
|
||||||
if (exif != null) "exif": exif,
|
|
||||||
if (resolution.width > 0 && resolution.height > 0)
|
|
||||||
"resolution": {
|
|
||||||
"width": resolution.width,
|
|
||||||
"height": resolution.height,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -110,11 +110,11 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "1.0.0"
|
ref: "1.1.0"
|
||||||
resolved-ref: "6d52c90f5e48dd1a2eeefb04b43d90b993387568"
|
resolved-ref: "3b5712b23252e695c4767eb1be044af18668570d"
|
||||||
url: "https://gitlab.com/nkming2/exifdart.git"
|
url: "https://gitlab.com/nkming2/exifdart.git"
|
||||||
source: git
|
source: git
|
||||||
version: "1.0.0"
|
version: "1.1.0"
|
||||||
ffi:
|
ffi:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -36,7 +36,7 @@ dependencies:
|
||||||
exifdart:
|
exifdart:
|
||||||
git:
|
git:
|
||||||
url: https://gitlab.com/nkming2/exifdart.git
|
url: https://gitlab.com/nkming2/exifdart.git
|
||||||
ref: 1.0.0
|
ref: 1.1.0
|
||||||
flutter_bloc: ^7.0.0
|
flutter_bloc: ^7.0.0
|
||||||
flutter_staggered_grid_view: ^0.3.3
|
flutter_staggered_grid_view: ^0.3.3
|
||||||
google_maps_flutter: ^2.0.3
|
google_maps_flutter: ^2.0.3
|
||||||
|
|
Loading…
Reference in a new issue