@photivra/engine 2.15.0 → 2.17.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.
Files changed (119) hide show
  1. package/CHANGELOG.md +102 -1
  2. package/CITATION.cff +1 -1
  3. package/README.md +6 -6
  4. package/SECURITY.md +1 -1
  5. package/THIRD_PARTY.md +38 -0
  6. package/dist/camera/lens-projection.d.ts +5 -0
  7. package/dist/camera/lens-projection.js +10 -0
  8. package/dist/camera/lens-projection.js.map +1 -1
  9. package/dist/capture/native-environment-lean.js +1 -1
  10. package/dist/capture/native-environment-lean.js.map +1 -1
  11. package/dist/capture/native-raw-development.d.ts +15 -0
  12. package/dist/capture/native-raw-development.js +12 -6
  13. package/dist/capture/native-raw-development.js.map +1 -1
  14. package/dist/capture/raw-development-kernel.d.ts +10 -3
  15. package/dist/capture/raw-development-kernel.js +25 -6
  16. package/dist/capture/raw-development-kernel.js.map +1 -1
  17. package/dist/core/internal-radiance-evaluator.d.ts +5 -2
  18. package/dist/core/internal-radiance-evaluator.js.map +1 -1
  19. package/dist/core/version.d.ts +1 -1
  20. package/dist/core/version.js +1 -1
  21. package/dist/core/version.js.map +1 -1
  22. package/dist/equipment/generic-lens-catalogue.d.ts +227 -0
  23. package/dist/equipment/generic-lens-catalogue.js +243 -0
  24. package/dist/equipment/generic-lens-catalogue.js.map +1 -0
  25. package/dist/facade/defocus-bokeh-zones.d.ts +33 -0
  26. package/dist/facade/defocus-bokeh-zones.js +53 -0
  27. package/dist/facade/defocus-bokeh-zones.js.map +1 -0
  28. package/dist/facade/defocus-image-space-provider.d.ts +118 -0
  29. package/dist/facade/defocus-image-space-provider.js +448 -0
  30. package/dist/facade/defocus-image-space-provider.js.map +1 -0
  31. package/dist/facade/diffraction-provider.d.ts +45 -0
  32. package/dist/facade/diffraction-provider.js +120 -14
  33. package/dist/facade/diffraction-provider.js.map +1 -1
  34. package/dist/facade/display-view-gpu-session.js +4 -0
  35. package/dist/facade/display-view-gpu-session.js.map +1 -1
  36. package/dist/facade/display-view-gpu.d.ts +10 -0
  37. package/dist/facade/display-view-gpu.js.map +1 -1
  38. package/dist/facade/display-view-lens-signal.d.ts +30 -0
  39. package/dist/facade/display-view-lens-signal.js +427 -0
  40. package/dist/facade/display-view-lens-signal.js.map +1 -0
  41. package/dist/facade/display-view.d.ts +21 -0
  42. package/dist/facade/display-view.js +66 -8
  43. package/dist/facade/display-view.js.map +1 -1
  44. package/dist/facade/expected-signal-setup.d.ts +7 -0
  45. package/dist/facade/expected-signal-setup.js +12 -2
  46. package/dist/facade/expected-signal-setup.js.map +1 -1
  47. package/dist/facade/expected-signal.d.ts +8 -0
  48. package/dist/facade/expected-signal.js +150 -0
  49. package/dist/facade/expected-signal.js.map +1 -1
  50. package/dist/facade/generic-lens-capture.d.ts +6 -0
  51. package/dist/facade/generic-lens-capture.js +8 -0
  52. package/dist/facade/generic-lens-capture.js.map +1 -0
  53. package/dist/facade/large-defocus-lattice.d.ts +39 -0
  54. package/dist/facade/large-defocus-lattice.js +64 -0
  55. package/dist/facade/large-defocus-lattice.js.map +1 -0
  56. package/dist/facade/scene-radiance.d.ts +5 -0
  57. package/dist/facade/scene-radiance.js +5 -2
  58. package/dist/facade/scene-radiance.js.map +1 -1
  59. package/dist/facade/simulate-capture.d.ts +148 -6
  60. package/dist/facade/simulate-capture.js +521 -88
  61. package/dist/facade/simulate-capture.js.map +1 -1
  62. package/dist/facade/simulate-display-view.js +29 -19
  63. package/dist/facade/simulate-display-view.js.map +1 -1
  64. package/dist/gpu/display-view-quality-gpu.d.ts +2 -9
  65. package/dist/gpu/display-view-quality-gpu.js +63 -13
  66. package/dist/gpu/display-view-quality-gpu.js.map +1 -1
  67. package/dist/gpu/display-view-speed-gpu.d.ts +2 -0
  68. package/dist/gpu/display-view-speed-gpu.js +47 -16
  69. package/dist/gpu/display-view-speed-gpu.js.map +1 -1
  70. package/dist/gpu/image-kernel-accelerator.js +3 -0
  71. package/dist/gpu/image-kernel-accelerator.js.map +1 -1
  72. package/dist/gpu/wgsl-display-view-quality-kernel.d.ts +4 -0
  73. package/dist/gpu/wgsl-display-view-quality-kernel.js +53 -2
  74. package/dist/gpu/wgsl-display-view-quality-kernel.js.map +1 -1
  75. package/dist/gpu/wgsl-display-view-speed-kernel.d.ts +15 -0
  76. package/dist/gpu/wgsl-display-view-speed-kernel.js +42 -1
  77. package/dist/gpu/wgsl-display-view-speed-kernel.js.map +1 -1
  78. package/dist/index.d.ts +5 -2
  79. package/dist/index.js +4 -1
  80. package/dist/index.js.map +1 -1
  81. package/dist/optics/defocus-bokeh-kernel.d.ts +207 -0
  82. package/dist/optics/defocus-bokeh-kernel.js +380 -0
  83. package/dist/optics/defocus-bokeh-kernel.js.map +1 -0
  84. package/dist/optics/defocus-disc-kernel.d.ts +44 -21
  85. package/dist/optics/defocus-disc-kernel.js +47 -25
  86. package/dist/optics/defocus-disc-kernel.js.map +1 -1
  87. package/dist/optics/generic-lens-psf.d.ts +68 -0
  88. package/dist/optics/generic-lens-psf.js +337 -0
  89. package/dist/optics/generic-lens-psf.js.map +1 -0
  90. package/dist/optics/illumination-vignetting.d.ts +6 -0
  91. package/dist/optics/illumination-vignetting.js +24 -7
  92. package/dist/optics/illumination-vignetting.js.map +1 -1
  93. package/dist/optics/sensor-environment-query.d.ts +37 -0
  94. package/dist/optics/sensor-environment-query.js +58 -19
  95. package/dist/optics/sensor-environment-query.js.map +1 -1
  96. package/dist/optics/site-kernel-runs.d.ts +77 -0
  97. package/dist/optics/site-kernel-runs.js +200 -0
  98. package/dist/optics/site-kernel-runs.js.map +1 -0
  99. package/dist/output/generic-lens-corrections.d.ts +24 -0
  100. package/dist/output/generic-lens-corrections.js +51 -0
  101. package/dist/output/generic-lens-corrections.js.map +1 -0
  102. package/dist/processing/development-detail.d.ts +132 -0
  103. package/dist/processing/development-detail.js +325 -0
  104. package/dist/processing/development-detail.js.map +1 -0
  105. package/docs/AGENT_GUIDE.md +1 -0
  106. package/docs/API_REFERENCE.md +54 -1
  107. package/docs/QUICK_START.md +444 -26
  108. package/docs/USAGE.md +71 -8
  109. package/docs/api/capture-native-raw-development.md +16 -0
  110. package/docs/api/core-version.md +1 -1
  111. package/docs/api/equipment-generic-lens-catalogue.md +281 -0
  112. package/docs/api/exports.json +162 -2
  113. package/docs/api/facade-simulate-capture.md +151 -5
  114. package/docs/api/optics-defocus-bokeh-kernel.md +145 -0
  115. package/docs/api/optics-defocus-disc-kernel.md +25 -17
  116. package/docs/api/optics-sensor-environment-query.md +6 -0
  117. package/docs/api/output-generic-lens-corrections.md +39 -0
  118. package/llms.txt +1 -0
  119. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,107 @@
1
1
  # Changelog
2
2
 
3
- ## 2.15.0 — unreleased (prepared November 7, 2026)
3
+ ## 2.17.0 — unreleased (prepared November 7, 2026)
4
+
5
+ A minor release of four issues: large defocus discs (#564), bokeh character (#553), lens projection, distortion, vignetting and rotation in the display view (#563), and the generic lens catalogue (#549). Captures, RAW codes, files and assumptions are the same as 2.16.0 for every request that 2.16.0 renders and that uses none of the new options (every hash lock holds).
6
+ - **New:** `lens.defocus` up to a kernel radius of 512 sites (#564); `lens.defocus.blades`, `sphericalAberration` and `catsEye` and `calculateDefocusBokehKernel` (#553); the display view with `lens.projection`, `lens.distortion`, `lens.vignetting` and global-shutter rotation (#563); `lens.catalogue`, `lens.focusScatter` and the 30-lens `GENERIC_LENS_CATALOGUE`, each lens with a short `summary` (#549).
7
+ - **Root exports:** 27 new, 1,810 → 1,837 (runtime exports 614 → 623): 9 from #553 (2 runtime) and 18 from #549 (7 runtime). #564 and #563 add none.
8
+ - **Why minor:** new root exports and new opt-in options; requests that 2.16.0 refused (discs above 64 sites, the display view with lens options) now render. Nothing is removed or changed incompatibly, and no default changes.
9
+ - **GPU:** #564 changes `src/gpu` (the display view's renderers refuse a disc above 64 sites, so it renders on the CPU, labelled); the hardware gates are in docs/RELEASE_2_17_0.md and docs/WEBGPU_DEVICES.md.
10
+ - **Bundle:** the display view adds 45,791 B minified and 18,159 B gzip to a capture bundle (2.16.0: 46,380 B and 18,540 B; budgets 46,500 B and 18,550 B, unchanged).
11
+ - **Follow-ups filed:** #565 (in-focus diffraction quadrature and chart-boundary ties), #566 (a PSF mode mirrors asymmetric PSFs; owner decision 2026-11-07: fixed in 2.18.0 as a breaking fix), #567 (catalogue character into bokeh).
12
+
13
+ - **New: large defocus discs (#564).** `lens.defocus` now renders blur discs up to a kernel radius of 512 sites (1,025 sites across, 6.15 mm at 6 µm) instead of 64, in `simulateCapture` (object-space, image-space and tabulated paths) and in `simulateDisplayView` / `prepareDisplayView`. The owner's case, 50 mm f/1.4 on 6 µm full frame focused at infinity with the subject at 0.83 m (a 2,144 µm blur, 357 sites, radius 179), renders where 2.16.0 refused it.
14
+ - **Method:** above 64 sites each kernel row is split into runs of equal weights, and a run's sum is a difference of two prefix sums of the source row (summed-area tables, Crow 1984; Heckbert 1986). The disc's interior cells share one weight, so it costs about 12·R reads per output instead of (2R + 1)² (2,149 against 101,689 at R = 179). It is the same sum regrouped, not an approximation: within 2.5e-14 of a compensated sum on the Siemens star, slanted edge and dead leaves at R = 65, 179 and 512, where the direct gather was up to 9.9e-12 off. Fixed tiles at absolute positions keep regions, parts and DNG parts bit-identical to the whole frame. The tabulated expected signal applies the disc once per channel to the in-focus signal (defocus commutes with the spectral, offset and diffraction sums); with `lens.diffraction` the providers apply each node's diffraction kernel after the disc.
15
+ - **Cost** (Apple M5 Pro, Node 24.19.0, shared machine): a 1024 × 683 Siemens-star capture at 6 µm took 0.72–0.77 s at R = 65, 1.6–1.7 s at R = 179 and 5.4–5.7 s at R = 512 (peak memory 216–457 MiB), against 5.7–6.8 s at R = 64 (direct). The app's display view (24 MP, 2028 × 1352, Speed) extrapolates to 98 s at R = 179 and 296 s at R = 512 on one thread, against 431 s at R = 64. `node scripts/benchmark-large-defocus.mjs` reproduces these.
16
+ - **Unchanged:** every request with a disc radius of 64 sites or less renders byte-identically to 2.16.0 (the direct convolution, the same assumptions; all hash locks hold).
17
+ - **API:** `DEFOCUS_DISC_KERNEL_MAXIMUM_RADIUS_SITES` is 512 (was 64). `calculateDefocusDiscKernelRadius` (model 1.1.0) reports the new limit and gains `convolution` (`"direct"`, `"runs"`, or null past the limit). The `lens.defocus` and `view.defocus` assumptions gain `convolution: "runs"` above 64 sites only. No root export is added or removed.
18
+ - **Errors:** a blur past the limit fails with a short message, for example `lens.defocus: The blur circle is 7.81 mm (1,303 sites) across; the engine renders at most 1,025 sites (DEFOCUS_DISC_KERNEL_MAXIMUM_RADIUS_SITES).`
19
+ - **GPU (`src/gpu`):** the display view's Speed and Quality renderers refuse a disc above 64 sites (a new `DisplayViewGpuRequest.largeDefocus` and a render-time check), so `gpu: "auto"` renders it on the CPU, labelled `unsupported-on-backend`. In-focus and ≤ 64-site requests reach the GPU as before; no kernel or WGSL changed.
20
+ - **Bokeh (#553):** the run convolution takes the shaped kernel when bokeh options are given (blade polygons share the disc's uniform interior). A kernel needing more than 16,641 reads per site (spherical aberration's ray binning, above 64 sites) is refused with `lens.defocus: this blur needs … reads per site; above a kernel radius of 64 sites the limit is 16,641. Reduce the spherical aberration or the defocus.` A cat's eye above 64 sites is refused (this path takes one kernel per request). See "Integration" below.
21
+ - **Docs:** docs/QUICK_START.md ("Large defocus discs"), docs/DISPLAY_VIEW.md, docs/USAGE.md, docs/WEBGPU.md; API reference regenerated. Tests: `test/site-kernel-runs.test.ts`, `test/large-defocus.test.ts`, and updated limit tests.
22
+ - **New: bokeh character, the defocus kernel shaped by the lens (#553, for #549).** `lens.defocus` takes three optional parts, each off by default: `blades` `{ count, firstBladeEdgeAngleDegrees?, curvature?, circularAtOrBelowFNumber? }` (a regular or rounded-blade polygon, scaled to the f/N circle's area), `sphericalAberration` `{ w040Micrometers, atFNumber }` (primary W040, scaled to the working f-number as (N₀/N)⁴) and `catsEye` `{ apertures: [{ radiusMm, shiftPerTanFieldMm }], fieldZonesAcrossLongSide? }` (mechanical vignetting, `calculateMechanicalVignetting`'s model).
23
+ - **Model** (a geometric approximation, labelled in the `lens.defocus` assumption's new `bokeh` record): the open pupil projected onto the sensor by the ray map (σ·c/2 + b·ρ²)·P, with c the thin-lens blur diameter, σ = +1 behind the focus plane and −1 in front, and b = 8·N·W040/pitch the transverse ray aberration (Wyant & Creath 1992, free). Front and back blurs are the same pupil turned through 180°; with undercorrected spherical aberration the blur behind the focus plane is soft-edged and the one in front bright-rimmed (reversed when overcorrected). Without spherical aberration each weight is the exact polygon area in the site's cell; with it, rays are binned per cell. Bit-identical in every JavaScript engine.
24
+ - **Where:** `simulateCapture` (tabulated, object-space and image-space paths) renders all three; the display view (CPU and GPU) renders `blades` and `sphericalAberration`. Above a kernel radius of 64 sites the shaped kernel takes #564's run path (CPU only); a shaped kernel past 512 sites is refused with #564's short message. The cat's eye is applied per square field zone (a piecewise-constant approximation whose largest step is reported), leaves the tabulated fast path, does not apply the light it removes (declare it with `lens.vignetting`), and is refused with `lens.diffraction` and in the display view.
25
+ - **API:** new root exports `calculateDefocusBokehKernel`, `DEFOCUS_BOKEH_MAXIMUM_BLADES` and the types `CalculateDefocusBokehKernelInput`, `DefocusBokehKernel`, `DefocusBokehOptions`, `DefocusBokehBlades`, `DefocusBokehSphericalAberration`, `DefocusBokehCatsEye`, `DefocusBokehClippingAperture` (9 new, 2 runtime). `SimulateCaptureOptions.lens.defocus` gains the three optional fields.
26
+ - **Compatibility:** requests without the new fields, and in-focus requests with them, give the same captures, RAW codes, files and assumptions (`lens.defocus` keeps the exact disc). No `src/gpu` change.
27
+ - **Tests:** `test/defocus-bokeh-kernel.test.ts` (polygon area and shape against a supersampled closed-form polygon; cat's eye against `calculateMechanicalVignetting`'s exact area at 0–25°; the spherical-aberration encircled energy and rim profile against the analytic ray map; front against back) and `test/simulate-capture-defocus-bokeh.test.ts` (visible on the point grid out of focus; cat's eye by field zone; byte-identity; regions; validation; the GPU display view's float32 emulation). Numbers and cost: docs/QUICK_START.md, "Bokeh character".
28
+ - **Display view: lens projection, distortion, vignetting and camera rotation (#563, for Photivra/apps#252; with #548, #549 and #553).** `simulateDisplayView` and `prepareDisplayView` now render `lens.projection`, `lens.distortion`, `lens.vignetting` and camera rotation (`motion.angularVelocityRadPerSec`, global shutter), in focus and with `lens.defocus` out of focus, the combinations `simulateCapture` renders since #548. Until now they refused them in any focus.
29
+ - **Model:** each site's expected electrons are the capture environment chain's sum, μ_c = Σ_o w_o·(1/T)Σ_t Σ_λ A_c(λ) Σ_k K_λ(k)·F(s)·L(D_t(s), λ): the query point's (or, with diffraction or defocus, each lattice source point's) scene ray through the inverse distortion, the projection and the rotation at each temporal midpoint, times its field factor (vignetting × distortion area factor), with the view's own combined kernels and material tables. In focus it is the environment's per-query sum (with `lens.diffraction`, its PSF quadrature); out of focus it is #548's image-space disc, and the view records the capture's `lens.defocus` assumption. The estimators, noise, AHD, development and highlight count are unchanged (`src/facade/display-view-lens-signal.ts`, loaded on demand; docs/DISPLAY_VIEW.md, "Lens projection, distortion, vignetting and rotation").
30
+ - **Accuracy:** every site's expected electrons equal the capture's within 1e-9 relative (the rectilinear view's tolerance) in eight in-focus and two out-of-focus combinations. Exception: with `lens.diffraction` in focus, a lattice source point exactly on a chart boundary (a Siemens star's diagonals through a symmetric frame's centre) is rounded as the lattice rounds it, as the rectilinear view and the out-of-focus capture do; the in-focus capture's PSF quadrature can resolve it to the other material, as it does against its own rectilinear path. Against box-downsized captures (a slanted edge through distortion and vignetting, in and out of focus) within the rectilinear test's 0.6-code RMS and 3-code maximum. On 6000 × 4000 blocks at the frame's corner (4 real pixels per display pixel, a checkerboard, ISO 100), the view's expected value differs from the three-seed capture mean by 0.25–0.29 codes RMS (at most 1.36), no more than the reference's own noise (0.30–0.34), and by at most 0.04 code in each channel's mean, over Speed and Quality with distortion and vignetting, a fisheye, rotation (Speed) and defocus.
31
+ - **Still refused:** rotation with `motion.shutter: "rolling"`, and a mapping or vignetting profile that does not reach the outer site centres plus the kernel radius and the largest query offset (the message names the reach).
32
+ - **GPU:** these requests stay on the CPU reference: `gpu: "auto"` falls back with `unsupported-on-backend` before any device is requested (the limitation names #563), `"require"` fails with it. `src/gpu` is unchanged, so no new hardware evidence is needed.
33
+ - **Cost:** on the app request (2028 × 1352 in 96 × 96 parts, f/8, Apple M5 Pro under a load average of 10–33, so ratios are the measure), µs per display pixel against the rectilinear view: Speed 5.7–6.3 with vignetting (1.2×), 7.2–7.8 with an equisolid fisheye (1.5×), 18.2–19.3 with distortion and vignetting (3.8×, the capture's own inverse-distortion bisection per point), 30.4–32.7 with rotation at eight midpoints (6.5×), against 4.6–5.2; Quality 41.8–44.1 (5.2×), 37.5 (4.5×) and 54.8–56.5 (6.7×) against 8.1–8.4 (every kernel tap carries its own field factor, so the one-material shortcut does not apply). Quality with rotation is refused by the capture's own limit of 100 000 scene queries per site. Prepare times unchanged.
34
+ - **Bundle:** the display view's addition to a capture bundle is 46,341 B minified and 18,527 B gzip, down from 46,380 B and 18,540 B (budget 46,500 B and 18,550 B, unchanged): a simpler Kelvin white-balance branch and one view-region expression in `simulate-display-view.ts` pay for the lens hook. The lens module is a separate chunk (4,380 B, 2,173 B gzip) loaded only for these options; the capture-only entry grows by 642 B (212 B gzip) for the request setup in `runCapture`, and a bundler emits that chunk there too, never loaded.
35
+ - **Internal:** `prepareIlluminationVignettingThroughput` (not exported from the package) evaluates `calculateIlluminationVignetting`'s throughput with the profile validated once; #548's image-space geometry uses it, with the same numbers. `DisplayViewGpuRequest` gains `lens`. `scripts/benchmark-display-view.mjs --app` gains `LENS` variants.
36
+ - **Compatibility:** no new root export; every request that renders today gives the same bytes (hash locks unchanged). Tests: `test/display-view-lens.test.ts`; `test/display-view.test.ts` and `test/simulate-capture-defocus-optics.test.ts` updated for the refusals that are gone.
37
+ - **New: the generic lens catalogue, 30 primes with documented optical character (#549, for the apps "Pro and consumer lens sets" epic).** Two sets, Professional (17: *PV 8 3.5 Fisheye Pro* to *PV 1200 8 Pro*) and Consumer (13: *PV 16 2.8* to *PV 800 9*), named `PV <focal length> <maximum aperture>` with ids such as `pv-50-1.2-pro`, `pv-50-1.8`, `pv-100-2.8-macro-pro`. Every lens is Photivra's own generic design, not modelled on any product; every number is a labelled approximation (docs/LENS_CATALOGUE.md).
38
+ - **Lenses:** the owner's table of focal lengths and widest apertures; the generic smallest aperture (f/16 to 16 mm, f/22 to 135 mm, f/32 beyond) and close focus (0.15×, 1:1 for the macro, at least 10 cm); equisolid fisheyes (8 mm circular, 15 mm full frame). Focal lengths scale by the crop factor, as `lens.prime`.
39
+ - **Character:** a set baseline (the owner's table) times per-lens adjustments, each with its reason: Seidel spherical (balanced by defocus), coma, astigmatism and field curvature at the corner, scaled with the pupil (a⁴, a³, a², a², a = N0/N) and a close-focus factor; axial colour (defocus) and lateral colour (radial shift) with the normalised Cauchy dispersion; radial distortion; vignetting E = (1 − bρ²)² with optical vignetting fading over two stops; flare, focus breathing and focus scatter as numbers (Hopkins 1950; Wyant & Creath 1992, free).
40
+ - **`simulateCapture` `lens.catalogue`:** renders the lens's PSF (scalar Fraunhofer diffraction of the aberrated pupil by FFT, integrated over site cells, on a 5 × 5 field grid × 5 wavelengths, centroid-aligned interpolation, window keeping all but ≤ 3 % of each node's energy) through the environment PSF quadrature, its distortion as the lens field mapping, its vignetting as field throughput and the fisheyes' projection. Directions at or beyond 90° see no scene, so the circular fisheye's image ends at its 180° circle (opt-in `zeroBeyondHorizon` in the facade's provider, and `EnvironmentLensFieldMapping.outsideImageCircle: "backward-ray"` for points outside the equisolid image circle). `lens.defocus` convolves the disc into the PSF (combined radius up to 16 sites); `lens.focusScatter: { seed, shotIndex? }` applies the seeded autofocus error, off by default. Recorded in the assumptions `lens.catalogue` and `lens.catalogue.character`; `diagnostics.options` gains `lens.catalogue` (`SIMULATE_CAPTURE_COST_OPTIONS` lists it). Not combinable with `prime`, `focalLengthMm`, `projection`, `distortion`, `vignetting`, `psf`, `diffraction` or `pupilSampling`; the display view refuses it. The catalogue and its PSF builder are loaded on demand (`src/facade/generic-lens-capture.ts`).
41
+ - **Measured on the charts** (`test/simulate-capture-lens-catalogue.test.ts`, *PV 24 1.4 Pro* against *PV 24 1.8* at their widest apertures, full frame): slanted-edge 10–90 % rise 0.91 / 1.09 px against 1.01 / 1.44 px (centre / corner, 6 µm); corner coma (point, wide open minus f/5.6, 3 µm) 0.02 px against 0.36 px; corner lateral colour 0.31 px against 0.71 px; grid-line bow 0.00 px (expected 0.31) against 0.60 px (expected 0.92) at 120 µm; corner vignetting 1.15 against 1.64 stops, 0.74 at f/5.6, each within 0.02 stops of the profile with the distortion's area factor; the 8 mm's black surround and the 15 mm's filled frame. The PSF builder matches the engine's diffraction-limited site kernels without aberrations (to 0.004 per cell), samples every lens's wavefront within Nyquist (wide open, minimum focus, corner, 380 nm) and points coma and the blue image outward in every quadrant (`test/generic-lens-catalogue.test.ts`).
42
+ - **Focus consistency:** `simulateGenericLensFocusError` (seeded, reproducible; σ = 0.1 / 0.3 of the depth of focus 2·N·c for the sets' baselines, tested over 4000 shots).
43
+ - **Correction profiles:** `createGenericLensCorrectionProfile` builds each lens's generic correction profile (distortion map, per-channel lateral-colour scale, vignetting gain) for `resolveLensCorrectionPlan`; `simulateCapture` does not apply it.
44
+ - **Cost:** like `lens.distortion`, one scene query per kernel tap through the lens field mapping: a 48 × 48 region of a full frame at 6 µm takes 1.2–1.3 s (pro, 3 × 3 kernel) to 5.9–9.7 s (consumer, 7 × 7 to 9 × 9) at the default spectral step, against 0.01 s with `lens.prime` (Apple M5 Pro, Node.js 24.19.0).
45
+ - **Found, left as is:** the sampled-PSF mode `rotationally-symmetric-radial-field-centroid-aligned` rotates kernels as if rows ran towards −Y, while the environment PSF quadrature (`sensorPsfSourcePoint`) applies rows as +Y, so an asymmetric kernel under that mode renders mirrored in y. The catalogue uses the 2-D grid mode; changing either would change existing captures. Owner decision 2026-11-07: fixed in 2.18.0, as a breaking fix with an orientation test (#566); 2.17.0 leaves it as is.
46
+ - **API:** 18 new root exports (7 runtime): `GENERIC_LENS_CATALOGUE`, `GENERIC_LENS_IDS`, `GENERIC_LENS_SET_BASELINES`, `resolveGenericLens`, `simulateGenericLensFocusError`, `createGenericLensCorrectionProfile`, `GENERIC_LENS_CORRECTION_CHANNEL_WAVELENGTHS_NM` and the types `GenericLensCatalogueEntry`, `GenericLensSet`, `GenericLensKind`, `GenericLensCharacterValues`, `GenericLensAdjustments`, `GenericLensCharacter`, `ResolvedGenericLens`, `ResolveGenericLensInput`, `SimulateGenericLensFocusErrorInput`, `GenericLensFocusError`, `CreateGenericLensCorrectionProfileInput`. Each `GenericLensCatalogueEntry` and `ResolvedGenericLens` has `summary`, a short plain-English description of the lens's character (at most 40 characters, US spelling, written from its adjustments and reason; tested against them). `SimulateCaptureOptions.lens` gains `catalogue` and `focusScatter`; `EnvironmentLensFieldMapping` gains the optional `outsideImageCircle`. Root exports 1,810 → 1,828 (runtime 614 → 621).
47
+ - **Compatibility:** requests without `lens.catalogue` give the same captures, RAW codes, files and assumptions; a lens field mapping without `outsideImageCircle` still refuses points outside the image circle. The display view's added bundle size is 46,366 B minified and 18,498 B gzip (2.16.0: 46,380 B and 18,540 B; budgets unchanged). No `src/gpu` change.
48
+ - **Not in 2.17.0:** a catalogue lens's bokeh character. #553's bokeh options are refused with `lens.catalogue` (the lens folds a plain disc into its PSF), and feeding each lens's spherical aberration and character into the bokeh kernel is a follow-up (#567). The display view still refuses `lens.catalogue`. The phone profile's three fixed lenses are #554. Docs: docs/LENS_CATALOGUE.md (new), `docs/QUICK_START.md` ("Generic lens catalogue"), `docs/USAGE.md`; API reference regenerated.
49
+ - **Integration of #564, #553, #563 and #549 (this release).**
50
+ - **The defocus kernel is the shaped kernel or the disc** (`siteKernel ?? disc`) in the capture and the display view, so a blade-shaped kernel above 64 sites takes #564's run path. The shaped kernel's radius cap is 512 sites, refused with #564's short message (`lens.defocus: The blur circle is … across; the engine renders at most 1,025 sites …`). The run path's refusal is now a plain `lens.defocus:` message stating the 16,641-read limit, and a cat's eye above 64 sites is refused by name. The `lens.defocus` assumption gains `convolution: "runs"` whenever the applied kernel is above 64 sites.
51
+ - **The display view's lens signal with a large disc.** #563's lens signal read only the combined kernels, so with #564 a lens view above 64 sites would have rendered without the blur. It now applies the disc by runs to each channel's in-focus signal through the lens, as the rectilinear view does. With radial distortion, vignetting and a disc of radius 179, every site matches the capture's image-space provider within 1e-9 relative, and `gpu: "auto"` falls back to the labelled CPU reference.
52
+ - **Fixed tiles and lens profiles.** #564's fixed 64-site tiles in the image-space provider mapped lattice points up to a tile beyond the reach #548 checks, which threw with a distortion profile sized to that reach. Points beyond the reach (which feed no queried value) are now set to 0 and never mapped, and so are the lens signal's in-focus tiles. Every queried value is the same sum; only the prefix sums' rounding can change, within the run path's stated accuracy. These requests are new in 2.17.0, so no 2.16.0 bytes are involved.
53
+ - **`resolveGenericLens` profiles reach past the corner (app report).** Its distortion and vignetting profiles stopped at the half-diagonal (21.633 mm on full frame), while the display view and the capture read slightly beyond the outer site centres (21.637 mm), so `simulateDisplayView` and `simulateCapture` refused even PV 50 1.8 with its own profiles. They now reach 1.25 of the half-diagonal (the distortion's range is widened for barrel lenses, whose image points come from farther out). The coefficients are unchanged, so every value inside the frame is too; every lens stays valid there (vignetting E > 0, distortion monotonic; tested for all 30). `createGenericLensCorrectionProfile` keeps its own 1.05.
54
+ - **The catalogue and bokeh.** `lens.catalogue` with `blades`, `sphericalAberration` or `catsEye` is refused by name; before, the options were validated and then dropped. The catalogue's combined defocus limit of 16 sites stays as built.
55
+ - **The app's bundle (app report).** Built against this release, the app's total JavaScript grows from 498.6 KiB (2.15.0) to 521,974 B (2.16.0) and 546,366 B gzip (2.17.0), against its 512,000 B budget. An engine bundle of exactly the app's worker imports grows the same: 311,439 → 323,428 → 347,775 B gzip over all chunks. Tree-shaking works: unused root exports such as `calculateDefocusBokehKernel` are absent. The growth is the new options' code, which `simulateCapture` and `prepareDisplayView` reach at run time. The capture worker chunk's +65 KB is mostly about 60 KB of existing modules (the display-view GPU host, text metadata, pixel limits) that the bundler now places in the worker's entry chunk instead of three chunks of their own, so they are not new bytes. `test/capture-bundle.test.ts` now checks that shape against its measured total (348,000 B gzip), so growth shows in the engine first.
56
+ - **Tests:** `test/defocus-integration-2-17.test.ts`; the bokeh limit tests updated for the 512-site cap and the new messages.
57
+
58
+ ## 2.16.0 — published November 7, 2026
59
+
60
+ A minor release of five issues: the display view's highlight count (#533), a development exposure push (#556), sharpening and diffraction correction (#552), `lens.defocus` with projection, distortion, vignetting and camera rotation (#548), and docs (#400). Captures, RAW codes, files and assumptions are the same as 2.15.0 for every request that 2.15.0 renders and that uses none of the new options; the display view's result gains one diagnostic.
61
+ - **New:** `DisplayViewResult.diagnostics.highlight` (#533); `output.exposureCompensationStops` (#556); `output.sharpening` and `output.diffractionCorrection` (#552); out-of-focus `lens.defocus` with `lens.projection`, `lens.distortion`, `lens.vignetting` or camera rotation under a global shutter, in image space (#548).
62
+ - **Docs:** 2.15.0 recorded as published; display-view cost rows re-measured (#400).
63
+ - **Root exports:** 5 new, 1,805 → 1,810 (runtime exports 613 → 614): the type `DisplayViewHighlightDiagnostics` (#533); `NATIVE_RAW_DEVELOPMENT_EXPOSURE_RANGE_STOPS` (#556); the types `SimulateCaptureSharpening`, `SimulateCaptureDiffractionCorrection` and `SimulateCaptureDetailDiagnostics` (#552). #548 adds none.
64
+ - **Why minor:** new root exports and new opt-in options; requests that 2.15.0 refused (#548) now render. Nothing is removed or changed incompatibly, and no default changes.
65
+ - **GPU:** #533 changes `src/gpu` (the display view's Speed and Quality kernels); the hardware gates passed on an Apple M5 Pro (docs/WEBGPU_DEVICES.md, docs/RELEASE_2_16_0.md).
66
+
67
+ - **New: the display view reports its highlight count (#533, for Photivra/apps#158, #223 and #240).** `simulateDisplayView` and `prepareDisplayView(...).render` return `diagnostics.highlight: { saturatedPixelCount, statistic: "expected-value" }`: the real capture's saturated output pixels (at least one clipped contributing RAW site) in the rendered region. `simulateCapture` counts these on its one noise sample as `diagnostics.highlight.saturatedPixelCount`. Until now an app could only show the count of a small quick capture.
68
+ - **Definition:** the expected value over the noise, Σ_j w_j·(1 − Π_k (1 − p_k)). j runs over the region's real pixels, with w_j the part of each inside the region. p_k is the probability that a site pixel j's demosaic reads is at or above the white level, under the view's own site model (normal, with exact expected electrons and shot, dark, read and ADC noise). It is estimated like the expected value (exact area mean, or stratified), so it is a real number. It equals the capture's count exactly where every site is more than 8.5 σ from white. With AHD it counts the 25–29 sites the view's candidates read, not the capture's full 7 × 7 square: an approximation that can be lower at clipped corners and specks (docs/DISPLAY_VIEW.md, "Highlight count").
69
+ - **Additive over parts:** a display pixel's share is the same in every region, so the counts of regions that tile a view sum to the whole view's.
70
+ - **No change to the view:** samples, expected values, noise, every other diagnostic and the assumptions are unchanged. The hash locks of `test/display-view.test.ts`, `display-view-pixel-memo.test.ts` and `display-view-speed-material.test.ts` leave the new field out and keep their recorded hashes.
71
+ - **GPU (`src/gpu`):** the Speed and Quality kernels mark each site certainly unclipped, certainly clipped (beyond twice the reference's 8.5 σ after their error bounds) or undecided. They return a bit per real pixel that is certainly saturated, and flag a display pixel with an undecided real pixel. The host forms the count with the reference's arithmetic and takes an undecided pixel's count from a one-pixel reference render; that pixel's samples stay the GPU's. The count is therefore the reference's bit for bit and `diagnosticsExact` stays true. The run-time self-checks now also compare the count. The flag output grows from one to three words per display pixel (Speed band: 48 → 56 bytes per display pixel).
72
+ - **Cost:** on the app request (Apple M5 Pro, Node 24.19.0, load average about 6), part medians were 38–41 ms against 2.15.0's 39 ms (Speed) and 74–79 ms against 74–78 ms (Quality). The extrapolated whole view was 0–4 % slower.
73
+ - **Tests:** `test/display-view-highlight.test.ts`: the capture's count reproduced exactly (bilinear and AHD, three exact views); the mean of 8 noise seeds near white; additivity per display pixel and over regions; a prepared view; the GPU float32 emulation (Speed and Quality, decided and undecided pixels) against the reference bit for bit.
74
+ - **API:** one new root export, the type `DisplayViewHighlightDiagnostics`; `DisplayViewResult.diagnostics` gains `highlight`. Nothing is removed or changed.
75
+ - **Docs (#400):**
76
+ - 2.15.0 recorded as published (`README.md`, `SECURITY.md`, `docs/DEVELOPERS.md`, its record, this changelog).
77
+ - App-request display-view rows re-measured on 2.15.0 (docs/DISPLAY_VIEW.md, "A device-pixel view rendered in parts"; docs/QUICK_START.md, "Cost").
78
+ - A stale "no GPU display-view renderer exists yet" removed from docs/USAGE.md.
79
+ - **New: development exposure push, `output.exposureCompensationStops` (#556).** Underexpose, then brighten the same RAW in development, like a raw editor's exposure slider, so dynamic range, read noise and bit depth become visible in recovered shadows (for the app's "Brighten in development" control).
80
+ - **Model:** a linear gain 2^stops, −2 to +5 stops (whole or fractional), on each site's black-subtracted, white-normalized value (code − black)/(white − black), before demosaic, white balance, the highlight mode, colour, the tone curve and encoding. No photons are added: raised shadows show the RAW's own shot, dark and read noise and its ADC quantization, scaled by the gain. A site pushed to or past white clips at white and counts in `diagnostics.highlight.saturatedPixelCount`; `highlightMode: "reconstruct"` rolls it off. The SDR profile's `renderingExposureEv` is a different, post-clip scale and stays 0.
81
+ - **Where:** the developed samples (`image.samples`, also with format `"dng"`), JPEG, PNG (every encoding), bilinear and AHD, `simulateIdealReference` and `simulateDisplayView` (its per-site readout moments are scaled by G and G²) honour it. The RAW codes, `result.raw` and the DNG stay the unmodified RAW; `output.whiteBalance: "auto"` is measured on the unpushed RAW.
82
+ - **Reported** in the assumption `output.exposureCompensationStops` (`{ stops, gain, appliedTo, dng }`) when the option is given. A non-zero push is carried in `request.development` and replayed by `createNativeRawDevelopmentTask`, which gains the same optional `exposureCompensationStops`. The WebGPU accelerator's `developNativeRaw` rejects a non-zero push with `unsupported-on-backend`.
83
+ - **Tests** (`test/simulate-capture-exposure-push.test.ts`): a +3-stop push of a 3-stop underexposure matches the normal exposure's mean within noise (0.4 % here, with about √8 times its noise) and keeps the underexposed RAW codes; after a +5-stop push of a 5-stop underexposure, a sensor with 20 e⁻ read noise is noisier than one with 1 e⁻; a pushed noise-free gradient shows 12-bit quantization plateaus and none at 14 or 16 bits; pushed highlights clip, and reconstruct rolls them off; JPEG, PNG (sRGB and Display P3), AHD, the DNG format's samples, the ideal reference and the display view are brighter by the gain, while the DNG bytes are unchanged; validation in the facade and the development task.
84
+ - **Compatibility:** one new root export, `NATIVE_RAW_DEVELOPMENT_EXPOSURE_RANGE_STOPS` (`{ minimum: -2, maximum: 5 }`); `NativeRawDevelopmentInput` and the facade's `output` gain an optional field. Without the option (or with 0), captures, RAW codes, files, requests and assumptions are byte-identical. Docs: `docs/QUICK_START.md` ("Development exposure push"), `docs/USAGE.md`, `docs/DISPLAY_VIEW.md`, `docs/WEBGPU.md`; API reference regenerated.
85
+ - **New: sharpening and diffraction correction, with honest trade-offs (#552).** Two opt-in development stages of `simulateCapture`, off by default, for the app's per-correction toggles (on for the JPEG, off in the DNG).
86
+ - **`output.diffractionCorrection`** `{ wavelengthNm?, regularization?, maximumGain?, kernelRadiusPixels? }`, which needs `lens.diffraction`: a bounded, regularized deconvolution of the developed linear colour with the diffraction OTF of the ideal circular pupil at the capture's working f-number, H(s) = (2/π)(acos s − s√(1 − s²)), s = f/f_c, f_c = 1/(λ·N_w) (MIT OCW 2.71). The gain min(maximumGain, H(1 + α)/(H² + α)) is Wiener deconvolution with a constant noise-to-signal ratio α, built as a tapered (2R + 1)² filter with unit DC gain; its response is measured and reported. Defaults: 550 nm, α = 0.01, gain bound 4, R = the Airy third dark ring (1–16 pixels). Frequencies beyond the cut-off never reached the sensor and stay lost: the design gain there is 0, and the assumption says `recoversBeyondCutoff: false`.
87
+ - **`output.sharpening`** `{ radiusPixels?, amount?, threshold? }`: an unsharp mask y = x + amount·(x − G_σ∗x) where |x − G_σ∗x| ≥ threshold (as in GIMP and ImageMagick), per channel on the sRGB-encoded values after the tone curve and gamut handling, before quantization. Defaults: σ = 1 pixel, amount 0.5, threshold 0. sRGB output only.
88
+ - **Order** (the `output.developmentOrder` assumption): demosaic → colour and white balance → diffraction correction → rendering exposure and tone curve → gamut and transfer → unsharp mask → quantization. With a development exposure push (#556) the order starts with it, on the RAW.
89
+ - **Reported** in the `output.diffractionCorrection` and `output.sharpening` assumptions (settings, defaults used, cut-off, measured filter response), in `diagnostics.detail` (ringing below black and above white; sharpened, held and clipped samples; the largest halo increase and decrease) and in `diagnostics.options`.
90
+ - **Limits:** neither combines with `output.region`; neither is offered by `simulateDisplayView` or `simulateIdealReference`. Both hold the whole developed image, as AHD does. The DNG is never modified: with both stages a DNG request writes the same DNG bytes.
91
+ - **Trade-off tests** (`test/lens-correction-tradeoffs.test.ts`, `test/development-detail.test.ts`; numbers in docs/DIGITAL_OPTICS_FOUNDATION.md): distortion correction stretches the corners, so a 0.25 cycle/pixel source grating lands at 0.186 cycles per output pixel in the corner (0.250 at the centre) with lower modulation; vignetting correction raises corner noise by the gain (×1.29 over the corner patch) and leaves the SNR unchanged; lateral CA correction registers the edges (to 0.005 px) but red and blue stay 1.8–2.2 px wider than green (longitudinal CA); sharpening overshoots and undershoots a step by 0.367·amount·h at σ = 1.5, as predicted; diffraction correction leaves a grating beyond the cut-off at exactly zero and restores one at 0.55·f_c only from 0.34 to 0.82 of its contrast.
92
+ - **Compatibility:** 3 new root type exports (`SimulateCaptureSharpening`, `SimulateCaptureDiffractionCorrection`, `SimulateCaptureDetailDiagnostics`); `SIMULATE_CAPTURE_COST_OPTIONS` gains `output.diffractionCorrection` and `output.sharpening`; `diagnostics.detail` is new and present only when a stage ran. Requests without the two options give the same captures, RAW codes, files and assumptions. No version bump here.
93
+ - **`lens.defocus` out of focus with `lens.projection`, `lens.distortion`, `lens.vignetting` or camera rotation (#548, for Photivra/apps#252, Photivra/apps#230, #549 and #553).** Until now `simulateCapture` refused these combinations, because the defocus disc ran as an object-space convolution on the plane lattice the sites see, and each of these options moves the sites' scene points off that lattice (or, for vignetting, gives each point its own radiance-to-irradiance factor).
94
+ - **Now supported, in image space:** for each spectral node (and, with rotation, each temporal midpoint, in that instant's camera frame) the sensor-plane irradiance before any PSF is formed on the sensor's site lattice through the inverse distortion, the declared projection, the rotation and the field factor (vignetting × distortion area factor), convolved with the disc, and each site query is answered with the result divided by the queried point's field factor (`src/facade/defocus-image-space-provider.ts`). It is the environment PSF quadrature with the disc as a sampled PSF, summed in another order. With `lens.diffraction`, each node's diffraction kernel convolved with the disc is the kernel.
95
+ - **Decisions per combination:** vignetting: supported, no approximation beyond the disc (field throughput applied where the light enters, before the blur, as for any environment PSF; no commutation error). Projection and distortion: supported; the disc has the same diameter at every field point, centred on each chief ray (exact for the rectilinear distortion-free thin lens), and the `lens.defocus` assumption records `fieldVariation` bounds for the request (`distortionMaximumLocalScaleDeviation`, `projectionMaximumDiameterChangeSites`). Camera rotation with a global shutter: supported, per temporal midpoint; `rotationMaximumDiameterChangeSites` bounds the tilt of the plane under pitch and yaw (0 for roll). Still refused, each with a message that says why: rotation with `motion.shutter: "rolling"` (every row has its own instants), and a vignetting or distortion profile that does not reach the frame's corners plus the kernel radius. `lens.pupilSampling` stays refused with projection and distortion (a traced reference needs the 3D ray provider, #358). `simulateDisplayView` and `prepareDisplayView` refuse projection, distortion, vignetting and rotation in any focus, as before, so they share no #548 refusal and do not change.
96
+ - **Accuracy:** RAW codes equal those of the same request with the disc passed as `lens.psf` (the per-tap environment quadrature), for each combination, all together, and with `lens.diffraction`; expected electrons agree to 1e-12 per site. The identity mapping (`lens.projection: "rectilinear"`) gives the object-space path's RAW. Against a fine-grid oracle (the disc sampled 5 times finer, 3 times with the 4 × 4 box), the lattice-sampling error is that of the rectilinear capture: on a 16 × 12 slanted edge with a 5.95-site disc, max / RMS relative difference in expected electrons 0.110 / 0.026 (point) and 0.032 / 0.006 (4 × 4 box) for the rectilinear capture, vignetting, a fisheye and radial distortion alike, and lower with rotation (0.069 / 0.016 and 0.017 / 0.003). The field-variation bounds on the app's full frame (50 mm f/2.8, focus 1 m, a 5.0-site disc): equisolid fisheye 0.43 sites, radial k1 −0.1 a local scale 0.28 off 1 at the corners, typical shake rotation 8e-4 sites.
97
+ - **Performance** (app defaults: Speed preset, 384 × 256 whole frame at 93.75 µm with the 2 × 2 box, Siemens star, 50 mm f/2.8, subject 2 m, focus 1 m, disc 5.0 sites, R 3; Apple M5 Pro, Node.js 24.19.0, medians of 3 on a shared machine): vignetting 1.0 s in focus, 1.6 s out of focus (R 3) and 1.7 s (R 6); rotation 2.1–3.3 s in focus, 7.5–8.8 s (R 3) and 6.5 s (R 6); fisheye 11 s, 15–19 s; radial distortion 18–21 s, 19–20 s; all four together 94–97 s, 101–124 s. Out of focus without these options stays on the object-space path (0.05–0.07 s). Table in docs/QUICK_START.md ("Optics"). Without rotation and lens mapping, and with rotation, the lean executor reads the image-space values by lattice key (`InternalRadianceAccess.keyOfDirection` now takes the request time; internal).
98
+ - **API:** `request.diffraction.execution` gains `"image-space-convolution"`; the `lens.defocus` assumption gains `execution: "image-space-convolution"`, `imageSpaceOptions` and `fieldVariation`. No new root export. Every request that 2.15.0 renders gives the same RAW codes, files and assumptions (in focus, and out of focus without these options).
99
+ - **Tests:** `test/simulate-capture-defocus-optics.test.ts` (each combination against the environment quadrature, 1e-12 per site, diffraction, identity mapping, in focus byte-identical, bounds, refusals, regions with the Quality filters); `test/simulate-capture-defocus-render.test.ts` updated. Docs: `docs/QUICK_START.md` ("Optics", "Modelling choices").
100
+
101
+ - **Integration of #556 with #552 and #548 (this release).** With `output.sharpening` or `output.diffractionCorrection` the capture develops through `developLinearSrgb` (the native development's own linear operator) instead of `createNativeRawDevelopmentTask`; the exposure push applies on both paths, on the black-subtracted, white-normalized RAW, so pushed sites clip at white before the diffraction correction. `output.developmentOrder` lists `"development exposure push (RAW)"` first when a push is given.
102
+ - **Tests** (`test/development-detail-integration.test.ts`): a +2-stop push with an unsharp mask that changes nothing is byte-identical to the push alone (the two paths); a +2-stop push of a quarter exposure (1/32 s), sharpened and diffraction-corrected, matches the full exposure (1/8 s) column by column within noise, with the same clipped highlight (saturated counts within 5 %) and the unclipped quarter-exposure RAW; image-space `lens.defocus` (vignetting, distortion and diffraction) with each of `output.exposureCompensationStops`, `output.sharpening` and `output.diffractionCorrection`, and all three: the RAW is unchanged, the push doubles linear light per sample at +1 stop, the mask adds halos, the correction raises contrast and reports that defocus is not inverted.
103
+
104
+ ## 2.15.0 — published November 7, 2026
4
105
 
5
106
  A minor release: `lens.diffraction` at every spectral step (a fix for the app's color chart), and the defocus size limit with a pre-check as root exports (#532, #560). Captures, RAW codes, files and assumptions are the same as 2.14.1 for every request that 2.14.1 renders.
6
107
  - **Fixed:** `lens.diffraction` with `sensor.spectralStepNanometers` under 6.25 nm, for example the color chart at the recommended 5 nm.
package/CITATION.cff CHANGED
@@ -9,7 +9,7 @@ abstract: "An open TypeScript engine for the science and mathematics of photogra
9
9
  repository-code: "https://github.com/photivra/photivra"
10
10
  url: "https://photivra.com"
11
11
  license: "Apache-2.0"
12
- version: "2.15.0"
12
+ version: "2.17.0"
13
13
  keywords:
14
14
  - photography
15
15
  - camera optics
package/README.md CHANGED
@@ -32,10 +32,10 @@ The source is licensed under Apache-2.0.
32
32
 
33
33
  ## Quick start
34
34
 
35
- Install the published ESM package below. The [2.15.0 release record](https://github.com/Photivra/photivra/blob/main/docs/RELEASE_2_15_0.md) and [changelog](https://github.com/Photivra/photivra/blob/main/CHANGELOG.md) describe the current release:
35
+ Install the published ESM package below. The [2.17.0 release record](https://github.com/Photivra/photivra/blob/main/docs/RELEASE_2_17_0.md) and [changelog](https://github.com/Photivra/photivra/blob/main/CHANGELOG.md) describe the current release:
36
36
 
37
37
  ```sh
38
- npm install @photivra/engine@2.15.0
38
+ npm install @photivra/engine@2.17.0
39
39
  ```
40
40
 
41
41
  Simulate a photograph of a test chart with a generic camera, then read the developed sRGB pixels:
@@ -75,7 +75,7 @@ console.log(horizontal.provenance);
75
75
 
76
76
  Start with the [Developer Guide](https://github.com/Photivra/photivra/blob/main/docs/DEVELOPERS.md). Then use the [Usage Guide](https://github.com/Photivra/photivra/blob/main/docs/USAGE.md) and the [API reference](https://github.com/Photivra/photivra/blob/main/docs/API_REFERENCE.md), which is generated from the package exports.
77
77
 
78
- Repository `main` may describe newer, unreleased work. For the stable contract, use the docs bundled in the published package, or the exact `v2.15.0` tag.
78
+ Repository `main` may describe newer, unreleased work. For the stable contract, use the docs bundled in the published package, or the exact `v2.17.0` tag.
79
79
 
80
80
  ## Documentation
81
81
 
@@ -363,13 +363,13 @@ The application can then use those results, while the photography calculations t
363
363
 
364
364
  ## Status
365
365
 
366
- - Repository package version: `2.15.0` (release candidate prepared November 7, 2026; publication is separate)
367
- - Engine API contract: `2.15.0`
366
+ - Repository package version: `2.17.0` (release candidate prepared November 7, 2026; publication is separate)
367
+ - Engine API contract: `2.17.0`
368
368
  - Versioned generic tier reference assets: [GENERIC_TIER_PRESETS.md](https://github.com/Photivra/photivra/blob/main/docs/GENERIC_TIER_PRESETS.md).
369
369
  - Composed POC simulation API contract: `1.0.0`
370
370
  - Stability: 1.0 root-package compatibility policy; bounded scientific models and independent POC contract
371
371
 
372
- From 1.0.1, the package version and `ENGINE_API_VERSION` are equal. New captures/plans record 2.15.0; existing archives keep their original creator identities. Schema, model and POC contract versions stay independent.
372
+ From 1.0.1, the package version and `ENGINE_API_VERSION` are equal. New captures/plans record 2.17.0; existing archives keep their original creator identities. Schema, model and POC contract versions stay independent.
373
373
 
374
374
  A breaking change to the root contracts now needs a new package major version. Additive and corrective changes follow [compatibility and migration](https://github.com/Photivra/photivra/blob/main/docs/RELEASE_1_3_0.md). A 1.0 package is not a claim of calibrated physical accuracy.
375
375
 
package/SECURITY.md CHANGED
@@ -4,7 +4,7 @@ Please do not open a public issue that contains vulnerability details.
4
4
 
5
5
  ## Supported versions
6
6
 
7
- The published 1.0.0 release started the 1.x root-package compatibility line, and 2.0.0 started the 2.x line. The current release is **2.14.1**, published on November 3, 2026 (see [CHANGELOG.md](CHANGELOG.md)).
7
+ The published 1.0.0 release started the 1.x root-package compatibility line, and 2.0.0 started the 2.x line. The current release is **2.16.0**, published on November 7, 2026 (see [CHANGELOG.md](CHANGELOG.md)).
8
8
 
9
9
  Security fixes target the current maintained development and release line. Do not assume that older 1.x releases, snapshots or pre-1.0 releases will receive fixes.
10
10
 
package/THIRD_PARTY.md CHANGED
@@ -203,6 +203,44 @@ factual constants only, independently implemented; no code or data copied):
203
203
  - Bradford cone matrix (Lam 1985), already used by the ICC serializer, now also
204
204
  for ForwardMatrix1.
205
205
 
206
+ Development detail references (#552; published equations and documented
207
+ behaviour only, independently implemented in `src/processing/development-detail.ts`;
208
+ no code, table or data copied):
209
+
210
+ - Circular-pupil incoherent OTF and its cut-off 1/(λN): MIT OpenCourseWare 2.71
211
+ *Optics* (Spring 2009), lectures 21–22 (already cited for `lens.diffraction`).
212
+ - Wiener deconvolution with a constant noise-to-signal ratio: the scikit-image
213
+ `skimage.restoration.wiener` documentation (BSD-3-Clause project; documentation
214
+ read, no code used) and Orieux, Giovannelli & Rodet (2010), JOSA A 27(7).
215
+ - Unsharp mask (radius, amount, threshold): the GIMP 2.10 manual, "Unsharp Mask",
216
+ and ImageMagick's `-unsharp` option documentation (documented behaviour only).
217
+ - Patent status: no public-record patent check has been recorded for these two
218
+ long-published methods; it is left for the owner's review with the others.
219
+
220
+ Defocus and lens-character references (2.17.0: #564, #553, #549; published
221
+ methods and qualitative descriptions only, independently implemented; no code,
222
+ table or data copied):
223
+
224
+ - Run-length convolution by prefix sums (#564, `src/optics/site-kernel-runs.ts`):
225
+ F. C. Crow, "Summed-area tables for texture mapping", SIGGRAPH 1984, and
226
+ P. S. Heckbert, "Filtering by repeated integration", SIGGRAPH 1986.
227
+ - Bokeh kernel (#553, `src/optics/defocus-bokeh-kernel.ts`): the transverse ray
228
+ aberration of primary spherical aberration, Wyant & Creath (1992), *Applied
229
+ Optics and Optical Engineering* XI ch. 1 (free author copy); mechanical
230
+ vignetting, Greivenkamp, OPTI-502 course notes sec. 10; sectioned
231
+ shift-variant blur, Denis, Thiébaut, Soulez, Becker & Mourya (2015), IJCV 115
232
+ (open preprint arXiv:1502.03305); the photographic description of front and
233
+ back bokeh, H. H. Nasse, "Depth of Field and Bokeh", Carl Zeiss (2010).
234
+ - Generic lens catalogue (#549, `src/equipment/generic-lens-catalogue.ts`,
235
+ `src/optics/generic-lens-psf.ts`): Seidel aberrations, Hopkins (1950) and
236
+ Wyant & Creath (1992); scalar Fraunhofer imaging, Goodman, *Introduction to
237
+ Fourier Optics*; the FFT, Cooley & Tukey (1965); qualitative Wikipedia
238
+ articles on vignetting, distortion, chromatic aberration, coma, flare and
239
+ focus breathing (CC BY-SA text read, nothing reproduced). Every catalogue
240
+ number is Photivra's own choice (docs/LENS_CATALOGUE.md).
241
+ - Patent status: no public-record patent check has been recorded for these
242
+ methods; it is left for the owner's review with the others.
243
+
206
244
  The DNG patent-license notice appears in `NOTICE` and exporter source. These
207
245
  references do not authorize copying SDK code or scientific datasets. Human
208
246
  provenance/license review remains required before release.
@@ -114,6 +114,11 @@ export interface LensProjectionFieldOfViewBounds {
114
114
  export declare function parseLensProjectionModel(value: unknown): LensProjectionModel;
115
115
  /** Image radius r(theta) for one radial model. */
116
116
  export declare function radialProjectionImageRadius(model: RadialLensProjectionModel, focalLengthMm: number, fieldAngleRadians: number): number;
117
+ /**
118
+ * @internal Whether an image radius lies inside a radial model's image circle (the domain of {@link radialProjectionFieldAngle}).
119
+ * Equirectangular is not radial and returns true.
120
+ */
121
+ export declare function insideRadialImageCircle(model: LensProjectionModel, focalLengthMm: number, imageRadiusMm: number): boolean;
117
122
  /** Inverse theta(r) for one radial model; throws outside the image circle. */
118
123
  export declare function radialProjectionFieldAngle(model: RadialLensProjectionModel, focalLengthMm: number, imageRadiusMm: number): number;
119
124
  /**
@@ -111,6 +111,16 @@ function radialImageRadiusLimit(model, focalLengthMm) {
111
111
  return { radiusMm: focalLengthMm, inclusive: true };
112
112
  }
113
113
  }
114
+ /**
115
+ * @internal Whether an image radius lies inside a radial model's image circle (the domain of {@link radialProjectionFieldAngle}).
116
+ * Equirectangular is not radial and returns true.
117
+ */
118
+ export function insideRadialImageCircle(model, focalLengthMm, imageRadiusMm) {
119
+ if (model === "equirectangular")
120
+ return true;
121
+ const limit = radialImageRadiusLimit(model, focalLengthMm);
122
+ return imageRadiusMm >= 0 && (imageRadiusMm < limit.radiusMm || (limit.inclusive && imageRadiusMm === limit.radiusMm));
123
+ }
114
124
  /** Inverse theta(r) for one radial model; throws outside the image circle. */
115
125
  export function radialProjectionFieldAngle(model, focalLengthMm, imageRadiusMm) {
116
126
  const limit = radialImageRadiusLimit(model, focalLengthMm);
@@ -1 +1 @@
1
- {"version":3,"file":"lens-projection.js","sourceRoot":"","sources":["../../src/camera/lens-projection.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACL,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAiB3E,MAAM,CAAC,MAAM,sBAAsB;AACjC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,aAAa;IACb,qBAAqB;IACrB,yBAAyB;IACzB,uBAAuB;IACvB,sBAAsB;IACtB,iBAAiB;CAClB,CAAC,CAAC;AAiFL,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAE5B,iGAAiG;AACjG,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAE,sBAA4C,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC9D,CAAC;QACD,MAAM,IAAI,yBAAyB,CACjC,iCAAiC;YAC/B,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;YACjC,GAAG,CACN,CAAC;IACJ,CAAC;IACD,OAAO,KAA4B,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,IAAY,EAAE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,CAAC,MAAM,CAAC,CAAC;IACjF,OAAO;QACL,aAAa,EAAE,OAAO,CAAC,KAAK;QAC5B,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,6BAA6B,CAC3C,KAA0B,EAC1B,aAAqB,EACrB,YAAoB;IAEpB,OAAO,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Ideal lens projection (mapping) functions. They convert between a scene direction and a point on the\n * image plane.\n *\n * A radial projection maps the field angle theta (the angle from the optical axis) to the image\n * radius r:\n * rectilinear r = f tan(theta) (gnomonic / pinhole)\n * equidistant r = f theta (\"f-theta\" fisheye)\n * equisolid-angle r = 2 f sin(theta / 2) (equal-area fisheye)\n * stereographic r = 2 f tan(theta / 2) (conformal fisheye)\n * orthographic r = f sin(theta)\n * The image point keeps the direction's azimuth about the optical axis, so every radial projection is\n * rotationally symmetric. Equirectangular (spherical, or cylindrical equidistant) is not radial:\n * x = f * longitude, y = f * latitude, where f is the image distance per radian.\n *\n * Sources: Kannala & Brandt 2006 (IEEE TPAMI 28:1335, generic camera model listing these\n * projections, eqs. 1-5; free author copy); Miyamoto 1964 (JOSA 54:1060, fish-eye projection\n * functions); Snyder 1987 (Map Projections - A Working Manual, USGS PP 1395, free) for the\n * equirectangular and stereographic projections. Also see: Kingslake 1989 (A History of the\n * Photographic Lens, ch. on fish-eye lenses); Ray 2002 (Applied Photographic Optics, 3rd ed., ch. 6\n * and 47).\n *\n * These are ideal mapping functions. Real fisheye lenses deviate from them. Modelling a real lens\n * would need a calibrated polynomial (for example Kannala-Brandt) with defensible provenance.\n *\n * Camera frame: +X right, +Y up, +Z along the optical axis toward the scene. Image-plane coordinates\n * use the same non-inverted +X right / +Y up convention as the rest of the engine.\n * @see docs/PHYSICS_FOUNDATION.md for the equations, units, coordinate conventions, known blockers\n * and support limits.\n */\n\nimport {\n calculatedResult,\n type CalculationResult\n} from \"../core/calculation-result.js\";\nimport {\n InvalidScientificInputError,\n requirePositiveFinite\n} from \"../core/validation.js\";\nimport { rejectUnknownFields, requireInputKeys } from \"../core/record-validation.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\n\n/** Ideal projection model discriminator. `rectilinear` is the engine default. */\nexport type LensProjectionModel =\n | \"rectilinear\"\n | \"fisheye-equidistant\"\n | \"fisheye-equisolid-angle\"\n | \"fisheye-stereographic\"\n | \"fisheye-orthographic\"\n | \"equirectangular\";\n\n/** Radial (rotationally symmetric) projection models. */\nexport type RadialLensProjectionModel = Exclude<\n LensProjectionModel,\n \"equirectangular\"\n>;\n\nexport const LENS_PROJECTION_MODELS: readonly LensProjectionModel[] =\n /* @__PURE__ */ Object.freeze([\n \"rectilinear\",\n \"fisheye-equidistant\",\n \"fisheye-equisolid-angle\",\n \"fisheye-stereographic\",\n \"fisheye-orthographic\",\n \"equirectangular\"\n ]);\n\nexport interface LensDirection {\n /** Camera-frame direction component, +X right. Any positive length. */\n x: number;\n /** Camera-frame direction component, +Y up. */\n y: number;\n /** Camera-frame direction component along the optical axis toward the scene. */\n z: number;\n}\n\nexport interface CalculateLensProjectionImagePointInput {\n projectionModel: LensProjectionModel;\n /**\n * Projection scale in millimetres: the focal length f of the mapping function, or for\n * equirectangular the image distance per radian.\n */\n focalLengthMm: number;\n /** Scene direction in the camera frame. Need not be normalized; must be non-zero. */\n direction: LensDirection;\n}\n\nexport interface LensProjectionImagePoint {\n projectionModel: LensProjectionModel;\n imagePointMm: { x: number; y: number };\n /** Angle between the direction and the optical axis, in radians. */\n fieldAngleRadians: number;\n /** Distance of the image point from the optical axis, in millimetres. */\n imageRadiusMm: number;\n}\n\nexport interface CalculateLensProjectionDirectionInput {\n projectionModel: LensProjectionModel;\n focalLengthMm: number;\n /** Image-plane point relative to the optical axis, in millimetres. */\n imagePointMm: { x: number; y: number };\n}\n\nexport interface LensProjectionDirection {\n projectionModel: LensProjectionModel;\n /** Unit direction in the camera frame. */\n direction: LensDirection;\n fieldAngleRadians: number;\n imageRadiusMm: number;\n}\n\nexport interface CalculateLensProjectionFieldOfViewInput {\n projectionModel: LensProjectionModel;\n focalLengthMm: number;\n /** Centred sensor/capture dimension along one axis through the optical axis, in mm. */\n sensorDimensionMm: number;\n}\n\nexport interface CalculateLensProjectionFieldOfViewBoundsInput {\n projectionModel: LensProjectionModel;\n focalLengthMm: number;\n /** Signed minimum sensor coordinate along one axis through the optical axis, in mm. */\n minimumSensorCoordinateMm: number;\n /** Signed maximum sensor coordinate along the same axis, in mm. */\n maximumSensorCoordinateMm: number;\n}\n\nexport interface LensProjectionFieldOfView {\n projectionModel: LensProjectionModel;\n degrees: number;\n radians: number;\n /** Projection scale used by the mapping, in millimetres. */\n projectionDistanceMm: number;\n}\n\nexport interface LensProjectionFieldOfViewBounds {\n projectionModel: LensProjectionModel;\n minimumRadians: number;\n maximumRadians: number;\n radians: number;\n minimumDegrees: number;\n maximumDegrees: number;\n degrees: number;\n projectionDistanceMm: number;\n}\n\nconst HALF_PI = Math.PI / 2;\n\n/** Runtime parser for the projection discriminator. Rejects (fails closed on) unknown values. */\nexport function parseLensProjectionModel(\n value: unknown\n): LensProjectionModel {\n if (\n typeof value !== \"string\" ||\n !(LENS_PROJECTION_MODELS as readonly string[]).includes(value)\n ) {\n throw new InvalidConfigurationError(\n \"projectionModel must be one of \" +\n LENS_PROJECTION_MODELS.join(\", \") +\n \".\"\n );\n }\n return value as LensProjectionModel;\n}\n\nfunction requireRecord(name: string, value: unknown): void {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new InvalidConfigurationError(`${name} must be an object.`);\n }\n}\n\nfunction requireFinite(name: string, value: unknown): number {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new InvalidScientificInputError(`${name} must be a finite number.`);\n }\n return value;\n}\n\n/**\n * Largest field angle (radians) a radial model maps, and whether the model can reach it.\n * Rectilinear, stereographic, equidistant and equisolid exclude the limit: the radius there is\n * infinite, or the azimuth of the backward direction is undefined. Orthographic reaches 90 degrees.\n */\nfunction radialFieldAngleLimit(model: RadialLensProjectionModel): {\n radians: number;\n inclusive: boolean;\n} {\n switch (model) {\n case \"rectilinear\":\n return { radians: HALF_PI, inclusive: false };\n case \"fisheye-orthographic\":\n return { radians: HALF_PI, inclusive: true };\n default:\n return { radians: Math.PI, inclusive: false };\n }\n}\n\n/** Image radius r(theta) for one radial model. */\nexport function radialProjectionImageRadius(\n model: RadialLensProjectionModel,\n focalLengthMm: number,\n fieldAngleRadians: number\n): number {\n switch (model) {\n case \"rectilinear\":\n return focalLengthMm * Math.tan(fieldAngleRadians);\n case \"fisheye-equidistant\":\n return focalLengthMm * fieldAngleRadians;\n case \"fisheye-equisolid-angle\":\n return 2 * focalLengthMm * Math.sin(fieldAngleRadians / 2);\n case \"fisheye-stereographic\":\n return 2 * focalLengthMm * Math.tan(fieldAngleRadians / 2);\n case \"fisheye-orthographic\":\n return focalLengthMm * Math.sin(fieldAngleRadians);\n }\n}\n\n/**\n * Largest image radius a radial model reaches inside its field-angle domain, in mm\n * (Infinity for rectilinear and stereographic).\n */\nfunction radialImageRadiusLimit(\n model: RadialLensProjectionModel,\n focalLengthMm: number\n): { radiusMm: number; inclusive: boolean } {\n switch (model) {\n case \"rectilinear\":\n case \"fisheye-stereographic\":\n return { radiusMm: Number.POSITIVE_INFINITY, inclusive: false };\n case \"fisheye-equidistant\":\n return { radiusMm: Math.PI * focalLengthMm, inclusive: false };\n case \"fisheye-equisolid-angle\":\n return { radiusMm: 2 * focalLengthMm, inclusive: false };\n case \"fisheye-orthographic\":\n return { radiusMm: focalLengthMm, inclusive: true };\n }\n}\n\n/** Inverse theta(r) for one radial model; throws outside the image circle. */\nexport function radialProjectionFieldAngle(\n model: RadialLensProjectionModel,\n focalLengthMm: number,\n imageRadiusMm: number\n): number {\n const limit = radialImageRadiusLimit(model, focalLengthMm);\n if (\n imageRadiusMm < 0 ||\n imageRadiusMm > limit.radiusMm ||\n (!limit.inclusive && imageRadiusMm === limit.radiusMm)\n ) {\n throw new InvalidScientificInputError(\n `Image radius lies outside the ${model} image circle.`\n );\n }\n switch (model) {\n case \"rectilinear\":\n return Math.atan(imageRadiusMm / focalLengthMm);\n case \"fisheye-equidistant\":\n return imageRadiusMm / focalLengthMm;\n case \"fisheye-equisolid-angle\":\n return 2 * Math.asin(imageRadiusMm / (2 * focalLengthMm));\n case \"fisheye-stereographic\":\n return 2 * Math.atan(imageRadiusMm / (2 * focalLengthMm));\n case \"fisheye-orthographic\":\n return Math.asin(Math.min(1, imageRadiusMm / focalLengthMm));\n }\n}\n\nfunction assumptions(model: LensProjectionModel): readonly string[] {\n const common = [\n \"Ideal mapping function of a perfect projection; real lenses deviate from it and need calibrated distortion data\",\n \"Camera frame +X right, +Y up, +Z toward the scene; image plane +X right, +Y up (non-inverted)\"\n ];\n if (model === \"equirectangular\") {\n return [\n \"Equirectangular (spherical) projection: x = f * longitude, y = f * latitude, longitude measured about +Y from +Z\",\n ...common\n ];\n }\n return [\n `Radial projection ${model}; image azimuth equals scene azimuth about the optical axis`,\n ...common\n ];\n}\n\nfunction validateCommon(\n input: { projectionModel: unknown; focalLengthMm: number },\n name: string\n): LensProjectionModel {\n requireRecord(name, input);\n const model = parseLensProjectionModel(input.projectionModel);\n requirePositiveFinite(\"focalLengthMm\", input.focalLengthMm);\n return model;\n}\n\n/**\n * Maps one camera-frame scene direction to its ideal image-plane point under the declared\n * projection model.\n */\nexport function calculateLensProjectionImagePoint(\n input: CalculateLensProjectionImagePointInput\n): CalculationResult<LensProjectionImagePoint> {\n requireInputKeys(input, \"calculateLensProjectionImagePoint\", [\"projectionModel\", \"focalLengthMm\", \"direction\"]);\n const model = validateCommon(input, \"input\");\n requireRecord(\"direction\", input.direction);\n rejectUnknownFields(input.direction, [\"x\", \"y\", \"z\"], \"direction\");\n const x = requireFinite(\"direction.x\", input.direction.x);\n const y = requireFinite(\"direction.y\", input.direction.y);\n const z = requireFinite(\"direction.z\", input.direction.z);\n const length = Math.hypot(x, y, z);\n if (!(length > 0) || !Number.isFinite(length)) {\n throw new InvalidScientificInputError(\n \"direction must be a finite non-zero vector.\"\n );\n }\n const { imagePointMm, fieldAngleRadians } = lensProjectionImagePointValue(\n model,\n input.focalLengthMm,\n x,\n y,\n z\n );\n\n return calculatedResult(\n {\n projectionModel: model,\n imagePointMm,\n fieldAngleRadians,\n imageRadiusMm: Math.hypot(imagePointMm.x, imagePointMm.y)\n },\n `${model}-lens-projection`,\n \"1.0.0\",\n assumptions(model)\n );\n}\n\n/**\n * Inverse-maps one image-plane point to its unit camera-frame scene direction under the declared\n * projection model. It rejects points outside the model's image circle. For equirectangular, it\n * rejects points outside +/-pi longitude and +/-pi/2 latitude.\n */\nexport function calculateLensProjectionDirection(\n input: CalculateLensProjectionDirectionInput\n): CalculationResult<LensProjectionDirection> {\n requireInputKeys(input, \"calculateLensProjectionDirection\", [\"projectionModel\", \"focalLengthMm\", \"imagePointMm\"]);\n const model = validateCommon(input, \"input\");\n requireRecord(\"imagePointMm\", input.imagePointMm);\n rejectUnknownFields(input.imagePointMm, [\"x\", \"y\"], \"imagePointMm\");\n const px = requireFinite(\"imagePointMm.x\", input.imagePointMm.x);\n const py = requireFinite(\"imagePointMm.y\", input.imagePointMm.y);\n const imageRadiusMm = Math.hypot(px, py);\n const direction = lensProjectionDirectionValue(\n model,\n input.focalLengthMm,\n px,\n py\n );\n\n return calculatedResult(\n {\n projectionModel: model,\n direction,\n fieldAngleRadians: Math.atan2(\n Math.hypot(direction.x, direction.y),\n direction.z\n ),\n imageRadiusMm\n },\n `inverse-${model}-lens-projection`,\n \"1.0.0\",\n assumptions(model)\n );\n}\n\n/** Signed angle subtended along one axis through the optical axis for a signed coordinate. */\nfunction signedAxisAngle(\n model: LensProjectionModel,\n focalLengthMm: number,\n coordinateMm: number\n): number {\n if (model === \"equirectangular\") {\n // Along a horizontal or vertical line through the centre the angle is linear in position.\n return coordinateMm / focalLengthMm;\n }\n const theta = radialProjectionFieldAngle(\n model,\n focalLengthMm,\n Math.abs(coordinateMm)\n );\n return coordinateMm < 0 ? -theta : theta;\n}\n\n/**\n * Angular field of view across a centred sensor dimension along one axis through the optical\n * axis: 2 * theta(d / 2) for radial models and d / f for equirectangular.\n *\n * For equirectangular, the result is the longitude span for a horizontal dimension and the latitude\n * span for a vertical one. A sensor dimension larger than a fisheye's image circle is rejected, not\n * clipped.\n */\nexport function calculateLensProjectionFieldOfView(\n input: CalculateLensProjectionFieldOfViewInput\n): CalculationResult<LensProjectionFieldOfView> {\n requireInputKeys(input, \"calculateLensProjectionFieldOfView\", [\"projectionModel\", \"focalLengthMm\", \"sensorDimensionMm\"]);\n const model = validateCommon(input, \"input\");\n requirePositiveFinite(\"sensorDimensionMm\", input.sensorDimensionMm);\n const radians =\n 2 *\n signedAxisAngle(model, input.focalLengthMm, input.sensorDimensionMm / 2);\n if (model === \"equirectangular\" && radians > 2 * Math.PI) {\n throw new InvalidScientificInputError(\n \"sensorDimensionMm exceeds the full 360-degree equirectangular span.\"\n );\n }\n return calculatedResult(\n {\n projectionModel: model,\n radians,\n degrees: (radians * 180) / Math.PI,\n projectionDistanceMm: input.focalLengthMm\n },\n `${model}-field-of-view`,\n \"1.0.0\",\n [\n ...assumptions(model),\n \"Field of view is measured along one axis through the optical axis\"\n ]\n );\n}\n\n/**\n * Asymmetric angular span between two signed sensor coordinates on one axis through the optical\n * axis, for off-centre crops.\n */\nexport function calculateLensProjectionFieldOfViewBounds(\n input: CalculateLensProjectionFieldOfViewBoundsInput\n): CalculationResult<LensProjectionFieldOfViewBounds> {\n requireInputKeys(input, \"calculateLensProjectionFieldOfViewBounds\", [\"projectionModel\", \"focalLengthMm\", \"minimumSensorCoordinateMm\", \"maximumSensorCoordinateMm\"]);\n const model = validateCommon(input, \"input\");\n const minimum = requireFinite(\n \"minimumSensorCoordinateMm\",\n input.minimumSensorCoordinateMm\n );\n const maximum = requireFinite(\n \"maximumSensorCoordinateMm\",\n input.maximumSensorCoordinateMm\n );\n if (maximum <= minimum) {\n throw new InvalidScientificInputError(\n \"maximumSensorCoordinateMm must be greater than minimumSensorCoordinateMm.\"\n );\n }\n const minimumRadians = signedAxisAngle(model, input.focalLengthMm, minimum);\n const maximumRadians = signedAxisAngle(model, input.focalLengthMm, maximum);\n const radians = maximumRadians - minimumRadians;\n if (model === \"equirectangular\" && radians > 2 * Math.PI) {\n throw new InvalidScientificInputError(\n \"Sensor bounds exceed the full 360-degree equirectangular span.\"\n );\n }\n return calculatedResult(\n {\n projectionModel: model,\n minimumRadians,\n maximumRadians,\n radians,\n minimumDegrees: (minimumRadians * 180) / Math.PI,\n maximumDegrees: (maximumRadians * 180) / Math.PI,\n degrees: (radians * 180) / Math.PI,\n projectionDistanceMm: input.focalLengthMm\n },\n `asymmetric-${model}-field-of-view`,\n \"1.0.0\",\n [\n ...assumptions(model),\n \"Signed sensor-plane bounds are measured relative to the optical axis along one axis through it\"\n ]\n );\n}\n\n/**\n * @internal Image point of a non-zero camera-frame direction under one model (no envelope).\n * Shared by the public mapping, geometric remaps and the environment ray query.\n */\nexport function lensProjectionImagePointValue(\n model: LensProjectionModel,\n focalLengthMm: number,\n x: number,\n y: number,\n z: number\n): { imagePointMm: { x: number; y: number }; fieldAngleRadians: number } {\n const length = Math.hypot(x, y, z);\n const f = focalLengthMm;\n const transverse = Math.hypot(x, y);\n const fieldAngleRadians = Math.atan2(transverse, z);\n\n let imagePointMm: { x: number; y: number };\n if (model === \"equirectangular\") {\n const latitude = Math.asin(Math.max(-1, Math.min(1, y / length)));\n const horizontal = Math.hypot(x, z);\n if (horizontal === 0) {\n // Poles have an undefined longitude; the projection is singular there.\n throw new InvalidScientificInputError(\n \"Equirectangular projection is undefined at the poles (direction parallel to +/-Y).\"\n );\n }\n const longitude = Math.atan2(x, z);\n imagePointMm = { x: f * longitude, y: f * latitude };\n } else {\n const limit = radialFieldAngleLimit(model);\n if (\n fieldAngleRadians > limit.radians ||\n (!limit.inclusive && fieldAngleRadians === limit.radians)\n ) {\n throw new InvalidScientificInputError(\n `direction lies outside the ${model} projection domain.`\n );\n }\n const radius = radialProjectionImageRadius(model, f, fieldAngleRadians);\n imagePointMm =\n transverse === 0\n ? { x: 0, y: 0 }\n : { x: (radius * x) / transverse, y: (radius * y) / transverse };\n }\n\n return { imagePointMm, fieldAngleRadians };\n}\n\n/** @internal Unit camera-frame direction of one image point under one model (no envelope). */\nexport function lensProjectionDirectionValue(\n model: LensProjectionModel,\n focalLengthMm: number,\n px: number,\n py: number\n): LensDirection {\n const f = focalLengthMm;\n const imageRadiusMm = Math.hypot(px, py);\n\n let direction: LensDirection;\n if (model === \"equirectangular\") {\n const longitude = px / f;\n const latitude = py / f;\n if (Math.abs(longitude) > Math.PI || Math.abs(latitude) > HALF_PI) {\n throw new InvalidScientificInputError(\n \"imagePointMm lies outside the equirectangular longitude/latitude domain.\"\n );\n }\n const cosLatitude = Math.cos(latitude);\n direction = {\n x: cosLatitude * Math.sin(longitude),\n y: Math.sin(latitude),\n z: cosLatitude * Math.cos(longitude)\n };\n } else {\n const theta = radialProjectionFieldAngle(model, f, imageRadiusMm);\n const sinTheta = Math.sin(theta);\n direction =\n imageRadiusMm === 0\n ? { x: 0, y: 0, z: 1 }\n : {\n x: (sinTheta * px) / imageRadiusMm,\n y: (sinTheta * py) / imageRadiusMm,\n z: Math.cos(theta)\n };\n }\n\n return direction;\n}\n\n/** d r / d theta of a radial model. */\nfunction radialDerivative(\n model: RadialLensProjectionModel,\n f: number,\n theta: number\n): number {\n switch (model) {\n case \"rectilinear\":\n return f / Math.cos(theta) ** 2;\n case \"fisheye-equidistant\":\n return f;\n case \"fisheye-equisolid-angle\":\n return f * Math.cos(theta / 2);\n case \"fisheye-stereographic\":\n return f / Math.cos(theta / 2) ** 2;\n case \"fisheye-orthographic\":\n return f * Math.cos(theta);\n }\n}\n\ntype Matrix32 = readonly [readonly [number, number], readonly [number, number], readonly [number, number]];\n\n/** Unit direction of an image point and its derivative d(direction)/d(point) (3 x 2). */\nfunction directionWithDerivative(\n model: LensProjectionModel,\n f: number,\n px: number,\n py: number\n): { direction: LensDirection; derivative: Matrix32 } {\n const direction = lensProjectionDirectionValue(model, f, px, py);\n if (model === \"equirectangular\") {\n const lambda = px / f;\n const phi = py / f;\n const cp = Math.cos(phi);\n const sp = Math.sin(phi);\n const cl = Math.cos(lambda);\n const sl = Math.sin(lambda);\n return {\n direction,\n derivative: [\n [(cp * cl) / f, (-sp * sl) / f],\n [0, cp / f],\n [(-cp * sl) / f, (-sp * cl) / f]\n ]\n };\n }\n const rho = Math.hypot(px, py);\n if (rho === 0) {\n const a = 1 / radialDerivative(model, f, 0);\n return { direction, derivative: [[a, 0], [0, a], [0, 0]] };\n }\n const theta = radialProjectionFieldAngle(model, f, rho);\n const dTheta = 1 / radialDerivative(model, f, theta);\n const a = Math.sin(theta) / rho;\n const aPrime = (Math.cos(theta) * dTheta * rho - Math.sin(theta)) / (rho * rho);\n const ux = px / rho;\n const uy = py / rho;\n const dz = -Math.sin(theta) * dTheta;\n return {\n direction,\n derivative: [\n [a + aPrime * px * ux, aPrime * px * uy],\n [aPrime * py * ux, a + aPrime * py * uy],\n [dz * ux, dz * uy]\n ]\n };\n}\n\n/** Image point of a unit direction and its derivative d(point)/d(direction) (2 x 3). */\nfunction imagePointWithDerivative(\n model: LensProjectionModel,\n f: number,\n v: LensDirection\n): { point: { x: number; y: number }; derivative: readonly [readonly [number, number, number], readonly [number, number, number]] } {\n const point = lensProjectionImagePointValue(model, f, v.x, v.y, v.z).imagePointMm;\n if (model === \"equirectangular\") {\n const h2 = v.x * v.x + v.z * v.z;\n const c = Math.sqrt(Math.max(0, 1 - v.y * v.y));\n return {\n point,\n derivative: [\n [(f * v.z) / h2, 0, (-f * v.x) / h2],\n [0, f / c, 0]\n ]\n };\n }\n const t = Math.hypot(v.x, v.y);\n const theta = Math.atan2(t, v.z);\n if (theta < 1e-9) {\n const g = radialDerivative(model, f, 0);\n return { point, derivative: [[g, 0, 0], [0, g, 0]] };\n }\n const s = Math.sin(theta);\n const g = radialProjectionImageRadius(model, f, theta);\n const b = g / s;\n const bPrime = (radialDerivative(model, f, theta) * s - g * Math.cos(theta)) / (s * s);\n // q = b(theta) (vx, vy); on the unit sphere d theta = -d vz / sin theta.\n const k = -bPrime / s;\n return {\n point,\n derivative: [\n [b, 0, k * v.x],\n [0, b, k * v.y]\n ]\n };\n}\n\n/**\n * @internal Destination-to-source remap between two ideal projections: the destination point is\n * unprojected with the destination model and reprojected with the source model. Returns the\n * source point and the 2 x 2 Jacobian d(source)/d(destination), row-major.\n */\nexport function lensProjectionRemapValue(\n destinationModel: LensProjectionModel,\n destinationFocalLengthMm: number,\n sourceModel: LensProjectionModel,\n sourceFocalLengthMm: number,\n px: number,\n py: number\n): { sourcePointMm: { x: number; y: number }; jacobian: readonly [number, number, number, number] } {\n const inverse = directionWithDerivative(destinationModel, destinationFocalLengthMm, px, py);\n const forward = imagePointWithDerivative(sourceModel, sourceFocalLengthMm, inverse.direction);\n const d = inverse.derivative;\n const q = forward.derivative;\n const j = (row: 0 | 1, column: 0 | 1): number =>\n q[row][0] * d[0][column] + q[row][1] * d[1][column] + q[row][2] * d[2][column];\n return {\n sourcePointMm: forward.point,\n jacobian: [j(0, 0), j(0, 1), j(1, 0), j(1, 1)]\n };\n}\n\n/** @internal Signed angle along one axis through the optical axis (exported for sampling plans). */\nexport function lensProjectionSignedAxisAngle(\n model: LensProjectionModel,\n focalLengthMm: number,\n coordinateMm: number\n): number {\n return signedAxisAngle(model, focalLengthMm, coordinateMm);\n}\n"]}
1
+ {"version":3,"file":"lens-projection.js","sourceRoot":"","sources":["../../src/camera/lens-projection.ts"],"names":[],"mappings":"A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CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACjF,OAAO;QACL,aAAa,EAAE,OAAO,CAAC,KAAK;QAC5B,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,6BAA6B,CAC3C,KAA0B,EAC1B,aAAqB,EACrB,YAAoB;IAEpB,OAAO,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Ideal lens projection (mapping) functions. They convert between a scene direction and a point on the\n * image plane.\n *\n * A radial projection maps the field angle theta (the angle from the optical axis) to the image\n * radius r:\n * rectilinear r = f tan(theta) (gnomonic / pinhole)\n * equidistant r = f theta (\"f-theta\" fisheye)\n * equisolid-angle r = 2 f sin(theta / 2) (equal-area fisheye)\n * stereographic r = 2 f tan(theta / 2) (conformal fisheye)\n * orthographic r = f sin(theta)\n * The image point keeps the direction's azimuth about the optical axis, so every radial projection is\n * rotationally symmetric. Equirectangular (spherical, or cylindrical equidistant) is not radial:\n * x = f * longitude, y = f * latitude, where f is the image distance per radian.\n *\n * Sources: Kannala & Brandt 2006 (IEEE TPAMI 28:1335, generic camera model listing these\n * projections, eqs. 1-5; free author copy); Miyamoto 1964 (JOSA 54:1060, fish-eye projection\n * functions); Snyder 1987 (Map Projections - A Working Manual, USGS PP 1395, free) for the\n * equirectangular and stereographic projections. Also see: Kingslake 1989 (A History of the\n * Photographic Lens, ch. on fish-eye lenses); Ray 2002 (Applied Photographic Optics, 3rd ed., ch. 6\n * and 47).\n *\n * These are ideal mapping functions. Real fisheye lenses deviate from them. Modelling a real lens\n * would need a calibrated polynomial (for example Kannala-Brandt) with defensible provenance.\n *\n * Camera frame: +X right, +Y up, +Z along the optical axis toward the scene. Image-plane coordinates\n * use the same non-inverted +X right / +Y up convention as the rest of the engine.\n * @see docs/PHYSICS_FOUNDATION.md for the equations, units, coordinate conventions, known blockers\n * and support limits.\n */\n\nimport {\n calculatedResult,\n type CalculationResult\n} from \"../core/calculation-result.js\";\nimport {\n InvalidScientificInputError,\n requirePositiveFinite\n} from \"../core/validation.js\";\nimport { rejectUnknownFields, requireInputKeys } from \"../core/record-validation.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\n\n/** Ideal projection model discriminator. `rectilinear` is the engine default. */\nexport type LensProjectionModel =\n | \"rectilinear\"\n | \"fisheye-equidistant\"\n | \"fisheye-equisolid-angle\"\n | \"fisheye-stereographic\"\n | \"fisheye-orthographic\"\n | \"equirectangular\";\n\n/** Radial (rotationally symmetric) projection models. */\nexport type RadialLensProjectionModel = Exclude<\n LensProjectionModel,\n \"equirectangular\"\n>;\n\nexport const LENS_PROJECTION_MODELS: readonly LensProjectionModel[] =\n /* @__PURE__ */ Object.freeze([\n \"rectilinear\",\n \"fisheye-equidistant\",\n \"fisheye-equisolid-angle\",\n \"fisheye-stereographic\",\n \"fisheye-orthographic\",\n \"equirectangular\"\n ]);\n\nexport interface LensDirection {\n /** Camera-frame direction component, +X right. Any positive length. */\n x: number;\n /** Camera-frame direction component, +Y up. */\n y: number;\n /** Camera-frame direction component along the optical axis toward the scene. */\n z: number;\n}\n\nexport interface CalculateLensProjectionImagePointInput {\n projectionModel: LensProjectionModel;\n /**\n * Projection scale in millimetres: the focal length f of the mapping function, or for\n * equirectangular the image distance per radian.\n */\n focalLengthMm: number;\n /** Scene direction in the camera frame. Need not be normalized; must be non-zero. */\n direction: LensDirection;\n}\n\nexport interface LensProjectionImagePoint {\n projectionModel: LensProjectionModel;\n imagePointMm: { x: number; y: number };\n /** Angle between the direction and the optical axis, in radians. */\n fieldAngleRadians: number;\n /** Distance of the image point from the optical axis, in millimetres. */\n imageRadiusMm: number;\n}\n\nexport interface CalculateLensProjectionDirectionInput {\n projectionModel: LensProjectionModel;\n focalLengthMm: number;\n /** Image-plane point relative to the optical axis, in millimetres. */\n imagePointMm: { x: number; y: number };\n}\n\nexport interface LensProjectionDirection {\n projectionModel: LensProjectionModel;\n /** Unit direction in the camera frame. */\n direction: LensDirection;\n fieldAngleRadians: number;\n imageRadiusMm: number;\n}\n\nexport interface CalculateLensProjectionFieldOfViewInput {\n projectionModel: LensProjectionModel;\n focalLengthMm: number;\n /** Centred sensor/capture dimension along one axis through the optical axis, in mm. */\n sensorDimensionMm: number;\n}\n\nexport interface CalculateLensProjectionFieldOfViewBoundsInput {\n projectionModel: LensProjectionModel;\n focalLengthMm: number;\n /** Signed minimum sensor coordinate along one axis through the optical axis, in mm. */\n minimumSensorCoordinateMm: number;\n /** Signed maximum sensor coordinate along the same axis, in mm. */\n maximumSensorCoordinateMm: number;\n}\n\nexport interface LensProjectionFieldOfView {\n projectionModel: LensProjectionModel;\n degrees: number;\n radians: number;\n /** Projection scale used by the mapping, in millimetres. */\n projectionDistanceMm: number;\n}\n\nexport interface LensProjectionFieldOfViewBounds {\n projectionModel: LensProjectionModel;\n minimumRadians: number;\n maximumRadians: number;\n radians: number;\n minimumDegrees: number;\n maximumDegrees: number;\n degrees: number;\n projectionDistanceMm: number;\n}\n\nconst HALF_PI = Math.PI / 2;\n\n/** Runtime parser for the projection discriminator. Rejects (fails closed on) unknown values. */\nexport function parseLensProjectionModel(\n value: unknown\n): LensProjectionModel {\n if (\n typeof value !== \"string\" ||\n !(LENS_PROJECTION_MODELS as readonly string[]).includes(value)\n ) {\n throw new InvalidConfigurationError(\n \"projectionModel must be one of \" +\n LENS_PROJECTION_MODELS.join(\", \") +\n \".\"\n );\n }\n return value as LensProjectionModel;\n}\n\nfunction requireRecord(name: string, value: unknown): void {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new InvalidConfigurationError(`${name} must be an object.`);\n }\n}\n\nfunction requireFinite(name: string, value: unknown): number {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new InvalidScientificInputError(`${name} must be a finite number.`);\n }\n return value;\n}\n\n/**\n * Largest field angle (radians) a radial model maps, and whether the model can reach it.\n * Rectilinear, stereographic, equidistant and equisolid exclude the limit: the radius there is\n * infinite, or the azimuth of the backward direction is undefined. Orthographic reaches 90 degrees.\n */\nfunction radialFieldAngleLimit(model: RadialLensProjectionModel): {\n radians: number;\n inclusive: boolean;\n} {\n switch (model) {\n case \"rectilinear\":\n return { radians: HALF_PI, inclusive: false };\n case \"fisheye-orthographic\":\n return { radians: HALF_PI, inclusive: true };\n default:\n return { radians: Math.PI, inclusive: false };\n }\n}\n\n/** Image radius r(theta) for one radial model. */\nexport function radialProjectionImageRadius(\n model: RadialLensProjectionModel,\n focalLengthMm: number,\n fieldAngleRadians: number\n): number {\n switch (model) {\n case \"rectilinear\":\n return focalLengthMm * Math.tan(fieldAngleRadians);\n case \"fisheye-equidistant\":\n return focalLengthMm * fieldAngleRadians;\n case \"fisheye-equisolid-angle\":\n return 2 * focalLengthMm * Math.sin(fieldAngleRadians / 2);\n case \"fisheye-stereographic\":\n return 2 * focalLengthMm * Math.tan(fieldAngleRadians / 2);\n case \"fisheye-orthographic\":\n return focalLengthMm * Math.sin(fieldAngleRadians);\n }\n}\n\n/**\n * Largest image radius a radial model reaches inside its field-angle domain, in mm\n * (Infinity for rectilinear and stereographic).\n */\nfunction radialImageRadiusLimit(\n model: RadialLensProjectionModel,\n focalLengthMm: number\n): { radiusMm: number; inclusive: boolean } {\n switch (model) {\n case \"rectilinear\":\n case \"fisheye-stereographic\":\n return { radiusMm: Number.POSITIVE_INFINITY, inclusive: false };\n case \"fisheye-equidistant\":\n return { radiusMm: Math.PI * focalLengthMm, inclusive: false };\n case \"fisheye-equisolid-angle\":\n return { radiusMm: 2 * focalLengthMm, inclusive: false };\n case \"fisheye-orthographic\":\n return { radiusMm: focalLengthMm, inclusive: true };\n }\n}\n\n/**\n * @internal Whether an image radius lies inside a radial model's image circle (the domain of {@link radialProjectionFieldAngle}).\n * Equirectangular is not radial and returns true.\n */\nexport function insideRadialImageCircle(model: LensProjectionModel, focalLengthMm: number, imageRadiusMm: number): boolean {\n if (model === \"equirectangular\") return true;\n const limit = radialImageRadiusLimit(model, focalLengthMm);\n return imageRadiusMm >= 0 && (imageRadiusMm < limit.radiusMm || (limit.inclusive && imageRadiusMm === limit.radiusMm));\n}\n\n/** Inverse theta(r) for one radial model; throws outside the image circle. */\nexport function radialProjectionFieldAngle(\n model: RadialLensProjectionModel,\n focalLengthMm: number,\n imageRadiusMm: number\n): number {\n const limit = radialImageRadiusLimit(model, focalLengthMm);\n if (\n imageRadiusMm < 0 ||\n imageRadiusMm > limit.radiusMm ||\n (!limit.inclusive && imageRadiusMm === limit.radiusMm)\n ) {\n throw new InvalidScientificInputError(\n `Image radius lies outside the ${model} image circle.`\n );\n }\n switch (model) {\n case \"rectilinear\":\n return Math.atan(imageRadiusMm / focalLengthMm);\n case \"fisheye-equidistant\":\n return imageRadiusMm / focalLengthMm;\n case \"fisheye-equisolid-angle\":\n return 2 * Math.asin(imageRadiusMm / (2 * focalLengthMm));\n case \"fisheye-stereographic\":\n return 2 * Math.atan(imageRadiusMm / (2 * focalLengthMm));\n case \"fisheye-orthographic\":\n return Math.asin(Math.min(1, imageRadiusMm / focalLengthMm));\n }\n}\n\nfunction assumptions(model: LensProjectionModel): readonly string[] {\n const common = [\n \"Ideal mapping function of a perfect projection; real lenses deviate from it and need calibrated distortion data\",\n \"Camera frame +X right, +Y up, +Z toward the scene; image plane +X right, +Y up (non-inverted)\"\n ];\n if (model === \"equirectangular\") {\n return [\n \"Equirectangular (spherical) projection: x = f * longitude, y = f * latitude, longitude measured about +Y from +Z\",\n ...common\n ];\n }\n return [\n `Radial projection ${model}; image azimuth equals scene azimuth about the optical axis`,\n ...common\n ];\n}\n\nfunction validateCommon(\n input: { projectionModel: unknown; focalLengthMm: number },\n name: string\n): LensProjectionModel {\n requireRecord(name, input);\n const model = parseLensProjectionModel(input.projectionModel);\n requirePositiveFinite(\"focalLengthMm\", input.focalLengthMm);\n return model;\n}\n\n/**\n * Maps one camera-frame scene direction to its ideal image-plane point under the declared\n * projection model.\n */\nexport function calculateLensProjectionImagePoint(\n input: CalculateLensProjectionImagePointInput\n): CalculationResult<LensProjectionImagePoint> {\n requireInputKeys(input, \"calculateLensProjectionImagePoint\", [\"projectionModel\", \"focalLengthMm\", \"direction\"]);\n const model = validateCommon(input, \"input\");\n requireRecord(\"direction\", input.direction);\n rejectUnknownFields(input.direction, [\"x\", \"y\", \"z\"], \"direction\");\n const x = requireFinite(\"direction.x\", input.direction.x);\n const y = requireFinite(\"direction.y\", input.direction.y);\n const z = requireFinite(\"direction.z\", input.direction.z);\n const length = Math.hypot(x, y, z);\n if (!(length > 0) || !Number.isFinite(length)) {\n throw new InvalidScientificInputError(\n \"direction must be a finite non-zero vector.\"\n );\n }\n const { imagePointMm, fieldAngleRadians } = lensProjectionImagePointValue(\n model,\n input.focalLengthMm,\n x,\n y,\n z\n );\n\n return calculatedResult(\n {\n projectionModel: model,\n imagePointMm,\n fieldAngleRadians,\n imageRadiusMm: Math.hypot(imagePointMm.x, imagePointMm.y)\n },\n `${model}-lens-projection`,\n \"1.0.0\",\n assumptions(model)\n );\n}\n\n/**\n * Inverse-maps one image-plane point to its unit camera-frame scene direction under the declared\n * projection model. It rejects points outside the model's image circle. For equirectangular, it\n * rejects points outside +/-pi longitude and +/-pi/2 latitude.\n */\nexport function calculateLensProjectionDirection(\n input: CalculateLensProjectionDirectionInput\n): CalculationResult<LensProjectionDirection> {\n requireInputKeys(input, \"calculateLensProjectionDirection\", [\"projectionModel\", \"focalLengthMm\", \"imagePointMm\"]);\n const model = validateCommon(input, \"input\");\n requireRecord(\"imagePointMm\", input.imagePointMm);\n rejectUnknownFields(input.imagePointMm, [\"x\", \"y\"], \"imagePointMm\");\n const px = requireFinite(\"imagePointMm.x\", input.imagePointMm.x);\n const py = requireFinite(\"imagePointMm.y\", input.imagePointMm.y);\n const imageRadiusMm = Math.hypot(px, py);\n const direction = lensProjectionDirectionValue(\n model,\n input.focalLengthMm,\n px,\n py\n );\n\n return calculatedResult(\n {\n projectionModel: model,\n direction,\n fieldAngleRadians: Math.atan2(\n Math.hypot(direction.x, direction.y),\n direction.z\n ),\n imageRadiusMm\n },\n `inverse-${model}-lens-projection`,\n \"1.0.0\",\n assumptions(model)\n );\n}\n\n/** Signed angle subtended along one axis through the optical axis for a signed coordinate. */\nfunction signedAxisAngle(\n model: LensProjectionModel,\n focalLengthMm: number,\n coordinateMm: number\n): number {\n if (model === \"equirectangular\") {\n // Along a horizontal or vertical line through the centre the angle is linear in position.\n return coordinateMm / focalLengthMm;\n }\n const theta = radialProjectionFieldAngle(\n model,\n focalLengthMm,\n Math.abs(coordinateMm)\n );\n return coordinateMm < 0 ? -theta : theta;\n}\n\n/**\n * Angular field of view across a centred sensor dimension along one axis through the optical\n * axis: 2 * theta(d / 2) for radial models and d / f for equirectangular.\n *\n * For equirectangular, the result is the longitude span for a horizontal dimension and the latitude\n * span for a vertical one. A sensor dimension larger than a fisheye's image circle is rejected, not\n * clipped.\n */\nexport function calculateLensProjectionFieldOfView(\n input: CalculateLensProjectionFieldOfViewInput\n): CalculationResult<LensProjectionFieldOfView> {\n requireInputKeys(input, \"calculateLensProjectionFieldOfView\", [\"projectionModel\", \"focalLengthMm\", \"sensorDimensionMm\"]);\n const model = validateCommon(input, \"input\");\n requirePositiveFinite(\"sensorDimensionMm\", input.sensorDimensionMm);\n const radians =\n 2 *\n signedAxisAngle(model, input.focalLengthMm, input.sensorDimensionMm / 2);\n if (model === \"equirectangular\" && radians > 2 * Math.PI) {\n throw new InvalidScientificInputError(\n \"sensorDimensionMm exceeds the full 360-degree equirectangular span.\"\n );\n }\n return calculatedResult(\n {\n projectionModel: model,\n radians,\n degrees: (radians * 180) / Math.PI,\n projectionDistanceMm: input.focalLengthMm\n },\n `${model}-field-of-view`,\n \"1.0.0\",\n [\n ...assumptions(model),\n \"Field of view is measured along one axis through the optical axis\"\n ]\n );\n}\n\n/**\n * Asymmetric angular span between two signed sensor coordinates on one axis through the optical\n * axis, for off-centre crops.\n */\nexport function calculateLensProjectionFieldOfViewBounds(\n input: CalculateLensProjectionFieldOfViewBoundsInput\n): CalculationResult<LensProjectionFieldOfViewBounds> {\n requireInputKeys(input, \"calculateLensProjectionFieldOfViewBounds\", [\"projectionModel\", \"focalLengthMm\", \"minimumSensorCoordinateMm\", \"maximumSensorCoordinateMm\"]);\n const model = validateCommon(input, \"input\");\n const minimum = requireFinite(\n \"minimumSensorCoordinateMm\",\n input.minimumSensorCoordinateMm\n );\n const maximum = requireFinite(\n \"maximumSensorCoordinateMm\",\n input.maximumSensorCoordinateMm\n );\n if (maximum <= minimum) {\n throw new InvalidScientificInputError(\n \"maximumSensorCoordinateMm must be greater than minimumSensorCoordinateMm.\"\n );\n }\n const minimumRadians = signedAxisAngle(model, input.focalLengthMm, minimum);\n const maximumRadians = signedAxisAngle(model, input.focalLengthMm, maximum);\n const radians = maximumRadians - minimumRadians;\n if (model === \"equirectangular\" && radians > 2 * Math.PI) {\n throw new InvalidScientificInputError(\n \"Sensor bounds exceed the full 360-degree equirectangular span.\"\n );\n }\n return calculatedResult(\n {\n projectionModel: model,\n minimumRadians,\n maximumRadians,\n radians,\n minimumDegrees: (minimumRadians * 180) / Math.PI,\n maximumDegrees: (maximumRadians * 180) / Math.PI,\n degrees: (radians * 180) / Math.PI,\n projectionDistanceMm: input.focalLengthMm\n },\n `asymmetric-${model}-field-of-view`,\n \"1.0.0\",\n [\n ...assumptions(model),\n \"Signed sensor-plane bounds are measured relative to the optical axis along one axis through it\"\n ]\n );\n}\n\n/**\n * @internal Image point of a non-zero camera-frame direction under one model (no envelope).\n * Shared by the public mapping, geometric remaps and the environment ray query.\n */\nexport function lensProjectionImagePointValue(\n model: LensProjectionModel,\n focalLengthMm: number,\n x: number,\n y: number,\n z: number\n): { imagePointMm: { x: number; y: number }; fieldAngleRadians: number } {\n const length = Math.hypot(x, y, z);\n const f = focalLengthMm;\n const transverse = Math.hypot(x, y);\n const fieldAngleRadians = Math.atan2(transverse, z);\n\n let imagePointMm: { x: number; y: number };\n if (model === \"equirectangular\") {\n const latitude = Math.asin(Math.max(-1, Math.min(1, y / length)));\n const horizontal = Math.hypot(x, z);\n if (horizontal === 0) {\n // Poles have an undefined longitude; the projection is singular there.\n throw new InvalidScientificInputError(\n \"Equirectangular projection is undefined at the poles (direction parallel to +/-Y).\"\n );\n }\n const longitude = Math.atan2(x, z);\n imagePointMm = { x: f * longitude, y: f * latitude };\n } else {\n const limit = radialFieldAngleLimit(model);\n if (\n fieldAngleRadians > limit.radians ||\n (!limit.inclusive && fieldAngleRadians === limit.radians)\n ) {\n throw new InvalidScientificInputError(\n `direction lies outside the ${model} projection domain.`\n );\n }\n const radius = radialProjectionImageRadius(model, f, fieldAngleRadians);\n imagePointMm =\n transverse === 0\n ? { x: 0, y: 0 }\n : { x: (radius * x) / transverse, y: (radius * y) / transverse };\n }\n\n return { imagePointMm, fieldAngleRadians };\n}\n\n/** @internal Unit camera-frame direction of one image point under one model (no envelope). */\nexport function lensProjectionDirectionValue(\n model: LensProjectionModel,\n focalLengthMm: number,\n px: number,\n py: number\n): LensDirection {\n const f = focalLengthMm;\n const imageRadiusMm = Math.hypot(px, py);\n\n let direction: LensDirection;\n if (model === \"equirectangular\") {\n const longitude = px / f;\n const latitude = py / f;\n if (Math.abs(longitude) > Math.PI || Math.abs(latitude) > HALF_PI) {\n throw new InvalidScientificInputError(\n \"imagePointMm lies outside the equirectangular longitude/latitude domain.\"\n );\n }\n const cosLatitude = Math.cos(latitude);\n direction = {\n x: cosLatitude * Math.sin(longitude),\n y: Math.sin(latitude),\n z: cosLatitude * Math.cos(longitude)\n };\n } else {\n const theta = radialProjectionFieldAngle(model, f, imageRadiusMm);\n const sinTheta = Math.sin(theta);\n direction =\n imageRadiusMm === 0\n ? { x: 0, y: 0, z: 1 }\n : {\n x: (sinTheta * px) / imageRadiusMm,\n y: (sinTheta * py) / imageRadiusMm,\n z: Math.cos(theta)\n };\n }\n\n return direction;\n}\n\n/** d r / d theta of a radial model. */\nfunction radialDerivative(\n model: RadialLensProjectionModel,\n f: number,\n theta: number\n): number {\n switch (model) {\n case \"rectilinear\":\n return f / Math.cos(theta) ** 2;\n case \"fisheye-equidistant\":\n return f;\n case \"fisheye-equisolid-angle\":\n return f * Math.cos(theta / 2);\n case \"fisheye-stereographic\":\n return f / Math.cos(theta / 2) ** 2;\n case \"fisheye-orthographic\":\n return f * Math.cos(theta);\n }\n}\n\ntype Matrix32 = readonly [readonly [number, number], readonly [number, number], readonly [number, number]];\n\n/** Unit direction of an image point and its derivative d(direction)/d(point) (3 x 2). */\nfunction directionWithDerivative(\n model: LensProjectionModel,\n f: number,\n px: number,\n py: number\n): { direction: LensDirection; derivative: Matrix32 } {\n const direction = lensProjectionDirectionValue(model, f, px, py);\n if (model === \"equirectangular\") {\n const lambda = px / f;\n const phi = py / f;\n const cp = Math.cos(phi);\n const sp = Math.sin(phi);\n const cl = Math.cos(lambda);\n const sl = Math.sin(lambda);\n return {\n direction,\n derivative: [\n [(cp * cl) / f, (-sp * sl) / f],\n [0, cp / f],\n [(-cp * sl) / f, (-sp * cl) / f]\n ]\n };\n }\n const rho = Math.hypot(px, py);\n if (rho === 0) {\n const a = 1 / radialDerivative(model, f, 0);\n return { direction, derivative: [[a, 0], [0, a], [0, 0]] };\n }\n const theta = radialProjectionFieldAngle(model, f, rho);\n const dTheta = 1 / radialDerivative(model, f, theta);\n const a = Math.sin(theta) / rho;\n const aPrime = (Math.cos(theta) * dTheta * rho - Math.sin(theta)) / (rho * rho);\n const ux = px / rho;\n const uy = py / rho;\n const dz = -Math.sin(theta) * dTheta;\n return {\n direction,\n derivative: [\n [a + aPrime * px * ux, aPrime * px * uy],\n [aPrime * py * ux, a + aPrime * py * uy],\n [dz * ux, dz * uy]\n ]\n };\n}\n\n/** Image point of a unit direction and its derivative d(point)/d(direction) (2 x 3). */\nfunction imagePointWithDerivative(\n model: LensProjectionModel,\n f: number,\n v: LensDirection\n): { point: { x: number; y: number }; derivative: readonly [readonly [number, number, number], readonly [number, number, number]] } {\n const point = lensProjectionImagePointValue(model, f, v.x, v.y, v.z).imagePointMm;\n if (model === \"equirectangular\") {\n const h2 = v.x * v.x + v.z * v.z;\n const c = Math.sqrt(Math.max(0, 1 - v.y * v.y));\n return {\n point,\n derivative: [\n [(f * v.z) / h2, 0, (-f * v.x) / h2],\n [0, f / c, 0]\n ]\n };\n }\n const t = Math.hypot(v.x, v.y);\n const theta = Math.atan2(t, v.z);\n if (theta < 1e-9) {\n const g = radialDerivative(model, f, 0);\n return { point, derivative: [[g, 0, 0], [0, g, 0]] };\n }\n const s = Math.sin(theta);\n const g = radialProjectionImageRadius(model, f, theta);\n const b = g / s;\n const bPrime = (radialDerivative(model, f, theta) * s - g * Math.cos(theta)) / (s * s);\n // q = b(theta) (vx, vy); on the unit sphere d theta = -d vz / sin theta.\n const k = -bPrime / s;\n return {\n point,\n derivative: [\n [b, 0, k * v.x],\n [0, b, k * v.y]\n ]\n };\n}\n\n/**\n * @internal Destination-to-source remap between two ideal projections: the destination point is\n * unprojected with the destination model and reprojected with the source model. Returns the\n * source point and the 2 x 2 Jacobian d(source)/d(destination), row-major.\n */\nexport function lensProjectionRemapValue(\n destinationModel: LensProjectionModel,\n destinationFocalLengthMm: number,\n sourceModel: LensProjectionModel,\n sourceFocalLengthMm: number,\n px: number,\n py: number\n): { sourcePointMm: { x: number; y: number }; jacobian: readonly [number, number, number, number] } {\n const inverse = directionWithDerivative(destinationModel, destinationFocalLengthMm, px, py);\n const forward = imagePointWithDerivative(sourceModel, sourceFocalLengthMm, inverse.direction);\n const d = inverse.derivative;\n const q = forward.derivative;\n const j = (row: 0 | 1, column: 0 | 1): number =>\n q[row][0] * d[0][column] + q[row][1] * d[1][column] + q[row][2] * d[2][column];\n return {\n sourcePointMm: forward.point,\n jacobian: [j(0, 0), j(0, 1), j(1, 0), j(1, 1)]\n };\n}\n\n/** @internal Signed angle along one axis through the optical axis (exported for sampling plans). */\nexport function lensProjectionSignedAxisAngle(\n model: LensProjectionModel,\n focalLengthMm: number,\n coordinateMm: number\n): number {\n return signedAxisAngle(model, focalLengthMm, coordinateMm);\n}\n"]}
@@ -287,7 +287,7 @@ function geometry(t, k, frame, environment, index, access) {
287
287
  return undefined;
288
288
  // #394: the key the evaluator would read for this request (undefined where it would throw: the full path decides).
289
289
  if (access !== undefined) {
290
- key = access.keyOfDirection(direction);
290
+ key = access.keyOfDirection(direction, time);
291
291
  if (key === undefined)
292
292
  return undefined;
293
293
  }