This commit is contained in:
Manav Rathi 2024-05-18 15:56:45 +05:30
parent bef7574c29
commit 433d0e81fc
No known key found for this signature in database
2 changed files with 7 additions and 24 deletions

View file

@ -23,7 +23,6 @@ import {
createGrayscaleIntMatrixFromNormalized2List,
fetchImageBitmap,
getLocalFileImageBitmap,
getThumbnailImageBitmap,
pixelRGBBilinear,
warpAffineFloat32List,
} from "./image";
@ -72,29 +71,21 @@ export const indexFaces = async (
};
const fetchImageBitmapForContext = async (fileContext: MLSyncFileContext) => {
if (fileContext.imageBitmap) {
return fileContext.imageBitmap;
}
if (fileContext.imageBitmap) return fileContext.imageBitmap;
const fileType = fileContext.enteFile.metadata.fileType;
if (fileContext.localFile) {
if (fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE) {
if (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,
)
) {
} else if ([FILE_TYPE.IMAGE, FILE_TYPE.LIVE_PHOTO].includes(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,
);
throw new Error(`Cannot index unsupported file type ${fileType}`);
}
const { width, height } = fileContext.imageBitmap;

View file

@ -1,6 +1,5 @@
import { FILE_TYPE } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
import log from "@/next/log";
import { Matrix, inverse } from "ml-matrix";
import DownloadManager from "services/download";
import { FaceAlignment } from "services/face/types";
@ -36,13 +35,6 @@ async function fetchRenderableBlob(file: EnteFile) {
}
}
export async function getThumbnailImageBitmap(file: EnteFile) {
const thumb = await DownloadManager.getThumbnail(file);
log.info("[MLService] Got thumbnail: ", file.id.toString());
return createImageBitmap(new Blob([thumb]));
}
export async function getLocalFileImageBitmap(
enteFile: EnteFile,
localFile: globalThis.File,