π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(photos):limit-new-raw-formats-to-selected-five
Aswin Asok3fde3c16fc7a
diff --git a/desktop/changes/raw-format-support.md b/desktop/changes/raw-format-support.mdindex 44b2f7bfd5..106c8eb22b 100644--- a/desktop/changes/raw-format-support.md+++ b/desktop/changes/raw-format-support.md@@ -1 +1 @@-- Improved support for additional camera RAW formats when uploading and viewing photos.+- Improved desktop previews for RAF, ORF, PEF, NRW, and SRW camera RAW photos.diff --git a/web/apps/photos/tests/raw-formats.test.ts b/web/apps/photos/tests/raw-formats.test.tsindex 4bebd6c874..41e89d0fd7 100644--- a/web/apps/photos/tests/raw-formats.test.ts+++ b/web/apps/photos/tests/raw-formats.test.ts@@ -9,11 +9,8 @@ vi.mock("ente-base/log", () => ({}));vi.mock("ente-media/heic-convert", () => ({ heicToJPEG: vi.fn() }));-// The public extension contract of the bundled libvips 8.18.7 RAW loader.-const rawExtensions = (- "3fr ari arw cap cin cr2 cr3 crw dcr dng erf fff iiq k25 kdc mdc " +- "mos mrw nef nrw orf ori pef pxn raf raw rw2 rwl sr2 srf srw x3f"-).split(" ");+// Keep this change scoped to the five selected camera RAW formats.+const rawExtensions = ["raf", "orf", "pef", "nrw", "srw"];// Intentionally unrecognized bytes exercise the filename fallback, not decoding.const unknownBytes = new Uint8Array([0, 1, 2, 3]);@@ -98,7 +95,7 @@ describe("camera RAW format support", () => {test("preserves content detection for a JPEG with a RAW filename", async () => {const file = new File([new Uint8Array([0xff, 0xd8, 0xff, 0xe0])],- "photo.RAW",+ "photo.PEF",);expect(await detectFileTypeInfo(file)).toEqual({fileType: FileType.image,@@ -114,24 +111,26 @@ describe("camera RAW format support", () => {});test("keeps original bytes when the platform decoder does not support a RAW file", async () => {- const file = new File([unknownBytes], "photo.x3f");+ const file = new File([unknownBytes], "photo.pef");const error = new Error("Camera is not supported by the native decoder",);const convertToJPEG = vi.fn().mockRejectedValue(error);const onConvertToJPEGError = vi.fn();- expect(- await renderableImageBlobWeb(file, file.name, {- convertToJPEG,- onConvertToJPEGError,- }),- ).toBe(file);+ const result = await renderableImageBlobWeb(file, file.name, {+ convertToJPEG,+ onConvertToJPEGError,+ });+ expect(await result.arrayBuffer()).toEqual(await file.arrayBuffer());+ expect(result.type).toBe("image/x-pentax-pef");expect(onConvertToJPEGError).toHaveBeenCalledExactlyOnceWith(error);});test("leaves RAW bytes unchanged when no native converter is available", async () => {- const file = new File([unknownBytes], "photo.x3f");- expect(await renderableImageBlobWeb(file, file.name)).toBe(file);+ const file = new File([unknownBytes], "photo.pef");+ const result = await renderableImageBlobWeb(file, file.name);+ expect(await result.arrayBuffer()).toEqual(await file.arrayBuffer());+ expect(result.type).toBe("image/x-pentax-pef");});test.each([@@ -149,6 +148,32 @@ describe("camera RAW format support", () => {},);+ test.each(["arw", "cr2", "cr3", "dng", "nef", "rw2"])(+ "retains existing .%s conversion eligibility",+ (extension) => {+ expect(needsJPEGConversion(extension)).toBe(true);+ },+ );++ test("keeps CRW upload recognition without adding its preview conversion", async () => {+ expect(needsJPEGConversion("crw")).toBe(false);+ expect(+ await detectFileTypeInfo(new File([unknownBytes], "photo.crw")),+ ).toMatchObject({ fileType: FileType.image, extension: "crw" });+ });++ test.each(["x3f", "3fr", "raw"])(+ "does not add fallback recognition or conversion for .%s",+ async (extension) => {+ expect(needsJPEGConversion(extension)).toBe(false);+ await expect(+ detectFileTypeInfo(+ new File([unknownBytes], `photo.${extension}`),+ ),+ ).rejects.toThrow();+ },+ );+test("still rejects files without a recognized media type or extension", async () => {await expect(detectFileTypeInfo(new File([unknownBytes], "notes.txt")),diff --git a/web/packages/media/file-type.ts b/web/packages/media/file-type.tsindex a86dab8f43..313a78a43c 100644--- a/web/packages/media/file-type.ts+++ b/web/packages/media/file-type.ts@@ -1,5 +1,3 @@-import { cameraRawExtensions } from "./formats";-export const FileType = { image: 0, video: 1, livePhoto: 2 } as const;export type FileType = (typeof FileType)[keyof typeof FileType];@@ -10,14 +8,6 @@ export interface FileTypeInfo {mimeType?: string;}-// Retain the MIME types used by the existing RAW fallbacks. Other RAW formats-// can be accepted and sent to the native decoder using only their extension.-const cameraRawMIMETypes: Partial<Record<string, string>> = {- crw: "image/x-canon-crw",- orf: "image/x-olympus-orf",- raf: "image/x-fuji-raf",-};-// These are formats that automatic file type detection misses for some files// found in the wild.export const KnownFileTypeInfos: FileTypeInfo[] = [@@ -30,12 +20,37 @@ export const KnownFileTypeInfos: FileTypeInfo[] = [{ fileType: FileType.video, extension: "dv", mimeType: "video/x-dv" },{ fileType: FileType.video, extension: "wmv", mimeType: "video/x-ms-asf" },{ fileType: FileType.video, extension: "hevc", mimeType: "video/hevc" },- { fileType: FileType.video, extension: "mov", mimeType: "video/quicktime" },- ...cameraRawExtensions.map((extension) => ({+ {+ fileType: FileType.image,+ extension: "raf",+ mimeType: "image/x-fuji-raf",+ },+ {+ fileType: FileType.image,+ extension: "orf",+ mimeType: "image/x-olympus-orf",+ },+ {fileType: FileType.image,- extension,- mimeType: cameraRawMIMETypes[extension],- })),+ extension: "crw",+ mimeType: "image/x-canon-crw",+ },+ {+ fileType: FileType.image,+ extension: "nrw",+ mimeType: "image/x-nikon-nrw",+ },+ {+ fileType: FileType.image,+ extension: "pef",+ mimeType: "image/x-pentax-pef",+ },+ {+ fileType: FileType.image,+ extension: "srw",+ mimeType: "image/x-samsung-srw",+ },+ { fileType: FileType.video, extension: "mov", mimeType: "video/quicktime" },];export const KnownNonMediaFileExtensions = ["xmp", "html", "txt"];diff --git a/web/packages/media/formats.ts b/web/packages/media/formats.tsindex 9d054ce034..4633adfe10 100644--- a/web/packages/media/formats.ts+++ b/web/packages/media/formats.ts@@ -1,48 +1,21 @@-// Camera RAW suffixes recognized by the libvips 8.18.7 dcraw loader bundled on-// Windows and Linux. macOS conversion uses sips and depends on OS/camera support.-// https://github.com/libvips/libvips/blob/v8.18.7/libvips/foreign/dcrawload.c-export const cameraRawExtensions = [- "3fr",- "ari",+// Image extensions that browsers are unlikely to render, for which the desktop+// app should attempt native JPEG conversion. RAW support depends on the+// platform decoder and camera model.+const needsJPEGConversionExtensions = ["arw",- "cap",- "cin","cr2","cr3",- "crw",- "dcr","dng",- "erf",- "fff",- "iiq",- "k25",- "kdc",- "mdc",- "mos",- "mrw",+ "heic",+ "jp2","nef","nrw","orf",- "ori","pef",- "pxn",+ "psd","raf",- "raw","rw2",- "rwl",- "sr2",- "srf","srw",- "x3f",-];--// Formats that need a native conversion attempt before the browser can render-// them. The platform decoder may not support every camera or RAW variant.-const needsJPEGConversionExtensions = [- ...cameraRawExtensions,- "heic",- "jp2",- "psd","tif","tiff",];