Name the clipped channels in the Ctrl clipping overlay again.

0c113e7 packed clipping into two alpha states (shadow / highlight), so the finish
pass could only paint white even though the legend still promised red, green,
blue and yellow. The grade pass now writes a 4-bit code (R/G/B + shadow) into
alpha and the overlay paints the channels it actually lost: red for one, yellow
for two, white for all three. The render check renders the overlay so this
cannot regress silently.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-28 14:35:30 +00:00
parent 1e7ec0cf15
commit fe9d2aff3f
3 changed files with 94 additions and 22 deletions
+8 -6
View File
@@ -992,12 +992,14 @@ Conventions worth knowing before changing code:
There are no server integration tests; the API is exercised through the UI. There are no server integration tests; the API is exercised through the UI.
`npm run check:render` covers the one thing the unit suite cannot: real GPU upload `npm run check:render` covers the one thing the unit suite cannot: what a shader does to
orientation. It encodes a two-tone 16-bit sidecar with the server's own encoder, serves real GPU pixels. It encodes a 16-bit sidecar with the server's own encoder, serves it
it beside the matching JPEG proxy and measures the rows that reach a WebGL2 texture in beside the matching JPEG proxy and measures the rows that reach a WebGL2 texture in
headless Chrome. If the sidecar ever lands upside down against the proxy again, it fails headless Chrome. Then it renders that image through the real `Renderer` with the Ctrl
with the measured row values. It needs Chrome (`CHROME_PATH` overrides discovery) and clipping preview on, so the overlay has to paint red for one clipped channel and yellow
skips with a notice when none is installed. for two instead of collapsing to white. It fails on either regression, printing the
measured values, needs Chrome (`CHROME_PATH` overrides discovery) and skips with a notice
when none is installed.
--- ---
+55 -5
View File
@@ -58,14 +58,18 @@ function spawnSyncOk(bin) {
}); });
} }
/** Three horizontal bands, so any vertical reversal changes every row band. */ /**
* Three horizontal bands. The first clips only red, the second clips red and
* green (the yellow warning) and the third clips nothing, so the same image
* also proves the clipping overlay still names the channels.
*/
function buildSource() { function buildSource() {
const rgb16 = new Uint16Array(W * H * 3); const rgb16 = new Uint16Array(W * H * 3);
const rgb8 = new Uint8Array(W * H * 3); const rgb8 = new Uint8Array(W * H * 3);
const bands = [ const bands = [
[0.86, 0.22, 0.16], [1.0, 0.55, 0.08],
[0.24, 0.70, 0.28], [1.0, 1.0, 0.08],
[0.16, 0.26, 0.88], [0.24, 0.28, 0.35],
]; ];
for (let y = 0; y < H; y++) { for (let y = 0; y < H; y++) {
const band = bands[Math.min(bands.length - 1, Math.floor((y / H) * bands.length))]; const band = bands[Math.min(bands.length - 1, Math.floor((y / H) * bands.length))];
@@ -85,6 +89,8 @@ const PAGE_HTML = `<!doctype html>
<pre id="out">boot</pre> <pre id="out">boot</pre>
<script type="module"> <script type="module">
import { parsePreview16 } from '/src/lib/preview16.ts'; import { parsePreview16 } from '/src/lib/preview16.ts';
import { Renderer } from '/src/gl/renderer.ts';
import { defaultEdits } from '/src/lib/edits.ts';
const pre = document.getElementById('out'); const pre = document.getElementById('out');
const half = (bits) => { const half = (bits) => {
const s = bits >> 15 ? -1 : 1; const s = bits >> 15 ? -1 : 1;
@@ -172,7 +178,37 @@ try {
const sideBottom = rowLuma(sideBottomTex, 0, w); const sideBottom = rowLuma(sideBottomTex, 0, w);
const same = (a, b) => Math.abs(a - b) < 0.02; 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)) / 3);
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];
pre.textContent = 'RESULT ' + JSON.stringify({ 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]),
flagHonouredForBitmap: !same(proxyTop, proxyNoFlipTop), flagHonouredForBitmap: !same(proxyTop, proxyNoFlipTop),
proxyTop: +proxyTop.toFixed(4), proxyTop: +proxyTop.toFixed(4),
sidecarTop: +sideTop.toFixed(4), sidecarTop: +sideTop.toFixed(4),
@@ -314,6 +350,11 @@ async function main() {
` | sidecar top=${result.sidecarTop} bottom=${result.sidecarBottom}` + ` | sidecar top=${result.sidecarTop} bottom=${result.sidecarBottom}` +
` | flip flag honoured for ImageBitmap=${result.flagHonouredForBitmap}`, ` | 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])}`,
);
if (!result.matchTop || !result.matchBottom) { if (!result.matchTop || !result.matchBottom) {
console.error( console.error(
result.reversed result.reversed
@@ -322,7 +363,16 @@ async function main() {
); );
return 1; return 1;
} }
console.log('render check PASSED: proxy and sidecar upload in the same row order.'); 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;
}
console.log(
'render check PASSED: proxy and sidecar share a row order and the clipping overlay names the channels.',
);
return 0; return 0;
} }
+31 -11
View File
@@ -549,10 +549,15 @@ void main(){
// Alpha carries the *source* clipping state to the finish pass, so the // Alpha carries the *source* clipping state to the finish pass, so the
// warning reflects the pixels the sensor/proxy had, not the graded result. // warning reflects the pixels the sensor/proxy had, not the graded result.
float clipFlag = 0.0; // It is a 4-bit code in sixteenths: bit 0/1/2 = red/green/blue clipped and
if (max(src.r, max(src.g, src.b)) >= 0.996) clipFlag += 0.5; // bit 3 = shadow clipped, so the overlay can still name the channels instead
if (min(src.r, min(src.g, src.b)) <= 0.004) clipFlag += 0.25; // of collapsing every highlight warning to white.
outColor = vec4(clamp(srgb, 0.0, 1.0), clipFlag); float clipCode = 0.0;
if (src.r >= 0.996) clipCode += 1.0;
if (src.g >= 0.996) clipCode += 2.0;
if (src.b >= 0.996) clipCode += 4.0;
if (min(src.r, min(src.g, src.b)) <= 0.004) clipCode += 8.0;
outColor = vec4(clamp(srgb, 0.0, 1.0), clipCode / 16.0);
}`; }`;
const BLUR_FRAG = `#version 300 es const BLUR_FRAG = `#version 300 es
@@ -857,15 +862,30 @@ void main(){
// Clipping overlay: which channels have run out of headroom. Red/green/blue // Clipping overlay: which channels have run out of headroom. Red/green/blue
// mean one channel clipped, yellow means two, white means all three — the // mean one channel clipped, yellow means two, white means all three — the
// same reading Aperture's exposure warnings gave while you dragged. // same reading Aperture's exposure warnings gave while you dragged.
// The grade pass wrote the untouched source's clipping state into alpha: // The grade pass wrote the untouched source's clipping state into alpha as a
// 0.25 shadow, 0.50 highlight, 0.75 both. Warning about the source means it // 4-bit code in sixteenths, so warning about the source still tells the truth
// still tells the truth after a curve or a shadow lift. // after a curve or a shadow lift and the channels are still known here.
float srcClip = texture(u_graded, v_uv).a; int clipCode = int(texture(u_graded, v_uv).a * 16.0 + 0.5);
bool clipR = (clipCode & 1) != 0;
bool clipG = (clipCode & 2) != 0;
bool clipB = (clipCode & 4) != 0;
bool clipShadow = (clipCode & 8) != 0;
if (u_clip > 1.5) { if (u_clip > 1.5) {
if (srcClip >= 0.2 && srcClip < 0.5) finalCol = vec3(0.15, 0.4, 1.0); // Shadow clipping: everything that has fallen to the bottom of the range.
else if (srcClip >= 0.7) finalCol = vec3(0.15, 0.4, 1.0); if (clipShadow) finalCol = vec3(0.15, 0.4, 1.0);
} else if (u_clip > 0.5) { } else if (u_clip > 0.5) {
if (srcClip >= 0.5) finalCol = vec3(1.0); float n = float(clipR) + float(clipG) + float(clipB);
if (n > 0.5) {
vec3 mark = vec3(1.0);
if (n < 1.5) {
if (clipR) mark = vec3(1.0, 0.12, 0.12);
else if (clipG) mark = vec3(0.1, 1.0, 0.2);
else mark = vec3(0.15, 0.4, 1.0);
} else if (n < 2.5) {
mark = vec3(1.0, 0.9, 0.1);
}
finalCol = mark;
}
} }
outColor = vec4(finalCol, 1.0); outColor = vec4(finalCol, 1.0);
}`; }`;