fix(editor): decode camera raws to PNG so previews and thumbs render
CI / build (push) Has been cancelled
CI / build (push) Has been cancelled
ImageMagick 7 in the app image refuses to write TIFF from its LibRaw coder
("no encode delegate for this image format `NEF'"), so every RAW thumbnail,
preview and bridge proxy returned 415. The editor showed "The preview could
not be prepared" and the advanced editor had no editable proxy to open.
PNG is decoded reliably by the same build and read back by sharp.
This commit is contained in:
+10
-8
@@ -2,9 +2,11 @@
|
|||||||
* Full-resolution photo rendering.
|
* Full-resolution photo rendering.
|
||||||
*
|
*
|
||||||
* JPEG/PNG/WebP/TIFF/HEIC originals go through sharp. Camera RAW files are
|
* JPEG/PNG/WebP/TIFF/HEIC originals go through sharp. Camera RAW files are
|
||||||
* decoded by ImageMagick's LibRaw delegate into a temporary TIFF, then sharp
|
* decoded by ImageMagick's LibRaw delegate into a temporary PNG, then sharp
|
||||||
* applies the same tone/colour recipe as the browser preview, crops and encodes
|
* applies the same tone/colour recipe as the browser preview, crops and encodes
|
||||||
* the final JPEG. The original is read-only throughout.
|
* the final JPEG. PNG is used rather than TIFF because ImageMagick 7 refuses
|
||||||
|
* to write TIFF from its RAW coder ("no encode delegate for this image format
|
||||||
|
* `NEF'"). The original is read-only throughout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
@@ -28,12 +30,12 @@ export class PhotoRenderError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rawToTiff(
|
async function rawToPng(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
maxDimension?: number,
|
maxDimension?: number,
|
||||||
): Promise<{ path: string; cleanup: () => Promise<void> }> {
|
): Promise<{ path: string; cleanup: () => Promise<void> }> {
|
||||||
const directory = await mkdtemp(path.join(tmpdir(), "glenloch-raw-"));
|
const directory = await mkdtemp(path.join(tmpdir(), "glenloch-raw-"));
|
||||||
const output = path.join(directory, "decoded.tiff");
|
const output = path.join(directory, "decoded.png");
|
||||||
const args = [
|
const args = [
|
||||||
"-limit",
|
"-limit",
|
||||||
"memory",
|
"memory",
|
||||||
@@ -51,13 +53,13 @@ async function rawToTiff(
|
|||||||
"-depth",
|
"-depth",
|
||||||
"8",
|
"8",
|
||||||
"-strip",
|
"-strip",
|
||||||
"-compress",
|
"-define",
|
||||||
"Zip",
|
"png:compression-level=1",
|
||||||
];
|
];
|
||||||
if (maxDimension) {
|
if (maxDimension) {
|
||||||
args.push("-resize", `${maxDimension}x${maxDimension}>`);
|
args.push("-resize", `${maxDimension}x${maxDimension}>`);
|
||||||
}
|
}
|
||||||
args.push(`tiff:${output}`);
|
args.push(`png:${output}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await execFileAsync("convert", args, {
|
await execFileAsync("convert", args, {
|
||||||
@@ -118,7 +120,7 @@ export async function renderPhotoJpeg(input: {
|
|||||||
let cleanup: (() => Promise<void>) | undefined;
|
let cleanup: (() => Promise<void>) | undefined;
|
||||||
|
|
||||||
if (input.kind === "raw") {
|
if (input.kind === "raw") {
|
||||||
const decoded = await rawToTiff(input.filePath, input.maxDimension);
|
const decoded = await rawToPng(input.filePath, input.maxDimension);
|
||||||
decodedPath = decoded.path;
|
decodedPath = decoded.path;
|
||||||
cleanup = decoded.cleanup;
|
cleanup = decoded.cleanup;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user