spine-parts 2.12.0 → 2.13.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.
- package/docs/AUTHORING.md +19 -0
- package/docs/STABILITY.md +13 -0
- package/package.json +1 -1
- package/src/check.ts +6 -3
- package/src/paintingedges.ts +47 -2
- package/src/setupfiguremask.ts +37 -0
- package/src/setuppainting.ts +41 -11
package/docs/AUTHORING.md
CHANGED
|
@@ -875,6 +875,9 @@ Final recomposite and error measurements use those retained parts together with
|
|
|
875
875
|
the taken targets. The counterfactual is never written. A take adds this extra
|
|
876
876
|
assembly evaluation. Builds without region takes follow the existing single
|
|
877
877
|
assembly path. Target filter halos are reported separately and have no bar.
|
|
878
|
+
The core-mode guard bounds projection-first changes by the exact warp-tap footprint dilated by the erosion reach plus both closing-pass reaches from `CORE_KERNEL` plus the Gaussian reach from `FEATHER_SIGMA`, and every other first writer by the footprint itself.
|
|
879
|
+
The current generated controls' observed projection-first changes remain within the blur support.
|
|
880
|
+
Visible-mode edge plans can change outside a take's exact warp-tap footprint; this is tracked on [#1033](https://github.com/rig-c/parts/issues/1033).
|
|
878
881
|
|
|
879
882
|
No polygon, rectangle or brush input is accepted. A drawn bound is scissors.
|
|
880
883
|
The log reports the derived pixel count, run-grid `[left, top, width, height]`
|
|
@@ -5579,6 +5582,7 @@ documents do not ship). Each is an input this package built; none is an author's
|
|
|
5579
5582
|
| <a id="CHECK_SOURCE_SIZE"></a>`CHECK_SOURCE_SIZE` | the painting `--source` names is not this rig's: no single `rig_scale` takes its width and height to the stage's (assemble makes the canvas `trunc(w × rig_scale)` x `trunc(h × rig_scale)`), or, with `parts.json` read, its `scale_rig_per_source` does not; or the stage is not whole pixels. Refused before anything is built | the painting the rig was made from — the stage's own size, or the painting `assemble` was given |
|
|
5580
5583
|
| <a id="CHECK_SOURCE_PNG"></a>`CHECK_SOURCE_PNG` | `--source` names a file that does not read as a PNG | a PNG |
|
|
5581
5584
|
| <a id="CHECK_SETUP_MATCHES_PAINTING"></a>`CHECK_SETUP_MATCHES_PAINTING` | region, slot, failing-pixel box, slot pixelcount, complete region pixelcount and declared limit | compare the source painting beside the actual setup; follow [Source before scissors](#source-before-scissors), then rerun with the same authored limit |
|
|
5585
|
+
| <a id="CHECK_SETUP_PAINTING_MASK"></a>`CHECK_SETUP_PAINTING_MASK` | declared figure-mask PNG cannot be read or decoded, its byte SHA-256 or original painting grid differs, or its alpha support is empty | supply independent figure alpha support with the declared hash and source grid; rendering never supplies the missing mask |
|
|
5582
5586
|
| <a id="CHECK_SETUP_PAINTING_BACKDROP"></a>`CHECK_SETUP_PAINTING_BACKDROP` | declared backdrop PNG cannot be read or decoded, its byte SHA-256 differs, its original painting grid differs, or any alpha is not 255 | supply an opaque plate with the declared lowercase SHA-256, aligned to the original painting; no fitting or white fallback |
|
|
5583
5587
|
| <a id="CHECK_SETUP_PAINTING_SOURCE"></a>`CHECK_SETUP_PAINTING_SOURCE` | a declaration without a source painting | supply `--source`; the assembled composite is not an independent reference |
|
|
5584
5588
|
| <a id="CHECK_SETUP_PAINTING_MEASURED"></a>`CHECK_SETUP_PAINTING_MEASURED` | missing native setup/ownership or unsupported clipping | supply observable textured setup geometry; an unavailable instrument never passes |
|
|
@@ -6966,6 +6970,21 @@ background difference, morphological opening and hole filling. This includes
|
|
|
6966
6970
|
missing output over source figure and extra rendered support. It is not an
|
|
6967
6971
|
independent segmentation oracle for arbitrary backgrounds.
|
|
6968
6972
|
|
|
6973
|
+
For a scene painting with a figure-only rig, optionally declare
|
|
6974
|
+
`setup_painting.figure_mask` as `{"path": "figure.png", "sha256": "<64 lowercase hex digits>"}`.
|
|
6975
|
+
The PNG is independent figure support on the original painting grid. Its path
|
|
6976
|
+
is relative to requirements, its exact bytes are hashed before decoding, and
|
|
6977
|
+
its alpha above zero selects figure pixels. RGB is ignored. Each stage pixel
|
|
6978
|
+
samples the nearest original pixel centre on each axis, without morphology
|
|
6979
|
+
or interpolated support. Empty original or stage support is refused before
|
|
6980
|
+
building. Only selected pixels count toward region limits, including missing
|
|
6981
|
+
figure material with no rendered owner. The mask replaces the legacy union
|
|
6982
|
+
domain, including its backdrop-difference term. Uncovered mismatches outside
|
|
6983
|
+
it are reported once across the whole stage as an `UNBARRED` row, independent
|
|
6984
|
+
of region boxes and limits. Owned mismatches outside the mask have a separate stage-wide `UNBARRED` row; the declared region limits apply inside the mask. Room and plate fidelity remain outside this gate.
|
|
6985
|
+
The report records the mask path and verified hash. Omitting this field keeps
|
|
6986
|
+
the previous domain, output shape and bytes.
|
|
6987
|
+
|
|
6969
6988
|
`SETUP_MATCHES_PAINTING` reports each region's box, pixel count and limit.
|
|
6970
6989
|
Diagnostic slot rows partition that count and report their failing-pixel box.
|
|
6971
6990
|
The slot is the **last actual textured drawing with sampled alpha above zero**
|
package/docs/STABILITY.md
CHANGED
|
@@ -554,6 +554,19 @@ The separate ordering scalar is unchanged. No-image outputs retain legacy bytes.
|
|
|
554
554
|
|
|
555
555
|
### Declared setup-painting regions
|
|
556
556
|
|
|
557
|
+
| Optional field | Additive contract |
|
|
558
|
+
| --- | --- |
|
|
559
|
+
| `setup_painting.figure_mask` | Verified source-grid alpha support restricts region counts; omission preserves the shipped domain and output bytes. |
|
|
560
|
+
|
|
561
|
+
The optional `setup_painting.figure_mask` (issue #974, additive) declares a
|
|
562
|
+
`path` and byte `sha256` for independent figure alpha support on the original
|
|
563
|
+
painting grid. Paths resolve relative to requirements. Alpha above zero is
|
|
564
|
+
sampled at nearest source pixel centres onto the stage, with empty support
|
|
565
|
+
refused. Region limits count only inside that support. Outside-mask uncovered
|
|
566
|
+
mismatches have their own unbarred stage-wide row. The verified declaration is
|
|
567
|
+
recorded in the report. Omitting it preserves existing output bytes and the
|
|
568
|
+
shipped domain predicate.
|
|
569
|
+
|
|
557
570
|
The optional `setup_painting` key in `spine-parts-requirements/1` adds a
|
|
558
571
|
`SETUP_MATCHES_PAINTING` measurement when declared. It requires authored
|
|
559
572
|
`rgb_tolerance` and named native-stage boxes. Each optional `max_pixels` is
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spine-parts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.1",
|
|
4
4
|
"description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/check.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readSetupFigureMask } from './setupfiguremask.ts';
|
|
1
2
|
import { readSetupBackdrop } from './setupbackdrop.ts';
|
|
2
3
|
import { COINCIDE_LINE, type SupportReport } from './coincide.ts';
|
|
3
4
|
import { observeSupport } from './coincideio.ts';
|
|
@@ -1947,7 +1948,7 @@ export function officialRenderer(): OfficialRenderer {
|
|
|
1947
1948
|
|
|
1948
1949
|
/** Observe the actual setup on the declared stage grid. No frame-zero motion,
|
|
1949
1950
|
* fitted alignment, flat recomposite or duplicate core validation. */
|
|
1950
|
-
export function measureSetupPainting(build: string, stage: StageBox, source: Raster, declared: SetupPainting, problems: Problem[], backdrop?: Raster): SetupPaintingLine {
|
|
1951
|
+
export function measureSetupPainting(build: string, stage: StageBox, source: Raster, declared: SetupPainting, problems: Problem[], backdrop?: Raster, figureMask?: Uint8Array): SetupPaintingLine {
|
|
1951
1952
|
const api = officialRenderer();
|
|
1952
1953
|
const skeleton = join(build, 'skeleton.json'), atlas = join(build, 'skeleton.atlas');
|
|
1953
1954
|
const candidate = api.loadCandidate({ skeletonText: readFileSync(skeleton, 'utf8'), atlasText: readFileSync(atlas, 'utf8'), atlasDir: build, label: 'setup versus painting' }, { skeleton, atlas }, undefined);
|
|
@@ -1971,7 +1972,7 @@ export function measureSetupPainting(build: string, stage: StageBox, source: Ras
|
|
|
1971
1972
|
}
|
|
1972
1973
|
const painting = sourceInRig(whiteSource, W, H);
|
|
1973
1974
|
const setup = api.renderFrame(pose, candidate.pages, vp, [0, 0, 0, 0]);
|
|
1974
|
-
return setupPaintingLine(declared, painting, { width: W, height: H, data: new Uint8ClampedArray(setup.data) }, figureSilhouette(painting).data, owners, pose.pieces.map(p => p.slot), problems, backdrop === undefined ? undefined : sourceInRig(backdrop, W, H));
|
|
1975
|
+
return setupPaintingLine(declared, painting, { width: W, height: H, data: new Uint8ClampedArray(setup.data) }, figureSilhouette(painting).data, owners, pose.pieces.map(p => p.slot), problems, backdrop === undefined ? undefined : sourceInRig(backdrop, W, H), figureMask);
|
|
1975
1976
|
}
|
|
1976
1977
|
|
|
1977
1978
|
/** One decoder/poser lifetime per state; retain only finite bounds and identities, never atlas pages or rasters. */
|
|
@@ -6419,6 +6420,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
6419
6420
|
}
|
|
6420
6421
|
};
|
|
6421
6422
|
let setupBackdrop: Raster | undefined;
|
|
6423
|
+
let setupFigureMask: Uint8Array | undefined;
|
|
6422
6424
|
// Issue #538: the schedule is read once, first, by rigc's own reader; refused, nothing is built or written.
|
|
6423
6425
|
const env = environment === undefined ? null : take(() => readCheckEnvironment(environment));
|
|
6424
6426
|
// Issue #590: the steady-wind band spec is read and resolved before anything is built or written.
|
|
@@ -6444,6 +6446,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
6444
6446
|
refuseIfAny(setupPaintingBounds(file.setup_painting as SetupPainting, ready.stage.width, ready.stage.height));
|
|
6445
6447
|
if (ready.source === null) refuseIfAny([{ code: 'CHECK_SETUP_PAINTING_SOURCE', object: 'requirements.setup_painting', detail: 'requires --source naming the painting; the assembled composite is not an independent source painting' }]);
|
|
6446
6448
|
setupBackdrop = readSetupBackdrop(file.setup_painting as SetupPainting, requirements, ready.source?.painting ?? null);
|
|
6449
|
+
setupFigureMask = readSetupFigureMask(file.setup_painting as SetupPainting, requirements, ready.source?.painting ?? null, ready.stage.width, ready.stage.height);
|
|
6447
6450
|
});
|
|
6448
6451
|
// Issue #942: a declared boundary_colour reads parts.json's pieces and the idle; without either it cannot be taken.
|
|
6449
6452
|
if (file.boundary_colour !== undefined) take(() => refuseIfAny([
|
|
@@ -7051,7 +7054,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7051
7054
|
if (sr.status !== 0) refuseIfAny(rigcFailed('render (the setup-pose still)', sr, sr.out.split('\n').filter((l) => l.includes('FAIL'))));
|
|
7052
7055
|
const stillSet = readFrameSet(join(stillDir, 'render'));
|
|
7053
7056
|
partSupport = observeSupport(join(stillDir, 'build'), inp, supportSource, supportFigure);
|
|
7054
|
-
if (reqFile?.setup_painting !== undefined && inp.source !== null) setupPainting = measureSetupPainting(join(stillDir, 'build'), inp.stage, inp.source.painting, reqFile.setup_painting, problems, setupBackdrop);
|
|
7057
|
+
if (reqFile?.setup_painting !== undefined && inp.source !== null) setupPainting = measureSetupPainting(join(stillDir, 'build'), inp.stage, inp.source.painting, reqFile.setup_painting, problems, setupBackdrop, setupFigureMask);
|
|
7055
7058
|
if (fixedSkeleton !== undefined) {
|
|
7056
7059
|
const geometryPath = join(stillSet.dir, GEOMETRY_FILE);
|
|
7057
7060
|
const geometry = readGeometry(geometryPath, stillSet.written);
|
package/src/paintingedges.ts
CHANGED
|
@@ -173,7 +173,7 @@ export interface PaintingEdgeOptions {
|
|
|
173
173
|
* figure there, and taking the behind colour from it would take a painted line.
|
|
174
174
|
*/
|
|
175
175
|
painted: Uint8Array;
|
|
176
|
-
/** Canonical painted figure domain for completing allocated
|
|
176
|
+
/** Canonical painted figure domain for completing allocated gaps and interior translucency. */
|
|
177
177
|
figure?: Mask;
|
|
178
178
|
/** Per part: whether the step may write it (false for a painting patch). */
|
|
179
179
|
editable: readonly boolean[];
|
|
@@ -269,9 +269,9 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
const fill: Array<[number, number]> = [];
|
|
272
|
+
const near: Uint8Array[] = [];
|
|
272
273
|
// A painted pixel no part covers goes to the nearest part (ties to the one drawn in front); farther than the cap, it stays background.
|
|
273
274
|
{
|
|
274
|
-
const near: Uint8Array[] = [];
|
|
275
275
|
for (let k = 0; k < n; k++) {
|
|
276
276
|
const set = new Uint8Array(W * H);
|
|
277
277
|
for (let p = 0; p < W * H; p++) if (owner[p] === k) set[p] = 1;
|
|
@@ -629,6 +629,51 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
629
629
|
(p >= W && d[(p - W) * 4 + 3] > OPAQUE_ALPHA_ABOVE) ||
|
|
630
630
|
(p + W < W * H && d[(p + W) * 4 + 3] > OPAQUE_ALPHA_ABOVE);
|
|
631
631
|
});
|
|
632
|
+
// Freeze the final rest witnesses before filling: a new write cannot supply
|
|
633
|
+
// another pixel's owner. Keep the existing allocation and all soft boundaries.
|
|
634
|
+
// Busy-ground figure/support policy is a separate contract.
|
|
635
|
+
const figure = options.figure;
|
|
636
|
+
if (!busy && figure !== undefined) {
|
|
637
|
+
for (let y = 1; y + 1 < H; y++) {
|
|
638
|
+
for (let x = 1; x + 1 < W; x++) {
|
|
639
|
+
const p = y * W + x;
|
|
640
|
+
if (locked[p] === 1 ||
|
|
641
|
+
options.keep?.some(m => m?.data[p] === 1) || options.feathered?.some(m => m?.data[p] === 1)) continue;
|
|
642
|
+
const neighbours = [p - 1, p + 1, p - W, p + W];
|
|
643
|
+
if (![p, ...neighbours].every(q => figure.data[q] === 1 && srcr.data[q * 4 + 3] > 0)) continue;
|
|
644
|
+
// PIL's integer source-over alpha, including divide-by-255 rounding.
|
|
645
|
+
let alpha = 0;
|
|
646
|
+
for (const part of parts) {
|
|
647
|
+
const a = part.data[p * 4 + 3];
|
|
648
|
+
const t = a * 255 + alpha * (255 - a) + 128;
|
|
649
|
+
alpha = ((t >>> 8) + t) >>> 8;
|
|
650
|
+
}
|
|
651
|
+
if (alpha === 0 || alpha >= 128) continue;
|
|
652
|
+
// The gap rule's distances and front-first ties, restricted to owners
|
|
653
|
+
// with a four-connected witness in the assembled rest output.
|
|
654
|
+
let front = -1;
|
|
655
|
+
let distance = cap;
|
|
656
|
+
for (let k = n - 1; k >= 0; k--) {
|
|
657
|
+
if (near[k][p] < distance && neighbours.some(q => parts[k].data[q * 4 + 3] > 0)) {
|
|
658
|
+
front = k;
|
|
659
|
+
distance = near[k][p];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
// Complete an existing surface in front before adding opaque paint
|
|
663
|
+
// beneath it. Without a witnessed holder, retain the gap allocation.
|
|
664
|
+
for (let k = n - 1; k >= 0; k--) {
|
|
665
|
+
if (parts[k].data[p * 4 + 3] > 0 && neighbours.some(q => parts[k].data[q * 4 + 3] > 0)) {
|
|
666
|
+
front = k;
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (front < 0 || !options.editable[front]) continue;
|
|
671
|
+
// A covered edge decision can return before setting locked[p].
|
|
672
|
+
if (parts.some((part, k) => k !== front && part.data[p * 4 + 3] > 0 && options.movingPair?.(front, k) === true)) continue;
|
|
673
|
+
restore.push([p, front]);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
632
677
|
for (const [p, front] of restore) {
|
|
633
678
|
const s = p * 4;
|
|
634
679
|
parts[front].data.set([srcr.data[s], srcr.data[s + 1], srcr.data[s + 2], 255], s);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Independent declared alpha support, verified before any candidate build. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
import { refuseIfAny } from './errors.ts';
|
|
6
|
+
import { decodePngBytes } from './raster/png.ts';
|
|
7
|
+
import type { Raster } from './raster/types.ts';
|
|
8
|
+
import type { SetupPainting } from './setuppainting.ts';
|
|
9
|
+
|
|
10
|
+
export function readSetupFigureMask(declared: SetupPainting, requirements: string, source: Raster | null, width: number, height: number): Uint8Array | undefined {
|
|
11
|
+
const mask = declared.figure_mask;
|
|
12
|
+
if (mask === undefined) return undefined;
|
|
13
|
+
const fail = (detail: string): never => {
|
|
14
|
+
refuseIfAny([{ code: 'CHECK_SETUP_PAINTING_MASK', object: 'setup_painting.figure_mask', detail }]);
|
|
15
|
+
throw new Error('unreachable');
|
|
16
|
+
};
|
|
17
|
+
let bytes: Uint8Array;
|
|
18
|
+
try { bytes = new Uint8Array(readFileSync(resolve(dirname(requirements), mask.path))); }
|
|
19
|
+
catch { return fail(`cannot read declared PNG "${mask.path}"; requires independent figure alpha support`); }
|
|
20
|
+
const hash = createHash('sha256').update(bytes).digest('hex');
|
|
21
|
+
if (hash !== mask.sha256) return fail(`PNG "${mask.path}" has sha256 ${hash}; requires declared ${mask.sha256}`);
|
|
22
|
+
let image: Raster;
|
|
23
|
+
try { image = decodePngBytes(bytes, mask.path); }
|
|
24
|
+
catch { return fail(`"${mask.path}" is not a decodable PNG; requires independent figure alpha support`); }
|
|
25
|
+
if (source === null || image.width !== source.width || image.height !== source.height) return fail(`PNG "${mask.path}" is ${image.width}x${image.height}; requires the original source painting grid ${source === null ? '(no source)' : `${source.width}x${source.height}`}, without fitting`);
|
|
26
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width <= 0 || height <= 0) return fail('requires positive integer stage dimensions');
|
|
27
|
+
if (!image.data.some((v, i) => i % 4 === 3 && v > 0)) return fail(`PNG "${mask.path}" has empty alpha support; requires at least one figure pixel`);
|
|
28
|
+
// Nearest source pixel centre, independently on each axis. No colour,
|
|
29
|
+
// morphology, rendered alpha or interpolated support enters this domain.
|
|
30
|
+
const support = new Uint8Array(width * height);
|
|
31
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
32
|
+
const sx = Math.floor((x + 0.5) * image.width / width), sy = Math.floor((y + 0.5) * image.height / height);
|
|
33
|
+
support[y * width + x] = image.data[(sy * image.width + sx) * 4 + 3] > 0 ? 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
if (!support.some(v => v === 1)) return fail(`PNG "${mask.path}" has no figure support on the declared stage grid`);
|
|
36
|
+
return support;
|
|
37
|
+
}
|
package/src/setuppainting.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface SetupPainting {
|
|
|
16
16
|
* refused by name (SETUP_PAINTING_REQUIRED_LIMIT) instead of reported as
|
|
17
17
|
* SKIP. Absent or false: the pre-#943 reading, unchanged. */
|
|
18
18
|
required?: boolean;
|
|
19
|
+
/** Independent alpha support on the original painting grid. */
|
|
20
|
+
figure_mask?: { path: string; sha256: string };
|
|
19
21
|
/** Opaque plate on the original painting grid; path relative to requirements. */
|
|
20
22
|
backdrop?: { path: string; sha256: string };
|
|
21
23
|
/** A pixel counts when its maximum RGB difference is strictly greater. */
|
|
@@ -35,8 +37,17 @@ export function setupPaintingProblems(value: unknown, at: string): Problem[] {
|
|
|
35
37
|
for (const k of Object.keys(v)) if (!allowed.includes(k) && !free(k, v[k])) fail(`${where}.${k}`, `is unknown; fields are ${allowed.join(', ')}`);
|
|
36
38
|
};
|
|
37
39
|
if (!object(value)) return [{ code: 'REQUIREMENTS_FIELD', object: at, detail: 'requires {rgb_tolerance, regions: [{name, box, max_pixels?}]}' }];
|
|
38
|
-
keys(value, ['required', 'backdrop', 'rgb_tolerance', 'regions'], at);
|
|
40
|
+
keys(value, ['required', 'figure_mask', 'backdrop', 'rgb_tolerance', 'regions'], at);
|
|
39
41
|
if ('required' in value && typeof value.required !== 'boolean') fail(`${at}.required`, `is ${JSON.stringify(value.required)}; requires true (the check may not SKIP: every limit must be declared) or false (the same as omitting it)`);
|
|
42
|
+
if ('figure_mask' in value) {
|
|
43
|
+
const b = value.figure_mask, where = `${at}.figure_mask`;
|
|
44
|
+
if (!object(b)) fail(where, 'requires {path, sha256} for an alpha-support PNG on the original painting grid');
|
|
45
|
+
else {
|
|
46
|
+
keys(b, ['path', 'sha256'], where);
|
|
47
|
+
if (typeof b.path !== 'string' || b.path.trim() === '') fail(`${where}.path`, 'requires a nonempty PNG path relative to the requirements file');
|
|
48
|
+
if (typeof b.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(b.sha256)) fail(`${where}.sha256`, 'requires the lowercase SHA-256 of the PNG bytes');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
40
51
|
if ('backdrop' in value) {
|
|
41
52
|
const b = value.backdrop, where = `${at}.backdrop`;
|
|
42
53
|
if (!object(b)) fail(where, 'requires {path, sha256} for an opaque PNG on the original painting grid');
|
|
@@ -94,7 +105,10 @@ export interface SetupPaintingLine {
|
|
|
94
105
|
registration: 'declared stage grid, scale 1, no fitting';
|
|
95
106
|
compositing: 'source-over white, RGBA8' | 'source-over declared backdrop, RGBA8';
|
|
96
107
|
backdrop?: { path: string; sha256: string };
|
|
97
|
-
|
|
108
|
+
figure_mask?: { path: string; sha256: string };
|
|
109
|
+
outside_figure?: { slot: '(uncovered)'; pixel_count: number; status: 'UNBARRED' };
|
|
110
|
+
outside_figure_owned?: { pixel_count: number; status: 'UNBARRED' };
|
|
111
|
+
figure: 'declared figure mask alpha > 0' | 'source figureSilhouette union rendered alpha > 0' | 'source figureSilhouette union rendered alpha > 0 union source-backdrop RGB difference > tolerance';
|
|
98
112
|
ownership: 'last actual drawn piece with sampled alpha > 0; uncovered explicit';
|
|
99
113
|
rgb_tolerance: number;
|
|
100
114
|
regions: SetupPaintingReading[];
|
|
@@ -113,7 +127,7 @@ export const UNDECLARED_SETUP_PAINTING_REASON = 'setup_painting is undeclared; s
|
|
|
113
127
|
*/
|
|
114
128
|
export function setupPaintingLine(
|
|
115
129
|
declared: SetupPainting, source: Raster, setup: Raster, figure: Uint8Array,
|
|
116
|
-
owners: Int32Array, slots: readonly string[], problems: Problem[], backdrop?: Raster,
|
|
130
|
+
owners: Int32Array, slots: readonly string[], problems: Problem[], backdrop?: Raster, figureMask?: Uint8Array,
|
|
117
131
|
): SetupPaintingLine {
|
|
118
132
|
refuseIfAny(setupPaintingProblems(declared, 'setup_painting'));
|
|
119
133
|
refuseIfAny(setupPaintingBounds(declared, source.width, source.height));
|
|
@@ -124,18 +138,32 @@ export function setupPaintingLine(
|
|
|
124
138
|
if ((declared.backdrop !== undefined) !== (backdrop !== undefined) || (backdrop !== undefined && (backdrop.width !== W || backdrop.height !== H || backdrop.data.length !== n * 4 || backdrop.data.some((v, i) => i % 4 === 3 && v !== 255)))) {
|
|
125
139
|
refuseIfAny([{ code: 'CHECK_SETUP_PAINTING_BACKDROP', object: 'setup_painting.backdrop', detail: 'requires the declared opaque backdrop pixels on the native stage grid; an absent or mismatched plate is never replaced with white' }]);
|
|
126
140
|
}
|
|
141
|
+
if ((declared.figure_mask !== undefined) !== (figureMask !== undefined) || (figureMask !== undefined && (figureMask.length !== n || figureMask.some(v => v !== 0 && v !== 1)))) {
|
|
142
|
+
refuseIfAny([{ code: 'CHECK_SETUP_PAINTING_MASK', object: 'setup_painting.figure_mask', detail: 'requires the verified declared alpha support on the native stage grid; no rendered support or inferred silhouette is substituted' }]);
|
|
143
|
+
}
|
|
144
|
+
const difference = (p: number): number => {
|
|
145
|
+
const q = p * 4;
|
|
146
|
+
let delta = 0;
|
|
147
|
+
for (let c = 0; c < 3; c++) {
|
|
148
|
+
const over = (image: Raster): number => Math.round(image.data[q + c] * image.data[q + 3] / 255 + (backdrop?.data[q + c] ?? 255) * (1 - image.data[q + 3] / 255));
|
|
149
|
+
delta = Math.max(delta, Math.abs(over(source) - over(setup)));
|
|
150
|
+
}
|
|
151
|
+
return delta;
|
|
152
|
+
};
|
|
153
|
+
let outside = 0, outsideOwned = 0;
|
|
154
|
+
if (figureMask !== undefined) for (let p = 0; p < n; p++) {
|
|
155
|
+
if (figureMask[p] === 0 && difference(p) > declared.rgb_tolerance) {
|
|
156
|
+
if (owners[p] < 0) outside++;
|
|
157
|
+
else outsideOwned++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
127
160
|
const regions = declared.regions.map<SetupPaintingReading>(r => {
|
|
128
161
|
const rows = new Map<string, { pixels: number; x0: number; y0: number; x1: number; y1: number }>();
|
|
129
162
|
let count = 0;
|
|
130
163
|
for (let y = r.box[1]; y < r.box[1] + r.box[3]; y++) for (let x = r.box[0]; x < r.box[0] + r.box[2]; x++) {
|
|
131
164
|
const p = y * W + x, q = p * 4;
|
|
132
|
-
if (figure[p] === 0 && setup.data[q + 3] === 0 && (backdrop === undefined || ![0, 1, 2].some(c => Math.abs(source.data[q + c] - backdrop.data[q + c]) > declared.rgb_tolerance))) continue;
|
|
133
|
-
|
|
134
|
-
for (let c = 0; c < 3; c++) {
|
|
135
|
-
const white = (image: Raster): number => Math.round(image.data[q + c] * image.data[q + 3] / 255 + (backdrop?.data[q + c] ?? 255) * (1 - image.data[q + 3] / 255));
|
|
136
|
-
delta = Math.max(delta, Math.abs(white(source) - white(setup)));
|
|
137
|
-
}
|
|
138
|
-
if (delta <= declared.rgb_tolerance) continue;
|
|
165
|
+
if (figureMask !== undefined ? figureMask[p] === 0 : figure[p] === 0 && setup.data[q + 3] === 0 && (backdrop === undefined || ![0, 1, 2].some(c => Math.abs(source.data[q + c] - backdrop.data[q + c]) > declared.rgb_tolerance))) continue;
|
|
166
|
+
if (difference(p) <= declared.rgb_tolerance) continue;
|
|
139
167
|
count++;
|
|
140
168
|
const slot = owners[p] < 0 ? '(uncovered)' : slots[owners[p]], row = rows.get(slot);
|
|
141
169
|
if (row === undefined) rows.set(slot, { pixels: 1, x0: x, y0: y, x1: x + 1, y1: y + 1 });
|
|
@@ -150,13 +178,15 @@ export function setupPaintingLine(
|
|
|
150
178
|
return result;
|
|
151
179
|
});
|
|
152
180
|
const noLimit = regions.some(r => r.status === 'SKIP');
|
|
153
|
-
return { status: regions.some(r => r.status === 'FAIL') ? 'FAIL' : noLimit ? 'SKIP' : 'PASS', instrument: 'rigc renderer setup textured pieces', registration: 'declared stage grid, scale 1, no fitting', compositing: backdrop === undefined ? 'source-over white, RGBA8' : 'source-over declared backdrop, RGBA8', ...(declared.backdrop === undefined ? {} : { backdrop: { ...declared.backdrop } }), figure: backdrop === undefined ? 'source figureSilhouette union rendered alpha > 0' : 'source figureSilhouette union rendered alpha > 0 union source-backdrop RGB difference > tolerance', ownership: 'last actual drawn piece with sampled alpha > 0; uncovered explicit', rgb_tolerance: declared.rgb_tolerance, regions,
|
|
181
|
+
return { status: regions.some(r => r.status === 'FAIL') ? 'FAIL' : noLimit ? 'SKIP' : 'PASS', instrument: 'rigc renderer setup textured pieces', registration: 'declared stage grid, scale 1, no fitting', compositing: backdrop === undefined ? 'source-over white, RGBA8' : 'source-over declared backdrop, RGBA8', ...(declared.backdrop === undefined ? {} : { backdrop: { ...declared.backdrop } }), ...(declared.figure_mask === undefined ? {} : { figure_mask: { ...declared.figure_mask }, outside_figure: { slot: '(uncovered)' as const, pixel_count: outside, status: 'UNBARRED' as const }, outside_figure_owned: { pixel_count: outsideOwned, status: 'UNBARRED' as const } }), figure: figureMask !== undefined ? 'declared figure mask alpha > 0' : backdrop === undefined ? 'source figureSilhouette union rendered alpha > 0' : 'source figureSilhouette union rendered alpha > 0 union source-backdrop RGB difference > tolerance', ownership: 'last actual drawn piece with sampled alpha > 0; uncovered explicit', rgb_tolerance: declared.rgb_tolerance, regions,
|
|
154
182
|
...(noLimit ? { reason: 'a region has no declared max_pixels; it is measured as SKIP, never PASS' } : {}) };
|
|
155
183
|
}
|
|
156
184
|
|
|
157
185
|
export function setupPaintingLines(line: SetupPaintingObservation): string[] {
|
|
158
186
|
if (!('regions' in line)) return [`${SETUP_PAINTING_LINE}: SKIP — ${line.reason}`];
|
|
159
187
|
return [`${SETUP_PAINTING_LINE}: ${line.status}${line.reason === undefined ? '' : ` — ${line.reason}`}; ${line.registration}; ${line.compositing}`,
|
|
188
|
+
...(line.outside_figure === undefined ? [] : [`${SETUP_PAINTING_LINE}: slot "(uncovered)" outside figure mask — pixelcount ${line.outside_figure.pixel_count}; UNBARRED, outside every region limit`]),
|
|
189
|
+
...(line.outside_figure_owned === undefined ? [] : [`${SETUP_PAINTING_LINE}: owned pixels outside figure mask — pixelcount ${line.outside_figure_owned.pixel_count}; UNBARRED, outside every region limit`]),
|
|
160
190
|
...line.regions.flatMap(r => [`${SETUP_PAINTING_LINE}: region "${r.name}" ${r.status} — box [${r.box.join(', ')}], pixelcount ${r.pixel_count}, limit ${r.limit ?? 'undeclared (SKIP)'}, RGB tolerance ${line.rgb_tolerance}`,
|
|
161
191
|
...r.slots.map(s => `${SETUP_PAINTING_LINE}: slot "${s.slot}" region "${r.name}" — box [${s.box.join(', ')}], pixelcount ${s.pixel_count}; region total ${r.pixel_count}, limit ${r.limit ?? 'undeclared (SKIP)'}`)])];
|
|
162
192
|
}
|