Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Remove old face crop widget

laurenspriem160f2794644d
diff --git a/mobile/lib/ui/viewer/file_details/face_widget.dart b/mobile/lib/ui/viewer/file_details/face_widget.dart
index 48e9a43bb1..9c0d7decdb 100644
--- a/mobile/lib/ui/viewer/file_details/face_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/face_widget.dart
@@ -15,13 +15,9 @@ import "package:photos/services/search_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";
import "package:photos/ui/viewer/people/cluster_page.dart";
-import "package:photos/ui/viewer/people/cropped_face_image_view.dart";
import "package:photos/ui/viewer/people/people_page.dart";
import "package:photos/utils/face/face_box_crop.dart";
import "package:photos/utils/thumbnail_util.dart";
-// import "package:photos/utils/toast_util.dart";
-
-const useGeneratedFaceCrops = true;
class FaceWidget extends StatefulWidget {
final EnteFile file;
@@ -53,11 +49,7 @@ class _FaceWidgetState extends State<FaceWidget> {
@override
Widget build(BuildContext context) {
final bool givenFaces = widget.faceCrops != null;
- if (useGeneratedFaceCrops) {
- return _buildFaceImageGenerated(givenFaces);
- } else {
- return _buildFaceImageFlutterZoom();
- }
+ return _buildFaceImageGenerated(givenFaces);
}
Widget _buildFaceImageGenerated(bool givenFaces) {
@@ -333,178 +325,4 @@ class _FaceWidgetState extends State<FaceWidget> {
return null;
}
}
-
- Widget _buildFaceImageFlutterZoom() {
- return Builder(
- builder: (context) {
- return GestureDetector(
- onTap: () async {
- log(
- "FaceWidget is tapped, with person ${widget.person} and clusterID ${widget.clusterID}",
- name: "FaceWidget",
- );
- if (widget.person == null && widget.clusterID == null) {
- // Get faceID and double check that it doesn't belong to an existing clusterID. If it does, push that cluster page
- final w = (kDebugMode ? EnteWatch('FaceWidget') : null)?..start();
- final existingClusterID = await FaceMLDataDB.instance
- .getClusterIDForFaceID(widget.face.faceID);
- w?.log('getting existing clusterID for faceID');
- if (existingClusterID != null) {
- final fileIdsToClusterIds =
- await FaceMLDataDB.instance.getFileIdToClusterIds();
- final files = await SearchService.instance.getAllFiles();
- final clusterFiles = files
- .where(
- (file) =>
- fileIdsToClusterIds[file.uploadedFileID]
- ?.contains(existingClusterID) ??
- false,
- )
- .toList();
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => ClusterPage(
- clusterFiles,
- clusterID: existingClusterID,
- ),
- ),
- );
- }
-
- // Create new clusterID for the faceID and update DB to assign the faceID to the new clusterID
- final int newClusterID = DateTime.now().microsecondsSinceEpoch;
- await FaceMLDataDB.instance.updateFaceIdToClusterId(
- {widget.face.faceID: newClusterID},
- );
-
- // Push page for the new cluster
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => ClusterPage(
- [widget.file],
- clusterID: newClusterID,
- ),
- ),
- );
- }
- if (widget.person != null) {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => PeoplePage(
- person: widget.person!,
- ),
- ),
- );
- } else if (widget.clusterID != null) {
- final fileIdsToClusterIds =
- await FaceMLDataDB.instance.getFileIdToClusterIds();
- final files = await SearchService.instance.getAllFiles();
- final clusterFiles = files
- .where(
- (file) =>
- fileIdsToClusterIds[file.uploadedFileID]
- ?.contains(widget.clusterID) ??
- false,
- )
- .toList();
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => ClusterPage(
- clusterFiles,
- clusterID: widget.clusterID!,
- ),
- ),
- );
- }
- },
- child: Column(
- children: [
- Stack(
- children: [
- Container(
- height: 60,
- width: 60,
- decoration: ShapeDecoration(
- shape: RoundedRectangleBorder(
- borderRadius: const BorderRadius.all(
- Radius.elliptical(16, 12),
- ),
- side: widget.highlight
- ? BorderSide(
- color: getEnteColorScheme(context).primary700,
- width: 1.0,
- )
- : BorderSide.none,
- ),
- ),
- child: ClipRRect(
- borderRadius:
- const BorderRadius.all(Radius.elliptical(16, 12)),
- child: SizedBox(
- width: 60,
- height: 60,
- child: CroppedFaceImageView(
- enteFile: widget.file,
- face: widget.face,
- ),
- ),
- ),
- ),
- if (widget.editMode)
- Positioned(
- right: 0,
- top: 0,
- child: GestureDetector(
- onTap: _cornerIconPressed,
- child: isJustRemoved
- ? const Icon(
- CupertinoIcons.add_circled_solid,
- color: Colors.green,
- )
- : const Icon(
- Icons.cancel,
- color: Colors.red,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- if (widget.person != null)
- Text(
- widget.person!.data.name.trim(),
- style: Theme.of(context).textTheme.bodySmall,
- overflow: TextOverflow.ellipsis,
- maxLines: 1,
- ),
- if (kDebugMode)
- Text(
- 'S: ${widget.face.score.toStringAsFixed(3)}',
- style: Theme.of(context).textTheme.bodySmall,
- maxLines: 1,
- ),
- if (kDebugMode)
- Text(
- 'B: ${widget.face.blur.toStringAsFixed(0)}',
- style: Theme.of(context).textTheme.bodySmall,
- maxLines: 1,
- ),
- if (kDebugMode)
- Text(
- 'D: ${widget.face.detection.getFaceDirection().toDirectionString()}',
- style: Theme.of(context).textTheme.bodySmall,
- maxLines: 1,
- ),
- if (kDebugMode)
- Text(
- 'Sideways: ${widget.face.detection.faceIsSideways().toString()}',
- style: Theme.of(context).textTheme.bodySmall,
- maxLines: 1,
- ),
- ],
- ),
- );
- },
- );
- }
}
diff --git a/mobile/lib/ui/viewer/people/cropped_face_image_view.dart b/mobile/lib/ui/viewer/people/cropped_face_image_view.dart
deleted file mode 100644
index a76dbe5f0a..0000000000
--- a/mobile/lib/ui/viewer/people/cropped_face_image_view.dart
+++ /dev/null
@@ -1,121 +0,0 @@
-import 'dart:developer' show log;
-import "dart:io" show File;
-
-import 'package:flutter/material.dart';
-import "package:photos/face/model/face.dart";
-import "package:photos/models/file/file.dart";
-import "package:photos/models/file/file_type.dart";
-import "package:photos/ui/viewer/file/thumbnail_widget.dart";
-import "package:photos/utils/file_util.dart";
-import "package:photos/utils/thumbnail_util.dart";
-
-class CroppedFaceInfo {
- final Image image;
- final double scale;
- final double offsetX;
- final double offsetY;
-
- const CroppedFaceInfo({
- required this.image,
- required this.scale,
- required this.offsetX,
- required this.offsetY,
- });
-}
-
-class CroppedFaceImageView extends StatelessWidget {
- final EnteFile enteFile;
- final Face face;
-
- const CroppedFaceImageView({
- Key? key,
- required this.enteFile,
- required this.face,
- }) : super(key: key);
-
- @override
- Widget build(BuildContext context) {
- return FutureBuilder(
- future: getImage(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return LayoutBuilder(
- builder: ((context, constraints) {
- final double imageAspectRatio = enteFile.width / enteFile.height;
- final Image image = snapshot.data!;
-
- final double viewWidth = constraints.maxWidth;
- final double viewHeight = constraints.maxHeight;
-
- final faceBox = face.detection.box;
-
- final double relativeFaceCenterX = faceBox.x + faceBox.width / 2;
- final double relativeFaceCenterY = faceBox.y + faceBox.height / 2;
-
- const double desiredFaceHeightRelativeToWidget = 8 / 10;
- final double scale =
- (1 / faceBox.height) * desiredFaceHeightRelativeToWidget;
-
- final double widgetCenterX = viewWidth / 2;
- final double widgetCenterY = viewHeight / 2;
-
- final double widgetAspectRatio = viewWidth / viewHeight;
- final double imageToWidgetRatio =
- imageAspectRatio / widgetAspectRatio;
-
- double offsetX =
- (widgetCenterX - relativeFaceCenterX * viewWidth) * scale;
- double offsetY =
- (widgetCenterY - relativeFaceCenterY * viewHeight) * scale;
-
- if (imageAspectRatio < widgetAspectRatio) {
- // Landscape Image: Adjust offsetX more conservatively
- offsetX = offsetX * imageToWidgetRatio;
- } else {
- // Portrait Image: Adjust offsetY more conservatively
- offsetY = offsetY / imageToWidgetRatio;
- }
- return ClipRRect(
- borderRadius: const BorderRadius.all(Radius.elliptical(16, 12)),
- child: Transform.translate(
- offset: Offset(
- offsetX,
- offsetY,
- ),
- child: Transform.scale(
- scale: scale,
- child: image,
- ),
- ),
- );
- }),
- );
- } else {
- if (snapshot.hasError) {
- log('Error getting cover face for person: ${snapshot.error}');
- }
- return ThumbnailWidget(
- enteFile,
- );
- }
- },
- );
- }
-
- Future<Image?> getImage() async {
- final File? ioFile;
- if (enteFile.fileType == FileType.video) {
- ioFile = await getThumbnailForUploadedFile(enteFile);
- } else {
- ioFile = await getFile(enteFile);
- }
- if (ioFile == null) {
- return null;
- }
-
- final imageData = await ioFile.readAsBytes();
- final image = Image.memory(imageData, fit: BoxFit.contain);
-
- return image;
- }
-}
diff --git a/mobile/lib/ui/viewer/search/result/person_face_widget.dart b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
index 57fe5af654..c63a8cd890 100644
--- a/mobile/lib/ui/viewer/search/result/person_face_widget.dart
+++ b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
@@ -1,5 +1,4 @@
import "dart:developer";
-// import "dart:io";
import "dart:typed_data";
import 'package:flutter/widgets.dart';
@@ -11,8 +10,6 @@ import 'package:photos/models/file/file.dart';
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
-import "package:photos/ui/viewer/file_details/face_widget.dart";
-import "package:photos/ui/viewer/people/cropped_face_image_view.dart";
import "package:photos/utils/face/face_box_crop.dart";
import "package:photos/utils/thumbnail_util.dart";
import "package:pool/pool.dart";
@@ -54,54 +51,30 @@ class PersonFaceWidget extends StatelessWidget {
],
);
}
- if (useGeneratedFaceCrops) {
- return FutureBuilder<Uint8List?>(
- future: getFaceCrop(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- final ImageProvider imageProvider = MemoryImage(snapshot.data!);
- return Stack(
- fit: StackFit.expand,
- children: [
- Image(
- image: imageProvider,
- fit: BoxFit.cover,
- ),
- ],
- );
- } else {
- if (snapshot.hasError) {
- log('Error getting cover face for person: ${snapshot.error}');
- }
- return thumbnailFallback
- ? ThumbnailWidget(file)
- : const EnteLoadingWidget();
- }
- },
- );
- } else {
- return FutureBuilder<Face?>(
- future: _getFace(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- final Face face = snapshot.data!;
- return Stack(
- fit: StackFit.expand,
- children: [
- CroppedFaceImageView(enteFile: file, face: face),
- ],
- );
- } else {
- if (snapshot.hasError) {
- log('Error getting cover face for person: ${snapshot.error}');
- }
- return thumbnailFallback
- ? ThumbnailWidget(file)
- : const EnteLoadingWidget();
+ return FutureBuilder<Uint8List?>(
+ future: getFaceCrop(),
+ builder: (context, snapshot) {
+ if (snapshot.hasData) {
+ final ImageProvider imageProvider = MemoryImage(snapshot.data!);
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ Image(
+ image: imageProvider,
+ fit: BoxFit.cover,
+ ),
+ ],
+ );
+ } else {
+ if (snapshot.hasError) {
+ log('Error getting cover face for person: ${snapshot.error}');
}
- },
- );
- }
+ return thumbnailFallback
+ ? ThumbnailWidget(file)
+ : const EnteLoadingWidget();
+ }
+ },
+ );
}
Future<Face?> _getFace() async {
@@ -188,7 +161,7 @@ class PersonFaceWidget extends StatelessWidget {
stackTrace: s,
);
resetPool(fullFile: useFullFile);
- if(fetchAttempt <= retryLimit) {
+ if (fetchAttempt <= retryLimit) {
return getFaceCrop(fetchAttempt: fetchAttempt + 1);
}
return null;