Skip to content

armgit / ente

Public Imported from GitHub
0

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

Site of use

Manav Rathifb81a59d4bdd
diff --git a/web/apps/photos/src/services/face/f-index.ts b/web/apps/photos/src/services/face/f-index.ts
index 047a406937..90d9af1487 100644
--- a/web/apps/photos/src/services/face/f-index.ts
+++ b/web/apps/photos/src/services/face/f-index.ts
@@ -21,14 +21,17 @@ import {
clamp,
createGrayscaleIntMatrixFromNormalized2List,
cropWithRotation,
- fetchImageBitmapForContext,
+ fetchImageBitmap,
getFaceId,
+ getLocalFileImageBitmap,
getPixelBilinear,
+ getThumbnailImageBitmap,
imageBitmapToBlob,
normalizePixelBetween0And1,
warpAffineFloat32List,
} from "./image";
import { transformFaceDetections } from "./transform-box";
+import { FILE_TYPE } from "@/media/file-type";
/**
* Index faces in the given file.
@@ -70,6 +73,38 @@ export const indexFaces = async (
return newMlFile;
};
+const fetchImageBitmapForContext = async (fileContext: MLSyncFileContext) => {
+ if (fileContext.imageBitmap) {
+ return fileContext.imageBitmap;
+ }
+ if (fileContext.localFile) {
+ if (fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE) {
+ throw new Error("Local file of only image type is supported");
+ }
+ fileContext.imageBitmap = await getLocalFileImageBitmap(
+ fileContext.enteFile,
+ fileContext.localFile,
+ );
+ } else if (
+ [FILE_TYPE.IMAGE, FILE_TYPE.LIVE_PHOTO].includes(
+ fileContext.enteFile.metadata.fileType,
+ )
+ ) {
+ fileContext.imageBitmap = await fetchImageBitmap(fileContext.enteFile);
+ } else {
+ // TODO-ML(MR): We don't do it on videos, when will we ever come
+ // here?
+ fileContext.imageBitmap = await getThumbnailImageBitmap(
+ fileContext.enteFile,
+ );
+ }
+
+ const { width, height } = fileContext.imageBitmap;
+ fileContext.newMlFile.imageDimensions = { width, height };
+
+ return fileContext.imageBitmap;
+};
+
const syncFileAnalyzeFaces = async (fileContext: MLSyncFileContext) => {
const { newMlFile } = fileContext;
const startTime = Date.now();
diff --git a/web/apps/photos/src/services/face/image.ts b/web/apps/photos/src/services/face/image.ts
index bf77f27154..c4bee3aba0 100644
--- a/web/apps/photos/src/services/face/image.ts
+++ b/web/apps/photos/src/services/face/image.ts
@@ -4,49 +4,11 @@ import log from "@/next/log";
import { Matrix, inverse } from "ml-matrix";
import DownloadManager from "services/download";
import { Box, Dimensions, enlargeBox } from "services/face/geom";
-import {
- DetectedFace,
- FaceAlignment,
- MLSyncFileContext,
-} from "services/face/types";
+import { DetectedFace, FaceAlignment } from "services/face/types";
import { getLocalFiles } from "services/fileService";
import { EnteFile } from "types/file";
import { getRenderableImage } from "utils/file";
-export const fetchImageBitmapForContext = async (
- fileContext: MLSyncFileContext,
-) => {
- if (fileContext.imageBitmap) {
- return fileContext.imageBitmap;
- }
- if (fileContext.localFile) {
- if (fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE) {
- throw new Error("Local file of only image type is supported");
- }
- fileContext.imageBitmap = await getLocalFileImageBitmap(
- fileContext.enteFile,
- fileContext.localFile,
- );
- } else if (
- [FILE_TYPE.IMAGE, FILE_TYPE.LIVE_PHOTO].includes(
- fileContext.enteFile.metadata.fileType,
- )
- ) {
- fileContext.imageBitmap = await fetchImageBitmap(fileContext.enteFile);
- } else {
- // TODO-ML(MR): We don't do it on videos, when will we ever come
- // here?
- fileContext.imageBitmap = await getThumbnailImageBitmap(
- fileContext.enteFile,
- );
- }
-
- const { width, height } = fileContext.imageBitmap;
- fileContext.newMlFile.imageDimensions = { width, height };
-
- return fileContext.imageBitmap;
-};
-
export async function getLocalFile(fileId: number) {
const localFiles = await getLocalFiles();
return localFiles.find((f) => f.id === fileId);