[mob][photos] Move code
This commit is contained in:
parent
29b9bee1be
commit
8d4f9fe966
1 changed files with 55 additions and 55 deletions
|
@ -35,61 +35,6 @@ class PersonFaceWidget extends StatelessWidget {
|
|||
),
|
||||
super(key: key);
|
||||
|
||||
static Future<void> precomputeNextFaceCrops(file, clusterID) async {
|
||||
try {
|
||||
final Face? face = await FaceMLDataDB.instance.getCoverFaceForPerson(
|
||||
recentFileID: file.uploadedFileID!,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
if (face == null) {
|
||||
debugPrint(
|
||||
"No cover face for cluster $clusterID and recentFile ${file.uploadedFileID}",
|
||||
);
|
||||
return;
|
||||
}
|
||||
final Uint8List? cachedFace = faceCropCache.get(face.faceID);
|
||||
if (cachedFace != null) {
|
||||
return;
|
||||
}
|
||||
final faceCropCacheFile = cachedFaceCropPath(face.faceID);
|
||||
if ((await faceCropCacheFile.exists())) {
|
||||
final data = await faceCropCacheFile.readAsBytes();
|
||||
faceCropCache.put(face.faceID, data);
|
||||
return;
|
||||
}
|
||||
EnteFile? fileForFaceCrop = file;
|
||||
if (face.fileID != file.uploadedFileID!) {
|
||||
fileForFaceCrop =
|
||||
await FilesDB.instance.getAnyUploadedFile(face.fileID);
|
||||
}
|
||||
if (fileForFaceCrop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await pool.withResource(
|
||||
() async => await getFaceCrops(
|
||||
fileForFaceCrop!,
|
||||
{
|
||||
face.faceID: face.detection.box,
|
||||
},
|
||||
),
|
||||
);
|
||||
final Uint8List? computedCrop = result?[face.faceID];
|
||||
if (computedCrop != null) {
|
||||
faceCropCache.put(face.faceID, computedCrop);
|
||||
faceCropCacheFile.writeAsBytes(computedCrop).ignore();
|
||||
}
|
||||
return;
|
||||
} catch (e, s) {
|
||||
log(
|
||||
"Error getting cover face for cluster $clusterID",
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (useGeneratedFaceCrops) {
|
||||
|
@ -222,4 +167,59 @@ class PersonFaceWidget extends StatelessWidget {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> precomputeNextFaceCrops(file, clusterID) async {
|
||||
try {
|
||||
final Face? face = await FaceMLDataDB.instance.getCoverFaceForPerson(
|
||||
recentFileID: file.uploadedFileID!,
|
||||
clusterID: clusterID,
|
||||
);
|
||||
if (face == null) {
|
||||
debugPrint(
|
||||
"No cover face for cluster $clusterID and recentFile ${file.uploadedFileID}",
|
||||
);
|
||||
return;
|
||||
}
|
||||
final Uint8List? cachedFace = faceCropCache.get(face.faceID);
|
||||
if (cachedFace != null) {
|
||||
return;
|
||||
}
|
||||
final faceCropCacheFile = cachedFaceCropPath(face.faceID);
|
||||
if ((await faceCropCacheFile.exists())) {
|
||||
final data = await faceCropCacheFile.readAsBytes();
|
||||
faceCropCache.put(face.faceID, data);
|
||||
return;
|
||||
}
|
||||
EnteFile? fileForFaceCrop = file;
|
||||
if (face.fileID != file.uploadedFileID!) {
|
||||
fileForFaceCrop =
|
||||
await FilesDB.instance.getAnyUploadedFile(face.fileID);
|
||||
}
|
||||
if (fileForFaceCrop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await pool.withResource(
|
||||
() async => await getFaceCrops(
|
||||
fileForFaceCrop!,
|
||||
{
|
||||
face.faceID: face.detection.box,
|
||||
},
|
||||
),
|
||||
);
|
||||
final Uint8List? computedCrop = result?[face.faceID];
|
||||
if (computedCrop != null) {
|
||||
faceCropCache.put(face.faceID, computedCrop);
|
||||
faceCropCacheFile.writeAsBytes(computedCrop).ignore();
|
||||
}
|
||||
return;
|
||||
} catch (e, s) {
|
||||
log(
|
||||
"Error getting cover face for cluster $clusterID",
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue