π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Improve face widget image optimization API
ashilkn377c7e0000c5
diff --git a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dartindex f6615f2f60..08f3dfa460 100644--- a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart+++ b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart@@ -98,7 +98,7 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {@overrideWidget build(BuildContext context) {final double size = getAvatarSize(widget.type);- final int pixelSize =+ final int cachedPixelWidth =(size * MediaQuery.devicePixelRatioOf(context)).toInt();return _personID != null? Container(@@ -129,7 +129,7 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {? PersonFaceWidget(key: ValueKey('$personID-$lastSyncTimeForKey'),personId: personID,- size: pixelSize,+ cachedPixelWidth: cachedPixelWidth,onErrorCallback: () {if (mounted) {setState(() {diff --git a/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dartindex 95f3a97e97..84d8c489e8 100644--- a/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart@@ -23,9 +23,15 @@ class FileFaceWidget extends StatefulWidget {final bool useFullFile;final bool thumbnailFallback;- /// Target display size in physical pixels (logical size Γ devicePixelRatio).- /// When provided, the image will be decoded at this size to reduce memory usage.- final int? size;+ /// Physical pixel width for image decoding optimization.+ ///+ /// When provided and > 0, the image will be decoded at this width, with height+ /// computed to preserve aspect ratio. This reduces memory usage for small displays.+ ///+ /// Typically calculated as: `(logicalWidth * MediaQuery.devicePixelRatioOf(context)).toInt()`+ ///+ /// If null or <= 0, the image is decoded at full resolution.+ final int? cachedPixelWidth;const FileFaceWidget(this.file, {@@ -34,7 +40,7 @@ class FileFaceWidget extends StatefulWidget {this.clusterID,this.useFullFile = true,this.thumbnailFallback = false,- this.size,+ this.cachedPixelWidth,super.key,});@@ -68,10 +74,15 @@ class _FileFaceWidgetState extends State<FileFaceWidget> {future: faceCropFuture,builder: (context, snapshot) {if (snapshot.hasData) {- final ImageProvider imageProvider = widget.size != null+ // Only cacheWidth (not cacheHeight) to preserve aspect ratio.+ // Face crops are typically portrait, so constraining width ensures+ // sufficient height for BoxFit.cover without upscaling.+ final shouldOptimize =+ widget.cachedPixelWidth != null && widget.cachedPixelWidth! > 0;+ final ImageProvider imageProvider = shouldOptimize? Image.memory(snapshot.data!,- cacheWidth: widget.size,+ cacheWidth: widget.cachedPixelWidth,).image: MemoryImage(snapshot.data!);return Stack(diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dartindex b02abc22b9..e339213cb7 100644--- a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart@@ -24,9 +24,15 @@ class PersonFaceWidget extends StatefulWidget {final VoidCallback? onErrorCallback;final bool keepAlive;- /// Target display size in physical pixels (logical size Γ devicePixelRatio).- /// When provided, the image will be decoded at this size to reduce memory usage.- final int? size;+ /// Physical pixel width for image decoding optimization.+ ///+ /// When provided and > 0, the image will be decoded at this width, with height+ /// computed to preserve aspect ratio. This reduces memory usage for small displays.+ ///+ /// Typically calculated as: `(logicalWidth * MediaQuery.devicePixelRatioOf(context)).toInt()`+ ///+ /// If null or <= 0, the image is decoded at full resolution.+ final int? cachedPixelWidth;// PersonFaceWidget constructor checks that both personId and clusterID are not null// and that the file is not null@@ -36,7 +42,7 @@ class PersonFaceWidget extends StatefulWidget {this.useFullFile = true,this.onErrorCallback,this.keepAlive = false,- this.size,+ this.cachedPixelWidth,super.key,}) : assert(personId != null || clusterID != null,@@ -96,10 +102,12 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget>// Only cacheWidth (not cacheHeight) to preserve aspect ratio.// Face crops are typically portrait, so constraining width ensures// sufficient height for BoxFit.cover without upscaling.- final ImageProvider imageProvider = widget.size != null+ final shouldOptimize =+ widget.cachedPixelWidth != null && widget.cachedPixelWidth! > 0;+ final ImageProvider imageProvider = shouldOptimize? Image.memory(snapshot.data!,- cacheWidth: widget.size,+ cacheWidth: widget.cachedPixelWidth,).image: MemoryImage(snapshot.data!);return Stack(