Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] move and rename getExif2, fix exif copying and silently ignore failures of reading exif from original files

Priyanshu Dangare12b062b54cc7
diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
index 84b287f3a9..63bb73276d 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
@@ -35,7 +35,7 @@ import "package:photos/ui/tools/editor/image_editor/image_editor_text_bar.dart";
import "package:photos/ui/tools/editor/image_editor/image_editor_tune_bar.dart";
import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/utils/dialog_util.dart";
-import "package:photos/utils/exif_util.dart";
+import 'package:photos/utils/file_util.dart';
import 'package:pro_image_editor/pro_image_editor.dart';
class ImageEditorPage extends StatefulWidget {
@@ -82,16 +82,18 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
format: CompressFormat.jpeg,
);
if (flagService.internalUser) {
- final originalImageExif = await getExif2(widget.originalFile);
+ final originalImageExif = await _readOriginalImageExif(
+ widget.originalFile,
+ );
final image = img.decodeJpg(result);
if (image == null) {
throw Exception("Failed to decode image");
}
- image.exif = originalImageExif;
+ if (originalImageExif != null) {
+ image.exif = originalImageExif;
+ }
for (final key in [
"Orientation",
- "ColorSpace",
- "Gamma",
"WhitePoint",
"PrimaryChromaticities",
"PhotometricInterpretation",
@@ -100,9 +102,6 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
"Compression",
"ImageWidth",
"ImageHeight",
- "ExifImageWidth",
- "ExifImageHeight",
- "ComponentsConfiguration",
"YCbCrPositioning",
"YCbCrSubSampling",
"YCbCrCoefficients",
@@ -110,8 +109,21 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
"XResolution",
"YResolution",
"ResolutionUnit",
+ ]) {
+ image.exif.imageIfd[key] = null;
+ }
+ for (final key in [
"JPEGInterchangeFormat",
"JPEGInterchangeFormatLength",
+ ]) {
+ image.exif.thumbnailIfd[key] = null;
+ }
+ for (final key in [
+ "ColorSpace",
+ "Gamma",
+ "ExifImageWidth",
+ "ExifImageHeight",
+ "ComponentsConfiguration",
"CustomRendered",
"SceneCaptureType",
"WhiteBalance",
@@ -200,6 +212,25 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
}
}
+ Future<img.ExifData?> _readOriginalImageExif(ente.EnteFile enteFile) async {
+ final file = await getFile(enteFile, isOrigin: true);
+ if (file == null) {
+ return null;
+ }
+ try {
+ final bytes = await file.readAsBytes();
+ final image = img.decodeImage(bytes);
+ if (image == null) {
+ return null;
+ }
+ return image.exif;
+ } finally {
+ if (!enteFile.isRemoteFile && Platform.isIOS) {
+ await file.delete();
+ }
+ }
+ }
+
Future<void> _showExitConfirmationDialog(BuildContext context) async {
final actionResult = await showActionSheet(
context: context,
diff --git a/mobile/apps/photos/lib/utils/exif_util.dart b/mobile/apps/photos/lib/utils/exif_util.dart
index bf78e9ddf5..3ca0955ccd 100644
--- a/mobile/apps/photos/lib/utils/exif_util.dart
+++ b/mobile/apps/photos/lib/utils/exif_util.dart
@@ -3,7 +3,6 @@ import "dart:io";
import "package:computer/computer.dart";
import 'package:exif_reader/exif_reader.dart';
-import "package:image/image.dart" as img;
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import "package:photos/models/ffmpeg/ffprobe_props.dart";
@@ -40,19 +39,6 @@ bool shouldReadExif(EnteFile file) {
return file.fileType == FileType.image || file.fileType == FileType.livePhoto;
}
-Future<img.ExifData> getExif2(EnteFile enteFile) async {
- final file = await getFile(enteFile, isOrigin: true);
- if (file == null) {
- throw Exception("Failed to fetch origin file");
- }
- final bytes = await file.readAsBytes();
- final image = img.decodeImage(bytes);
- if (image == null) {
- throw Exception("Failed to decode image");
- }
- return image.exif;
-}
-
Future<Map<String, IfdTag>> getExif(EnteFile file) async {
try {
if (!shouldReadExif(file)) {