7aef2e37bf
The Develop preview can put the untouched source left of a drag line and the edited frame right of it. Both halves come from one render on one view, so they line up exactly, and the split shares its handle behaviour with the lens correction split. The headless render check now asserts that each half shows its own edit.
781 lines
30 KiB
JavaScript
781 lines
30 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Headless render check for the 16-bit proxy swap.
|
|
*
|
|
* The editor shows the JPEG proxy first and swaps in the 16-bit sidecar a few
|
|
* seconds later. Both uploads go through `Renderer.setImage`, and whether they
|
|
* agree depends on a WebGL detail that no unit test can cover: `UNPACK_FLIP_Y_WEBGL`
|
|
* is ignored for `ImageBitmap` sources (the proxy) but honoured for typed arrays
|
|
* (the sidecar). If the two disagree, the picture jumps upside down at the swap.
|
|
*
|
|
* This script builds a two-tone 16-bit PNG with the server's own encoder plus the
|
|
* matching JPEG, serves `parsePreview16` through Vite, and measures the rows that
|
|
* actually reach the GPU in headless Chrome. It fails if the top row of the proxy
|
|
* is not the top row of the sidecar.
|
|
*
|
|
* Runs outside `npm test` because it needs a WebGL2-capable Chrome:
|
|
* npm run check:render
|
|
*/
|
|
import { spawn } from 'node:child_process';
|
|
import { existsSync } from 'node:fs';
|
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import sharp from 'sharp';
|
|
import { createServer } from 'vite';
|
|
import { encodePng16 } from '../server/imaging.mjs';
|
|
|
|
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const DIR = path.join(ROOT, '.render-check');
|
|
const PAGE = path.join(DIR, 'index.html');
|
|
const W = 96;
|
|
const H = 64;
|
|
|
|
const CHROME_CANDIDATES = [
|
|
process.env.CHROME_PATH,
|
|
'google-chrome',
|
|
'google-chrome-stable',
|
|
'chromium',
|
|
'chromium-browser',
|
|
].filter(Boolean);
|
|
|
|
async function findChrome() {
|
|
for (const candidate of CHROME_CANDIDATES) {
|
|
if (candidate.includes(path.sep)) {
|
|
if (existsSync(candidate)) return candidate;
|
|
continue;
|
|
}
|
|
if (await spawnSyncOk(candidate)) return candidate;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function spawnSyncOk(bin) {
|
|
const probe = spawn(bin, ['--version'], { stdio: 'ignore' });
|
|
return new Promise((resolve) => {
|
|
probe.on('error', () => resolve(false));
|
|
probe.on('exit', (code) => resolve(code === 0));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Horizontal bands that exercise both ends of the range: one and two channels
|
|
* blown, one clean band, then one and two channels crushed, plus a green+blue
|
|
* crush to check the secondary colour. The same image proves the clipping
|
|
* overlay names the channels instead of painting every warning one colour.
|
|
*/
|
|
const BANDS = [
|
|
[1.0, 0.55, 0.08], // highlight: red only
|
|
[1.0, 1.0, 0.08], // highlight: red + green (yellow)
|
|
[0.24, 0.28, 0.35], // nothing clipped
|
|
[0.0, 0.3, 0.35], // shadow: red only
|
|
[0.0, 0.0, 0.35], // shadow: red + green (yellow)
|
|
[0.3, 0.0, 0.0], // shadow: green + blue (cyan)
|
|
];
|
|
|
|
function buildSource() {
|
|
const rgb16 = new Uint16Array(W * H * 3);
|
|
const rgb8 = new Uint8Array(W * H * 3);
|
|
const bands = BANDS;
|
|
for (let y = 0; y < H; y++) {
|
|
const band = bands[Math.min(bands.length - 1, Math.floor((y / H) * bands.length))];
|
|
for (let x = 0; x < W; x++) {
|
|
const i = (y * W + x) * 3;
|
|
for (let c = 0; c < 3; c++) {
|
|
rgb16[i + c] = Math.round(band[c] * 65535);
|
|
rgb8[i + c] = Math.round(band[c] * 255);
|
|
}
|
|
}
|
|
}
|
|
return { rgb8, rgb16 };
|
|
}
|
|
|
|
const PAGE_HTML = `<!doctype html>
|
|
<meta charset="utf-8" />
|
|
<pre id="out">boot</pre>
|
|
<script type="module">
|
|
import { parsePreview16 } from '/src/lib/preview16.ts';
|
|
import { Renderer } from '/src/gl/renderer.ts';
|
|
import { defaultEdits, defaultLocalComponent, defaultLocalLayer } from '/src/lib/edits.ts';
|
|
const pre = document.getElementById('out');
|
|
const half = (bits) => {
|
|
const s = bits >> 15 ? -1 : 1;
|
|
const e = (bits >> 10) & 0x1f;
|
|
const m = bits & 0x3ff;
|
|
if (e === 0) return s * m * Math.pow(2, -24);
|
|
if (e === 31) return m ? NaN : s * Infinity;
|
|
return s * (1 + m / 1024) * Math.pow(2, e - 15);
|
|
};
|
|
try {
|
|
const canvas = document.createElement('canvas');
|
|
const gl = canvas.getContext('webgl2', { alpha: false, antialias: false });
|
|
if (!gl) { pre.textContent = 'ERROR no WebGL2 in this Chrome'; throw new Error('no webgl2'); }
|
|
const makeTex = () => {
|
|
const t = gl.createTexture();
|
|
gl.bindTexture(gl.TEXTURE_2D, t);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
return t;
|
|
};
|
|
// readPixels rows start at the framebuffer's bottom row, which is texel row 0.
|
|
const rowLuma = (tex, y, w) => {
|
|
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
const fb = gl.createFramebuffer();
|
|
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
|
|
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
|
throw new Error('framebuffer incomplete');
|
|
}
|
|
const buf = new Uint8Array(w * 4);
|
|
gl.readPixels(0, y, w, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
gl.deleteFramebuffer(fb);
|
|
let sum = 0;
|
|
for (let i = 0; i < w; i++) {
|
|
sum += 0.2126 * buf[i * 4] + 0.7152 * buf[i * 4 + 1] + 0.0722 * buf[i * 4 + 2];
|
|
}
|
|
return sum / w / 255;
|
|
};
|
|
|
|
const blob = await (await fetch('/.render-check/proxy.jpg')).blob();
|
|
const bitmap = await createImageBitmap(blob, { imageOrientation: 'from-image' });
|
|
const w = bitmap.width;
|
|
const h = bitmap.height;
|
|
|
|
// Exactly what Renderer.setImage does for the JPEG proxy.
|
|
const texFlip = makeTex();
|
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
|
|
const texNoFlip = makeTex();
|
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
|
|
|
|
const png = await (await fetch('/.render-check/side.p16.png')).arrayBuffer();
|
|
const parsed = await parsePreview16(png);
|
|
if (!parsed) throw new Error('parsePreview16 returned null');
|
|
if (parsed.width !== w || parsed.height !== h) {
|
|
throw new Error('sidecar ' + parsed.width + 'x' + parsed.height + ' vs proxy ' + w + 'x' + h);
|
|
}
|
|
// Exactly what Renderer.setImage does for the sidecar: rows in parser order, unflipped.
|
|
const sideRow = (y) => {
|
|
const out = new Uint8Array(w * 4);
|
|
for (let x = 0; x < w; x++) {
|
|
const i = (y * w + x) * 4;
|
|
const toByte = (bits) => Math.round(Math.min(1, Math.max(0, half(bits))) * 255);
|
|
out[x * 4] = toByte(parsed.rgba[i]);
|
|
out[x * 4 + 1] = toByte(parsed.rgba[i + 1]);
|
|
out[x * 4 + 2] = toByte(parsed.rgba[i + 2]);
|
|
out[x * 4 + 3] = 255;
|
|
}
|
|
const tex = makeTex();
|
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, w, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, out);
|
|
return tex;
|
|
};
|
|
const sideTopTex = sideRow(0);
|
|
const sideBottomTex = sideRow(h - 1);
|
|
|
|
const proxyTop = rowLuma(texFlip, 0, w);
|
|
const proxyBottom = rowLuma(texFlip, h - 1, w);
|
|
const proxyNoFlipTop = rowLuma(texNoFlip, 0, w);
|
|
const sideTop = rowLuma(sideTopTex, 0, w);
|
|
const sideBottom = rowLuma(sideBottomTex, 0, w);
|
|
const same = (a, b) => Math.abs(a - b) < 0.02;
|
|
|
|
// Clipping overlay: red for one clipped channel, yellow for two. This renders
|
|
// through the real Renderer, so a shader that collapses the warning to white
|
|
// (or loses the shadow/highlight bit) fails here.
|
|
const view = document.createElement('canvas');
|
|
const renderer = new Renderer(view);
|
|
renderer.setImage(bitmap, parsed);
|
|
renderer.render(defaultEdits(), { width: w, height: h, clipPreview: true });
|
|
const viewGl = view.getContext('webgl2');
|
|
const sampleBand = (index) => {
|
|
// readPixels rows start at the bottom, so flip the band centre.
|
|
const py = h - 1 - Math.floor((h * (index + 0.5)) / ${BANDS.length});
|
|
const px = new Uint8Array(4);
|
|
viewGl.readPixels(Math.floor(w / 2), py, 1, 1, viewGl.RGBA, viewGl.UNSIGNED_BYTE, px);
|
|
return [px[0], px[1], px[2]];
|
|
};
|
|
const clipPixels = [0, 1, 2].map(sampleBand);
|
|
const near = (pixel, target) =>
|
|
Math.abs(pixel[0] - target[0]) < 14 &&
|
|
Math.abs(pixel[1] - target[1]) < 14 &&
|
|
Math.abs(pixel[2] - target[2]) < 14;
|
|
const RED_MARK = [255, 31, 31];
|
|
const YELLOW_MARK = [255, 230, 26];
|
|
// The preview has to follow the sliders it is shown for: +6 EV blows every
|
|
// channel of the unclipped band, so it must turn white, not stay clear.
|
|
const brightEdits = defaultEdits();
|
|
brightEdits.exposure = 6;
|
|
renderer.render(brightEdits, { width: w, height: h, clipPreview: true });
|
|
const brightPixel = sampleBand(2);
|
|
|
|
// Shadow clipping: same palette at the other end of the histogram.
|
|
renderer.render(defaultEdits(), { width: w, height: h, clipping: 'shadows' });
|
|
const shadowPixels = [2, 3, 4, 5].map(sampleBand);
|
|
|
|
// And it has to move with the sliders, not just exist: -9 EV drives every
|
|
// channel of the clean band to black, so that band must turn white in shadow
|
|
// mode, just as it turns white at +6 EV in highlight mode.
|
|
const shadowEdits = defaultEdits();
|
|
shadowEdits.exposure = -9;
|
|
renderer.render(shadowEdits, { width: w, height: h, clipping: 'shadows' });
|
|
const shadowDarkPixel = sampleBand(2);
|
|
|
|
// Per-mask curve: a radial covering the whole frame, first with an identity
|
|
// curve and then with one that halves the output. The mask must leave the
|
|
// frame alone with the identity curve and darken it with the real one.
|
|
const maskLayer = defaultLocalLayer('radial', 0);
|
|
const maskShape = maskLayer.components[0];
|
|
maskShape.feather = 0;
|
|
maskShape.radial = { cx: 0.5, cy: 0.5, rx: 1.2, ry: 1.2 };
|
|
const darkCurve = [
|
|
{ x: 0, y: 0 },
|
|
{ x: 1, y: 0.4 },
|
|
];
|
|
const maskedEdits = defaultEdits();
|
|
maskedEdits.local = [{ ...maskLayer, curve: [{ x: 0, y: 0 }, { x: 1, y: 1 }] }];
|
|
renderer.render(maskedEdits, { width: w, height: h });
|
|
const maskIdentityPixel = sampleBand(2);
|
|
maskedEdits.local = [{ ...maskLayer, curve: darkCurve }];
|
|
renderer.render(maskedEdits, { width: w, height: h });
|
|
const maskCurvePixel = sampleBand(2);
|
|
|
|
// Mask groups: a second shape has to composite into the layer's own mask.
|
|
// Subtracting a frame-wide shape from an equally wide add shape clears the
|
|
// group, so the darkened curve must stop touching the frame; intersecting
|
|
// with the same shape keeps full coverage, so it must still darken.
|
|
const groupShape = defaultLocalComponent('radial');
|
|
groupShape.feather = 0;
|
|
groupShape.radial = { cx: 0.5, cy: 0.5, rx: 1.2, ry: 1.2 };
|
|
const groupEdits = defaultEdits();
|
|
groupEdits.local = [
|
|
{
|
|
...maskLayer,
|
|
curve: darkCurve,
|
|
components: [maskShape, { ...groupShape, mode: 'subtract' }],
|
|
},
|
|
];
|
|
renderer.render(groupEdits, { width: w, height: h });
|
|
const maskGroupSubtractPixel = sampleBand(2);
|
|
groupEdits.local = [
|
|
{
|
|
...maskLayer,
|
|
curve: darkCurve,
|
|
components: [maskShape, { ...groupShape, mode: 'intersect' }],
|
|
},
|
|
];
|
|
renderer.render(groupEdits, { width: w, height: h });
|
|
const maskGroupIntersectPixel = sampleBand(2);
|
|
|
|
// Brush masks are source-space and feather softens the rim inside the brush
|
|
// circle. The dab below has a radius of 0.08 of the frame width, so it spans
|
|
// 0.12 of the frame height; nothing outside that may be touched, even at a
|
|
// high feather, and the rim itself must be a gradient rather than a step.
|
|
const pixelAt = (fx, fy) => {
|
|
const px = new Uint8Array(4);
|
|
const py = h - 1 - Math.min(h - 1, Math.floor(fy * h));
|
|
viewGl.readPixels(Math.min(w - 1, Math.floor(fx * w)), py, 1, 1, viewGl.RGBA, viewGl.UNSIGNED_BYTE, px);
|
|
return [px[0], px[1], px[2]];
|
|
};
|
|
const dabRadiusY = 0.08 * (w / h);
|
|
const brushEdits = (feather) => {
|
|
const layer = defaultLocalLayer('brush', 0);
|
|
const shape = layer.components[0];
|
|
shape.feather = feather;
|
|
shape.brush.strokes = [{ points: [{ x: 0.25, y: 0.2 }], size: 0.08, erase: false }];
|
|
return { ...defaultEdits(), local: [{ ...layer, curve: darkCurve }] };
|
|
};
|
|
renderer.render(brushEdits(0), { width: w, height: h });
|
|
const dabHard = pixelAt(0.25, 0.2);
|
|
const dabOutsideHard = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
|
|
renderer.render(brushEdits(80), { width: w, height: h });
|
|
const dabSoft = pixelAt(0.25, 0.2);
|
|
const dabRimSoft = pixelAt(0.25, 0.2 + dabRadiusY * 0.75);
|
|
const dabOutsideSoft = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
|
|
// The develop view tints the baked mask instead of redrawing the stroke, so
|
|
// the overlay has to follow the same coverage: strong in the core, a real
|
|
// gradient at the rim, and nothing at all outside the brush circle.
|
|
renderer.render(brushEdits(80), { width: w, height: h, maskView: 0 });
|
|
const tintCore = pixelAt(0.25, 0.2);
|
|
const tintRim = pixelAt(0.25, 0.2 + dabRadiusY * 0.75);
|
|
const tintOutside = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
|
|
|
|
// Source-space alignment. Masks are baked over the whole source, so a crop
|
|
// that keeps a dab in frame but moves it on screen must move its tint and
|
|
// its local detail with it: source (0.6, 0.4) inside a quarter-frame crop
|
|
// lands at screen (0.4, 0.6), and nothing may be tinted at (0.6, 0.4).
|
|
const cropRect = {
|
|
x: 0.5,
|
|
y: 0.25,
|
|
w: 0.25,
|
|
h: 0.25,
|
|
angle: 0,
|
|
quarter: 0,
|
|
aspect: 'original',
|
|
flipH: false,
|
|
flipV: false,
|
|
};
|
|
const dabEdits = (at, size, adjust) => {
|
|
const layer = defaultLocalLayer('brush', 0);
|
|
const shape = layer.components[0];
|
|
shape.feather = 0;
|
|
shape.brush.strokes = [{ points: [at], size, erase: false }];
|
|
return {
|
|
...defaultEdits(),
|
|
local: [{ ...layer, adjust: { ...layer.adjust, ...(adjust || {}) } }],
|
|
};
|
|
};
|
|
const cropped = { ...defaultEdits(), crop: cropRect };
|
|
renderer.render(cropped, { width: w, height: h });
|
|
const cropRef = pixelAt(0.4, 0.6);
|
|
const cropRefOff = pixelAt(0.6, 0.4);
|
|
const cropDab = dabEdits({ x: 0.6, y: 0.4 }, 0.02);
|
|
cropDab.crop = cropRect;
|
|
renderer.render(cropDab, { width: w, height: h, maskView: 0 });
|
|
const cropTintOn = pixelAt(0.4, 0.6);
|
|
const cropTintOff = pixelAt(0.6, 0.4);
|
|
// Same crop and dab, but as a local detail amount instead of a tint: the
|
|
// finish pass has to read the mask through the same source coordinate.
|
|
const cropDetail = dabEdits({ x: 0.6, y: 0.4 }, 0.02, { dehaze: 100 });
|
|
cropDetail.crop = cropRect;
|
|
renderer.render(cropDetail, { width: w, height: h });
|
|
const cropDetailOn = pixelAt(0.4, 0.6);
|
|
const cropDetailOff = pixelAt(0.6, 0.4);
|
|
|
|
// Tint strength and toggle: full strength must read stronger than the default
|
|
// half, and no maskView at all must leave the photo untouched.
|
|
renderer.render(brushEdits(80), { width: w, height: h, maskView: 0, maskStrength: 1 });
|
|
const tintFull = pixelAt(0.25, 0.2);
|
|
renderer.render(brushEdits(80), { width: w, height: h });
|
|
const tintOffPixel = pixelAt(0.25, 0.2);
|
|
|
|
// Lens warp: a geometry map that magnifies the centre by 1.6 puts the dab at
|
|
// source (0.7, 0.45) at screen (0.625, 0.469); its source uv must be clear.
|
|
const lensN = 33;
|
|
const lensData = new Float32Array(lensN * lensN * 4);
|
|
for (let ly = 0; ly < lensN; ly++) {
|
|
for (let lx = 0; lx < lensN; lx++) {
|
|
const i = (ly * lensN + lx) * 4;
|
|
lensData[i] = 0.5 + ((lx + 0.5) / lensN - 0.5) * 1.6;
|
|
lensData[i + 1] = 0.5 + ((ly + 0.5) / lensN - 0.5) * 1.6;
|
|
lensData[i + 2] = 0;
|
|
lensData[i + 3] = 1;
|
|
}
|
|
}
|
|
const lensWarp = {
|
|
key: 'render-check-warp',
|
|
scale: 1,
|
|
geometry: { data: lensData, width: lensN, height: lensN },
|
|
};
|
|
renderer.render(defaultEdits(), { width: w, height: h, lens: lensWarp });
|
|
const lensRef = pixelAt(0.625, 0.469);
|
|
const lensRefOff = pixelAt(0.7, 0.469);
|
|
const lensDab = dabEdits({ x: 0.7, y: 0.45 }, 0.04);
|
|
renderer.render(lensDab, { width: w, height: h, lens: lensWarp, maskView: 0 });
|
|
const lensTintOn = pixelAt(0.625, 0.469);
|
|
const lensTintOff = pixelAt(0.7, 0.469);
|
|
|
|
// Before / after split: the edit is drawn full-frame, then the untouched
|
|
// source is painted over the left slice. Reading the same band either side of
|
|
// the line must give the moved slider on the right and the default on the
|
|
// left, which is what proves the scissor lands where the drag line sits.
|
|
const splitAfter = defaultEdits();
|
|
splitAfter.exposure = 2;
|
|
renderer.render(splitAfter, { width: w, height: h });
|
|
const splitAfterFull = pixelAt(0.75, 0.5);
|
|
renderer.render(defaultEdits(), { width: w, height: h });
|
|
const splitBeforeFull = pixelAt(0.75, 0.5);
|
|
renderer.render(splitAfter, { width: w, height: h });
|
|
renderer.render(defaultEdits(), {
|
|
width: w,
|
|
height: h,
|
|
scissor: { x: 0, w: Math.round(w / 2) },
|
|
});
|
|
const splitLeft = pixelAt(0.25, 0.5);
|
|
const splitRight = pixelAt(0.75, 0.5);
|
|
const sameRgb = (a, b) => a.every((v, i) => Math.abs(v - b[i]) <= 1);
|
|
|
|
pre.textContent = 'RESULT ' + JSON.stringify({
|
|
clipPixels,
|
|
clipRed: near(clipPixels[0], RED_MARK),
|
|
clipYellow: near(clipPixels[1], YELLOW_MARK),
|
|
clipClear:
|
|
!near(clipPixels[2], RED_MARK) &&
|
|
!near(clipPixels[2], YELLOW_MARK) &&
|
|
!near(clipPixels[2], [255, 255, 255]),
|
|
clipFollowsExposure: near(brightPixel, [255, 255, 255]),
|
|
brightPixel,
|
|
shadowPixels,
|
|
shadowClear:
|
|
!near(shadowPixels[0], RED_MARK) && !near(shadowPixels[0], YELLOW_MARK),
|
|
shadowRed: near(shadowPixels[1], RED_MARK),
|
|
shadowYellow: near(shadowPixels[2], YELLOW_MARK),
|
|
shadowCyan: near(shadowPixels[3], [26, 217, 255]),
|
|
shadowFollowsExposure: near(shadowDarkPixel, [255, 255, 255]),
|
|
shadowDarkPixel,
|
|
maskIdentityPixel,
|
|
maskCurvePixel,
|
|
maskIdentityFlat: near(maskIdentityPixel, [61, 71, 89]),
|
|
maskCurveDarkens: maskCurvePixel[0] < maskIdentityPixel[0] * 0.75,
|
|
maskGroupSubtractPixel,
|
|
maskGroupSubtractCleared: near(maskGroupSubtractPixel, maskIdentityPixel),
|
|
maskGroupIntersectPixel,
|
|
maskGroupIntersectDarkens: maskGroupIntersectPixel[0] < maskIdentityPixel[0] * 0.75,
|
|
dabHard,
|
|
dabOutsideHard,
|
|
dabSoft,
|
|
dabRimSoft,
|
|
dabOutsideSoft,
|
|
tintCore,
|
|
tintRim,
|
|
tintOutside,
|
|
// Orange tint: blue is the channel the overlay pushes up, so it ranks the
|
|
// coverage without depending on how dark the adjustment left the pixels.
|
|
tintFollowsMask: tintCore[2] > tintRim[2] && tintRim[2] > tintOutside[2] + 5,
|
|
tintBounded: Math.abs(tintOutside[2] - dabOutsideSoft[2]) <= 1,
|
|
cropRef,
|
|
cropRefOff,
|
|
cropTintOn,
|
|
cropTintOff,
|
|
cropDetailOn,
|
|
cropDetailOff,
|
|
lensRef,
|
|
lensRefOff,
|
|
lensTintOn,
|
|
lensTintOff,
|
|
tintFull,
|
|
tintOffPixel,
|
|
// The tint pushes red up hard on the dark mid band, so red ranks coverage.
|
|
cropTintAligned: cropTintOn[0] > cropRef[0] + 40,
|
|
cropTintBounded: Math.abs(cropTintOff[0] - cropRefOff[0]) <= 2,
|
|
// Local dehaze lifts the blue of that band, so blue marks where it landed.
|
|
cropDetailAligned: cropDetailOn[2] > cropDetailOff[2] + 10,
|
|
cropDetailBounded: Math.abs(cropDetailOff[2] - cropRefOff[2]) <= 3,
|
|
lensTintAligned: lensTintOn[0] > lensRef[0] + 40,
|
|
lensTintBounded: Math.abs(lensTintOff[0] - lensRefOff[0]) <= 2,
|
|
splitLeft,
|
|
splitRight,
|
|
splitBeforeFull,
|
|
splitAfterFull,
|
|
splitShowsBoth:
|
|
sameRgb(splitLeft, splitBeforeFull) &&
|
|
sameRgb(splitRight, splitAfterFull) &&
|
|
!sameRgb(splitAfterFull, splitBeforeFull),
|
|
tintStrengthWorks: tintFull[2] > tintCore[2] + 8,
|
|
tintOffMatches: Math.abs(tintOffPixel[2] - dabSoft[2]) <= 1,
|
|
// A hard dab covers the core, and even an 80 % feather stops at the rim.
|
|
dabCoreDarkened: dabHard[0] < 140,
|
|
dabSoftCoreDarkened: dabSoft[0] < 140,
|
|
dabRimSmooth: dabRimSoft[0] > 140 && dabRimSoft[0] < 240,
|
|
dabBoundedHard: dabOutsideHard[0] > 240,
|
|
dabBoundedSoft: dabOutsideSoft[0] > 240,
|
|
flagHonouredForBitmap: !same(proxyTop, proxyNoFlipTop),
|
|
proxyTop: +proxyTop.toFixed(4),
|
|
sidecarTop: +sideTop.toFixed(4),
|
|
proxyBottom: +proxyBottom.toFixed(4),
|
|
sidecarBottom: +sideBottom.toFixed(4),
|
|
matchTop: same(proxyTop, sideTop),
|
|
matchBottom: same(proxyBottom, sideBottom),
|
|
reversed: same(proxyTop, sideBottom) && same(proxyBottom, sideTop),
|
|
});
|
|
} catch (err) {
|
|
if (!String(pre.textContent).startsWith('ERROR')) {
|
|
pre.textContent = 'ERROR ' + (err && err.message ? err.message : String(err));
|
|
}
|
|
}
|
|
</script>`;
|
|
|
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
async function drive(chromeBin, url) {
|
|
const port = 9333 + Math.floor(Math.random() * 200);
|
|
const child = spawn(
|
|
chromeBin,
|
|
[
|
|
'--headless=new',
|
|
'--no-sandbox',
|
|
'--disable-gpu-sandbox',
|
|
'--use-gl=angle',
|
|
'--use-angle=swiftshader',
|
|
'--enable-unsafe-swiftshader',
|
|
`--remote-debugging-port=${port}`,
|
|
`--user-data-dir=${path.join(DIR, 'profile')}`,
|
|
'about:blank',
|
|
],
|
|
{ stdio: 'ignore' },
|
|
);
|
|
|
|
try {
|
|
let target = null;
|
|
for (let i = 0; i < 120 && !target; i++) {
|
|
try {
|
|
const res = await fetch(`http://127.0.0.1:${port}/json/list`);
|
|
target = (await res.json()).find((t) => t.type === 'page') ?? null;
|
|
} catch {
|
|
/* devtools not up yet */
|
|
}
|
|
if (!target) await sleep(250);
|
|
}
|
|
if (!target) throw new Error('Chrome DevTools endpoint never came up');
|
|
|
|
const ws = new WebSocket(target.webSocketDebuggerUrl);
|
|
await new Promise((resolve, reject) => {
|
|
ws.onopen = resolve;
|
|
ws.onerror = () => reject(new Error('DevTools websocket failed'));
|
|
});
|
|
let nextId = 1;
|
|
const pending = new Map();
|
|
ws.onmessage = (event) => {
|
|
const message = JSON.parse(event.data);
|
|
if (message.id && pending.has(message.id)) {
|
|
pending.get(message.id)(message);
|
|
pending.delete(message.id);
|
|
}
|
|
};
|
|
const send = (method, params = {}) => {
|
|
const id = nextId++;
|
|
return new Promise((resolve) => {
|
|
pending.set(id, resolve);
|
|
ws.send(JSON.stringify({ id, method, params }));
|
|
});
|
|
};
|
|
|
|
await send('Page.enable');
|
|
await send('Runtime.enable');
|
|
await send('Page.navigate', { url });
|
|
|
|
let text = '';
|
|
const deadline = Date.now() + 90000;
|
|
while (Date.now() < deadline) {
|
|
const res = await send('Runtime.evaluate', {
|
|
expression: "document.getElementById('out')?.textContent ?? ''",
|
|
returnByValue: true,
|
|
});
|
|
text = res.result?.result?.value ?? '';
|
|
if (text.includes('RESULT') || text.startsWith('ERROR')) break;
|
|
await sleep(500);
|
|
}
|
|
ws.close();
|
|
return text;
|
|
} finally {
|
|
child.kill('SIGKILL');
|
|
// Chrome writes its profile until the process is gone; give it a moment so
|
|
// the cleanup below does not race the file handles it still holds.
|
|
await sleep(500);
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const chromeBin = await findChrome();
|
|
const { rgb8, rgb16 } = buildSource();
|
|
await mkdir(DIR, { recursive: true });
|
|
await writeFile(path.join(DIR, 'proxy.jpg'), await sharp(rgb8, { raw: { width: W, height: H, channels: 3 } })
|
|
.jpeg({ quality: 96, chromaSubsampling: '4:4:4' })
|
|
.toBuffer());
|
|
await writeFile(path.join(DIR, 'side.p16.png'), encodePng16(rgb16, W, H));
|
|
await writeFile(PAGE, PAGE_HTML);
|
|
|
|
const server = await createServer({
|
|
root: ROOT,
|
|
logLevel: 'error',
|
|
server: { host: '127.0.0.1', port: 5199, strictPort: false },
|
|
});
|
|
await server.listen();
|
|
const base = server.resolvedUrls?.local?.[0] ?? 'http://127.0.0.1:5199/';
|
|
|
|
let text = '';
|
|
try {
|
|
if (!chromeBin) {
|
|
console.log('render check SKIPPED: no Chrome/Chromium found (set CHROME_PATH to run it).');
|
|
return 0;
|
|
}
|
|
text = await drive(chromeBin, `${base.replace(/\/$/, '')}/.render-check/`);
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
|
|
if (text.startsWith('ERROR')) {
|
|
console.error(`render check FAILED: ${text.slice(6)}`);
|
|
return 1;
|
|
}
|
|
const marker = text.indexOf('RESULT');
|
|
if (marker < 0) {
|
|
console.error('render check FAILED: the probe never reported a result.');
|
|
console.error(text.slice(0, 500));
|
|
return 1;
|
|
}
|
|
const result = JSON.parse(text.slice(marker + 7));
|
|
console.log(
|
|
`render check: proxy top=${result.proxyTop} bottom=${result.proxyBottom}` +
|
|
` | sidecar top=${result.sidecarTop} bottom=${result.sidecarBottom}` +
|
|
` | flip flag honoured for ImageBitmap=${result.flagHonouredForBitmap}`,
|
|
);
|
|
console.log(
|
|
`render check: clipping overlay red=${JSON.stringify(result.clipPixels[0])}` +
|
|
` yellow=${JSON.stringify(result.clipPixels[1])}` +
|
|
` clear=${JSON.stringify(result.clipPixels[2])}` +
|
|
` | at +6EV the clear band is ${JSON.stringify(result.brightPixel)}`,
|
|
);
|
|
console.log(
|
|
`render check: shadow overlay clear=${JSON.stringify(result.shadowPixels[0])}` +
|
|
` red=${JSON.stringify(result.shadowPixels[1])}` +
|
|
` yellow=${JSON.stringify(result.shadowPixels[2])}` +
|
|
` cyan=${JSON.stringify(result.shadowPixels[3])}` +
|
|
` | at -9EV the clean band is ${JSON.stringify(result.shadowDarkPixel)}`,
|
|
);
|
|
console.log(
|
|
`render check: mask curve identity=${JSON.stringify(result.maskIdentityPixel)}` +
|
|
` darkened=${JSON.stringify(result.maskCurvePixel)}`,
|
|
);
|
|
console.log(
|
|
`render check: mask group subtract=${JSON.stringify(result.maskGroupSubtractPixel)}` +
|
|
` intersect=${JSON.stringify(result.maskGroupIntersectPixel)}`,
|
|
);
|
|
if (!result.matchTop || !result.matchBottom) {
|
|
console.error(
|
|
result.reversed
|
|
? 'render check FAILED: the sidecar lands upside down against the proxy.'
|
|
: 'render check FAILED: proxy and sidecar rows do not line up.',
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.clipRed || !result.clipYellow || !result.clipClear) {
|
|
console.error(
|
|
'render check FAILED: the clipping overlay lost its channel colours ' +
|
|
`(red=${result.clipRed}, yellow=${result.clipYellow}, clear=${result.clipClear}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.shadowClear || !result.shadowRed || !result.shadowYellow || !result.shadowCyan) {
|
|
console.error(
|
|
'render check FAILED: the shadow clipping overlay lost its channel colours ' +
|
|
`(clear=${result.shadowClear}, red=${result.shadowRed}, ` +
|
|
`yellow=${result.shadowYellow}, cyan=${result.shadowCyan}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.maskIdentityFlat || !result.maskCurveDarkens) {
|
|
console.error(
|
|
'render check FAILED: the per-mask curve is not reaching the grade ' +
|
|
`(identity=${JSON.stringify(result.maskIdentityPixel)}, ` +
|
|
`curve=${JSON.stringify(result.maskCurvePixel)}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.maskGroupSubtractCleared || !result.maskGroupIntersectDarkens) {
|
|
console.error(
|
|
'render check FAILED: mask group shapes are not compositing ' +
|
|
`(subtract=${JSON.stringify(result.maskGroupSubtractPixel)}, ` +
|
|
`intersect=${JSON.stringify(result.maskGroupIntersectPixel)}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.shadowFollowsExposure) {
|
|
console.error(
|
|
'render check FAILED: the shadow clipping overlay does not follow Exposure; ' +
|
|
`at -9EV the clean band stayed ${JSON.stringify(result.shadowDarkPixel)}.`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.clipFollowsExposure) {
|
|
console.error(
|
|
'render check FAILED: the clipping overlay does not follow Exposure; ' +
|
|
`the unclipped band stayed ${JSON.stringify(result.brightPixel)} at +6 EV.`,
|
|
);
|
|
return 1;
|
|
}
|
|
console.log(
|
|
`render check: brush dab hard=${JSON.stringify(result.dabHard)}` +
|
|
` outsideHard=${JSON.stringify(result.dabOutsideHard)} soft=${JSON.stringify(result.dabSoft)}` +
|
|
` rimSoft=${JSON.stringify(result.dabRimSoft)} outsideSoft=${JSON.stringify(result.dabOutsideSoft)}`,
|
|
);
|
|
console.log(
|
|
`render check: mask overlay core=${JSON.stringify(result.tintCore)}` +
|
|
` rim=${JSON.stringify(result.tintRim)} outside=${JSON.stringify(result.tintOutside)}`,
|
|
);
|
|
console.log(
|
|
`render check: crop mask tint on=${JSON.stringify(result.cropTintOn)}` +
|
|
` off=${JSON.stringify(result.cropTintOff)} ref=${JSON.stringify(result.cropRef)}` +
|
|
` | local detail on=${JSON.stringify(result.cropDetailOn)}` +
|
|
` off=${JSON.stringify(result.cropDetailOff)}`,
|
|
);
|
|
console.log(
|
|
`render check: lens mask tint on=${JSON.stringify(result.lensTintOn)}` +
|
|
` off=${JSON.stringify(result.lensTintOff)} ref=${JSON.stringify(result.lensRef)}` +
|
|
` | tint strength full=${JSON.stringify(result.tintFull)}` +
|
|
` half=${JSON.stringify(result.tintCore)}`,
|
|
);
|
|
if (
|
|
!result.cropTintAligned ||
|
|
!result.cropTintBounded ||
|
|
!result.cropDetailAligned ||
|
|
!result.cropDetailBounded ||
|
|
!result.lensTintAligned ||
|
|
!result.lensTintBounded ||
|
|
!result.tintStrengthWorks ||
|
|
!result.tintOffMatches
|
|
) {
|
|
console.error(
|
|
'render check FAILED: the local mask does not stay on its source pixels ' +
|
|
'through a crop or a lens warp ' +
|
|
`(crop tint ${JSON.stringify(result.cropTintOn)}/${JSON.stringify(result.cropTintOff)}` +
|
|
` vs ${JSON.stringify(result.cropRef)}, detail ` +
|
|
`${JSON.stringify(result.cropDetailOn)}/${JSON.stringify(result.cropDetailOff)}` +
|
|
`, lens tint ${JSON.stringify(result.lensTintOn)}/${JSON.stringify(result.lensTintOff)}` +
|
|
` vs ${JSON.stringify(result.lensRef)}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (!result.splitShowsBoth) {
|
|
console.error(
|
|
'render check FAILED: the before / after split does not follow its drag line ' +
|
|
`(left=${JSON.stringify(result.splitLeft)} vs ${JSON.stringify(result.splitBeforeFull)}, ` +
|
|
`right=${JSON.stringify(result.splitRight)} vs ${JSON.stringify(result.splitAfterFull)}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
if (
|
|
!result.dabCoreDarkened ||
|
|
!result.dabSoftCoreDarkened ||
|
|
!result.dabRimSmooth ||
|
|
!result.dabBoundedHard ||
|
|
!result.dabBoundedSoft ||
|
|
!result.tintFollowsMask ||
|
|
!result.tintBounded
|
|
) {
|
|
console.error(
|
|
'render check FAILED: the brush mask does not follow the brush circle ' +
|
|
`(hard=${JSON.stringify(result.dabHard)}, rim=${JSON.stringify(result.dabRimSoft)}, ` +
|
|
`outsideHard=${JSON.stringify(result.dabOutsideHard)}, ` +
|
|
`outsideSoft=${JSON.stringify(result.dabOutsideSoft)}, ` +
|
|
`tint=${JSON.stringify(result.tintCore)}/${JSON.stringify(result.tintRim)}/` +
|
|
`${JSON.stringify(result.tintOutside)}).`,
|
|
);
|
|
return 1;
|
|
}
|
|
console.log(
|
|
`render check: before / after split left=${JSON.stringify(result.splitLeft)}` +
|
|
` right=${JSON.stringify(result.splitRight)}`,
|
|
);
|
|
console.log(
|
|
'render check PASSED: proxy and sidecar share a row order, the clipping overlay names the channels, and the split keeps each side to its own edit.',
|
|
);
|
|
return 0;
|
|
}
|
|
|
|
let code = 1;
|
|
try {
|
|
code = await main();
|
|
} catch (err) {
|
|
console.error(`render check FAILED: ${err instanceof Error ? err.message : String(err)}`);
|
|
} finally {
|
|
await rm(DIR, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 }).catch(() => {
|
|
/* a stray Chrome profile is not worth failing the check over */
|
|
});
|
|
}
|
|
process.exit(code);
|