@photivra/engine 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -1
- package/CITATION.cff +1 -1
- package/README.md +6 -6
- package/SECURITY.md +1 -1
- package/THIRD_PARTY.md +1 -0
- package/dist/capture/native-environment-lean.d.ts +1 -1
- package/dist/capture/native-environment-lean.js +17 -3
- package/dist/capture/native-environment-lean.js.map +1 -1
- package/dist/capture/native-environment-raw.d.ts +0 -4
- package/dist/capture/native-environment-raw.js +6 -2
- package/dist/capture/native-environment-raw.js.map +1 -1
- package/dist/color/illuminants.d.ts +15 -0
- package/dist/color/illuminants.js +81 -24
- package/dist/color/illuminants.js.map +1 -1
- package/dist/color/srgb-transfer.d.ts +6 -0
- package/dist/color/srgb-transfer.js +9 -0
- package/dist/color/srgb-transfer.js.map +1 -1
- package/dist/color/white-balance.d.ts +6 -0
- package/dist/color/white-balance.js +15 -2
- package/dist/color/white-balance.js.map +1 -1
- package/dist/core/internal-radiance-evaluator.d.ts +6 -0
- package/dist/core/internal-radiance-evaluator.js +33 -0
- package/dist/core/internal-radiance-evaluator.js.map +1 -0
- package/dist/core/portable-math.d.ts +33 -0
- package/dist/core/portable-math.js +342 -0
- package/dist/core/portable-math.js.map +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/core/version.js.map +1 -1
- package/dist/facade/chart-scenes.d.ts +9 -0
- package/dist/facade/chart-scenes.js +17 -4
- package/dist/facade/chart-scenes.js.map +1 -1
- package/dist/facade/diffraction-provider.d.ts +10 -0
- package/dist/facade/diffraction-provider.js +38 -17
- package/dist/facade/diffraction-provider.js.map +1 -1
- package/dist/facade/display-view.d.ts +208 -0
- package/dist/facade/display-view.js +1461 -0
- package/dist/facade/display-view.js.map +1 -0
- package/dist/facade/scene-radiance.d.ts +7 -0
- package/dist/facade/scene-radiance.js +18 -5
- package/dist/facade/scene-radiance.js.map +1 -1
- package/dist/facade/simulate-capture.d.ts +229 -5
- package/dist/facade/simulate-capture.js +119 -35
- package/dist/facade/simulate-capture.js.map +1 -1
- package/dist/facade/simulate-display-view.d.ts +21 -0
- package/dist/facade/simulate-display-view.js +168 -0
- package/dist/facade/simulate-display-view.js.map +1 -0
- package/dist/facade/subject-framing.d.ts +78 -0
- package/dist/facade/subject-framing.js +69 -20
- package/dist/facade/subject-framing.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/optics/diffraction-psf-profile.d.ts +59 -3
- package/dist/optics/diffraction-psf-profile.js +147 -5
- package/dist/optics/diffraction-psf-profile.js.map +1 -1
- package/dist/optics/irradiance-convolution.js +1 -1
- package/dist/optics/irradiance-convolution.js.map +1 -1
- package/dist/optics/scene-to-sensor-irradiance.d.ts +7 -0
- package/dist/optics/scene-to-sensor-irradiance.js +10 -5
- package/dist/optics/scene-to-sensor-irradiance.js.map +1 -1
- package/dist/output/print-plan.d.ts +8 -1
- package/dist/output/print-plan.js +8 -1
- package/dist/output/print-plan.js.map +1 -1
- package/dist/schema/scene-radiance.d.ts +16 -0
- package/dist/schema/scene-radiance.js +25 -4
- package/dist/schema/scene-radiance.js.map +1 -1
- package/dist/sensor/raw-readout.d.ts +12 -0
- package/dist/sensor/raw-readout.js +131 -9
- package/dist/sensor/raw-readout.js.map +1 -1
- package/dist/sensor/stochastic-seed.d.ts +13 -0
- package/dist/sensor/stochastic-seed.js +42 -8
- package/dist/sensor/stochastic-seed.js.map +1 -1
- package/docs/AGENT_GUIDE.md +1 -0
- package/docs/API_REFERENCE.md +16 -1
- package/docs/QUICK_START.md +245 -9
- package/docs/USAGE.md +15 -0
- package/docs/api/core-version.md +1 -1
- package/docs/api/exports.json +37 -2
- package/docs/api/facade-simulate-capture.md +70 -2
- package/docs/api/facade-simulate-display-view.md +18 -0
- package/docs/api/facade-subject-framing.md +83 -0
- package/docs/api/optics-diffraction-psf-profile.md +8 -1
- package/docs/api/output-print-plan.md +8 -1
- package/package.json +3 -2
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* provider then answers each site-centre query with B instead of L, and the environment request declares no
|
|
21
21
|
* PSF. Incoherent imaging is a linear superposition of intensity PSFs, so convolving radiance on the object
|
|
22
22
|
* plane and convolving irradiance on the image plane agree for a planar object and a space-invariant PSF
|
|
23
|
-
* (MIT OpenCourseWare 2.71, lecture 22, free; also see: Goodman, Introduction to Fourier Optics, 4th ed., §
|
|
23
|
+
* (MIT OpenCourseWare 2.71, lecture 22, free; also see: Goodman, Introduction to Fourier Optics, 4th ed., §7.1).
|
|
24
24
|
*
|
|
25
25
|
* With an anti-aliasing point-splitting filter (2.1, `sensor.antiAliasing`) the environment queries the PSF taps
|
|
26
26
|
* around each pre-filter source point q − a (a = a split offset) instead of around q. Those taps lie on the site
|
|
@@ -29,10 +29,18 @@
|
|
|
29
29
|
* one-site separation needs a single half-site-shifted lattice) over the native raster widened by the largest
|
|
30
30
|
* offset, and the environment's spatial quadrature still forms the weighted split sum.
|
|
31
31
|
*
|
|
32
|
+
* Region renders (2.6, `window`): only the lattice rows and columns that the region's sites can query (the window
|
|
33
|
+
* plus the largest offset on each side) are convolved, over a grid that adds the kernel radius on each side. Every
|
|
34
|
+
* output value is the same gather as in the whole render: the grid always holds every tap of every value it keeps
|
|
35
|
+
* (real scene radiance out to the kernel radius, never a truncated edge), the single kernel patch does not depend on
|
|
36
|
+
* the grid's origin, and `convolveIrradianceRows` sums each value in a fixed tap order (v outer, u inner). Narrowing
|
|
37
|
+
* the grid therefore removes only values that no query reads, and the kept values are bit-identical.
|
|
38
|
+
*
|
|
32
39
|
* A query that does not land on one of the lattices (within 1e-6 site) is refused rather than approximated: the
|
|
33
|
-
* facade uses this path only when the lattice argument above holds.
|
|
40
|
+
* facade uses this path only when the lattice argument above holds. A query outside the window is refused too.
|
|
34
41
|
*/
|
|
35
42
|
import { InvalidConfigurationError } from "../core/configuration-error.js";
|
|
43
|
+
import { isInternalSceneRadianceEvaluator, markInternalSceneRadianceEvaluator } from "../core/internal-radiance-evaluator.js";
|
|
36
44
|
import { calculateIrradianceConvolution } from "../optics/irradiance-convolution.js";
|
|
37
45
|
import { resolveLensPsfConvolutionKernels } from "../optics/lens-psf-kernels.js";
|
|
38
46
|
/** Rows of native sites per convolution band, and the bands kept. Banding changes memory only, never values. */
|
|
@@ -55,6 +63,14 @@ export function createDiffractedPlanarProvider(input) {
|
|
|
55
63
|
}
|
|
56
64
|
const M = Math.max(0, ...offsets.map((o) => Math.ceil(Math.max(Math.abs(o.x), Math.abs(o.y)) - LATTICE_TOLERANCE_SITES)));
|
|
57
65
|
const LW = W + 2 * M, LH = H + 2 * M;
|
|
66
|
+
// Lattice window (indices i + M, j + M): the sites the region queries plus the largest offset on each side, clipped
|
|
67
|
+
// to the lattice. A site i queries i + floor(offset), and floor(offset) lies in [-M, M].
|
|
68
|
+
const win = input.window ?? { x: 0, y: 0, width: W, height: H };
|
|
69
|
+
const lx0 = Math.max(0, win.x), lx1 = Math.min(LW, win.x + win.width + 2 * M);
|
|
70
|
+
const ly0 = Math.max(0, win.y), ly1 = Math.min(LH, win.y + win.height + 2 * M);
|
|
71
|
+
if (!(lx0 < lx1 && ly0 < ly1))
|
|
72
|
+
throw new InvalidConfigurationError("Diffraction window must overlap the native raster.");
|
|
73
|
+
const NW = lx1 - lx0;
|
|
58
74
|
// One kernel per wavelength, on the site grid, from the engine's own tap-to-site mapping (field point 0, 0).
|
|
59
75
|
const kernels = wavelengthsNm.map((wavelengthNm) => {
|
|
60
76
|
const k = resolveLensPsfConvolutionKernels({ schemaVersion: "0.1.0", psf: input.psf, spectralWeights: [{ wavelengthNm, weight: 1 }],
|
|
@@ -64,7 +80,7 @@ export function createDiffractedPlanarProvider(input) {
|
|
|
64
80
|
throw new InvalidConfigurationError("Diffraction kernels must sample the site pitch exactly.");
|
|
65
81
|
return k.kernels;
|
|
66
82
|
});
|
|
67
|
-
const gridWidth =
|
|
83
|
+
const gridWidth = NW + 2 * R;
|
|
68
84
|
const now = () => globalThis.performance?.now() ?? Date.now();
|
|
69
85
|
const bands = new Map();
|
|
70
86
|
function band(b) {
|
|
@@ -75,19 +91,19 @@ export function createDiffractedPlanarProvider(input) {
|
|
|
75
91
|
return cached;
|
|
76
92
|
}
|
|
77
93
|
const started = input.onConvolution ? now() : 0;
|
|
78
|
-
const y0 = b * BAND_ROWS, rows = Math.min(BAND_ROWS,
|
|
94
|
+
const y0 = ly0 + b * BAND_ROWS, rows = Math.min(BAND_ROWS, ly1 - y0), gridHeight = rows + 2 * R;
|
|
79
95
|
const values = shifts.map((shift) => wavelengthsNm.map((nm, w) => {
|
|
80
96
|
const samples = new Float64Array(gridWidth * gridHeight);
|
|
81
97
|
for (let gy = 0; gy < gridHeight; gy++) {
|
|
82
98
|
const v = shift.y === 0 ? -(y0 + gy - R - M + 0.5 - H / 2) * g : -(y0 + gy - R - M + 0.5 + shift.y - H / 2) * g;
|
|
83
|
-
for (let gx = 0; gx < gridWidth; gx++)
|
|
84
|
-
samples[gy * gridWidth + gx] = base.radianceAt(shift.x === 0 ? (
|
|
99
|
+
for (let gx = 0, x = lx0; gx < gridWidth; gx++, x++)
|
|
100
|
+
samples[gy * gridWidth + gx] = base.radianceAt(shift.x === 0 ? (x - R - M + 0.5 - W / 2) * g : (x - R - M + 0.5 + shift.x - W / 2) * g, v, nm);
|
|
85
101
|
}
|
|
86
102
|
const blurred = calculateIrradianceConvolution({ schemaVersion: "0.1.0", width: gridWidth, height: gridHeight, samples, kernelRadius: R,
|
|
87
103
|
patchWidth: gridWidth, patchHeight: gridHeight, kernels: kernels[w], boundary: "zero-outside-grid" }).values;
|
|
88
|
-
const out = new Float64Array(
|
|
104
|
+
const out = new Float64Array(NW * rows);
|
|
89
105
|
for (let y = 0; y < rows; y++)
|
|
90
|
-
out.set(blurred.subarray((y + R) * gridWidth + R, (y + R) * gridWidth + R +
|
|
106
|
+
out.set(blurred.subarray((y + R) * gridWidth + R, (y + R) * gridWidth + R + NW), y * NW);
|
|
91
107
|
return out;
|
|
92
108
|
}));
|
|
93
109
|
bands.set(b, values);
|
|
@@ -104,21 +120,26 @@ export function createDiffractedPlanarProvider(input) {
|
|
|
104
120
|
const shift = shifts[s], i = Math.round(fi - shift.x), j = Math.round(fj - shift.y);
|
|
105
121
|
if (Math.abs(fi - shift.x - i) > LATTICE_TOLERANCE_SITES || Math.abs(fj - shift.y - j) > LATTICE_TOLERANCE_SITES)
|
|
106
122
|
continue;
|
|
107
|
-
|
|
123
|
+
const li = i + M, lj = j + M;
|
|
124
|
+
if (li < lx0 || lj < ly0 || li >= lx1 || lj >= ly1)
|
|
108
125
|
break;
|
|
109
|
-
|
|
110
|
-
return band(Math.floor(lj / BAND_ROWS))[s][w][(lj % BAND_ROWS) * LW + i + M];
|
|
126
|
+
return band(Math.floor((lj - ly0) / BAND_ROWS))[s][w][((lj - ly0) % BAND_ROWS) * NW + li - lx0];
|
|
111
127
|
}
|
|
112
128
|
throw new InvalidConfigurationError("Diffraction query is off the site lattice; the object-space convolution does not apply.");
|
|
113
129
|
}
|
|
114
|
-
const scale = input.metresPerFrameUnit, distance = input.distanceM;
|
|
130
|
+
const scale = input.metresPerFrameUnit, distance = input.distanceM, baseEvaluate = base.evaluateRadiance;
|
|
131
|
+
const evaluateRadiance = (request) => {
|
|
132
|
+
const result = baseEvaluate.call(base, request), o = request.target.outgoingDirectionUnitVector;
|
|
133
|
+
const t = distance / -o.z;
|
|
134
|
+
return { ...result, spectralRadianceWattsPerSquareMeterSteradianNanometer: blurredAt(-o.x * t / scale, -o.y * t / scale, request.wavelengthNanometers) };
|
|
135
|
+
};
|
|
136
|
+
// 2.6: the result is the base result with only its radiance replaced (same keys and records), so an engine-built base
|
|
137
|
+
// evaluator keeps its mark (see core/internal-radiance-evaluator.ts).
|
|
138
|
+
if (isInternalSceneRadianceEvaluator(baseEvaluate))
|
|
139
|
+
markInternalSceneRadianceEvaluator(evaluateRadiance);
|
|
115
140
|
return {
|
|
116
141
|
sceneId: base.sceneId, providerProfileId: base.providerProfileId, radianceAt: base.radianceAt,
|
|
117
|
-
evaluateRadiance
|
|
118
|
-
const result = base.evaluateRadiance(request), o = request.target.outgoingDirectionUnitVector;
|
|
119
|
-
const t = distance / -o.z;
|
|
120
|
-
return { ...result, spectralRadianceWattsPerSquareMeterSteradianNanometer: blurredAt(-o.x * t / scale, -o.y * t / scale, request.wavelengthNanometers) };
|
|
121
|
-
},
|
|
142
|
+
evaluateRadiance,
|
|
122
143
|
evaluateApertureRadiance() {
|
|
123
144
|
throw new InvalidConfigurationError("Diffraction by object-space convolution does not take pupil rays.");
|
|
124
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diffraction-provider.js","sourceRoot":"","sources":["../../src/facade/diffraction-provider.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAIjF,gHAAgH;AAChH,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,uBAAuB,GAAG,IAAI,CAAC;AA0BrC,2HAA2H;AAC3H,MAAM,UAAU,8BAA8B,CAAC,KAAoC;IACjF,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACxF,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK,CAAC,oBAAoB,CAAC;IACpE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,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I,CAAC,IAAI,CAAC,GAAG,CAAC;oBAAE,MAAM;gBACxD,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAE,CAAC;YAClF,CAAC;QACD,MAAM,IAAI,yBAAyB,CAAC,yFAAyF,CAAC,CAAC;IACjI,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,kBAAkB,EAAE,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;IACnE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU;QAC7F,gBAAgB,CAAC,OAAiD;YAChE,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAI,OAAO,CAAC,MAA+E,CAAC,2BAA2B,CAAC;YACxK,MAAM,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,OAAO,EAAE,GAAG,MAAM,EAAE,qDAAqD,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAC3J,CAAC;QACD,wBAAwB;YACtB,MAAM,IAAI,yBAAyB,CAAC,mEAAmE,CAAC,CAAC;QAC3G,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Fast execution of `simulateCapture`'s `lens.diffraction` (2.1): an object-space convolution in the scene\n * provider, instead of one scene query per PSF tap in the environment PSF quadrature.\n *\n * The environment quadrature computes, at each site centre q and spectral node λ,\n * E(q, λ) = Σ_k K_λ(k)·T·L(s_k(q), λ),\n * where s_k(q) is the tap's source point (`sensorPsfSourcePoint`), L the scene radiance at the plane point\n * that source point sees, and T the radiance-to-irradiance factor. For the facade's planar scene seen\n * through the ideal rectilinear projection with a still camera and no lens field mapping, field throughput or\n * pupil rays:\n * - T is the same at every sensor point (paraxial π/(4·N_w²), no cos⁴ term), and\n * - with the kernel sampled on the site pitch, every source point is the centre of another site, so the plane\n * points form one regular lattice: u = (i + ½ − W/2)·2/w, v = −(j + ½ − H/2)·2/w (frame units, native\n * site (i, j), W×H native sites, w output width).\n * So E(q, λ) = T·B(q, λ) with B = K_λ ⊛ L sampled on that lattice: the same sum, in a different floating-point\n * order. B is computed once per spectral node with the engine's isoplanatic convolution\n * (`calculateIrradianceConvolution`, kernels from `resolveLensPsfConvolutionKernels`, exact site sampling) over a\n * grid that holds every source (the native raster plus the kernel radius on each side), in row bands. The\n * provider then answers each site-centre query with B instead of L, and the environment request declares no\n * PSF. Incoherent imaging is a linear superposition of intensity PSFs, so convolving radiance on the object\n * plane and convolving irradiance on the image plane agree for a planar object and a space-invariant PSF\n * (MIT OpenCourseWare 2.71, lecture 22, free; also see: Goodman, Introduction to Fourier Optics, 4th ed., §6.1).\n *\n * With an anti-aliasing point-splitting filter (2.1, `sensor.antiAliasing`) the environment queries the PSF taps\n * around each pre-filter source point q − a (a = a split offset) instead of around q. Those taps lie on the site\n * lattice shifted by a, so the same argument holds on each shifted lattice: B is computed once per distinct\n * fractional shift (offsets that differ by whole sites share one lattice; the centred four-spot filter with a\n * one-site separation needs a single half-site-shifted lattice) over the native raster widened by the largest\n * offset, and the environment's spatial quadrature still forms the weighted split sum.\n *\n * A query that does not land on one of the lattices (within 1e-6 site) is refused rather than approximated: the\n * facade uses this path only when the lattice argument above holds.\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport type { SceneRadianceEvaluationRequest, SceneRadianceEvaluationResult } from \"../schema/scene-radiance.js\";\nimport { calculateIrradianceConvolution } from \"../optics/irradiance-convolution.js\";\nimport { resolveLensPsfConvolutionKernels } from \"../optics/lens-psf-kernels.js\";\nimport type { ResolveLensSampledPsfInput } from \"../optics/lens-psf-profile.js\";\nimport type { PlanarSceneRadianceProvider } from \"./scene-radiance.js\";\n\n/** Rows of native sites per convolution band, and the bands kept. Banding changes memory only, never values. */\nconst BAND_ROWS = 32;\nconst CACHED_BANDS = 4;\nconst LATTICE_TOLERANCE_SITES = 1e-6;\n\nexport interface DiffractedPlanarProviderInput {\n base: PlanarSceneRadianceProvider;\n /** The optical state of the sampled PSF, as for `resolveLensSampledPsf`, without field point and wavelength. */\n psf: Omit<ResolveLensSampledPsfInput, \"fieldPointMm\" | \"wavelengthNm\">;\n /** Spectral nodes the environment queries (the profile's wavelength nodes). */\n wavelengthsNm: readonly number[];\n kernelRadius: number;\n nativeWidth: number;\n nativeHeight: number;\n /** Output (active) width in sites: frame units are 2/outputWidth per site. */\n outputWidth: number;\n sitePitchMicrometers: number;\n /** Planar geometry of the base provider, to map query directions to plane points exactly as it does. */\n distanceM: number;\n metresPerFrameUnit: number;\n /**\n * Offsets of the query points from the site centres, in sites (+x right, +y down): the anti-aliasing split\n * offsets with their sign reversed (the environment queries q − a). Default: one zero offset.\n */\n queryOffsetsSites?: readonly { x: number; y: number }[];\n /** Called with the duration in ms of each band convolution (diagnostics only; never changes values). */\n onConvolution?: (milliseconds: number) => void;\n}\n\n/** Internal (not exported from the package): the base provider with diffraction applied as an object-space convolution. */\nexport function createDiffractedPlanarProvider(input: DiffractedPlanarProviderInput): PlanarSceneRadianceProvider {\n const { base, wavelengthsNm, nativeWidth: W, nativeHeight: H, kernelRadius: R } = input;\n const g = 2 / input.outputWidth, pitch = input.sitePitchMicrometers;\n const index = new Map(wavelengthsNm.map((nm, i) => [nm, i]));\n // One lattice per distinct fractional query offset; M extra sites per side hold the offset queries.\n const offsets = input.queryOffsetsSites ?? [{ x: 0, y: 0 }];\n const fraction = (value: number): number => { const f = value - Math.floor(value); return f > 1 - LATTICE_TOLERANCE_SITES ? 0 : f < LATTICE_TOLERANCE_SITES ? 0 : f; };\n const shifts: { x: number; y: number }[] = [];\n for (const o of offsets) {\n const f = { x: fraction(o.x), y: fraction(o.y) };\n if (!shifts.some((s) => Math.abs(s.x - f.x) <= LATTICE_TOLERANCE_SITES && Math.abs(s.y - f.y) <= LATTICE_TOLERANCE_SITES)) shifts.push(f);\n }\n const M = Math.max(0, ...offsets.map((o) => Math.ceil(Math.max(Math.abs(o.x), Math.abs(o.y)) - LATTICE_TOLERANCE_SITES)));\n const LW = W + 2 * M, LH = H + 2 * M;\n // One kernel per wavelength, on the site grid, from the engine's own tap-to-site mapping (field point 0, 0).\n const kernels = wavelengthsNm.map((wavelengthNm) => {\n const k = resolveLensPsfConvolutionKernels({ schemaVersion: \"0.1.0\", psf: input.psf, spectralWeights: [{ wavelengthNm, weight: 1 }],\n grid: { width: 1, height: 1, sitePitchMicrometers: { x: pitch, y: pitch }, opticalAxisSite: { x: 0.5, y: 0.5 } }, patchWidth: 1, patchHeight: 1,\n kernelRadius: R }).value;\n if (!k.exactSiteSampling || k.kernelRadius !== R) throw new InvalidConfigurationError(\"Diffraction kernels must sample the site pitch exactly.\");\n return k.kernels;\n });\n const gridWidth = LW + 2 * R;\n const now = (): number => globalThis.performance?.now() ?? Date.now();\n const bands = new Map<number, Float64Array[][]>();\n function band(b: number): Float64Array[][] {\n const cached = bands.get(b);\n if (cached) { bands.delete(b); bands.set(b, cached); return cached; }\n const started = input.onConvolution ? now() : 0;\n const y0 = b * BAND_ROWS, rows = Math.min(BAND_ROWS, LH - y0), gridHeight = rows + 2 * R;\n const values = shifts.map((shift) => wavelengthsNm.map((nm, w) => {\n const samples = new Float64Array(gridWidth * gridHeight);\n for (let gy = 0; gy < gridHeight; gy++) {\n const v = shift.y === 0 ? -(y0 + gy - R - M + 0.5 - H / 2) * g : -(y0 + gy - R - M + 0.5 + shift.y - H / 2) * g;\n for (let gx = 0; gx < gridWidth; gx++) samples[gy * gridWidth + gx] = base.radianceAt(shift.x === 0 ? (gx - R - M + 0.5 - W / 2) * g : (gx - R - M + 0.5 + shift.x - W / 2) * g, v, nm);\n }\n const blurred = calculateIrradianceConvolution({ schemaVersion: \"0.1.0\", width: gridWidth, height: gridHeight, samples, kernelRadius: R,\n patchWidth: gridWidth, patchHeight: gridHeight, kernels: kernels[w]!, boundary: \"zero-outside-grid\" }).values;\n const out = new Float64Array(LW * rows);\n for (let y = 0; y < rows; y++) out.set(blurred.subarray((y + R) * gridWidth + R, (y + R) * gridWidth + R + LW), y * LW);\n return out;\n }));\n bands.set(b, values);\n if (bands.size > CACHED_BANDS) bands.delete(bands.keys().next().value!);\n if (input.onConvolution) input.onConvolution(now() - started);\n return values;\n }\n function blurredAt(u: number, v: number, nm: number): number {\n const w = index.get(nm), fi = u / g - 0.5 + W / 2, fj = -v / g - 0.5 + H / 2;\n if (w !== undefined) for (let s = 0; s < shifts.length; s++) {\n const shift = shifts[s]!, i = Math.round(fi - shift.x), j = Math.round(fj - shift.y);\n if (Math.abs(fi - shift.x - i) > LATTICE_TOLERANCE_SITES || Math.abs(fj - shift.y - j) > LATTICE_TOLERANCE_SITES) continue;\n if (i < -M || j < -M || i >= W + M || j >= H + M) break;\n const lj = j + M;\n return band(Math.floor(lj / BAND_ROWS))[s]![w]![(lj % BAND_ROWS) * LW + i + M]!;\n }\n throw new InvalidConfigurationError(\"Diffraction query is off the site lattice; the object-space convolution does not apply.\");\n }\n const scale = input.metresPerFrameUnit, distance = input.distanceM;\n return {\n sceneId: base.sceneId, providerProfileId: base.providerProfileId, radianceAt: base.radianceAt,\n evaluateRadiance(request: Readonly<SceneRadianceEvaluationRequest>): SceneRadianceEvaluationResult {\n const result = base.evaluateRadiance(request), o = (request.target as { outgoingDirectionUnitVector: { x: number; y: number; z: number } }).outgoingDirectionUnitVector;\n const t = distance / -o.z;\n return { ...result, spectralRadianceWattsPerSquareMeterSteradianNanometer: blurredAt(-o.x * t / scale, -o.y * t / scale, request.wavelengthNanometers) };\n },\n evaluateApertureRadiance(): SceneRadianceEvaluationResult {\n throw new InvalidConfigurationError(\"Diffraction by object-space convolution does not take pupil rays.\");\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"diffraction-provider.js","sourceRoot":"","sources":["../../src/facade/diffraction-provider.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AAE9H,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAIjF,gHAAgH;AAChH,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,uBAAuB,GAAG,IAAI,CAAC;AA+BrC,2HAA2H;AAC3H,MAAM,UAAU,8BAA8B,CAAC,KAAoC;IACjF,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACxF,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK,CAAC,oBAAoB,CAAC;IACpE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,oGAAoG;IACpG,MAAM,OAAO,GAAG,KAAK,CAAC,iBAAiB,IAAI,CAAC,EAAE,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ACzG,MAAM,gBAAgB,GAAG,CAAC,OAAiD,EAAiC,EAAE;QAC5G,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,GAAI,OAAO,CAAC,MAA+E,CAAC,2BAA2B,CAAC;QAC1K,MAAM,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,OAAO,EAAE,GAAG,MAAM,EAAE,qDAAqD,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC;IAC3J,CAAC,CAAC;IACF,sHAAsH;IACtH,sEAAsE;IACtE,IAAI,gCAAgC,CAAC,YAAY,CAAC;QAAE,kCAAkC,CAAC,gBAAgB,CAAC,CAAC;IACzG,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU;QAC7F,gBAAgB;QAChB,wBAAwB;YACtB,MAAM,IAAI,yBAAyB,CAAC,mEAAmE,CAAC,CAAC;QAC3G,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Fast execution of `simulateCapture`'s `lens.diffraction` (2.1): an object-space convolution in the scene\n * provider, instead of one scene query per PSF tap in the environment PSF quadrature.\n *\n * The environment quadrature computes, at each site centre q and spectral node λ,\n * E(q, λ) = Σ_k K_λ(k)·T·L(s_k(q), λ),\n * where s_k(q) is the tap's source point (`sensorPsfSourcePoint`), L the scene radiance at the plane point\n * that source point sees, and T the radiance-to-irradiance factor. For the facade's planar scene seen\n * through the ideal rectilinear projection with a still camera and no lens field mapping, field throughput or\n * pupil rays:\n * - T is the same at every sensor point (paraxial π/(4·N_w²), no cos⁴ term), and\n * - with the kernel sampled on the site pitch, every source point is the centre of another site, so the plane\n * points form one regular lattice: u = (i + ½ − W/2)·2/w, v = −(j + ½ − H/2)·2/w (frame units, native\n * site (i, j), W×H native sites, w output width).\n * So E(q, λ) = T·B(q, λ) with B = K_λ ⊛ L sampled on that lattice: the same sum, in a different floating-point\n * order. B is computed once per spectral node with the engine's isoplanatic convolution\n * (`calculateIrradianceConvolution`, kernels from `resolveLensPsfConvolutionKernels`, exact site sampling) over a\n * grid that holds every source (the native raster plus the kernel radius on each side), in row bands. The\n * provider then answers each site-centre query with B instead of L, and the environment request declares no\n * PSF. Incoherent imaging is a linear superposition of intensity PSFs, so convolving radiance on the object\n * plane and convolving irradiance on the image plane agree for a planar object and a space-invariant PSF\n * (MIT OpenCourseWare 2.71, lecture 22, free; also see: Goodman, Introduction to Fourier Optics, 4th ed., §7.1).\n *\n * With an anti-aliasing point-splitting filter (2.1, `sensor.antiAliasing`) the environment queries the PSF taps\n * around each pre-filter source point q − a (a = a split offset) instead of around q. Those taps lie on the site\n * lattice shifted by a, so the same argument holds on each shifted lattice: B is computed once per distinct\n * fractional shift (offsets that differ by whole sites share one lattice; the centred four-spot filter with a\n * one-site separation needs a single half-site-shifted lattice) over the native raster widened by the largest\n * offset, and the environment's spatial quadrature still forms the weighted split sum.\n *\n * Region renders (2.6, `window`): only the lattice rows and columns that the region's sites can query (the window\n * plus the largest offset on each side) are convolved, over a grid that adds the kernel radius on each side. Every\n * output value is the same gather as in the whole render: the grid always holds every tap of every value it keeps\n * (real scene radiance out to the kernel radius, never a truncated edge), the single kernel patch does not depend on\n * the grid's origin, and `convolveIrradianceRows` sums each value in a fixed tap order (v outer, u inner). Narrowing\n * the grid therefore removes only values that no query reads, and the kept values are bit-identical.\n *\n * A query that does not land on one of the lattices (within 1e-6 site) is refused rather than approximated: the\n * facade uses this path only when the lattice argument above holds. A query outside the window is refused too.\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { isInternalSceneRadianceEvaluator, markInternalSceneRadianceEvaluator } from \"../core/internal-radiance-evaluator.js\";\nimport type { SceneRadianceEvaluationRequest, SceneRadianceEvaluationResult } from \"../schema/scene-radiance.js\";\nimport { calculateIrradianceConvolution } from \"../optics/irradiance-convolution.js\";\nimport { resolveLensPsfConvolutionKernels } from \"../optics/lens-psf-kernels.js\";\nimport type { ResolveLensSampledPsfInput } from \"../optics/lens-psf-profile.js\";\nimport type { PlanarSceneRadianceProvider } from \"./scene-radiance.js\";\n\n/** Rows of native sites per convolution band, and the bands kept. Banding changes memory only, never values. */\nconst BAND_ROWS = 32;\nconst CACHED_BANDS = 4;\nconst LATTICE_TOLERANCE_SITES = 1e-6;\n\nexport interface DiffractedPlanarProviderInput {\n base: PlanarSceneRadianceProvider;\n /** The optical state of the sampled PSF, as for `resolveLensSampledPsf`, without field point and wavelength. */\n psf: Omit<ResolveLensSampledPsfInput, \"fieldPointMm\" | \"wavelengthNm\">;\n /** Spectral nodes the environment queries (the profile's wavelength nodes). */\n wavelengthsNm: readonly number[];\n kernelRadius: number;\n nativeWidth: number;\n nativeHeight: number;\n /** Output (active) width in sites: frame units are 2/outputWidth per site. */\n outputWidth: number;\n sitePitchMicrometers: number;\n /** Planar geometry of the base provider, to map query directions to plane points exactly as it does. */\n distanceM: number;\n metresPerFrameUnit: number;\n /**\n * Offsets of the query points from the site centres, in sites (+x right, +y down): the anti-aliasing split\n * offsets with their sign reversed (the environment queries q − a). Default: one zero offset.\n */\n queryOffsetsSites?: readonly { x: number; y: number }[];\n /**\n * Region renders (2.6): the native sites that will be queried (x, y, width, height in the native raster). Only the\n * lattice they can reach is convolved; values are bit-identical to the whole render's. Default: the whole raster.\n */\n window?: { x: number; y: number; width: number; height: number };\n /** Called with the duration in ms of each band convolution (diagnostics only; never changes values). */\n onConvolution?: (milliseconds: number) => void;\n}\n\n/** Internal (not exported from the package): the base provider with diffraction applied as an object-space convolution. */\nexport function createDiffractedPlanarProvider(input: DiffractedPlanarProviderInput): PlanarSceneRadianceProvider {\n const { base, wavelengthsNm, nativeWidth: W, nativeHeight: H, kernelRadius: R } = input;\n const g = 2 / input.outputWidth, pitch = input.sitePitchMicrometers;\n const index = new Map(wavelengthsNm.map((nm, i) => [nm, i]));\n // One lattice per distinct fractional query offset; M extra sites per side hold the offset queries.\n const offsets = input.queryOffsetsSites ?? [{ x: 0, y: 0 }];\n const fraction = (value: number): number => { const f = value - Math.floor(value); return f > 1 - LATTICE_TOLERANCE_SITES ? 0 : f < LATTICE_TOLERANCE_SITES ? 0 : f; };\n const shifts: { x: number; y: number }[] = [];\n for (const o of offsets) {\n const f = { x: fraction(o.x), y: fraction(o.y) };\n if (!shifts.some((s) => Math.abs(s.x - f.x) <= LATTICE_TOLERANCE_SITES && Math.abs(s.y - f.y) <= LATTICE_TOLERANCE_SITES)) shifts.push(f);\n }\n const M = Math.max(0, ...offsets.map((o) => Math.ceil(Math.max(Math.abs(o.x), Math.abs(o.y)) - LATTICE_TOLERANCE_SITES)));\n const LW = W + 2 * M, LH = H + 2 * M;\n // Lattice window (indices i + M, j + M): the sites the region queries plus the largest offset on each side, clipped\n // to the lattice. A site i queries i + floor(offset), and floor(offset) lies in [-M, M].\n const win = input.window ?? { x: 0, y: 0, width: W, height: H };\n const lx0 = Math.max(0, win.x), lx1 = Math.min(LW, win.x + win.width + 2 * M);\n const ly0 = Math.max(0, win.y), ly1 = Math.min(LH, win.y + win.height + 2 * M);\n if (!(lx0 < lx1 && ly0 < ly1)) throw new InvalidConfigurationError(\"Diffraction window must overlap the native raster.\");\n const NW = lx1 - lx0;\n // One kernel per wavelength, on the site grid, from the engine's own tap-to-site mapping (field point 0, 0).\n const kernels = wavelengthsNm.map((wavelengthNm) => {\n const k = resolveLensPsfConvolutionKernels({ schemaVersion: \"0.1.0\", psf: input.psf, spectralWeights: [{ wavelengthNm, weight: 1 }],\n grid: { width: 1, height: 1, sitePitchMicrometers: { x: pitch, y: pitch }, opticalAxisSite: { x: 0.5, y: 0.5 } }, patchWidth: 1, patchHeight: 1,\n kernelRadius: R }).value;\n if (!k.exactSiteSampling || k.kernelRadius !== R) throw new InvalidConfigurationError(\"Diffraction kernels must sample the site pitch exactly.\");\n return k.kernels;\n });\n const gridWidth = NW + 2 * R;\n const now = (): number => globalThis.performance?.now() ?? Date.now();\n const bands = new Map<number, Float64Array[][]>();\n function band(b: number): Float64Array[][] {\n const cached = bands.get(b);\n if (cached) { bands.delete(b); bands.set(b, cached); return cached; }\n const started = input.onConvolution ? now() : 0;\n const y0 = ly0 + b * BAND_ROWS, rows = Math.min(BAND_ROWS, ly1 - y0), gridHeight = rows + 2 * R;\n const values = shifts.map((shift) => wavelengthsNm.map((nm, w) => {\n const samples = new Float64Array(gridWidth * gridHeight);\n for (let gy = 0; gy < gridHeight; gy++) {\n const v = shift.y === 0 ? -(y0 + gy - R - M + 0.5 - H / 2) * g : -(y0 + gy - R - M + 0.5 + shift.y - H / 2) * g;\n for (let gx = 0, x = lx0; gx < gridWidth; gx++, x++) samples[gy * gridWidth + gx] = base.radianceAt(shift.x === 0 ? (x - R - M + 0.5 - W / 2) * g : (x - R - M + 0.5 + shift.x - W / 2) * g, v, nm);\n }\n const blurred = calculateIrradianceConvolution({ schemaVersion: \"0.1.0\", width: gridWidth, height: gridHeight, samples, kernelRadius: R,\n patchWidth: gridWidth, patchHeight: gridHeight, kernels: kernels[w]!, boundary: \"zero-outside-grid\" }).values;\n const out = new Float64Array(NW * rows);\n for (let y = 0; y < rows; y++) out.set(blurred.subarray((y + R) * gridWidth + R, (y + R) * gridWidth + R + NW), y * NW);\n return out;\n }));\n bands.set(b, values);\n if (bands.size > CACHED_BANDS) bands.delete(bands.keys().next().value!);\n if (input.onConvolution) input.onConvolution(now() - started);\n return values;\n }\n function blurredAt(u: number, v: number, nm: number): number {\n const w = index.get(nm), fi = u / g - 0.5 + W / 2, fj = -v / g - 0.5 + H / 2;\n if (w !== undefined) for (let s = 0; s < shifts.length; s++) {\n const shift = shifts[s]!, i = Math.round(fi - shift.x), j = Math.round(fj - shift.y);\n if (Math.abs(fi - shift.x - i) > LATTICE_TOLERANCE_SITES || Math.abs(fj - shift.y - j) > LATTICE_TOLERANCE_SITES) continue;\n const li = i + M, lj = j + M;\n if (li < lx0 || lj < ly0 || li >= lx1 || lj >= ly1) break;\n return band(Math.floor((lj - ly0) / BAND_ROWS))[s]![w]![((lj - ly0) % BAND_ROWS) * NW + li - lx0]!;\n }\n throw new InvalidConfigurationError(\"Diffraction query is off the site lattice; the object-space convolution does not apply.\");\n }\n const scale = input.metresPerFrameUnit, distance = input.distanceM, baseEvaluate = base.evaluateRadiance;\n const evaluateRadiance = (request: Readonly<SceneRadianceEvaluationRequest>): SceneRadianceEvaluationResult => {\n const result = baseEvaluate.call(base, request), o = (request.target as { outgoingDirectionUnitVector: { x: number; y: number; z: number } }).outgoingDirectionUnitVector;\n const t = distance / -o.z;\n return { ...result, spectralRadianceWattsPerSquareMeterSteradianNanometer: blurredAt(-o.x * t / scale, -o.y * t / scale, request.wavelengthNanometers) };\n };\n // 2.6: the result is the base result with only its radiance replaced (same keys and records), so an engine-built base\n // evaluator keeps its mark (see core/internal-radiance-evaluator.ts).\n if (isInternalSceneRadianceEvaluator(baseEvaluate)) markInternalSceneRadianceEvaluator(evaluateRadiance);\n return {\n sceneId: base.sceneId, providerProfileId: base.providerProfileId, radianceAt: base.radianceAt,\n evaluateRadiance,\n evaluateApertureRadiance(): SceneRadianceEvaluationResult {\n throw new InvalidConfigurationError(\"Diffraction by object-space convolution does not take pupil rays.\");\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/** Stream IDs of the display view's two seeded streams, distinct from the native charge (0) and read-noise (1) streams. */
|
|
2
|
+
export declare const DISPLAY_VIEW_JITTER_STREAM_ID: 32;
|
|
3
|
+
export declare const DISPLAY_VIEW_NOISE_STREAM_ID: 33;
|
|
4
|
+
export declare const DISPLAY_VIEW_AHD_STREAM_ID: 34;
|
|
5
|
+
/** A query offset from a site centre in sites (+x right, +y down) and its weight (pixel-aperture node × filter spot). */
|
|
6
|
+
export interface DisplayViewQueryOffset {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
weight: number;
|
|
10
|
+
}
|
|
11
|
+
/** Scene access for the expected signal: chart materials (fast tables) or a radiance function. */
|
|
12
|
+
export type DisplayViewScene = {
|
|
13
|
+
kind: "materials";
|
|
14
|
+
materialAt(u: number, v: number): number;
|
|
15
|
+
/** Per material: `{ neutral: reflectance }` (radiance = reflectance × illuminant) or the spectral radiance at each node. */
|
|
16
|
+
materials: readonly ({
|
|
17
|
+
neutral: number;
|
|
18
|
+
} | {
|
|
19
|
+
radiance: Float64Array;
|
|
20
|
+
})[];
|
|
21
|
+
/** Illuminant radiance of a perfect white diffuser at each spectral node: irradianceScale·shape(λ)/π. */
|
|
22
|
+
whiteRadiance: Float64Array;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "radiance";
|
|
25
|
+
radianceAt(u: number, v: number, nm: number): number;
|
|
26
|
+
};
|
|
27
|
+
export interface DisplayViewExpectedSignalInput {
|
|
28
|
+
nativeWidth: number;
|
|
29
|
+
nativeHeight: number;
|
|
30
|
+
/** Frame output width: plane coordinates are 2 / outputWidth frame units per site. */
|
|
31
|
+
outputWidth: number;
|
|
32
|
+
/** Spectral nodes and, per CFA channel (red, green, blue), the expected electrons per unit spectral radiance at each node. */
|
|
33
|
+
wavelengthsNm: readonly number[];
|
|
34
|
+
electronsPerRadiance: readonly [Float64Array, Float64Array, Float64Array];
|
|
35
|
+
offsets: readonly DisplayViewQueryOffset[];
|
|
36
|
+
/** Diffraction: per-node kernels on the site lattice, (2R + 1)² taps in row-major order, out(x) = Σ in(x − t)·K(t). */
|
|
37
|
+
kernels?: {
|
|
38
|
+
radius: number;
|
|
39
|
+
perNode: readonly Float64Array[];
|
|
40
|
+
};
|
|
41
|
+
scene: DisplayViewScene;
|
|
42
|
+
/** CFA channel index (0 red, 1 green, 2 blue) of native site (x, y). */
|
|
43
|
+
channelAt(x: number, y: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Without diffraction: the plane point (frame units) that the environment queries for offset `o` of native site (x, y),
|
|
46
|
+
* computed with the environment's own arithmetic, so points that fall exactly on a chart boundary resolve to the same
|
|
47
|
+
* material as in the capture. With diffraction the facade's object-space convolution uses the lattice formula, as here.
|
|
48
|
+
*/
|
|
49
|
+
queryPoint?(x: number, y: number, offset: number, out: Float64Array): void;
|
|
50
|
+
}
|
|
51
|
+
/** Expected photo electrons of real native sites. */
|
|
52
|
+
export interface DisplayViewExpectedSignal {
|
|
53
|
+
/**
|
|
54
|
+
* Starts a new cache window: native sites [x0, x1) × [y0, y1) that the following `site` calls mostly read. Sites and
|
|
55
|
+
* scene lookups inside it are computed once; anything outside is computed without caching.
|
|
56
|
+
*/
|
|
57
|
+
window(x0: number, y0: number, x1: number, y1: number): void;
|
|
58
|
+
/** Expected photo electrons of native site (x, y) for its own CFA channel (x, y inside the native raster). */
|
|
59
|
+
site(x: number, y: number): number;
|
|
60
|
+
/** A cheap classifier value of the scene at plane point (u, v) frame units: the material, or the radiance at one node. */
|
|
61
|
+
pilot(u: number, v: number): number;
|
|
62
|
+
/** Scene lookups performed so far (material or radiance queries), for diagnostics. */
|
|
63
|
+
readonly lookups: number;
|
|
64
|
+
/**
|
|
65
|
+
* The chart material that every kernel tap of the last `site` call read, when they all read one material (its value is
|
|
66
|
+
* then a function of that material and the site's CFA channel only); −1 when unknown or mixed.
|
|
67
|
+
*/
|
|
68
|
+
readonly uniformMaterial: number;
|
|
69
|
+
/** Whether `uniformMaterial` is tracked in the current window (otherwise it is not meaningful). */
|
|
70
|
+
readonly tracksMaterial: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Expected photo electrons per site: μ_c(i, j) = Σ_o w_o Σ_λ A_c(λ) Σ_t K_λ(t)·L(p_o(i, j) − t, λ), where p_o is the
|
|
74
|
+
* query point of offset o and K the diffraction kernel (a single unit tap without diffraction). This is the sum the
|
|
75
|
+
* facade's environment chain forms for a still, rectilinear, distortion-free planar scene, where the
|
|
76
|
+
* radiance-to-irradiance factor is the same at every site (docs/DISPLAY_VIEW.md, "Expected signal").
|
|
77
|
+
*
|
|
78
|
+
* With diffraction, offsets that share a fractional shift read one lattice, and their kernels are combined in advance:
|
|
79
|
+
* C_c(d) = Σ_members w·Σ_λ A_c(λ)·K_λ(t)·L(λ) over the taps t that reach lattice offset d. A neutral material's radiance
|
|
80
|
+
* is its reflectance times the white radiance, so all neutral materials share one combined kernel per channel.
|
|
81
|
+
*/
|
|
82
|
+
export declare function createDisplayViewExpectedSignal(input: DisplayViewExpectedSignalInput): DisplayViewExpectedSignal;
|
|
83
|
+
/**
|
|
84
|
+
* Internal (exported for tests). Moments of min(Y, top) for Y ~ N(m, v): mean, variance and the slope d E/d m = P(Y < top). Exact for a normal Y:
|
|
85
|
+
* E[min(Y,t)] = m − s·(φ(z) − z·(1 − Φ(z))), z = (t − m)/s.
|
|
86
|
+
*/
|
|
87
|
+
export declare function upperClip(m: number, v: number, top: number, out: Float64Array): void;
|
|
88
|
+
/**
|
|
89
|
+
* Internal (exported for tests). Moments of clip(Y, 0, 1) for Y with mean m, variance v and standardized skewness γ
|
|
90
|
+
* (default 0: normal, closed form). The mean carries the first-order Edgeworth term of a skewed Y: for
|
|
91
|
+
* E[(Y − t)₊] it adds s·γ·z·φ(z)/6 at z = (t − m)/s, so E[clip] gains (s·γ/6)·(a·φ(a) − b·φ(b)) with a = −m/s,
|
|
92
|
+
* b = (1 − m)/s (docs/DISPLAY_VIEW.md, "Readout"). |γ| is limited to 1, where the first-order term is still a small part.
|
|
93
|
+
*/
|
|
94
|
+
export declare function unitClip(m: number, v: number, out: Float64Array, skewness?: number): void;
|
|
95
|
+
/** Internal (exported for tests). Positive Reinhard per channel then the clip to [0, 1]: h(x) = x/(1 + x) for x > 0, else 0 (its slope h' = 1/(1 + x)²). */
|
|
96
|
+
export declare function reinhardMoments(m: number, v: number, out: Float64Array): void;
|
|
97
|
+
/** Per CFA channel: normalized RAW value = (code − black)/(white − black) of a site with e expected electrons. */
|
|
98
|
+
export interface DisplayViewChannelReadout {
|
|
99
|
+
/** Normalized value per electron: digitalGain / (conversionGain·(white − black)). */
|
|
100
|
+
perElectron: number;
|
|
101
|
+
/** Mean dark electrons per site during the exposure. */
|
|
102
|
+
darkElectrons: number;
|
|
103
|
+
/** Variance of the normalized value not proportional to the electrons: read noise and ADC quantization. */
|
|
104
|
+
constantVariance: number;
|
|
105
|
+
}
|
|
106
|
+
export interface DisplayViewSetup {
|
|
107
|
+
frameWidth: number;
|
|
108
|
+
frameHeight: number;
|
|
109
|
+
/** Native site of output pixel (0, 0). */
|
|
110
|
+
margin: number;
|
|
111
|
+
nativeWidth: number;
|
|
112
|
+
nativeHeight: number;
|
|
113
|
+
viewWidth: number;
|
|
114
|
+
viewHeight: number;
|
|
115
|
+
region: {
|
|
116
|
+
x: number;
|
|
117
|
+
y: number;
|
|
118
|
+
width: number;
|
|
119
|
+
height: number;
|
|
120
|
+
};
|
|
121
|
+
/** Samples per axis in display pixels whose pilot finds detail; uniform ones use a quarter (at least 1). */
|
|
122
|
+
samplesPerAxis: number;
|
|
123
|
+
/** Sites beyond the footprint that can affect its pixels (demosaic, filter and kernel reach), for the pilot. */
|
|
124
|
+
reachSites: number;
|
|
125
|
+
bitDepth: 8 | 16;
|
|
126
|
+
seed: number;
|
|
127
|
+
signal: DisplayViewExpectedSignal;
|
|
128
|
+
readout: readonly [DisplayViewChannelReadout, DisplayViewChannelReadout, DisplayViewChannelReadout];
|
|
129
|
+
/** Bilinear demosaic kernels per absolute CFA phase (phaseY·2 + phaseX): for each output channel, (dx, dy, weight) triples. */
|
|
130
|
+
demosaic: readonly (readonly (readonly DisplayViewKernelTap[])[])[];
|
|
131
|
+
/**
|
|
132
|
+
* The demosaic whose pixel statistics the view reproduces, per phase: one candidate (bilinear) or AHD's two directional
|
|
133
|
+
* linear candidates (`ahdCandidateKernels`), each a kernel per output channel. Default: the bilinear kernels.
|
|
134
|
+
*/
|
|
135
|
+
candidates?: readonly (readonly (readonly (readonly DisplayViewKernelTap[])[])[])[];
|
|
136
|
+
/** White-balance gains applied to the normalized camera channels and the highlight clip level (the smallest gain). */
|
|
137
|
+
gains: readonly [number, number, number];
|
|
138
|
+
clipLevel: number;
|
|
139
|
+
/** Camera channels (after WB and the highlight clip) → linear sRGB: rows are output components. */
|
|
140
|
+
matrix: readonly (readonly number[])[];
|
|
141
|
+
toneCurve: "identity" | "positive-reinhard-per-channel";
|
|
142
|
+
/**
|
|
143
|
+
* AHD only: the low-signal correction. `labMatrix` is the camera → XYZ matrix AHD measures homogeneity with (the profile's
|
|
144
|
+
* matrix times the white-balance gains); samples whose pixel variance (linear light) exceeds `thresholdVariance` add the
|
|
145
|
+
* correction of a flat neighbourhood with their channel means, estimated once per quantized state with `drawsPerState` draws.
|
|
146
|
+
*/
|
|
147
|
+
ahdCorrection?: {
|
|
148
|
+
labMatrix: readonly (readonly number[])[];
|
|
149
|
+
drawsPerState: number;
|
|
150
|
+
thresholdVariance: number;
|
|
151
|
+
};
|
|
152
|
+
yieldControl(): Promise<void>;
|
|
153
|
+
checkAbort(): void;
|
|
154
|
+
}
|
|
155
|
+
export interface DisplayViewRenderResult {
|
|
156
|
+
samples: Uint8Array | Uint16Array;
|
|
157
|
+
/** Mean linear-light value of each display pixel before the noise draw (diagnostics and validation). */
|
|
158
|
+
expected: Float64Array;
|
|
159
|
+
/** Noise standard deviation of each display pixel's components in linear light (square root of the covariance diagonal). */
|
|
160
|
+
noiseStd: Float64Array;
|
|
161
|
+
sampleCount: number;
|
|
162
|
+
siteCount: number;
|
|
163
|
+
/** Display pixels whose pilot found detail (full samples) and uniform ones (a quarter per axis). */
|
|
164
|
+
detailPixelCount: number;
|
|
165
|
+
uniformPixelCount: number;
|
|
166
|
+
/** Display pixels whose expected value includes the AHD low-signal correction. */
|
|
167
|
+
ahdCorrectedPixelCount: number;
|
|
168
|
+
}
|
|
169
|
+
/** One tap of a linear demosaic kernel: the site at (dx, dy) from the pixel, and its weight. */
|
|
170
|
+
export interface DisplayViewKernelTap {
|
|
171
|
+
dx: number;
|
|
172
|
+
dy: number;
|
|
173
|
+
weight: number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* AHD's two directional candidates (`createAhdDemosaicTask`, after Hirakawa & Parks 2005) as linear kernels, for a pixel of
|
|
177
|
+
* CFA phase (phaseX, phaseY) of an RGGB mosaic: green along the rows (or columns) with the 5-tap filter
|
|
178
|
+
* [−1/4, 1/2, 1/2, 1/2, −1/4], then red and blue from bilinearly interpolated colour differences against that green. Each
|
|
179
|
+
* candidate is linear in the mosaic, so its kernel is its response to a unit site; AHD then picks one candidate per pixel
|
|
180
|
+
* by homogeneity, which is the only non-linear step. Returns [horizontal, vertical], each [red, green, blue] kernels.
|
|
181
|
+
*/
|
|
182
|
+
export declare function ahdCandidateKernels(phaseX: number, phaseY: number): DisplayViewKernelTap[][][];
|
|
183
|
+
/**
|
|
184
|
+
* Internal (exported for tests). Footprint sums along one axis, for the closed-form B_c (docs/DISPLAY_VIEW.md, "Demosaic correlation"). Native
|
|
185
|
+
* coordinate parity decides the CFA: red columns/rows are even, blue odd. With w(k) the overlap of real column k:
|
|
186
|
+
* - b(k) = w(k) + ½(w(k − 1) + w(k + 1)), the bilinear red/blue spread; sums of b² over even and odd native k;
|
|
187
|
+
* - p(k) = w(k), q(k) = ¼(w(k − 1) + w(k + 1)) for green: sums of p², q² and p·q over even and odd native k;
|
|
188
|
+
* - Σ w².
|
|
189
|
+
*/
|
|
190
|
+
export interface AxisSums {
|
|
191
|
+
bEven: number;
|
|
192
|
+
bOdd: number;
|
|
193
|
+
ppEven: number;
|
|
194
|
+
ppOdd: number;
|
|
195
|
+
qqEven: number;
|
|
196
|
+
qqOdd: number;
|
|
197
|
+
pqEven: number;
|
|
198
|
+
pqOdd: number;
|
|
199
|
+
ww: number;
|
|
200
|
+
}
|
|
201
|
+
export declare function axisSums(start: number, end: number, limit: number, margin: number): AxisSums;
|
|
202
|
+
/** Internal (exported for tests). B for red, green and blue (Σ β² over the channel's sites, β normalized to unit sum) and Σ (w/A)². */
|
|
203
|
+
export declare function footprintWeights(x: AxisSums, y: AxisSums, area: number, out: Float64Array): void;
|
|
204
|
+
/** Internal (exported for tests): the correction states kept across calls, and clearing them. */
|
|
205
|
+
export declare function displayViewCorrectionStateCount(): number;
|
|
206
|
+
export declare function clearDisplayViewCorrectionStates(): void;
|
|
207
|
+
/** Renders the display view (docs/DISPLAY_VIEW.md). */
|
|
208
|
+
export declare function renderDisplayView(setup: DisplayViewSetup): Promise<DisplayViewRenderResult>;
|