rig-parts 2.69.0 → 2.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/visibility.ts CHANGED
@@ -4,7 +4,7 @@ import { lstatSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { depthSheetProblems } from './depthsheets.ts';
6
6
  import { foldName, PartsError, type Problem, refuseIfAny } from './errors.ts';
7
- import { readWrapperLayers, type Layer, type LayerSet } from './layers.ts';
7
+ import { readWrapperLayers, type Layer, type LayerSet, type WrapperReadings } from './layers.ts';
8
8
  import { decodePngBytes } from './raster/png.ts';
9
9
  import type { Raster } from './raster/types.ts';
10
10
  import { readLayerTag } from './tags.ts';
@@ -177,9 +177,9 @@ function sourceNames(dir: string, bytes: Buffer): string[] {
177
177
  return names;
178
178
  }
179
179
 
180
- function readWrapper(dir: string, sealed: ReadonlyMap<string, Buffer>): ReturnType<typeof readWrapperLayers> {
180
+ function readWrapper(dir: string, sealed: ReadonlyMap<string, Buffer>, readings?: WrapperReadings): ReturnType<typeof readWrapperLayers> {
181
181
  try {
182
- return readWrapperLayers(dir, undefined, sealed);
182
+ return readWrapperLayers(dir, undefined, sealed, readings);
183
183
  } catch (error) {
184
184
  if (error instanceof PartsError) {
185
185
  throw new PartsError(error.problems.map(problem => ({ ...problem, code: 'VISIBILITY_SOURCE' })));
@@ -248,7 +248,7 @@ function score(crops: readonly Crop[], [width, height]: Pair): Uint8Array[] {
248
248
  });
249
249
  }
250
250
 
251
- function buildRecord(dir: string, identity: VisibilityIdentity, saved?: { value: unknown }): RecordFiles {
251
+ function buildRecord(dir: string, identity: VisibilityIdentity, saved?: { value: unknown }, readings?: WrapperReadings): RecordFiles {
252
252
  const manifestAt = join(dir, MANIFEST);
253
253
  const { prompt_id, input_sha256, graph_sha256 } = identity;
254
254
  const run = { spec: SPEC, prompt_id, input_sha256, graph_sha256 } as const;
@@ -277,7 +277,7 @@ function buildRecord(dir: string, identity: VisibilityIdentity, saved?: { value:
277
277
  return { tag, at, row, image: image.seal };
278
278
  });
279
279
 
280
- const set = readWrapper(dir, sealed);
280
+ const set = readWrapper(dir, sealed, readings);
281
281
  const canvas: Pair = [set.canvas.w, set.canvas.h];
282
282
  if (recorded !== undefined) match(recorded.canvas, canvas, manifestAt + '.canvas');
283
283
  if (!canvas.every(Number.isSafeInteger) || !Number.isSafeInteger(canvas[0] * canvas[1])) {
@@ -302,7 +302,12 @@ function buildRecord(dir: string, identity: VisibilityIdentity, saved?: { value:
302
302
  }
303
303
  const path = `parts/${tag}_depth.png`;
304
304
  const sheet = readSealed(dir, path, row && { value: row.depth, at: at + '.depth' });
305
- crops.push({ layer, depth: decodeDepth(sheet.bytes, size, join(dir, path)), image, sheet: sheet.seal });
305
+ const file = join(dir, path);
306
+ const depth = decodeDepth(sheet.bytes, size, file);
307
+ // The producer stages the wrapper-declared sheet here for visibility,
308
+ // which consumes it independently of the scalar geometry opt-in.
309
+ layer.depthHint?.recordDecode?.(file, sheet.seal.sha256);
310
+ crops.push({ layer, depth, image, sheet: sheet.seal });
306
311
  } catch (error) {
307
312
  if (!(error instanceof PartsError)) throw error;
308
313
  problems.push(...error.problems);
@@ -355,19 +360,19 @@ export function writeVisibilityRecord(dir: string, identity: VisibilityIdentity)
355
360
 
356
361
  /** Verify the run, current source bytes, native grids and exact scored masks. */
357
362
  export function readVisibilityRecord(dir: string, identity: VisibilityIdentity): VisibilityManifest;
358
- export function readVisibilityRecord(dir: string, identity: VisibilityIdentity, includeSamples: true): RecordFiles;
363
+ export function readVisibilityRecord(dir: string, identity: VisibilityIdentity, includeSamples: true, readings?: WrapperReadings): RecordFiles;
359
364
  export function readVisibilityRecord(
360
- dir: string, identity: VisibilityIdentity, includeSamples = false,
365
+ dir: string, identity: VisibilityIdentity, includeSamples = false, readings?: WrapperReadings,
361
366
  ): VisibilityManifest | RecordFiles {
362
367
  checkIdentity(identity);
363
368
  const file = join(dir, MANIFEST);
364
369
  const value = parse(readBytes(file), file, 'VISIBILITY_MANIFEST');
365
- const result = buildRecord(dir, identity, { value });
370
+ const result = buildRecord(dir, identity, { value }, readings);
366
371
  return includeSamples ? result : result.manifest;
367
372
  }
368
373
 
369
374
  /** The expected identity comes from the independent producer metadata. */
370
- export function readRunVisibility(dir: string): RecordFiles | undefined {
375
+ export function readRunVisibility(dir: string, readings?: WrapperReadings): RecordFiles | undefined {
371
376
  const path = join(dir, MANIFEST);
372
377
  if (lstatSync(path, { throwIfNoEntry: false }) === undefined) return;
373
378
  const meta = join(dir, 'meta.json');
@@ -380,5 +385,5 @@ export function readRunVisibility(dir: string): RecordFiles | undefined {
380
385
  !isSha256(uploaded_image_sha256) || !isSha256(graph_sha256)) {
381
386
  fail('VISIBILITY_SOURCE', meta, 'requires prompt_id and lowercase SHA-256 uploaded_image_sha256 and graph_sha256 from the producing run');
382
387
  }
383
- return readVisibilityRecord(dir, { prompt_id, input_sha256: uploaded_image_sha256, graph_sha256 }, true);
388
+ return readVisibilityRecord(dir, { prompt_id, input_sha256: uploaded_image_sha256, graph_sha256 }, true, readings);
384
389
  }