spine-parts 2.11.0 → 2.13.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/docs/AUTHORING.md +61 -1
- package/docs/STABILITY.md +21 -1
- package/package.json +1 -1
- package/src/assemble.ts +23 -2
- package/src/check.ts +6 -3
- package/src/coincideio.ts +3 -20
- package/src/paintingedges.ts +73 -3
- package/src/setupfiguremask.ts +37 -0
- package/src/setuppainting.ts +41 -11
- package/src/takeregion.ts +6 -4
package/docs/AUTHORING.md
CHANGED
|
@@ -851,7 +851,9 @@ shipped `source: true` semantics and prints one
|
|
|
851
851
|
stage painting for the predicate. A declared but unreadable reference, or a
|
|
852
852
|
hash or painting-dimension mismatch, is refused by name. Only an explicitly
|
|
853
853
|
declared painting reference keeps the selected mask fixed when `--source`
|
|
854
|
-
changes for projection.
|
|
854
|
+
changes for projection. The reference governs colour only and geometry follows `--source`.
|
|
855
|
+
A region take requires an opaque `--source` because its donor must match the run input and `inputs` refuses see-through paintings, so flatten the plate first.
|
|
856
|
+
Its input is derived as for whole-layer take above.
|
|
855
857
|
Both run canvases must agree, and the supplied original donor input
|
|
856
858
|
must match the entire target input in RGBA and dimensions, establishing the same
|
|
857
859
|
crop. Different crops await #973. Painting samples use the existing Lanczos3
|
|
@@ -5577,6 +5579,7 @@ documents do not ship). Each is an input this package built; none is an author's
|
|
|
5577
5579
|
| <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 |
|
|
5578
5580
|
| <a id="CHECK_SOURCE_PNG"></a>`CHECK_SOURCE_PNG` | `--source` names a file that does not read as a PNG | a PNG |
|
|
5579
5581
|
| <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 |
|
|
5582
|
+
| <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 |
|
|
5580
5583
|
| <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 |
|
|
5581
5584
|
| <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 |
|
|
5582
5585
|
| <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 |
|
|
@@ -6964,6 +6967,21 @@ background difference, morphological opening and hole filling. This includes
|
|
|
6964
6967
|
missing output over source figure and extra rendered support. It is not an
|
|
6965
6968
|
independent segmentation oracle for arbitrary backgrounds.
|
|
6966
6969
|
|
|
6970
|
+
For a scene painting with a figure-only rig, optionally declare
|
|
6971
|
+
`setup_painting.figure_mask` as `{"path": "figure.png", "sha256": "<64 lowercase hex digits>"}`.
|
|
6972
|
+
The PNG is independent figure support on the original painting grid. Its path
|
|
6973
|
+
is relative to requirements, its exact bytes are hashed before decoding, and
|
|
6974
|
+
its alpha above zero selects figure pixels. RGB is ignored. Each stage pixel
|
|
6975
|
+
samples the nearest original pixel centre on each axis, without morphology
|
|
6976
|
+
or interpolated support. Empty original or stage support is refused before
|
|
6977
|
+
building. Only selected pixels count toward region limits, including missing
|
|
6978
|
+
figure material with no rendered owner. The mask replaces the legacy union
|
|
6979
|
+
domain, including its backdrop-difference term. Uncovered mismatches outside
|
|
6980
|
+
it are reported once across the whole stage as an `UNBARRED` row, independent
|
|
6981
|
+
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.
|
|
6982
|
+
The report records the mask path and verified hash. Omitting this field keeps
|
|
6983
|
+
the previous domain, output shape and bytes.
|
|
6984
|
+
|
|
6967
6985
|
`SETUP_MATCHES_PAINTING` reports each region's box, pixel count and limit.
|
|
6968
6986
|
Diagnostic slot rows partition that count and report their failing-pixel box.
|
|
6969
6987
|
The slot is the **last actual textured drawing with sampled alpha above zero**
|
|
@@ -7161,6 +7179,48 @@ the load moves the same build by (the pre-change reference-demo build alone took
|
|
|
7161
7179
|
45.8 s there). Since issue #123 that build and render are gone again — the still regions read the
|
|
7162
7180
|
idle's geometry — and the `build` row was not re-measured for it either.
|
|
7163
7181
|
|
|
7182
|
+
### Private worker measurements (issue #1045)
|
|
7183
|
+
|
|
7184
|
+
Each shard unit carries an additive `measurement` record with spec
|
|
7185
|
+
`rig-parts-selftest-unit/1`. Its suite, unit, sorted case-ID set and execution
|
|
7186
|
+
profile identify the measured work. The profile records Bun, platform,
|
|
7187
|
+
architecture, available cores, configured worker count and sampling interval.
|
|
7188
|
+
The existing stdout replay and tally remain the source of case verdicts.
|
|
7189
|
+
Shard records now use `rig-parts-selftest-shard/2`, which requires a measurement
|
|
7190
|
+
on every unit. A dropped attachment is refused by unit name. Version `/1`
|
|
7191
|
+
remains readable, with absent measurements explicitly `UNMEASURED`.
|
|
7192
|
+
|
|
7193
|
+
On Linux, an independent process samples the worker's descendant family through
|
|
7194
|
+
`/proc` at a requested 200 ms interval. PID and kernel start time identify each
|
|
7195
|
+
holder, including observed descendants subsequently reparented. `family.bytes`
|
|
7196
|
+
is the largest sampled sum of per-process RSS, with the simultaneous `holders`,
|
|
7197
|
+
sample count and unreadable-entry count retained. Shared pages count per PID.
|
|
7198
|
+
Short-lived children and allocations between samples can be missed. An absent
|
|
7199
|
+
observation has `status: "UNMEASURED"` and `bytes: null`.
|
|
7200
|
+
The supervising shard excludes registered observer PID/start-time identities
|
|
7201
|
+
from its family peak and RT20 verdict. The exclusion control fixes its noise
|
|
7202
|
+
band at 16 MiB before measurement and compares against an observer-free run.
|
|
7203
|
+
If observer finalization or unit measurement construction throws, the launcher
|
|
7204
|
+
settles with `UNMEASURED` coverage and the named `measurement.error`. A failed
|
|
7205
|
+
stop-file write terminates and waits for that observer before settling.
|
|
7206
|
+
|
|
7207
|
+
Worker-result `phases` retain labelled monotonic spans and elapsed milliseconds.
|
|
7208
|
+
The hooks cover input readers `readPartSet` and `readFrom`, fixture writers
|
|
7209
|
+
`writeWrapperFixture`, `writePsdFixture`, `writeRigFixture`, `writeCheckRig` and
|
|
7210
|
+
`writeProposeFixture`, producer calls `build`, `buildRig` and `runCli`, and the
|
|
7211
|
+
case reporter. The assertion span measures reporting, while evaluating assertion
|
|
7212
|
+
arguments remains outside that hook. Unhooked work stays `unclassified`.
|
|
7213
|
+
These are observed boundaries, with no claim of exhaustive phase attribution.
|
|
7214
|
+
The requested command owns a `runCli` span, including any subprocess startup.
|
|
7215
|
+
|
|
7216
|
+
For overlapping spans, the latest starting span owns the overlap, with later
|
|
7217
|
+
registration breaking equal-start ties. Exclusive totals plus `unclassified`
|
|
7218
|
+
equal the worker's recorded elapsed time. The phase window excludes module
|
|
7219
|
+
loading and parent launch/collection, which the existing unit clocks include.
|
|
7220
|
+
A phase with no observed span is `UNMEASURED`. Old shard records remain readable
|
|
7221
|
+
and their absent measurements are represented as `UNMEASURED` when parsed.
|
|
7222
|
+
Measurements are private records, with no product output or new console line.
|
|
7223
|
+
|
|
7164
7224
|
### Machine-readable selftest summary (`--summary-json`, issue #725)
|
|
7165
7225
|
|
|
7166
7226
|
`bun run selftest -- --summary-json <file>` writes a JSON summary beside the normal console output
|
package/docs/STABILITY.md
CHANGED
|
@@ -158,7 +158,7 @@ part name, `[i]` an entry of a list):
|
|
|
158
158
|
- **assemble.extend_painting[i]** — required: `part`, `band`, `max_distance`; optional: `min_held_alpha`, `order` (issues #848, #854, #855; explicit final layer-derived part, half-open rig band and positive four-neighbour path bound; base painting only). The optional integer floor 1–255 admits exact original alpha-over coverage strictly below it; absent or 1 blocks every nonzero holder. Only selected target samples below the floor may take painting RGBA; target samples at/above the floor and every non-target holder remain exact. By default overlapping reachable claims refuse. With `order` on every entry (unique nonnegative safe integers), lower values claim first and their gains block later candidates and paths; array order never breaks ties or supplies missing precedence
|
|
159
159
|
- **assemble.take[i]** — required: `run`, `run_dir`, `st_input`; optional: `tags`, `part`, `seed`, `reference`, `crop` (issues #866, #973, #1000, #1031). Whole-layer entries require `tags`; region entries require `part` and `seed`. An absent `reference` preserves the shipped `source: true` predicate and emits one named implicit-reference warning; only an explicitly declared painting reference makes the mask invariant to changes in `--source`
|
|
160
160
|
- **assemble.take[i].crop** — required when present: `box`, `resample` (issue #973, additive, whole-layer entries only). `box` is an inside nonempty integer source-painting `[left, top, right, bottom]` with exclusive right/bottom. `resample: "bilinear"` is required explicitly. Donor input must match the square-padded crop under taken support plus its margin. Unit scale and integer translation copy RGBA exactly; other maps use the declared premultiplied float32 affine filter. Absent, the shipped geometry predicate and refusal message remain unchanged. Region entries reject this field
|
|
161
|
-
- **assemble.take[i].reference** — required: `sha256`; optional: `source`, `painting` (issue #1031). Exactly one of `source: true` or a config-relative `painting` PNG is required
|
|
161
|
+
- **assemble.take[i].reference** — required: `sha256`; optional: `source`, `painting` (issue #1031). Exactly one of `source: true` or a config-relative `painting` PNG is required. The reference governs colour only and geometry follows `--source`. A region take requires an opaque `--source` because its donor must match the run input and the inputs command refuses see-through paintings, so flatten the plate first.
|
|
162
162
|
- **assemble.editor_receipts** — required: `receipts`; optional: `required` (issue #946, additive), `trace_parts` (issue #947, additive)
|
|
163
163
|
- **assemble.editor_receipts.receipts[i]** — required: `file`, `sha256`, `from_sha256`, `editor` (issue #946)
|
|
164
164
|
- **assemble.patches[i]** — required: `name`, `box`, `alpha`, `draw`
|
|
@@ -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
|
|
@@ -692,3 +705,10 @@ Other maps carry `"bilinear"`. The strict reader refuses incomplete or malformed
|
|
|
692
705
|
transport records. Absent, the existing receipt fields and bytes are unchanged.
|
|
693
706
|
The output hash describes transport before downstream assembly, independently of
|
|
694
707
|
final part geometry. Existing no-take inputs emit no transport metadata.
|
|
708
|
+
|
|
709
|
+
### Region take source compatibility (issue #1054)
|
|
710
|
+
|
|
711
|
+
A see-through `--source` with an opaque explicit painting reference was accepted
|
|
712
|
+
when donor geometry followed the reference and is now refused with
|
|
713
|
+
`INPUTS_PAINTING_OPAQUE` before the donor is read. The reference remains a colour
|
|
714
|
+
binding. The donor continues to be bound to the opaque PNG accepted by `inputs`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spine-parts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
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/assemble.ts
CHANGED
|
@@ -2572,6 +2572,25 @@ export function visibilityCounts(object: string, part: Raster, visible: Mask, pr
|
|
|
2572
2572
|
return { visible_px: vis, occluded_px: occ, visible_not_projected_px: vis - proj, projected: proj };
|
|
2573
2573
|
}
|
|
2574
2574
|
|
|
2575
|
+
/** Reuse assembly's rig-sized painting only when its alpha is fully opaque.
|
|
2576
|
+
* Transparent inputs retain source-over-white before the Lanczos resize. */
|
|
2577
|
+
export function sourceSupportFigure(source: Raster, width: number, height: number, opaquePainting?: Raster): Mask {
|
|
2578
|
+
let painting = opaquePainting;
|
|
2579
|
+
for (let p = 3; painting !== undefined && p < source.data.length; p += 4) if (source.data[p] !== 255) painting = undefined;
|
|
2580
|
+
if (painting === undefined) {
|
|
2581
|
+
const white = newRaster(source.width, source.height);
|
|
2582
|
+
for (let p = 0; p < source.width * source.height; p++) {
|
|
2583
|
+
const alpha = source.data[p * 4 + 3] / 255;
|
|
2584
|
+
for (let c = 0; c < 3; c++) white.data[p * 4 + c] = Math.round(source.data[p * 4 + c] * alpha + 255 * (1 - alpha));
|
|
2585
|
+
white.data[p * 4 + 3] = 255;
|
|
2586
|
+
}
|
|
2587
|
+
painting = sourceInRig(white, width, height);
|
|
2588
|
+
}
|
|
2589
|
+
const painted = paintedFigure(painting), figure = figureSilhouette(painting, painted);
|
|
2590
|
+
for (let p = 0; p < painted.length; p++) figure.data[p] &= painted[p];
|
|
2591
|
+
return figure;
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2575
2594
|
// ---------------------------------------------------------------------------
|
|
2576
2595
|
// step 5 — seam override
|
|
2577
2596
|
// ---------------------------------------------------------------------------
|
|
@@ -5691,6 +5710,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5691
5710
|
}
|
|
5692
5711
|
});
|
|
5693
5712
|
// Issue #953: under `visible`, the parts' visible edges are the painting's (`paintingEdges`); See-through keeps the hidden surface.
|
|
5713
|
+
const visibleFigure = projectRule === 'visible' ? sourceSupportFigure(source, W, H, srcr) : undefined;
|
|
5694
5714
|
const edged = new Map<string, Mask>();
|
|
5695
5715
|
let edgeReading: PaintingEdgeReading | null = null;
|
|
5696
5716
|
if (projectRule === 'visible') {
|
|
@@ -5714,6 +5734,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5714
5734
|
};
|
|
5715
5735
|
const e = paintingEdges(stack.map(onRig), srcr, {
|
|
5716
5736
|
painted: supportPainted,
|
|
5737
|
+
figure: visibleFigure,
|
|
5717
5738
|
...(input.ground === undefined ? {} : { ground: input.ground }),
|
|
5718
5739
|
editable: order.map((d) => !('patch' in d)),
|
|
5719
5740
|
keep: keepInOrder,
|
|
@@ -5912,8 +5933,8 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
|
|
|
5912
5933
|
// read for ground coverage without changing the assembly silhouette.
|
|
5913
5934
|
let opaqueSource = true;
|
|
5914
5935
|
for (let p = 3; p < source.data.length; p += 4) if (source.data[p] !== 255) { opaqueSource = false; break; }
|
|
5915
|
-
const supportSilhouette = opaqueSource ? silhouette ?? figureSilhouette(srcr, supportPainted) : null;
|
|
5916
|
-
const supportFigure = supportSilhouette === null ? undefined : newMask(W, H);
|
|
5936
|
+
const supportSilhouette = opaqueSource && visibleFigure === undefined ? silhouette ?? figureSilhouette(srcr, supportPainted) : null;
|
|
5937
|
+
const supportFigure = visibleFigure ?? (supportSilhouette === null ? undefined : newMask(W, H));
|
|
5917
5938
|
if (supportFigure !== undefined && supportSilhouette !== null) for (let p = 0; p < supportPainted.length; p++) supportFigure.data[p] = supportSilhouette.data[p] & supportPainted[p];
|
|
5918
5939
|
return {
|
|
5919
5940
|
...(softOcclusion.length === 0 ? {} : { softOcclusion }),
|
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/coincideio.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** Pre-rig pair domains and actual textured setup observations (#998). */
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { sourceSupportFigure as supportFigure } from './assemble.ts';
|
|
5
5
|
import { officialRenderer, sourceSizeProblem, type CheckInputs } from './check.ts';
|
|
6
6
|
import { supportReport, unownedSupport, SUPPORT_GRID_CODE, type SupportPart, type SupportReport } from './coincide.ts';
|
|
7
7
|
import { refuseIfAny } from './errors.ts';
|
|
8
8
|
import { readPng } from './raster/png.ts';
|
|
9
|
-
import { assertBinary,
|
|
9
|
+
import { assertBinary, type Mask } from './raster/types.ts';
|
|
10
10
|
import { readSupportDomains } from './supportdomains.ts';
|
|
11
11
|
|
|
12
12
|
/** The setup candidate is already built by check. Only alpha callbacks are
|
|
@@ -59,21 +59,4 @@ export function observeSupport(build: string, input: CheckInputs, supportSource?
|
|
|
59
59
|
return report;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
* Transparent inputs retain source-over-white before the Lanczos resize. */
|
|
64
|
-
export function supportFigure(source: Raster, width: number, height: number, opaquePainting?: Raster): Mask {
|
|
65
|
-
let painting = opaquePainting;
|
|
66
|
-
for (let p = 3; painting !== undefined && p < source.data.length; p += 4) if (source.data[p] !== 255) painting = undefined;
|
|
67
|
-
if (painting === undefined) {
|
|
68
|
-
const white = newRaster(source.width, source.height);
|
|
69
|
-
for (let p = 0; p < source.width * source.height; p++) {
|
|
70
|
-
const alpha = source.data[p * 4 + 3] / 255;
|
|
71
|
-
for (let c = 0; c < 3; c++) white.data[p * 4 + c] = Math.round(source.data[p * 4 + c] * alpha + 255 * (1 - alpha));
|
|
72
|
-
white.data[p * 4 + 3] = 255;
|
|
73
|
-
}
|
|
74
|
-
painting = sourceInRig(white, width, height);
|
|
75
|
-
}
|
|
76
|
-
const painted = paintedFigure(painting), figure = figureSilhouette(painting, painted);
|
|
77
|
-
for (let p = 0; p < painted.length; p++) figure.data[p] &= painted[p];
|
|
78
|
-
return figure;
|
|
79
|
-
}
|
|
62
|
+
export { sourceSupportFigure as supportFigure } from './assemble.ts';
|
package/src/paintingedges.ts
CHANGED
|
@@ -173,6 +173,8 @@ 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 gaps and interior translucency. */
|
|
177
|
+
figure?: Mask;
|
|
176
178
|
/** Per part: whether the step may write it (false for a painting patch). */
|
|
177
179
|
editable: readonly boolean[];
|
|
178
180
|
keep?: ReadonlyArray<Mask | null>;
|
|
@@ -266,15 +268,15 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
270
|
}
|
|
271
|
+
const fill: Array<[number, number]> = [];
|
|
272
|
+
const near: Uint8Array[] = [];
|
|
269
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.
|
|
270
274
|
{
|
|
271
|
-
const near: Uint8Array[] = [];
|
|
272
275
|
for (let k = 0; k < n; k++) {
|
|
273
276
|
const set = new Uint8Array(W * H);
|
|
274
277
|
for (let p = 0; p < W * H; p++) if (owner[p] === k) set[p] = 1;
|
|
275
278
|
near.push(chebyshev(set, W, H, cap));
|
|
276
279
|
}
|
|
277
|
-
const fill: Array<[number, number]> = [];
|
|
278
280
|
for (let p = 0; p < W * H; p++) {
|
|
279
281
|
if (owner[p] !== -1 || options.painted[p] !== 1) continue;
|
|
280
282
|
// Busy ground: only where two parts' supports meet, and only to a part whose support holds the pixel.
|
|
@@ -307,6 +309,7 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
307
309
|
const distOf = (label: number): Uint8Array => dist[label < 0 ? n : label];
|
|
308
310
|
const skipped: PaintingEdgeSkips = { cover: 0, contrast: 0, locked: 0, noBehind: 0, pieces: 0, mix: 0, support: 0 };
|
|
309
311
|
const decisions: Decision[] = [];
|
|
312
|
+
const locked = new Uint8Array(W * H);
|
|
310
313
|
let resolved = 0;
|
|
311
314
|
let unseparated = 0;
|
|
312
315
|
for (let y = 0; y < H; y++) {
|
|
@@ -346,6 +349,7 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
346
349
|
(behind >= 0 && options.feathered?.[behind]?.data[p] === 1) ||
|
|
347
350
|
(behind >= 0 && options.movingPair?.(front, behind) === true)
|
|
348
351
|
) {
|
|
352
|
+
locked[p] = 1;
|
|
349
353
|
skipped.locked++;
|
|
350
354
|
continue;
|
|
351
355
|
}
|
|
@@ -610,8 +614,74 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
610
614
|
for (const [p, v] of writes) {
|
|
611
615
|
d.set(v, p * 4);
|
|
612
616
|
changed[i].data[p] = 1;
|
|
613
|
-
options.written?.(i, p);
|
|
614
617
|
}
|
|
615
618
|
});
|
|
619
|
+
// Complete the existing allocation only where the final stack draws nothing.
|
|
620
|
+
// Read every candidate before writes, retaining a four-connected witness in
|
|
621
|
+
// the receiver's existing art and all authored soft/locked boundaries.
|
|
622
|
+
const restore = fill.filter(([p, front]) => {
|
|
623
|
+
if (options.figure?.data[p] !== 1 || !options.editable[front] || locked[p] === 1 ||
|
|
624
|
+
options.keep?.some(m => m?.data[p] === 1) || options.feathered?.some(m => m?.data[p] === 1) ||
|
|
625
|
+
(busy && !supports(front, p)) || parts.some(r => r.data[p * 4 + 3] > 0)) return false;
|
|
626
|
+
const d = parts[front].data, x = p % W;
|
|
627
|
+
return (x > 0 && d[(p - 1) * 4 + 3] > OPAQUE_ALPHA_ABOVE) ||
|
|
628
|
+
(x + 1 < W && d[(p + 1) * 4 + 3] > OPAQUE_ALPHA_ABOVE) ||
|
|
629
|
+
(p >= W && d[(p - W) * 4 + 3] > OPAQUE_ALPHA_ABOVE) ||
|
|
630
|
+
(p + W < W * H && d[(p + W) * 4 + 3] > OPAQUE_ALPHA_ABOVE);
|
|
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
|
+
}
|
|
677
|
+
for (const [p, front] of restore) {
|
|
678
|
+
const s = p * 4;
|
|
679
|
+
parts[front].data.set([srcr.data[s], srcr.data[s + 1], srcr.data[s + 2], 255], s);
|
|
680
|
+
changed[front].data[p] = 1;
|
|
681
|
+
}
|
|
682
|
+
planned.forEach((writes, i) => {
|
|
683
|
+
for (const p of writes.keys()) options.written?.(i, p);
|
|
684
|
+
});
|
|
685
|
+
for (const [p, front] of restore) if (!planned[front].has(p)) options.written?.(front, p);
|
|
616
686
|
return { changed, resolved, unseparated, skipped };
|
|
617
687
|
}
|
|
@@ -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
|
}
|
package/src/takeregion.ts
CHANGED
|
@@ -141,14 +141,14 @@ export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleCon
|
|
|
141
141
|
return refuse('ASSEMBLE_REGION_TAKE_REFERENCE_MATCH', at, `reference sha256 ${referenceHash}, expected ${reference.sha256}; reference ${referencePainting.width}x${referencePainting.height}, source ${painting.width}x${painting.height}; matching hash and painting dimensions are required`);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const inputs = makeInputs(
|
|
144
|
+
const inputs = makeInputs(painting, cfg, 'region take painting (--source must be opaque because geometry follows the run input and inputs refuses see-through paintings, flatten the plate first)');
|
|
145
145
|
const set = runs[declaration.run];
|
|
146
146
|
const donor = readLayers(resolve(dirname(resolve(configPath)), declaration.run_dir));
|
|
147
147
|
refuseIfAny(missingReceipts(receipts, editedRunImages(
|
|
148
148
|
{ full: donor, head: donor, single: true },
|
|
149
149
|
`region take "${declaration.run}:${declaration.part}" donor "${declaration.run_dir}" `,
|
|
150
150
|
)));
|
|
151
|
-
const target = declaration.run === 'head' ? inputs.head : runs.single && set.canvas.w !== set.canvas.h ?
|
|
151
|
+
const target = declaration.run === 'head' ? inputs.head : runs.single && set.canvas.w !== set.canvas.h ? painting : inputs.full;
|
|
152
152
|
let supplied: Raster;
|
|
153
153
|
try { supplied = readPng(resolve(dirname(resolve(configPath)), declaration.st_input)); }
|
|
154
154
|
catch { return refuse('ASSEMBLE_REGION_TAKE_GEOMETRY', at, `st_input "${declaration.st_input}" must name the original readable donor input PNG so its geometry can be checked`); }
|
|
@@ -161,11 +161,13 @@ export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleCon
|
|
|
161
161
|
if (base.depthSheet !== undefined || material.depthSheet !== undefined || [...set.hidden, ...donor.hidden].some(layer => layer.of === plan[2])) {
|
|
162
162
|
return refuse('ASSEMBLE_REGION_TAKE_BINDING', at, 'hidden companions or active depth sheets require independent region bindings; a part without those companions is required');
|
|
163
163
|
}
|
|
164
|
-
const
|
|
164
|
+
const colourInputs = reference === undefined ? inputs : makeInputs(referencePainting, cfg, 'region take reference');
|
|
165
|
+
const colourTarget = declaration.run === 'head' ? colourInputs.head! : target === painting ? referencePainting : colourInputs.full;
|
|
166
|
+
const source = resize(colourTarget, set.canvas.w, set.canvas.h, 'lanczos3');
|
|
165
167
|
const derived = deriveTakenRegion(base, material, source, declaration.seed, tolerance, at);
|
|
166
168
|
lists[declaration.run] = lists[declaration.run].map(layer => layer === base ? derived.layer : layer);
|
|
167
169
|
const reading: RegionReading = { part: declaration.part, run: declaration.run, run_dir: declaration.run_dir, ...derived.reading };
|
|
168
|
-
const pad = target ===
|
|
170
|
+
const pad = target === painting ? [0, 0] : declaration.run === 'head' ? inputs.headBox! : [-inputs.padLeft, -inputs.padTop];
|
|
169
171
|
const transform = { scale: [set.canvas.w / target.width, set.canvas.h / target.height], origin: [pad[0], pad[1]], filter: 'lanczos3' };
|
|
170
172
|
if (reference !== undefined) notes.push(`region reference ${reading.run}:${reading.part}: sha256 ${referenceHash}; binding ${'source' in reference ? 'source' : 'painting'}; painting-to-run ${JSON.stringify(transform)}`);
|
|
171
173
|
notes.push(`region take ${reading.run}:${reading.part} from ${reading.run_dir}: ${reading.pixels} run px; box [${reading.box.join(', ')}] (left, top, width, height); painting-match share ${reading.painting_match_share}; RGB tolerance ${reading.rgb_tolerance}; seed [${declaration.seed.join(', ')}], 8-connected`);
|