@photivra/engine 2.8.0 → 2.8.1

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.
@@ -0,0 +1,5 @@
1
+ import { resolveLensPsfConvolutionKernels } from "./lens-psf-kernels.js";
2
+ type Psf = Parameters<typeof resolveLensPsfConvolutionKernels>[0]["psf"];
3
+ /** The (2·radius + 1)² kernel of `psf` at `wavelengthNm` on a square site grid of `pitchMicrometers`; `failure` is the error message when the kernel cannot sample the pitch exactly. */
4
+ export declare function siteDiffractionKernel(psf: Psf, wavelengthNm: number, pitchMicrometers: number, radius: number, failure: string): Float64Array;
5
+ export {};
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Internal (not exported from the package): one wavelength's diffraction kernel sampled on the site pitch, as the object-space
4
+ * convolution (facade/diffraction-provider.ts) and the tabulated expected signal (facade/expected-signal-setup.ts) use it.
5
+ *
6
+ * `resolveLensPsfConvolutionKernels` parses and samples the PSF profile on every call (about 10 ms per wavelength), and both users
7
+ * ask for the same kernels, so they are kept while the PSF record lives. The kernel is a function of its inputs alone; each caller
8
+ * gets its own copy.
9
+ */
10
+ import { InvalidConfigurationError } from "../core/configuration-error.js";
11
+ import { resolveLensPsfConvolutionKernels } from "./lens-psf-kernels.js";
12
+ /** Kernels per PSF record (by identity: the record is large, so it is not serialized), then per wavelength, pitch and radius. */
13
+ const cache = new WeakMap();
14
+ /** The (2·radius + 1)² kernel of `psf` at `wavelengthNm` on a square site grid of `pitchMicrometers`; `failure` is the error message when the kernel cannot sample the pitch exactly. */
15
+ export function siteDiffractionKernel(psf, wavelengthNm, pitchMicrometers, radius, failure) {
16
+ let kernels = cache.get(psf);
17
+ if (!kernels)
18
+ cache.set(psf, (kernels = new Map()));
19
+ const key = wavelengthNm + ":" + pitchMicrometers + ":" + radius;
20
+ let kernel = kernels.get(key);
21
+ if (!kernel) {
22
+ const k = resolveLensPsfConvolutionKernels({ schemaVersion: "0.1.0", psf, spectralWeights: [{ wavelengthNm, weight: 1 }],
23
+ grid: { width: 1, height: 1, sitePitchMicrometers: { x: pitchMicrometers, y: pitchMicrometers }, opticalAxisSite: { x: 0.5, y: 0.5 } }, patchWidth: 1, patchHeight: 1,
24
+ kernelRadius: radius }).value;
25
+ if (!k.exactSiteSampling || k.kernelRadius !== radius)
26
+ throw new InvalidConfigurationError(failure);
27
+ kernel = Float64Array.from(k.kernels);
28
+ kernels.set(key, kernel);
29
+ }
30
+ return Float64Array.from(kernel);
31
+ }
32
+ //# sourceMappingURL=site-diffraction-kernel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-diffraction-kernel.js","sourceRoot":"","sources":["../../src/optics/site-diffraction-kernel.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAIzE,iIAAiI;AACjI,MAAM,KAAK,GAAG,IAAI,OAAO,EAAqC,CAAC;AAE/D,yLAAyL;AACzL,MAAM,UAAU,qBAAqB,CAAC,GAAQ,EAAE,YAAoB,EAAE,gBAAwB,EAAE,MAAc,EAAE,OAAe;IAC7H,IAAI,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,OAAO;QAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,YAAY,GAAG,GAAG,GAAG,gBAAgB,GAAG,GAAG,GAAG,MAAM,CAAC;IACjE,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,CAAC,GAAG,gCAAgC,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;YACtH,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,oBAAoB,EAAE,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC;YACrK,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC;QAChC,IAAI,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,YAAY,KAAK,MAAM;YAAE,MAAM,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;QACpG,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Internal (not exported from the package): one wavelength's diffraction kernel sampled on the site pitch, as the object-space\n * convolution (facade/diffraction-provider.ts) and the tabulated expected signal (facade/expected-signal-setup.ts) use it.\n *\n * `resolveLensPsfConvolutionKernels` parses and samples the PSF profile on every call (about 10 ms per wavelength), and both users\n * ask for the same kernels, so they are kept while the PSF record lives. The kernel is a function of its inputs alone; each caller\n * gets its own copy.\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { resolveLensPsfConvolutionKernels } from \"./lens-psf-kernels.js\";\n\ntype Psf = Parameters<typeof resolveLensPsfConvolutionKernels>[0][\"psf\"];\n\n/** Kernels per PSF record (by identity: the record is large, so it is not serialized), then per wavelength, pitch and radius. */\nconst cache = new WeakMap<object, Map<string, Float64Array>>();\n\n/** The (2·radius + 1)² kernel of `psf` at `wavelengthNm` on a square site grid of `pitchMicrometers`; `failure` is the error message when the kernel cannot sample the pitch exactly. */\nexport function siteDiffractionKernel(psf: Psf, wavelengthNm: number, pitchMicrometers: number, radius: number, failure: string): Float64Array {\n let kernels = cache.get(psf);\n if (!kernels) cache.set(psf, (kernels = new Map()));\n const key = wavelengthNm + \":\" + pitchMicrometers + \":\" + radius;\n let kernel = kernels.get(key);\n if (!kernel) {\n const k = resolveLensPsfConvolutionKernels({ schemaVersion: \"0.1.0\", psf, spectralWeights: [{ wavelengthNm, weight: 1 }],\n grid: { width: 1, height: 1, sitePitchMicrometers: { x: pitchMicrometers, y: pitchMicrometers }, opticalAxisSite: { x: 0.5, y: 0.5 } }, patchWidth: 1, patchHeight: 1,\n kernelRadius: radius }).value;\n if (!k.exactSiteSampling || k.kernelRadius !== radius) throw new InvalidConfigurationError(failure);\n kernel = Float64Array.from(k.kernels);\n kernels.set(key, kernel);\n }\n return Float64Array.from(kernel);\n}\n"]}
@@ -137,56 +137,84 @@ export function createPrintJpegTask(input, provider) {
137
137
  }
138
138
  };
139
139
  const blocksX = Math.ceil(plan.outputWidth / 8), sums = new Float64Array(blocksX * 192);
140
- for (let by = 0; by < plan.outputHeight; by += 8) {
141
- check();
142
- sums.fill(0);
143
- const height = Math.min(8, plan.outputHeight - by), top = plan.crop.y + by * scaleY, bottom = by + height === plan.outputHeight ? cropBottom : plan.crop.y + (by + height) * scaleY;
144
- // Accumulation order per output pixel is unchanged from the per-block reader: 32-row bands from
145
- // floor(top), then 256-column chunks from floor(left), then rows, then columns. Identical IEEE sums.
146
- for (let sy = Math.floor(top); sy < Math.ceil(bottom); sy += 32) {
147
- const bandHeight = Math.min(32, Math.ceil(bottom) - sy);
148
- await ensureRows(sy, bandHeight);
140
+ // At 1:1 every output pixel is one source pixel with weight exactly 1, so its sum is exactly lut[code] and its
141
+ // sample is a function of the code alone: the same bytes from a 256-entry table, without the accumulation.
142
+ const identity = scaleX === 1 && scaleY === 1;
143
+ const direct = identity ? Uint8Array.from(lut, (value) => Math.min(255, Math.max(0, Math.round(encodeSrgbComponent(value) * 255)))) : undefined;
144
+ if (direct)
145
+ for (let by = 0; by < plan.outputHeight; by += 8) {
149
146
  check();
150
- for (let bx = 0, block = 0; bx < plan.outputWidth; bx += 8, block++) {
151
- const width = Math.min(8, plan.outputWidth - bx), left = plan.crop.x + bx * scaleX, right = bx + width === plan.outputWidth ? cropRight : plan.crop.x + (bx + width) * scaleX, base = block * 192;
152
- for (let sx = Math.floor(left); sx < Math.ceil(right); sx += 256) {
153
- const chunkWidth = Math.min(256, Math.ceil(right) - sx);
154
- for (let iy = 0; iy < bandHeight; iy++)
155
- for (let ix = 0; ix < chunkWidth; ix++) {
156
- const px = sx + ix, py = sy + iy;
157
- const firstX = Math.max(0, Math.floor((px - plan.crop.x) / scaleX) - bx), lastX = Math.min(width - 1, Math.ceil((px + 1 - plan.crop.x) / scaleX) - bx - 1);
158
- const firstY = Math.max(0, Math.floor((py - plan.crop.y) / scaleY) - by), lastY = Math.min(height - 1, Math.ceil((py + 1 - plan.crop.y) / scaleY) - by - 1);
159
- const index = (py - cacheTop) * rowBytes + (px - plan.crop.x) * 3, r = lut[cache[index]], g = lut[cache[index + 1]], b = lut[cache[index + 2]];
160
- for (let oy = firstY; oy <= lastY; oy++)
161
- for (let ox = firstX; ox <= lastX; ox++) {
162
- const x0 = plan.crop.x + (bx + ox) * scaleX, y0 = plan.crop.y + (by + oy) * scaleY;
163
- const weight = Math.max(0, Math.min(px + 1, x0 + scaleX) - Math.max(px, x0)) * Math.max(0, Math.min(py + 1, y0 + scaleY) - Math.max(py, y0)) / area;
164
- const i = base + (oy * 8 + ox) * 3;
165
- sums[i] = sums[i] + r * weight;
166
- sums[i + 1] = sums[i + 1] + g * weight;
167
- sums[i + 2] = sums[i + 2] + b * weight;
168
- }
169
- }
147
+ const height = Math.min(8, plan.outputHeight - by);
148
+ await ensureRows(plan.crop.y + by, height);
149
+ check();
150
+ for (let bx = 0; bx < plan.outputWidth; bx += 8) {
151
+ const width = Math.min(8, plan.outputWidth - bx), samples = [];
152
+ for (let y = 0; y < 8; y++) {
153
+ const row = (plan.crop.y + by + Math.min(y, height - 1) - cacheTop) * rowBytes + bx * 3;
154
+ for (let x = 0; x < 8; x++) {
155
+ const index = row + Math.min(x, width - 1) * 3;
156
+ samples.push(direct[cache[index]], direct[cache[index + 1]], direct[cache[index + 2]]);
157
+ }
158
+ }
159
+ check();
160
+ encoder.writeRgbBlock(samples);
161
+ if (++blocks % 32 === 0) {
162
+ await yieldControl(abort.signal);
163
+ check();
170
164
  }
171
165
  }
172
166
  }
173
- for (let bx = 0, block = 0; bx < plan.outputWidth; bx += 8, block++) {
174
- const width = Math.min(8, plan.outputWidth - bx), base = block * 192, samples = [];
175
- for (let y = 0; y < 8; y++)
176
- for (let x = 0; x < 8; x++)
177
- for (let c = 0; c < 3; c++) {
178
- const value = sums[base + (Math.min(y, height - 1) * 8 + Math.min(x, width - 1)) * 3 + c];
179
- // Nearest code, ties up. Math.round is used because floor(x+0.5) wrongly rounds 0.49999999999999994 up.
180
- samples.push(Math.min(255, Math.max(0, Math.round(encodeSrgbComponent(value) * 255))));
181
- }
167
+ else
168
+ for (let by = 0; by < plan.outputHeight; by += 8) {
182
169
  check();
183
- encoder.writeRgbBlock(samples);
184
- if (++blocks % 32 === 0) {
185
- await yieldControl(abort.signal);
170
+ sums.fill(0);
171
+ const height = Math.min(8, plan.outputHeight - by), top = plan.crop.y + by * scaleY, bottom = by + height === plan.outputHeight ? cropBottom : plan.crop.y + (by + height) * scaleY;
172
+ // Accumulation order per output pixel is unchanged from the per-block reader: 32-row bands from
173
+ // floor(top), then 256-column chunks from floor(left), then rows, then columns. Identical IEEE sums.
174
+ for (let sy = Math.floor(top); sy < Math.ceil(bottom); sy += 32) {
175
+ const bandHeight = Math.min(32, Math.ceil(bottom) - sy);
176
+ await ensureRows(sy, bandHeight);
186
177
  check();
178
+ for (let bx = 0, block = 0; bx < plan.outputWidth; bx += 8, block++) {
179
+ const width = Math.min(8, plan.outputWidth - bx), left = plan.crop.x + bx * scaleX, right = bx + width === plan.outputWidth ? cropRight : plan.crop.x + (bx + width) * scaleX, base = block * 192;
180
+ for (let sx = Math.floor(left); sx < Math.ceil(right); sx += 256) {
181
+ const chunkWidth = Math.min(256, Math.ceil(right) - sx);
182
+ for (let iy = 0; iy < bandHeight; iy++)
183
+ for (let ix = 0; ix < chunkWidth; ix++) {
184
+ const px = sx + ix, py = sy + iy;
185
+ const firstX = Math.max(0, Math.floor((px - plan.crop.x) / scaleX) - bx), lastX = Math.min(width - 1, Math.ceil((px + 1 - plan.crop.x) / scaleX) - bx - 1);
186
+ const firstY = Math.max(0, Math.floor((py - plan.crop.y) / scaleY) - by), lastY = Math.min(height - 1, Math.ceil((py + 1 - plan.crop.y) / scaleY) - by - 1);
187
+ const index = (py - cacheTop) * rowBytes + (px - plan.crop.x) * 3, r = lut[cache[index]], g = lut[cache[index + 1]], b = lut[cache[index + 2]];
188
+ for (let oy = firstY; oy <= lastY; oy++)
189
+ for (let ox = firstX; ox <= lastX; ox++) {
190
+ const x0 = plan.crop.x + (bx + ox) * scaleX, y0 = plan.crop.y + (by + oy) * scaleY;
191
+ const weight = Math.max(0, Math.min(px + 1, x0 + scaleX) - Math.max(px, x0)) * Math.max(0, Math.min(py + 1, y0 + scaleY) - Math.max(py, y0)) / area;
192
+ const i = base + (oy * 8 + ox) * 3;
193
+ sums[i] = sums[i] + r * weight;
194
+ sums[i + 1] = sums[i + 1] + g * weight;
195
+ sums[i + 2] = sums[i + 2] + b * weight;
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ for (let bx = 0, block = 0; bx < plan.outputWidth; bx += 8, block++) {
202
+ const width = Math.min(8, plan.outputWidth - bx), base = block * 192, samples = [];
203
+ for (let y = 0; y < 8; y++)
204
+ for (let x = 0; x < 8; x++)
205
+ for (let c = 0; c < 3; c++) {
206
+ const value = sums[base + (Math.min(y, height - 1) * 8 + Math.min(x, width - 1)) * 3 + c];
207
+ // Nearest code, ties up. Math.round is used because floor(x+0.5) wrongly rounds 0.49999999999999994 up.
208
+ samples.push(Math.min(255, Math.max(0, Math.round(encodeSrgbComponent(value) * 255))));
209
+ }
210
+ check();
211
+ encoder.writeRgbBlock(samples);
212
+ if (++blocks % 32 === 0) {
213
+ await yieldControl(abort.signal);
214
+ check();
215
+ }
187
216
  }
188
217
  }
189
- }
190
218
  await yieldControl(abort.signal);
191
219
  check();
192
220
  const bytes = encoder.finish();
@@ -1 +1 @@
1
- {"version":3,"file":"print-jpeg.js","sourceRoot":"","sources":["../../src/output/print-jpeg.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;GAGG;AACH,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAsB,MAAM,2BAA2B,CAAC;AAC5I,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGjH,MAAM,CAAC,MAAM,yBAAyB,GAAC,OAAgB,CAAC;AACxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAC,MAAM,CAAC,MAAM,CAAC,EAAC,aAAa,EAAC,UAAU,EAAC,aAAa,EAAC,8BAA8B,EAAC,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C,CAAA,CAAC;QACpF,UAAU,KAAmB,IAAG,KAAK,KAAG,WAAW,IAAE,CAAC,MAAM;YAAC,MAAM,IAAI,yBAAyB,CAAC,yBAAyB,CAAC,CAAC,CAAA,MAAM,KAAK,GAAC,MAAM,CAAC,CAAA,MAAM,GAAC,IAAI,CAAC,CAAA,KAAK,GAAC,aAAa,CAAC,CAAA,OAAO,KAAK,CAAC,CAAA,CAAC;KAC9L,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Print JPEG export: downsamples an SDR image by exact area averaging, then writes a baseline JPEG\n * with an ICC colour profile. Bounded in size; the encoder is written for this project.\n */\nimport { createExportJpegEncoder, EXPORT_JPEG_ENCODER_ID } from \"../capture/export-jpeg.js\";\nimport { packExportJpegExif, exportTiffNumbers, exportTiffAscii, exportTiffRationals, type ExportTiffTag } from \"../capture/export-tiff.js\";\nimport { createSrgbIccProfile, SRGB_ICC_PROFILE_VERSION } from \"../color/srgb-icc.js\";\nimport { decodeSrgbComponent, encodeSrgbComponent } from \"../color/srgb-transfer.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireAllowlistedRecord, requirePublicOpaqueId } from \"../core/record-validation.js\";\nimport { freezeOwnedData } from \"../core/owned-data.js\";\nimport { FULL_RESOLUTION_CEILING_PIXELS, resolveRaisedLimit, scaleBudgetCeiling } from \"../core/pixel-limits.js\";\nimport type { NativeRawTaskState } from \"../capture/native-raw.js\";\nimport type { RasterRect } from \"./capture-geometry.js\";\nexport const PRINT_JPEG_SCHEMA_VERSION=\"0.2.0\" as const;\n/**\n * Admission limits. `maximumPixels` is the default source limit; a request may raise it with its own\n * `maximumPixels`, up to `ceilingPixels`. A raised limit raises the `maximumEncodedBytes` ceiling in proportion\n * (256 000 000 bytes per 24 000 000 source pixels).\n */\nexport const PRINT_JPEG_LIMITS=Object.freeze({maximumPixels:24_000_000,ceilingPixels:FULL_RESOLUTION_CEILING_PIXELS,maximumDimension:16_384,\n maximumEncodedBytes:256_000_000,maximumProviderReads:1_000_000});\nlet srgbDecode:Float64Array|undefined;\n/** decodeSrgbComponent(v/255) for every 8-bit code v, computed once with the same function (identical values). */\nfunction srgbDecodeTable():Float64Array{return srgbDecode??=Float64Array.from({length:256},(_,v)=>decodeSrgbComponent(v/255));}\nexport interface PrintJpegSource {\n captureId:string;imageStateId:string;artifactId:string;sha256:string;\n width:number;height:number;\n encoding:\"encoded-srgb-8-rgb\";\n}\nexport interface PrintJpegInput {\n source:PrintJpegSource;\n /** Integer crop in the oriented output source image, not in sensor or CFA (colour filter array) coordinates. */\n crop:RasterRect;\n outputWidth:number;outputHeight:number;\n quantizationStep:number;\n maximumEncodedBytes:number;\n /**\n * Maximum provider `readTile` calls. The task reads each crop pixel exactly once, in tiles of at most\n * 256 x 32 pixels aligned to the crop origin, so it needs ceil(crop.height/32) x ceil(crop.width/256)\n * reads; a smaller budget fails before the first read.\n */\n maximumProviderReads:number;\n /**\n * Optional physical print density in pixels per inch (1..65535) from the caller's print plan. When present,\n * EXIF IFD0 records XResolution = YResolution = this value as a RATIONAL with ResolutionUnit = 2 (inches),\n * and JFIF APP0 records units = 1 with the nearest integer density (JFIF density fields are uint16).\n * When omitted no physical size is claimed: JFIF keeps units = 0 with a 1:1 aspect ratio. Exif 2.32 makes\n * the IFD0 resolution tags mandatory and says an unknown resolution \"shall\" be recorded as 72 dpi, so IFD0\n * carries 72/1 with ResolutionUnit = 2; that is the standard's unknown-resolution marker, not a print size.\n */\n pixelsPerInch?:number;\n /**\n * Optional opt-in source pixel limit for large images: an integer from 1 to `PRINT_JPEG_LIMITS.ceilingPixels`.\n * Default `PRINT_JPEG_LIMITS.maximumPixels` (24 000 000). When given it is recorded in the XMP export plan, like the\n * other admission budgets; the image data are unchanged.\n */\n maximumPixels?:number;\n}\nexport interface PrintJpegTileRequest {source:PrintJpegSource;x:number;y:number;width:number;height:number}\nexport interface PrintJpegTile extends PrintJpegTileRequest {samples:Uint8Array}\nexport interface PrintJpegProvider {\n readTile(request:Readonly<PrintJpegTileRequest>,signal:AbortSignal):Promise<PrintJpegTile>;\n yieldControl(signal:AbortSignal):Promise<void>;\n}\nexport interface PrintJpegOutput {\n schemaVersion:typeof PRINT_JPEG_SCHEMA_VERSION;\n input:PrintJpegInput;\n mediaType:\"image/jpeg\";\n bytes:Uint8Array;\n iccProfileVersion:typeof SRGB_ICC_PROFILE_VERSION;\n width:number;height:number;\n resampling:\"exact-area-average-in-decoded-linear-light\";\n sourceStage:\"post-SDR-8-bit-quantization\";\n digitalUpscalingApplied:false;\n sourceBytesVerified:false;\n /** Provider calls made: ceil(crop.height/32) x ceil(crop.width/256) tiles, each crop pixel read once. */\n providerReads:number;\n /** Byte behaviour of the baseline encoder that produced `bytes`. */\n encoderId:typeof EXPORT_JPEG_ENCODER_ID;\n}\nexport interface PrintJpegTask {\n readonly state:NativeRawTaskState;\n run():Promise<void>;cancel():void;dispose():void;takeOutput():PrintJpegOutput;\n}\n/** Exactly n/1 for a whole-number density; otherwise the shared bounded decimal-fraction approximation. */\nfunction resolutionRational(id:number,ppi:number):ExportTiffTag {\n if(!Number.isSafeInteger(ppi))return exportTiffRationals(id,false,[ppi]);\n const data=new Uint8Array(8),view=new DataView(data.buffer);view.setUint32(0,ppi,true);view.setUint32(4,1,true);\n return {id,type:5,count:1,data};\n}\n/**\n * Exif 2.32 APP1 for a compressed primary image with every mandatory tag (CIPA DC-008-2019 Tables 17-18):\n * IFD0 Orientation, X/YResolution + ResolutionUnit, Software, YCbCrPositioning; Exif IFD ExifVersion \"0232\",\n * ComponentsConfiguration, FlashpixVersion \"0100\", ColorSpace sRGB, PixelX/YDimension. Without a planned\n * density the resolution tags carry the standard's \"unknown resolution\" value of 72 dpi.\n */\nfunction printExif(plan:PrintJpegInput):Uint8Array {\n const ppi=plan.pixelsPerInch;\n const resolution=ppi===undefined ? [] : [resolutionRational(282,ppi),resolutionRational(283,ppi),exportTiffNumbers(296,3,[2])];\n return packExportJpegExif([exportTiffNumbers(274,3,[1]),...resolution,exportTiffAscii(305,\"Photivra Print JPEG\")],\n [exportTiffNumbers(40961,3,[1])],{pixelWidth:plan.outputWidth,pixelHeight:plan.outputHeight});\n}\nfunction integer(v:unknown,min=1):number {\n if(typeof v!==\"number\"||!Number.isSafeInteger(v)||v<min)throw new InvalidConfigurationError(\"Print raster/budgets require safe integers.\");return v;\n}\n/** Validates the input only. Source detail, perception and printer suitability are checked by separate APIs. */\nexport function parsePrintJpegInput(input:PrintJpegInput):PrintJpegInput {\n const r=requireAllowlistedRecord(input,[\"source\",\"crop\",\"outputWidth\",\"outputHeight\",\"quantizationStep\",\"maximumEncodedBytes\",\"maximumProviderReads\",\"pixelsPerInch\",\"maximumPixels\"],\"Invalid Print JPEG input.\");\n const s=requireAllowlistedRecord(r.source,[\"captureId\",\"imageStateId\",\"artifactId\",\"sha256\",\"width\",\"height\",\"encoding\"],\"Invalid Print source.\");\n if(typeof s.sha256!==\"string\"||!/^[a-f0-9]{64}$/.test(s.sha256)||s.encoding!==\"encoded-srgb-8-rgb\")throw new InvalidConfigurationError(\"Print requires identified encoded sRGB source bytes.\");\n const source:PrintJpegSource={captureId:requirePublicOpaqueId(s.captureId,\"Invalid capture ID.\"),imageStateId:requirePublicOpaqueId(s.imageStateId,\"Invalid image state ID.\"),artifactId:requirePublicOpaqueId(s.artifactId,\"Invalid artifact ID.\"),sha256:s.sha256,width:integer(s.width),height:integer(s.height),encoding:s.encoding};\n const c=requireAllowlistedRecord(r.crop,[\"x\",\"y\",\"width\",\"height\"],\"Invalid Print crop.\"),crop={x:integer(c.x,0),y:integer(c.y,0),width:integer(c.width),height:integer(c.height)};\n const outputWidth=integer(r.outputWidth),outputHeight=integer(r.outputHeight),quantizationStep=integer(r.quantizationStep),maximumEncodedBytes=integer(r.maximumEncodedBytes),maximumProviderReads=integer(r.maximumProviderReads);\n const L=PRINT_JPEG_LIMITS,maximumPixels=resolveRaisedLimit(r.maximumPixels,L.maximumPixels,L.ceilingPixels,\"Print maximumPixels must be an integer from 1 to \"+L.ceilingPixels+\".\");\n const encodedBytesCeiling=r.maximumPixels===undefined?L.maximumEncodedBytes:scaleBudgetCeiling(L.maximumEncodedBytes,maximumPixels);\n if(source.width>L.maximumDimension||source.height>L.maximumDimension||source.width*source.height>maximumPixels||crop.x+crop.width>source.width||crop.y+crop.height>source.height||\n outputWidth>crop.width||outputHeight>crop.height||quantizationStep>255||maximumEncodedBytes>encodedBytesCeiling||maximumProviderReads>L.maximumProviderReads||\n Math.abs(outputWidth*crop.height-outputHeight*crop.width)>.5*(crop.width+crop.height))throw new InvalidConfigurationError(\"Print requires bounded native/downsampled aspect-preserving crop output.\");\n const ppi=r.pixelsPerInch;\n if(ppi!==undefined&&(typeof ppi!==\"number\"||!Number.isFinite(ppi)||ppi<1||ppi>65535))throw new InvalidConfigurationError(\"Print density requires finite pixels per inch from 1 to 65535.\");\n return freezeOwnedData({source,crop,outputWidth,outputHeight,quantizationStep,maximumEncodedBytes,maximumProviderReads,...(ppi===undefined ? {} : {pixelsPerInch:ppi}),\n ...(r.maximumPixels===undefined ? {} : {maximumPixels})});\n}\n/** Creates the export task. Filtering weights each source pixel by its exact area overlap, after decoding the declared 8-bit SDR source. */\nexport function createPrintJpegTask(input:PrintJpegInput,provider:PrintJpegProvider):PrintJpegTask {\n const plan=parsePrintJpegInput(input);\n if(!provider||typeof provider.readTile!==\"function\"||typeof provider.yieldControl!==\"function\")throw new InvalidConfigurationError(\"Print export requires source reader and host yields.\");\n const read=provider.readTile.bind(provider),yieldControl=provider.yieldControl.bind(provider),abort=new AbortController();\n let state:NativeRawTaskState=\"ready\",output:PrintJpegOutput|null=null,encoder:ReturnType<typeof createExportJpegEncoder>|undefined;\n function check():void{if(abort.signal.aborted)throw new InvalidConfigurationError(\"Print export aborted.\");}\n function release():void{encoder?.dispose();encoder=undefined;output?.bytes.fill(0);output=null;}\n return {get state():NativeRawTaskState{return state;},\n async run():Promise<void>{\n if(state!==\"ready\")throw new InvalidConfigurationError(\"Print export is single-use.\");state=\"running\";\n try{\n const exif=printExif(plan);\n const escaped=JSON.stringify(plan).replaceAll(\"&\",\"&amp;\").replaceAll('\"',\"&quot;\").replaceAll(\"<\",\"&lt;\").replaceAll(\">\",\"&gt;\");\n const xmp=new TextEncoder().encode('<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description rdf:about=\"\" xmlns:photivra=\"https://photivra.com/ns/simulation/1.0/\" photivra:PrintExportPlan=\"'+escaped+'\" photivra:SourceBytesVerified=\"False\"/></rdf:RDF></x:xmpmeta>');\n encoder=createExportJpegEncoder({width:plan.outputWidth,height:plan.outputHeight,quantizationStep:plan.quantizationStep,maximumOutputBytes:plan.maximumEncodedBytes,icc:createSrgbIccProfile(),exif,xmp,\n ...(plan.pixelsPerInch===undefined ? {} : {densityDotsPerInch:Math.round(plan.pixelsPerInch)})});\n const scaleX=plan.crop.width/plan.outputWidth,scaleY=plan.crop.height/plan.outputHeight,area=scaleX*scaleY;\n const cropRight=plan.crop.x+plan.crop.width,cropBottom=plan.crop.y+plan.crop.height,rowBytes=plan.crop.width*3;\n // Every crop pixel is read exactly once, in tiles of at most 256 x 32 aligned to the crop origin.\n const tilesPerBand=Math.ceil(plan.crop.width/256),requiredReads=Math.ceil(plan.crop.height/32)*tilesPerBand;\n if(requiredReads>plan.maximumProviderReads)throw new InvalidConfigurationError(\"Print source exceeds provider-read budget.\");\n // Rolling cache of whole crop-width source rows [cacheTop, cacheBottom): at most 63 rows are retained.\n const cache=new Uint8Array(Math.min(64,plan.crop.height)*rowBytes),lut=srgbDecodeTable();\n let reads=0,blocks=0,cacheTop=plan.crop.y,cacheBottom=plan.crop.y;\n const ensureRows=async(firstRow:number,rowCount:number):Promise<void>=>{\n const keepFrom=Math.min(Math.max(cacheTop,firstRow),cacheBottom);\n if(keepFrom>cacheTop){cache.copyWithin(0,(keepFrom-cacheTop)*rowBytes,(cacheBottom-cacheTop)*rowBytes);cacheTop=keepFrom;}\n while(cacheBottom<firstRow+rowCount){\n const bandHeight=Math.min(32,cropBottom-cacheBottom);\n if((cacheBottom+bandHeight-cacheTop)*rowBytes>cache.length)throw new InvalidConfigurationError(\"Print source traversal is not monotonic.\");\n for(let sx=plan.crop.x;sx<cropRight;sx+=256){\n check();++reads;\n const request=Object.freeze({source:plan.source,x:sx,y:cacheBottom,width:Math.min(256,cropRight-sx),height:bandHeight});\n const supplied=await read(request,abort.signal);check();\n const tile=requireAllowlistedRecord(supplied,[\"source\",\"x\",\"y\",\"width\",\"height\",\"samples\"],\"Invalid Print source tile.\");\n const source=requireAllowlistedRecord(tile.source,[\"captureId\",\"imageStateId\",\"artifactId\",\"sha256\",\"width\",\"height\",\"encoding\"],\"Invalid Print tile source.\");\n for(const key of Object.keys(plan.source) as (keyof PrintJpegSource)[])if(source[key]!==plan.source[key])throw new InvalidConfigurationError(\"Print source identity mismatch.\");\n for(const key of [\"x\",\"y\",\"width\",\"height\"] as const)if(tile[key]!==request[key])throw new InvalidConfigurationError(\"Print source rectangle mismatch.\");\n const samples=tile.samples;if(!(samples instanceof Uint8Array)||!(samples.buffer instanceof ArrayBuffer)||samples.length!==request.width*request.height*3||samples.buffer.byteLength!==samples.byteLength)throw new InvalidConfigurationError(\"Print source requires exact owned bounded RGB tile storage.\");\n for(let iy=0;iy<bandHeight;iy++)cache.set(samples.subarray(iy*request.width*3,(iy+1)*request.width*3),(cacheBottom-cacheTop+iy)*rowBytes+(sx-plan.crop.x)*3);\n // One output block can cover a megapixel of source, so also yield to the host while reading the source.\n if(reads%32===0){await yieldControl(abort.signal);check();}\n }\n cacheBottom+=bandHeight;\n }\n };\n const blocksX=Math.ceil(plan.outputWidth/8),sums=new Float64Array(blocksX*192);\n for(let by=0;by<plan.outputHeight;by+=8){\n check();sums.fill(0);\n const height=Math.min(8,plan.outputHeight-by),top=plan.crop.y+by*scaleY,bottom=by+height===plan.outputHeight?cropBottom:plan.crop.y+(by+height)*scaleY;\n // Accumulation order per output pixel is unchanged from the per-block reader: 32-row bands from\n // floor(top), then 256-column chunks from floor(left), then rows, then columns. Identical IEEE sums.\n for(let sy=Math.floor(top);sy<Math.ceil(bottom);sy+=32){\n const bandHeight=Math.min(32,Math.ceil(bottom)-sy);await ensureRows(sy,bandHeight);check();\n for(let bx=0,block=0;bx<plan.outputWidth;bx+=8,block++){\n const width=Math.min(8,plan.outputWidth-bx),left=plan.crop.x+bx*scaleX,right=bx+width===plan.outputWidth?cropRight:plan.crop.x+(bx+width)*scaleX,base=block*192;\n for(let sx=Math.floor(left);sx<Math.ceil(right);sx+=256){\n const chunkWidth=Math.min(256,Math.ceil(right)-sx);\n for(let iy=0;iy<bandHeight;iy++)for(let ix=0;ix<chunkWidth;ix++){\n const px=sx+ix,py=sy+iy;\n const firstX=Math.max(0,Math.floor((px-plan.crop.x)/scaleX)-bx),lastX=Math.min(width-1,Math.ceil((px+1-plan.crop.x)/scaleX)-bx-1);\n const firstY=Math.max(0,Math.floor((py-plan.crop.y)/scaleY)-by),lastY=Math.min(height-1,Math.ceil((py+1-plan.crop.y)/scaleY)-by-1);\n const index=(py-cacheTop)*rowBytes+(px-plan.crop.x)*3,r=lut[cache[index]!]!,g=lut[cache[index+1]!]!,b=lut[cache[index+2]!]!;\n for(let oy=firstY;oy<=lastY;oy++)for(let ox=firstX;ox<=lastX;ox++){\n const x0=plan.crop.x+(bx+ox)*scaleX,y0=plan.crop.y+(by+oy)*scaleY;\n const weight=Math.max(0,Math.min(px+1,x0+scaleX)-Math.max(px,x0))*Math.max(0,Math.min(py+1,y0+scaleY)-Math.max(py,y0))/area;\n const i=base+(oy*8+ox)*3;sums[i]=sums[i]!+r*weight;sums[i+1]=sums[i+1]!+g*weight;sums[i+2]=sums[i+2]!+b*weight;\n }\n }\n }\n }\n }\n for(let bx=0,block=0;bx<plan.outputWidth;bx+=8,block++){\n const width=Math.min(8,plan.outputWidth-bx),base=block*192,samples:number[]=[];\n for(let y=0;y<8;y++)for(let x=0;x<8;x++)for(let c=0;c<3;c++){\n const value=sums[base+(Math.min(y,height-1)*8+Math.min(x,width-1))*3+c]!;\n // Nearest code, ties up. Math.round is used because floor(x+0.5) wrongly rounds 0.49999999999999994 up.\n samples.push(Math.min(255,Math.max(0,Math.round(encodeSrgbComponent(value)*255))));\n }\n check();encoder.writeRgbBlock(samples);if(++blocks%32===0){await yieldControl(abort.signal);check();}\n }\n }\n await yieldControl(abort.signal);check();const bytes=encoder.finish();encoder=undefined;\n output={schemaVersion:PRINT_JPEG_SCHEMA_VERSION,input:plan,mediaType:\"image/jpeg\",bytes,iccProfileVersion:SRGB_ICC_PROFILE_VERSION,width:plan.outputWidth,height:plan.outputHeight,resampling:\"exact-area-average-in-decoded-linear-light\",sourceStage:\"post-SDR-8-bit-quantization\",digitalUpscalingApplied:false,sourceBytesVerified:false,providerReads:reads,encoderId:EXPORT_JPEG_ENCODER_ID};state=\"completed\";\n }catch(error){release();if(!abort.signal.aborted){state=\"failed\";abort.abort();}throw error;}\n },cancel():void{if(state===\"ready\"||state===\"running\"||state===\"completed\"){state=\"cancelled\";abort.abort();release();}},\n dispose():void{if(state!==\"transferred\"){state=\"disposed\";abort.abort();release();}},\n takeOutput():PrintJpegOutput{if(state!==\"completed\"||!output)throw new InvalidConfigurationError(\"Print JPEG unavailable.\");const value=output;output=null;state=\"transferred\";return value;}\n };\n}\n"]}
1
+ {"version":3,"file":"print-jpeg.js","sourceRoot":"","sources":["../../src/output/print-jpeg.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;GAGG;AACH,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAsB,MAAM,2BAA2B,CAAC;AAC5I,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,m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CAAC;YAAA,OAAO,EAAE,CAAC;QAAA,CAAC,CAAA,CAAC;QACpF,UAAU,KAAmB,IAAG,KAAK,KAAG,WAAW,IAAE,CAAC,MAAM;YAAC,MAAM,IAAI,yBAAyB,CAAC,yBAAyB,CAAC,CAAC,CAAA,MAAM,KAAK,GAAC,MAAM,CAAC,CAAA,MAAM,GAAC,IAAI,CAAC,CAAA,KAAK,GAAC,aAAa,CAAC,CAAA,OAAO,KAAK,CAAC,CAAA,CAAC;KAC9L,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Print JPEG export: downsamples an SDR image by exact area averaging, then writes a baseline JPEG\n * with an ICC colour profile. Bounded in size; the encoder is written for this project.\n */\nimport { createExportJpegEncoder, EXPORT_JPEG_ENCODER_ID } from \"../capture/export-jpeg.js\";\nimport { packExportJpegExif, exportTiffNumbers, exportTiffAscii, exportTiffRationals, type ExportTiffTag } from \"../capture/export-tiff.js\";\nimport { createSrgbIccProfile, SRGB_ICC_PROFILE_VERSION } from \"../color/srgb-icc.js\";\nimport { decodeSrgbComponent, encodeSrgbComponent } from \"../color/srgb-transfer.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireAllowlistedRecord, requirePublicOpaqueId } from \"../core/record-validation.js\";\nimport { freezeOwnedData } from \"../core/owned-data.js\";\nimport { FULL_RESOLUTION_CEILING_PIXELS, resolveRaisedLimit, scaleBudgetCeiling } from \"../core/pixel-limits.js\";\nimport type { NativeRawTaskState } from \"../capture/native-raw.js\";\nimport type { RasterRect } from \"./capture-geometry.js\";\nexport const PRINT_JPEG_SCHEMA_VERSION=\"0.2.0\" as const;\n/**\n * Admission limits. `maximumPixels` is the default source limit; a request may raise it with its own\n * `maximumPixels`, up to `ceilingPixels`. A raised limit raises the `maximumEncodedBytes` ceiling in proportion\n * (256 000 000 bytes per 24 000 000 source pixels).\n */\nexport const PRINT_JPEG_LIMITS=Object.freeze({maximumPixels:24_000_000,ceilingPixels:FULL_RESOLUTION_CEILING_PIXELS,maximumDimension:16_384,\n maximumEncodedBytes:256_000_000,maximumProviderReads:1_000_000});\nlet srgbDecode:Float64Array|undefined;\n/** decodeSrgbComponent(v/255) for every 8-bit code v, computed once with the same function (identical values). */\nfunction srgbDecodeTable():Float64Array{return srgbDecode??=Float64Array.from({length:256},(_,v)=>decodeSrgbComponent(v/255));}\nexport interface PrintJpegSource {\n captureId:string;imageStateId:string;artifactId:string;sha256:string;\n width:number;height:number;\n encoding:\"encoded-srgb-8-rgb\";\n}\nexport interface PrintJpegInput {\n source:PrintJpegSource;\n /** Integer crop in the oriented output source image, not in sensor or CFA (colour filter array) coordinates. */\n crop:RasterRect;\n outputWidth:number;outputHeight:number;\n quantizationStep:number;\n maximumEncodedBytes:number;\n /**\n * Maximum provider `readTile` calls. The task reads each crop pixel exactly once, in tiles of at most\n * 256 x 32 pixels aligned to the crop origin, so it needs ceil(crop.height/32) x ceil(crop.width/256)\n * reads; a smaller budget fails before the first read.\n */\n maximumProviderReads:number;\n /**\n * Optional physical print density in pixels per inch (1..65535) from the caller's print plan. When present,\n * EXIF IFD0 records XResolution = YResolution = this value as a RATIONAL with ResolutionUnit = 2 (inches),\n * and JFIF APP0 records units = 1 with the nearest integer density (JFIF density fields are uint16).\n * When omitted no physical size is claimed: JFIF keeps units = 0 with a 1:1 aspect ratio. Exif 2.32 makes\n * the IFD0 resolution tags mandatory and says an unknown resolution \"shall\" be recorded as 72 dpi, so IFD0\n * carries 72/1 with ResolutionUnit = 2; that is the standard's unknown-resolution marker, not a print size.\n */\n pixelsPerInch?:number;\n /**\n * Optional opt-in source pixel limit for large images: an integer from 1 to `PRINT_JPEG_LIMITS.ceilingPixels`.\n * Default `PRINT_JPEG_LIMITS.maximumPixels` (24 000 000). When given it is recorded in the XMP export plan, like the\n * other admission budgets; the image data are unchanged.\n */\n maximumPixels?:number;\n}\nexport interface PrintJpegTileRequest {source:PrintJpegSource;x:number;y:number;width:number;height:number}\nexport interface PrintJpegTile extends PrintJpegTileRequest {samples:Uint8Array}\nexport interface PrintJpegProvider {\n readTile(request:Readonly<PrintJpegTileRequest>,signal:AbortSignal):Promise<PrintJpegTile>;\n yieldControl(signal:AbortSignal):Promise<void>;\n}\nexport interface PrintJpegOutput {\n schemaVersion:typeof PRINT_JPEG_SCHEMA_VERSION;\n input:PrintJpegInput;\n mediaType:\"image/jpeg\";\n bytes:Uint8Array;\n iccProfileVersion:typeof SRGB_ICC_PROFILE_VERSION;\n width:number;height:number;\n resampling:\"exact-area-average-in-decoded-linear-light\";\n sourceStage:\"post-SDR-8-bit-quantization\";\n digitalUpscalingApplied:false;\n sourceBytesVerified:false;\n /** Provider calls made: ceil(crop.height/32) x ceil(crop.width/256) tiles, each crop pixel read once. */\n providerReads:number;\n /** Byte behaviour of the baseline encoder that produced `bytes`. */\n encoderId:typeof EXPORT_JPEG_ENCODER_ID;\n}\nexport interface PrintJpegTask {\n readonly state:NativeRawTaskState;\n run():Promise<void>;cancel():void;dispose():void;takeOutput():PrintJpegOutput;\n}\n/** Exactly n/1 for a whole-number density; otherwise the shared bounded decimal-fraction approximation. */\nfunction resolutionRational(id:number,ppi:number):ExportTiffTag {\n if(!Number.isSafeInteger(ppi))return exportTiffRationals(id,false,[ppi]);\n const data=new Uint8Array(8),view=new DataView(data.buffer);view.setUint32(0,ppi,true);view.setUint32(4,1,true);\n return {id,type:5,count:1,data};\n}\n/**\n * Exif 2.32 APP1 for a compressed primary image with every mandatory tag (CIPA DC-008-2019 Tables 17-18):\n * IFD0 Orientation, X/YResolution + ResolutionUnit, Software, YCbCrPositioning; Exif IFD ExifVersion \"0232\",\n * ComponentsConfiguration, FlashpixVersion \"0100\", ColorSpace sRGB, PixelX/YDimension. Without a planned\n * density the resolution tags carry the standard's \"unknown resolution\" value of 72 dpi.\n */\nfunction printExif(plan:PrintJpegInput):Uint8Array {\n const ppi=plan.pixelsPerInch;\n const resolution=ppi===undefined ? [] : [resolutionRational(282,ppi),resolutionRational(283,ppi),exportTiffNumbers(296,3,[2])];\n return packExportJpegExif([exportTiffNumbers(274,3,[1]),...resolution,exportTiffAscii(305,\"Photivra Print JPEG\")],\n [exportTiffNumbers(40961,3,[1])],{pixelWidth:plan.outputWidth,pixelHeight:plan.outputHeight});\n}\nfunction integer(v:unknown,min=1):number {\n if(typeof v!==\"number\"||!Number.isSafeInteger(v)||v<min)throw new InvalidConfigurationError(\"Print raster/budgets require safe integers.\");return v;\n}\n/** Validates the input only. Source detail, perception and printer suitability are checked by separate APIs. */\nexport function parsePrintJpegInput(input:PrintJpegInput):PrintJpegInput {\n const r=requireAllowlistedRecord(input,[\"source\",\"crop\",\"outputWidth\",\"outputHeight\",\"quantizationStep\",\"maximumEncodedBytes\",\"maximumProviderReads\",\"pixelsPerInch\",\"maximumPixels\"],\"Invalid Print JPEG input.\");\n const s=requireAllowlistedRecord(r.source,[\"captureId\",\"imageStateId\",\"artifactId\",\"sha256\",\"width\",\"height\",\"encoding\"],\"Invalid Print source.\");\n if(typeof s.sha256!==\"string\"||!/^[a-f0-9]{64}$/.test(s.sha256)||s.encoding!==\"encoded-srgb-8-rgb\")throw new InvalidConfigurationError(\"Print requires identified encoded sRGB source bytes.\");\n const source:PrintJpegSource={captureId:requirePublicOpaqueId(s.captureId,\"Invalid capture ID.\"),imageStateId:requirePublicOpaqueId(s.imageStateId,\"Invalid image state ID.\"),artifactId:requirePublicOpaqueId(s.artifactId,\"Invalid artifact ID.\"),sha256:s.sha256,width:integer(s.width),height:integer(s.height),encoding:s.encoding};\n const c=requireAllowlistedRecord(r.crop,[\"x\",\"y\",\"width\",\"height\"],\"Invalid Print crop.\"),crop={x:integer(c.x,0),y:integer(c.y,0),width:integer(c.width),height:integer(c.height)};\n const outputWidth=integer(r.outputWidth),outputHeight=integer(r.outputHeight),quantizationStep=integer(r.quantizationStep),maximumEncodedBytes=integer(r.maximumEncodedBytes),maximumProviderReads=integer(r.maximumProviderReads);\n const L=PRINT_JPEG_LIMITS,maximumPixels=resolveRaisedLimit(r.maximumPixels,L.maximumPixels,L.ceilingPixels,\"Print maximumPixels must be an integer from 1 to \"+L.ceilingPixels+\".\");\n const encodedBytesCeiling=r.maximumPixels===undefined?L.maximumEncodedBytes:scaleBudgetCeiling(L.maximumEncodedBytes,maximumPixels);\n if(source.width>L.maximumDimension||source.height>L.maximumDimension||source.width*source.height>maximumPixels||crop.x+crop.width>source.width||crop.y+crop.height>source.height||\n outputWidth>crop.width||outputHeight>crop.height||quantizationStep>255||maximumEncodedBytes>encodedBytesCeiling||maximumProviderReads>L.maximumProviderReads||\n Math.abs(outputWidth*crop.height-outputHeight*crop.width)>.5*(crop.width+crop.height))throw new InvalidConfigurationError(\"Print requires bounded native/downsampled aspect-preserving crop output.\");\n const ppi=r.pixelsPerInch;\n if(ppi!==undefined&&(typeof ppi!==\"number\"||!Number.isFinite(ppi)||ppi<1||ppi>65535))throw new InvalidConfigurationError(\"Print density requires finite pixels per inch from 1 to 65535.\");\n return freezeOwnedData({source,crop,outputWidth,outputHeight,quantizationStep,maximumEncodedBytes,maximumProviderReads,...(ppi===undefined ? {} : {pixelsPerInch:ppi}),\n ...(r.maximumPixels===undefined ? {} : {maximumPixels})});\n}\n/** Creates the export task. Filtering weights each source pixel by its exact area overlap, after decoding the declared 8-bit SDR source. */\nexport function createPrintJpegTask(input:PrintJpegInput,provider:PrintJpegProvider):PrintJpegTask {\n const plan=parsePrintJpegInput(input);\n if(!provider||typeof provider.readTile!==\"function\"||typeof provider.yieldControl!==\"function\")throw new InvalidConfigurationError(\"Print export requires source reader and host yields.\");\n const read=provider.readTile.bind(provider),yieldControl=provider.yieldControl.bind(provider),abort=new AbortController();\n let state:NativeRawTaskState=\"ready\",output:PrintJpegOutput|null=null,encoder:ReturnType<typeof createExportJpegEncoder>|undefined;\n function check():void{if(abort.signal.aborted)throw new InvalidConfigurationError(\"Print export aborted.\");}\n function release():void{encoder?.dispose();encoder=undefined;output?.bytes.fill(0);output=null;}\n return {get state():NativeRawTaskState{return state;},\n async run():Promise<void>{\n if(state!==\"ready\")throw new InvalidConfigurationError(\"Print export is single-use.\");state=\"running\";\n try{\n const exif=printExif(plan);\n const escaped=JSON.stringify(plan).replaceAll(\"&\",\"&amp;\").replaceAll('\"',\"&quot;\").replaceAll(\"<\",\"&lt;\").replaceAll(\">\",\"&gt;\");\n const xmp=new TextEncoder().encode('<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description rdf:about=\"\" xmlns:photivra=\"https://photivra.com/ns/simulation/1.0/\" photivra:PrintExportPlan=\"'+escaped+'\" photivra:SourceBytesVerified=\"False\"/></rdf:RDF></x:xmpmeta>');\n encoder=createExportJpegEncoder({width:plan.outputWidth,height:plan.outputHeight,quantizationStep:plan.quantizationStep,maximumOutputBytes:plan.maximumEncodedBytes,icc:createSrgbIccProfile(),exif,xmp,\n ...(plan.pixelsPerInch===undefined ? {} : {densityDotsPerInch:Math.round(plan.pixelsPerInch)})});\n const scaleX=plan.crop.width/plan.outputWidth,scaleY=plan.crop.height/plan.outputHeight,area=scaleX*scaleY;\n const cropRight=plan.crop.x+plan.crop.width,cropBottom=plan.crop.y+plan.crop.height,rowBytes=plan.crop.width*3;\n // Every crop pixel is read exactly once, in tiles of at most 256 x 32 aligned to the crop origin.\n const tilesPerBand=Math.ceil(plan.crop.width/256),requiredReads=Math.ceil(plan.crop.height/32)*tilesPerBand;\n if(requiredReads>plan.maximumProviderReads)throw new InvalidConfigurationError(\"Print source exceeds provider-read budget.\");\n // Rolling cache of whole crop-width source rows [cacheTop, cacheBottom): at most 63 rows are retained.\n const cache=new Uint8Array(Math.min(64,plan.crop.height)*rowBytes),lut=srgbDecodeTable();\n let reads=0,blocks=0,cacheTop=plan.crop.y,cacheBottom=plan.crop.y;\n const ensureRows=async(firstRow:number,rowCount:number):Promise<void>=>{\n const keepFrom=Math.min(Math.max(cacheTop,firstRow),cacheBottom);\n if(keepFrom>cacheTop){cache.copyWithin(0,(keepFrom-cacheTop)*rowBytes,(cacheBottom-cacheTop)*rowBytes);cacheTop=keepFrom;}\n while(cacheBottom<firstRow+rowCount){\n const bandHeight=Math.min(32,cropBottom-cacheBottom);\n if((cacheBottom+bandHeight-cacheTop)*rowBytes>cache.length)throw new InvalidConfigurationError(\"Print source traversal is not monotonic.\");\n for(let sx=plan.crop.x;sx<cropRight;sx+=256){\n check();++reads;\n const request=Object.freeze({source:plan.source,x:sx,y:cacheBottom,width:Math.min(256,cropRight-sx),height:bandHeight});\n const supplied=await read(request,abort.signal);check();\n const tile=requireAllowlistedRecord(supplied,[\"source\",\"x\",\"y\",\"width\",\"height\",\"samples\"],\"Invalid Print source tile.\");\n const source=requireAllowlistedRecord(tile.source,[\"captureId\",\"imageStateId\",\"artifactId\",\"sha256\",\"width\",\"height\",\"encoding\"],\"Invalid Print tile source.\");\n for(const key of Object.keys(plan.source) as (keyof PrintJpegSource)[])if(source[key]!==plan.source[key])throw new InvalidConfigurationError(\"Print source identity mismatch.\");\n for(const key of [\"x\",\"y\",\"width\",\"height\"] as const)if(tile[key]!==request[key])throw new InvalidConfigurationError(\"Print source rectangle mismatch.\");\n const samples=tile.samples;if(!(samples instanceof Uint8Array)||!(samples.buffer instanceof ArrayBuffer)||samples.length!==request.width*request.height*3||samples.buffer.byteLength!==samples.byteLength)throw new InvalidConfigurationError(\"Print source requires exact owned bounded RGB tile storage.\");\n for(let iy=0;iy<bandHeight;iy++)cache.set(samples.subarray(iy*request.width*3,(iy+1)*request.width*3),(cacheBottom-cacheTop+iy)*rowBytes+(sx-plan.crop.x)*3);\n // One output block can cover a megapixel of source, so also yield to the host while reading the source.\n if(reads%32===0){await yieldControl(abort.signal);check();}\n }\n cacheBottom+=bandHeight;\n }\n };\n const blocksX=Math.ceil(plan.outputWidth/8),sums=new Float64Array(blocksX*192);\n // At 1:1 every output pixel is one source pixel with weight exactly 1, so its sum is exactly lut[code] and its\n // sample is a function of the code alone: the same bytes from a 256-entry table, without the accumulation.\n const identity=scaleX===1&&scaleY===1;\n const direct=identity?Uint8Array.from(lut,(value)=>Math.min(255,Math.max(0,Math.round(encodeSrgbComponent(value)*255)))):undefined;\n if(direct)for(let by=0;by<plan.outputHeight;by+=8){\n check();\n const height=Math.min(8,plan.outputHeight-by);await ensureRows(plan.crop.y+by,height);check();\n for(let bx=0;bx<plan.outputWidth;bx+=8){\n const width=Math.min(8,plan.outputWidth-bx),samples:number[]=[];\n for(let y=0;y<8;y++){\n const row=(plan.crop.y+by+Math.min(y,height-1)-cacheTop)*rowBytes+bx*3;\n for(let x=0;x<8;x++){const index=row+Math.min(x,width-1)*3;samples.push(direct[cache[index]!]!,direct[cache[index+1]!]!,direct[cache[index+2]!]!);}\n }\n check();encoder.writeRgbBlock(samples);if(++blocks%32===0){await yieldControl(abort.signal);check();}\n }\n }\n else for(let by=0;by<plan.outputHeight;by+=8){\n check();sums.fill(0);\n const height=Math.min(8,plan.outputHeight-by),top=plan.crop.y+by*scaleY,bottom=by+height===plan.outputHeight?cropBottom:plan.crop.y+(by+height)*scaleY;\n // Accumulation order per output pixel is unchanged from the per-block reader: 32-row bands from\n // floor(top), then 256-column chunks from floor(left), then rows, then columns. Identical IEEE sums.\n for(let sy=Math.floor(top);sy<Math.ceil(bottom);sy+=32){\n const bandHeight=Math.min(32,Math.ceil(bottom)-sy);await ensureRows(sy,bandHeight);check();\n for(let bx=0,block=0;bx<plan.outputWidth;bx+=8,block++){\n const width=Math.min(8,plan.outputWidth-bx),left=plan.crop.x+bx*scaleX,right=bx+width===plan.outputWidth?cropRight:plan.crop.x+(bx+width)*scaleX,base=block*192;\n for(let sx=Math.floor(left);sx<Math.ceil(right);sx+=256){\n const chunkWidth=Math.min(256,Math.ceil(right)-sx);\n for(let iy=0;iy<bandHeight;iy++)for(let ix=0;ix<chunkWidth;ix++){\n const px=sx+ix,py=sy+iy;\n const firstX=Math.max(0,Math.floor((px-plan.crop.x)/scaleX)-bx),lastX=Math.min(width-1,Math.ceil((px+1-plan.crop.x)/scaleX)-bx-1);\n const firstY=Math.max(0,Math.floor((py-plan.crop.y)/scaleY)-by),lastY=Math.min(height-1,Math.ceil((py+1-plan.crop.y)/scaleY)-by-1);\n const index=(py-cacheTop)*rowBytes+(px-plan.crop.x)*3,r=lut[cache[index]!]!,g=lut[cache[index+1]!]!,b=lut[cache[index+2]!]!;\n for(let oy=firstY;oy<=lastY;oy++)for(let ox=firstX;ox<=lastX;ox++){\n const x0=plan.crop.x+(bx+ox)*scaleX,y0=plan.crop.y+(by+oy)*scaleY;\n const weight=Math.max(0,Math.min(px+1,x0+scaleX)-Math.max(px,x0))*Math.max(0,Math.min(py+1,y0+scaleY)-Math.max(py,y0))/area;\n const i=base+(oy*8+ox)*3;sums[i]=sums[i]!+r*weight;sums[i+1]=sums[i+1]!+g*weight;sums[i+2]=sums[i+2]!+b*weight;\n }\n }\n }\n }\n }\n for(let bx=0,block=0;bx<plan.outputWidth;bx+=8,block++){\n const width=Math.min(8,plan.outputWidth-bx),base=block*192,samples:number[]=[];\n for(let y=0;y<8;y++)for(let x=0;x<8;x++)for(let c=0;c<3;c++){\n const value=sums[base+(Math.min(y,height-1)*8+Math.min(x,width-1))*3+c]!;\n // Nearest code, ties up. Math.round is used because floor(x+0.5) wrongly rounds 0.49999999999999994 up.\n samples.push(Math.min(255,Math.max(0,Math.round(encodeSrgbComponent(value)*255))));\n }\n check();encoder.writeRgbBlock(samples);if(++blocks%32===0){await yieldControl(abort.signal);check();}\n }\n }\n await yieldControl(abort.signal);check();const bytes=encoder.finish();encoder=undefined;\n output={schemaVersion:PRINT_JPEG_SCHEMA_VERSION,input:plan,mediaType:\"image/jpeg\",bytes,iccProfileVersion:SRGB_ICC_PROFILE_VERSION,width:plan.outputWidth,height:plan.outputHeight,resampling:\"exact-area-average-in-decoded-linear-light\",sourceStage:\"post-SDR-8-bit-quantization\",digitalUpscalingApplied:false,sourceBytesVerified:false,providerReads:reads,encoderId:EXPORT_JPEG_ENCODER_ID};state=\"completed\";\n }catch(error){release();if(!abort.signal.aborted){state=\"failed\";abort.abort();}throw error;}\n },cancel():void{if(state===\"ready\"||state===\"running\"||state===\"completed\"){state=\"cancelled\";abort.abort();release();}},\n dispose():void{if(state!==\"transferred\"){state=\"disposed\";abort.abort();release();}},\n takeOutput():PrintJpegOutput{if(state!==\"completed\"||!output)throw new InvalidConfigurationError(\"Print JPEG unavailable.\");const value=output;output=null;state=\"transferred\";return value;}\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  # Public API reference
2
2
 
3
- Generated from the exact root exports for **@photivra/engine 2.8.0 / root contract 2.8.0** by `node scripts/generate-api-reference.mjs`. No module deep import is supported.
3
+ Generated from the exact root exports for **@photivra/engine 2.8.1 / root contract 2.8.1** by `node scripts/generate-api-reference.mjs`. No module deep import is supported.
4
4
 
5
5
  Use [the developer guide](https://github.com/Photivra/photivra/blob/main/docs/DEVELOPERS.md) for executable paths and scientific boundaries. Types are contracts, not runtime validation: parse untrusted data, preserve units/reference frames, read assessment blockers, and retain evidence/limitations. Optional properties do not imply a universal default. Model/schema IDs remain independent of the distribution.
6
6
 
@@ -11,5 +11,5 @@ version they were made with. Proof-of-concept (POC), schema and model contracts
11
11
  own versions. Release checks confirm it matches package.json and the packed package.
12
12
 
13
13
  ```ts
14
- ENGINE_API_VERSION = "2.8.0" as const
14
+ ENGINE_API_VERSION = "2.8.1" as const
15
15
  ```
@@ -1,6 +1,6 @@
1
1
  {
2
- "packageVersion": "2.8.0",
3
- "engineApiVersion": "2.8.0",
2
+ "packageVersion": "2.8.1",
3
+ "engineApiVersion": "2.8.1",
4
4
  "exports": [
5
5
  {
6
6
  "name": "AbsoluteUncertaintyEstimate",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@photivra/engine",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "private": false,
5
5
  "description": "Scientific TypeScript engine for camera optics, exposure, focus, motion, sensor sampling, diffraction, and digital imaging calculations.",
6
6
  "type": "module",