π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Convert heic to jpg for ML on Android
laurenspriem87a17c003442
diff --git a/mobile/lib/utils/image_ml_util.dart b/mobile/lib/utils/image_ml_util.dartindex 04a5f3ab53..843f535343 100644--- a/mobile/lib/utils/image_ml_util.dart+++ b/mobile/lib/utils/image_ml_util.dart@@ -1,11 +1,12 @@import "dart:async";import "dart:developer" show log;-import "dart:io" show File;+import "dart:io" show File, Platform;import "dart:math" show max, min;import "dart:typed_data" show Float32List, Uint8List, ByteData;import "dart:ui";import 'package:flutter/painting.dart' as paint show decodeImageFromList;+import "package:heif_converter/heif_converter.dart";import "package:logging/logging.dart";import 'package:ml_linalg/linalg.dart';import "package:photos/models/ml/face/box.dart";@@ -27,12 +28,27 @@ Future<(Image, ByteData)> decodeImageFromPath(String imagePath) async {final ByteData imageByteData = await getByteDataFromImage(image);return (image, imageByteData);} catch (e, s) {- _logger.severe(- 'Error decoding image of format ${imagePath.split('.').last}:',- e,- s,- );- throw Exception('InvalidImageFormatException: Error decoding image');+ final format = imagePath.split('.').last;+ if ((format == 'heic' || format == 'heif') && Platform.isAndroid) {+ _logger.info('Cannot decode $format, converting to JPG format');+ final String? jpgPath =+ await HeifConverter.convert(imagePath, format: 'jpg');+ if (jpgPath == null) {+ _logger.severe('Error converting $format to jpg:', e, s);+ throw Exception('InvalidImageFormatException: Error decoding image');+ }+ final imageData = await File(jpgPath).readAsBytes();+ final image = await decodeImageFromData(imageData);+ final ByteData imageByteData = await getByteDataFromImage(image);+ return (image, imageByteData);+ } else {+ _logger.severe(+ 'Error decoding image of format ${imagePath.split('.').last}:',+ e,+ s,+ );+ throw Exception('InvalidImageFormatException: Error decoding image');+ }}}diff --git a/mobile/pubspec.lock b/mobile/pubspec.lockindex 73db1a24fa..cb234fe33a 100644--- a/mobile/pubspec.lock+++ b/mobile/pubspec.lock@@ -1024,6 +1024,14 @@ packages:url: "https://pub.dev"source: hostedversion: "2.3.1"+ heif_converter:+ dependency: "direct main"+ description:+ name: heif_converter+ sha256: "63ffc2a72026942de3fcb61450da197100759936085c8279aef35b995b3c1bb3"+ url: "https://pub.dev"+ source: hosted+ version: "1.0.0"hex:dependency: transitivedescription:diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yamlindex f48b17f250..d2a96cd883 100644--- a/mobile/pubspec.yaml+++ b/mobile/pubspec.yaml@@ -94,6 +94,7 @@ dependencies:fraction: ^5.0.2freezed_annotation: ^2.4.1google_nav_bar: ^5.0.5+ heif_converter: ^1.0.0home_widget: ^0.6.0html_unescape: ^2.0.0http: ^1.1.0