Files
RecipesCam/docker/frontend/scripts/white-level-check.mjs
T
3dtours 224ff0b935 web: open a RAW at the resolution of its sensor, not at the quarter of it
LibRaw's half-size demosaic was on. The Ricoh GR's own DNG (D0004128.DNG)
developed to 3010x2012 while the JPEG written beside it in the same second is
6000x4000, and the Fuji's RAF to 3008x2007 against its own 6000x4000 -- the
quarter was the flag, not the file. With `halfSize: false` the same develop
returns 6020x4024 and it is the sensor's frame on every body tried:

  D0004128.DNG  6020x4024   IMGP6916.DNG        6028x4024
  DSCF1701.RAF  6016x4014   _DSC0009.ARW        6024x4024
  AFXT2721.RAF  6246x4170   Nikon-D850 NEF      6216x4136
  _GDN0447.NEF  4284x2844   P1010607.RW2        3472x3472
  5G4A9396.CR2  2880x1920

Nine files, 27s to 155s a develop on one core. Checked through the app
itself, not only through LibRaw: photo-dims 6020x4024 on the DNG against
6000x4000 on the JPEG, both err none.

The colour it opens with is now fitted per file to the preview the camera wrote
into it (previewMatch.ts): a 3x3 over a block grid of the develop against the
same grid of that preview, then one cubic a channel for what the 3x3 leaves.
The offline per-body table this replaces (cameraMatch.ts) stopped matching the
moment the path under it changed -- its rows no longer summed to 1 once the
highlight knee landed ahead of it -- and a body with a row opened with a cast
one without did not. The file's own preview does not age.

The white level the gain carries is the frame's own plateau rather than
`maximum` (sensorWhite.ts), a factor of 1.89 to 2.00 out; without it every
frame opened a stop bright and a body that sat lower (X-Trans, 1.892) never
reached the highlight desaturation at all.

The desaturation gate reads the gain-lifted levels as well as the sensor's,
which is the whole of the magenta: on a body whose cam_mul lifts red and blue
(the GR's [2.64, 1, 1.73]) a blown sky crosses the white level at 0.38 of the
raw range in red while green crosses at 1.0, so a gate read on the sensor's
levels alone stayed shut across it. Measured in the app against the camera's
own JPEG, mean dRGB over a 16x16 block grid: +1.20, -5.95, -6.11 with the
sensor's clip alone, +0.21, +0.24, +0.47 with both, mean |dL| 21.5 against
10.3. The same grid on the Fuji comes back balanced (+4.7, +5.0, +3.6) and best
aligned at offset 0,0.

-HL is recovery and +HL is a lift, so they are different moves now: recovery is
the doc's soft knee in linear light over the top half, which is the only term
in the tone shader that is not a shift and the only one that can put detail
back into a blown sky rather than merely darken it.

The four checks pin the develop down where it can only run in a browser:
raw-develop-check, preview-match-check, white-level-check, highlight-knee-check.
2026-09-28 15:24:37 +07:00

68 lines
3.5 KiB
JavaScript

// Where the develop's white level comes from (src/engine/sensorWhite.ts). The
// probe reads the frame instead of trusting a constant: the plane's ceiling is
// 1.89-2.00x `maximum - black` and which one depends on the body, and a frame
// that sat below the desaturation's 0.95 start came out tinted (Fuji X-Trans,
// measured 1.892). These pin the two states it has to tell apart — a blown
// plateau (spike plus gap) and a bright smooth sky (a top bin no bigger than the
// ones under it) — and the fall-backs on frames with nothing to measure.
//
// node scripts/white-level-check.mjs
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import ts from 'typescript';
const src = readFileSync(new URL('../src/engine/sensorWhite.ts', import.meta.url), 'utf8');
const js = ts.transpileModule(src, {
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
}).outputText;
const { sensorWhite } = await import(`data:text/javascript,${encodeURIComponent(js)}`);
const N = 1_000_000;
const MAXIMUM = 16383;
const BLACK = 512;
const LEGACY = 2 * (MAXIMUM - BLACK);
const FLOOR = 8192; // an unremarkable mid-tone the frame is mostly made of
// A frame of `N` mid-tone samples plus `counts` of them sitting in the nine bins
// from top-8 up to top: counts[8] is the top bin, counts[0] the one eight below.
function plane(top, counts) {
const data = new Uint16Array(N);
data.fill(FLOOR);
let i = 0;
for (let d = 0; d < 9; d++) for (let k = 0; k < counts[d]; k++) data[i++] = top - 8 + d;
return data;
}
// The sensor's own plateau: a pile at the top with nine near-empty bins under it.
assert.equal(sensorWhite(plane(30995, [1, 1, 1, 1, 1, 1, 1, 1, 3000]), MAXIMUM, BLACK), 30995, 'X-Trans plateau missed');
assert.equal(sensorWhite(plane(31779, [1, 1, 1, 1, 1, 1, 1, 1, 3000]), MAXIMUM, BLACK), 31779, 'Sony plateau missed');
// ...and the body that really does sit at twice the white level is read as such,
// not as the constant it used to be. Same answer either way, which is the point:
// the probe does not need to know which body it has.
assert.equal(sensorWhite(plane(LEGACY, [1, 1, 1, 1, 1, 1, 1, 1, 3000]), MAXIMUM, BLACK), LEGACY);
// A smooth sky fills the bins around the top far more than a clipped one does,
// and its top bin is a tail, not a step: no gap, no clip, no move of the white.
assert.equal(
sensorWhite(plane(30995, [400, 900, 1500, 2000, 2400, 2600, 2600, 2400, 2000]), MAXIMUM, BLACK),
LEGACY,
'a smooth top read as a clip'
);
// A bright flat wall sits exactly on one value with a big pile — but the bins
// under it are empty too, so that one IS a clip and is meant to move the white.
assert.equal(sensorWhite(plane(30995, [0, 0, 0, 0, 0, 0, 0, 0, 5000]), MAXIMUM, BLACK), 30995);
// Nothing to measure: a frame that never reached the plane's ceiling, and one
// whose only pile is a handful of hot pixels, both stay on the fixed factor two.
assert.equal(sensorWhite(plane(9000, [1, 1, 1, 1, 1, 1, 1, 1, 3000]), MAXIMUM, BLACK), LEGACY, 'an unblown frame moved the white');
assert.equal(sensorWhite(plane(30995, [0, 0, 0, 0, 0, 0, 0, 0, 5]), MAXIMUM, BLACK), LEGACY, 'hot pixels moved the white');
// The pile is a fraction of the plane, not a fixed count, so a small sensor with
// the same clipping is read the same way as a large one.
const small = new Uint16Array(100_000);
small.fill(FLOOR);
for (let i = 0; i < 40; i++) small[i] = 30995;
assert.equal(sensorWhite(small, MAXIMUM, BLACK), 30995, 'a small plane moved the threshold');
console.log('white-level-check ok');