spine-parts 2.10.0 → 2.12.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 +96 -5
- package/docs/STABILITY.md +37 -2
- package/package.json +1 -1
- package/src/assemble.ts +23 -2
- package/src/coincideio.ts +3 -20
- package/src/config.ts +17 -3
- package/src/editreceipt.ts +9 -7
- package/src/paintingedges.ts +27 -2
- package/src/parts.ts +18 -1
- package/src/scene.ts +18 -4
- package/src/takelayers.ts +102 -6
- package/src/takeregion.ts +6 -4
- package/src/takesource.ts +38 -1
package/docs/AUTHORING.md
CHANGED
|
@@ -708,8 +708,8 @@ renaming a supplied image does not establish that it was the donor's input.
|
|
|
708
708
|
The target input is derived from the painting by the existing input model:
|
|
709
709
|
`full` uses the exact centred white `squarePad`, and `head` the configured
|
|
710
710
|
`head_box`. A nonsquare single-run file uses the painting at its original file
|
|
711
|
-
size before the assembler's existing padding.
|
|
712
|
-
have equal dimensions; donor and target input PNGs must also have equal
|
|
711
|
+
size before the assembler's existing padding. Without a declared `crop`, donor
|
|
712
|
+
and target run canvases must have equal dimensions; donor and target input PNGs must also have equal
|
|
713
713
|
dimensions. Incompatible canvases or input sizes are refused, never resized to
|
|
714
714
|
make the comparison pass.
|
|
715
715
|
|
|
@@ -768,6 +768,34 @@ identity an executable check on supplied original inputs instead of trusting
|
|
|
768
768
|
that claim or hand-editing `layers.json`. Seed and painting selection remain
|
|
769
769
|
the author's decisions.
|
|
770
770
|
|
|
771
|
+
|
|
772
|
+
With a whole-layer donor made from a crop of the original painting, add
|
|
773
|
+
`"crop": {"box": [left, top, right, bottom], "resample": "bilinear"}` to that
|
|
774
|
+
entry. The box uses integer source-painting pixels with exclusive right/bottom
|
|
775
|
+
bounds. Its input must be the white square-padded crop produced by the same
|
|
776
|
+
`inputs` geometry. The crop must be inside the painting. Donor RGBA under the
|
|
777
|
+
selected support and its existing margin must equal that reconstructed input.
|
|
778
|
+
Containment covers alpha > 8 support only. That support must fit both the crop
|
|
779
|
+
and the target canvas.
|
|
780
|
+
|
|
781
|
+
The map derives from donor canvas, crop padding/origin and target input geometry.
|
|
782
|
+
Unit scale with integer translation copies straight RGBA exactly. Every other map
|
|
783
|
+
uses one premultiplied float32 bilinear affine pass. The derived map uses pixel
|
|
784
|
+
corners. `warpAffine` samples by pixel index, as `layerToRig` does, with the
|
|
785
|
+
existing cv2-compatible fixed-point sampling and transparent border. The receipt's optional `transport`
|
|
786
|
+
records `crop`, `donor_canvas`, `target_canvas`, `scale`, `translate`, `filter`
|
|
787
|
+
(`exact` or `bilinear`) and `input_rgba_sha256`, `before_rgba_sha256`,
|
|
788
|
+
`after_rgba_sha256`. Hashes cover row-major straight RGBA over the entire named
|
|
789
|
+
canvas, with the donor input dimensions derived from the square-padded crop.
|
|
790
|
+
The production transport verifier checks canvas dimensions and the output hash
|
|
791
|
+
before downstream assembly changes. It refuses a changed canvas as
|
|
792
|
+
`PARTS_TAKEN_LAYERS`.
|
|
793
|
+
Resampling establishes the declared output bytes. It does not establish equality
|
|
794
|
+
between separately generated donor and target art. Omitting `crop` retains the
|
|
795
|
+
existing geometry refusal and its message.
|
|
796
|
+
|
|
797
|
+
Region take entries retain their existing geometry contract and refuse crop donors.
|
|
798
|
+
|
|
771
799
|
### Residual front/back edges (`edge_residuals.json`, issue #999)
|
|
772
800
|
|
|
773
801
|
Under `assemble.project: "visible"`, assemble writes `edge_residuals.json` beside
|
|
@@ -823,7 +851,9 @@ shipped `source: true` semantics and prints one
|
|
|
823
851
|
stage painting for the predicate. A declared but unreadable reference, or a
|
|
824
852
|
hash or painting-dimension mismatch, is refused by name. Only an explicitly
|
|
825
853
|
declared painting reference keeps the selected mask fixed when `--source`
|
|
826
|
-
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.
|
|
827
857
|
Both run canvases must agree, and the supplied original donor input
|
|
828
858
|
must match the entire target input in RGBA and dimensions, establishing the same
|
|
829
859
|
crop. Different crops await #973. Painting samples use the existing Lanczos3
|
|
@@ -858,6 +888,20 @@ every donor author/hidden image requires a valid receipt before pixels are
|
|
|
858
888
|
copied. A receipted author-layer target is accepted. The plan proposal command
|
|
859
889
|
refuses region entries because their part names depend on an existing plan.
|
|
860
890
|
|
|
891
|
+
### Scene plate editor receipts (issue #966)
|
|
892
|
+
|
|
893
|
+
Optional `scene.plate.editor_receipts` uses the assemble ledger shape
|
|
894
|
+
`{receipts: [{file, sha256, from_sha256, editor}], required?}`. Paths resolve
|
|
895
|
+
relative to the scene file. Every declared receipt is verified, and under
|
|
896
|
+
`required: true` the plate must match a verified receipt by content before
|
|
897
|
+
compose writes anything. The shared `trace_parts` boolean also requires a
|
|
898
|
+
matching receipt when true, as in assemble. `from_sha256` and `editor` remain
|
|
899
|
+
author declarations held to form and differing hashes. `provenance` remains
|
|
900
|
+
required and describes pixel origin (`observed`, `generated`, `unknown`).
|
|
901
|
+
A receipt verifies file identity and records an edit declaration. Neither
|
|
902
|
+
field judges pixel content. Omitting the ledger preserves output bytes and
|
|
903
|
+
accepted exit codes.
|
|
904
|
+
|
|
861
905
|
### Editor receipts (`assemble.editor_receipts`, issue #946)
|
|
862
906
|
|
|
863
907
|
An image edited in code — a layer re-segmented by a script, a patch
|
|
@@ -5160,7 +5204,8 @@ those settings. Changing a config seed alone cannot change a no-config run.
|
|
|
5160
5204
|
| <a id="ASSEMBLE_REGION_TAKE_SEED"></a>`ASSEMBLE_REGION_TAKE_SEED` | the seed touches no qualifying component | name an integer pixel in the derived region on the target run canvas |
|
|
5161
5205
|
| <a id="ASSEMBLE_REGION_TAKE_BINDING"></a>`ASSEMBLE_REGION_TAKE_BINDING` | active scalar depth or hidden companions have no region binding | supply a part without those companions |
|
|
5162
5206
|
| <a id="ASSEMBLE_REGION_TAKE_PLAN"></a>`ASSEMBLE_REGION_TAKE_PLAN` | a region entry is present during plan proposal | draft the plan before declaring region takes, then use assemble/build with requirements |
|
|
5163
|
-
| <a id="
|
|
5207
|
+
| <a id="ASSEMBLE_TAKE_CROP"></a>`ASSEMBLE_TAKE_CROP` | declared crop is outside the source, its square-padded input dimensions differ, or taken support would fall outside the crop or target | supply the original inside integer crop and its exact square-padded input, with explicit `resample: "bilinear"` |
|
|
5208
|
+
| <a id="ASSEMBLE_TAKE_GEOMETRY"></a>`ASSEMBLE_TAKE_GEOMETRY` | missing target head, unequal run canvases or unequal original input dimensions | supply matching geometry, or declare the whole-layer donor crop and resample explicitly |
|
|
5164
5209
|
| <a id="ASSEMBLE_TAKE_META"></a>`ASSEMBLE_TAKE_META` | donor `meta.json` lacks a readable prompt ID or seed | retain the original run metadata |
|
|
5165
5210
|
| <a id="ASSEMBLE_TAKE_INPUT"></a>`ASSEMBLE_TAKE_INPUT` | declared donor input PNG cannot be read | name its original PNG relative to the config |
|
|
5166
5211
|
| <a id="ASSEMBLE_TAKE_DEPTH_SHEET"></a>`ASSEMBLE_TAKE_DEPTH_SHEET` | taking layers with an active depth opt-in or bound scalar sheets has no declared mixed-run binding | keep scalar depth inactive; numeric ordering depth is retained, and a target sheet is never attached silently |
|
|
@@ -5703,6 +5748,10 @@ and stay absent).
|
|
|
5703
5748
|
| --- | --- | --- |
|
|
5704
5749
|
| <a id="SCENE_FILE"></a><a id="SCENE_SPEC"></a><a id="SCENE_FIELD_PRESENT"></a><a id="SCENE_FIELD_TYPE"></a><a id="SCENE_KEY_KNOWN"></a>`SCENE_FILE`, `SCENE_SPEC`, `SCENE_FIELD_PRESENT`, `SCENE_FIELD_TYPE`, `SCENE_KEY_KNOWN` | the scene file is missing, not a JSON object, not `spine-parts-scene/1`, or a field is missing, of the wrong type or not one the format reads (`canvas` two positive integers; `characters` at least one, each `id`, `build`, `offset` — an offset is never assumed (0, 0) — and an optional `scale`, a positive finite number: 0, a negative number or a non-number is refused at `characters[i].scale`; `order` a list of strings). `note`, `*_note` (strings) and `x-…` (any value) are read by nothing | the field |
|
|
5705
5750
|
| <a id="SCENE_ID_UNIQUE"></a><a id="SCENE_ID_FORM"></a>`SCENE_ID_UNIQUE`, `SCENE_ID_FORM` | an `id` repeated, empty, or holding `:` — the separator of a prefixed name — or `/`, `\` or a leading `.`, because an id begins every image file of its character | another id |
|
|
5751
|
+
| <a id="SCENE_EDITOR_RECEIPT"></a>`SCENE_EDITOR_RECEIPT` | `scene.plate.editor_receipts` has a malformed ledger or receipt (issue #966) | use `{receipts: [{file, sha256, from_sha256, editor}], required?}` with the same shape rules as assemble editor receipts |
|
|
5752
|
+
| <a id="SCENE_EDITOR_RECEIPT_FILE"></a>`SCENE_EDITOR_RECEIPT_FILE` | a plate receipt names a missing file | supply the edited image relative to the scene file |
|
|
5753
|
+
| <a id="SCENE_EDITOR_RECEIPT_SHA256"></a>`SCENE_EDITOR_RECEIPT_SHA256` | a plate receipt's file hashes differently from its declared `sha256` | record the current edited file's sha256 |
|
|
5754
|
+
| <a id="SCENE_EDITOR_RECEIPT_MISSING"></a>`SCENE_EDITOR_RECEIPT_MISSING` | `scene.plate.editor_receipts.required` is true and no verified receipt matches the plate's bytes | edit the plate in an image editor and record a matching receipt |
|
|
5706
5755
|
| <a id="SCENE_PLATE_PROVENANCE"></a><a id="SCENE_PLATE_PRESENT"></a><a id="SCENE_PLATE_SIZE"></a>`SCENE_PLATE_PROVENANCE`, `SCENE_PLATE_PRESENT`, `SCENE_PLATE_SIZE` | the plate's `provenance` is not `observed`, `generated` or `unknown`; its image is missing or not a PNG; it is not the canvas's size (it is drawn at canvas (0, 0) and never scaled) | the plate |
|
|
5707
5756
|
| <a id="SCENE_BUILD_PRESENT"></a>`SCENE_BUILD_PRESENT` | a build directory, or a file `build` writes in it (`parts.json`, `rig/rig.json`, `rig/motion.json` with an `idle`, an image its skin names, `check/check.json`), is missing | run `build` for that character |
|
|
5708
5757
|
| <a id="SCENE_BUILD_GREEN"></a>`SCENE_BUILD_GREEN` | the build's own `check/check.json` does not say `PASS` and `gate_spine_html_green`; under an accept list (`--accept`, `characters[].accept`), it failed a bar the list does not name, its gate is red, a declared requirement is not PASS, or it names no failing bar — the bars not met and the ones accepted are listed | finish that character first: compose binds finished characters. To look at the scene meanwhile, name the failing bars (§7, *Composing several characters*) |
|
|
@@ -6446,7 +6495,7 @@ single-character path (§4, steps 0–9) on its own, already isolated input to a
|
|
|
6446
6495
|
| field | what it is |
|
|
6447
6496
|
| --- | --- |
|
|
6448
6497
|
| `canvas` | the shared stage, canvas px, y down. The composed rig's stage is the canvas, `root` at its bottom centre, as a single character's is its own |
|
|
6449
|
-
| `plate` | optional. `image` (relative to the scene file) is a PNG of exactly the canvas's size; `provenance` is `observed` (the painting's own pixels), `generated` or `unknown` (a residual after the people were removed is `unknown` where they stood, and the author says so); `note` is free text.
|
|
6498
|
+
| `plate` | optional. `image` (relative to the scene file) is a PNG of exactly the canvas's size; `provenance` is `observed` (the painting's own pixels), `generated` or `unknown` (a residual after the people were removed is `unknown` where they stood, and the author says so); `note` is free text. `provenance` and `note` are copied into `scene.json` and **judged by nothing**. Optional `editor_receipts` uses the [editor receipt ledger](#scene-plate-editor-receipts-issue-966), with paths relative to the scene file and verified file hashes; `required: true` demands a matching plate receipt |
|
|
6450
6499
|
| `characters[].id` | the prefix: every bone, slot, attachment (skin entry), constraint (its name, and every bone and path slot it names), `stops` entry (its `chain`, `links` and `against`, issue #431), `invariants.detached` bone, track, group and easing of that character is renamed `<id>:<name>`. `root` is the one shared root. A name resolves to exactly one character, and nothing resolves across characters without its prefix |
|
|
6451
6500
|
| `characters[].build` | a `build --out` directory (relative to the scene file) whose own `check/check.json` is green |
|
|
6452
6501
|
| `characters[].offset` | `[x, y]`, a translation from the build's rig px to canvas px. Every character is built at one `assemble.rig_scale`, so its rig px are canvas px at scale 1 |
|
|
@@ -7114,6 +7163,48 @@ the load moves the same build by (the pre-change reference-demo build alone took
|
|
|
7114
7163
|
45.8 s there). Since issue #123 that build and render are gone again — the still regions read the
|
|
7115
7164
|
idle's geometry — and the `build` row was not re-measured for it either.
|
|
7116
7165
|
|
|
7166
|
+
### Private worker measurements (issue #1045)
|
|
7167
|
+
|
|
7168
|
+
Each shard unit carries an additive `measurement` record with spec
|
|
7169
|
+
`rig-parts-selftest-unit/1`. Its suite, unit, sorted case-ID set and execution
|
|
7170
|
+
profile identify the measured work. The profile records Bun, platform,
|
|
7171
|
+
architecture, available cores, configured worker count and sampling interval.
|
|
7172
|
+
The existing stdout replay and tally remain the source of case verdicts.
|
|
7173
|
+
Shard records now use `rig-parts-selftest-shard/2`, which requires a measurement
|
|
7174
|
+
on every unit. A dropped attachment is refused by unit name. Version `/1`
|
|
7175
|
+
remains readable, with absent measurements explicitly `UNMEASURED`.
|
|
7176
|
+
|
|
7177
|
+
On Linux, an independent process samples the worker's descendant family through
|
|
7178
|
+
`/proc` at a requested 200 ms interval. PID and kernel start time identify each
|
|
7179
|
+
holder, including observed descendants subsequently reparented. `family.bytes`
|
|
7180
|
+
is the largest sampled sum of per-process RSS, with the simultaneous `holders`,
|
|
7181
|
+
sample count and unreadable-entry count retained. Shared pages count per PID.
|
|
7182
|
+
Short-lived children and allocations between samples can be missed. An absent
|
|
7183
|
+
observation has `status: "UNMEASURED"` and `bytes: null`.
|
|
7184
|
+
The supervising shard excludes registered observer PID/start-time identities
|
|
7185
|
+
from its family peak and RT20 verdict. The exclusion control fixes its noise
|
|
7186
|
+
band at 16 MiB before measurement and compares against an observer-free run.
|
|
7187
|
+
If observer finalization or unit measurement construction throws, the launcher
|
|
7188
|
+
settles with `UNMEASURED` coverage and the named `measurement.error`. A failed
|
|
7189
|
+
stop-file write terminates and waits for that observer before settling.
|
|
7190
|
+
|
|
7191
|
+
Worker-result `phases` retain labelled monotonic spans and elapsed milliseconds.
|
|
7192
|
+
The hooks cover input readers `readPartSet` and `readFrom`, fixture writers
|
|
7193
|
+
`writeWrapperFixture`, `writePsdFixture`, `writeRigFixture`, `writeCheckRig` and
|
|
7194
|
+
`writeProposeFixture`, producer calls `build`, `buildRig` and `runCli`, and the
|
|
7195
|
+
case reporter. The assertion span measures reporting, while evaluating assertion
|
|
7196
|
+
arguments remains outside that hook. Unhooked work stays `unclassified`.
|
|
7197
|
+
These are observed boundaries, with no claim of exhaustive phase attribution.
|
|
7198
|
+
The requested command owns a `runCli` span, including any subprocess startup.
|
|
7199
|
+
|
|
7200
|
+
For overlapping spans, the latest starting span owns the overlap, with later
|
|
7201
|
+
registration breaking equal-start ties. Exclusive totals plus `unclassified`
|
|
7202
|
+
equal the worker's recorded elapsed time. The phase window excludes module
|
|
7203
|
+
loading and parent launch/collection, which the existing unit clocks include.
|
|
7204
|
+
A phase with no observed span is `UNMEASURED`. Old shard records remain readable
|
|
7205
|
+
and their absent measurements are represented as `UNMEASURED` when parsed.
|
|
7206
|
+
Measurements are private records, with no product output or new console line.
|
|
7207
|
+
|
|
7117
7208
|
### Machine-readable selftest summary (`--summary-json`, issue #725)
|
|
7118
7209
|
|
|
7119
7210
|
`bun run selftest -- --summary-json <file>` writes a JSON summary beside the normal console output
|
package/docs/STABILITY.md
CHANGED
|
@@ -156,8 +156,9 @@ part name, `[i]` an entry of a list):
|
|
|
156
156
|
- **assemble.alternates[i]** — required: `name`; optional: `source`, `full`, `head`, `parts`, `hides`, `head_box`, `cuts`, `skeleton`, `anchor`, `base_anchor`, `drawn`, `tips`, `front`, `layers`, `focus` (issues #454, #465, #543, #652, #664, #666, #719, #780). `focus` is an authored finite `[x, y]` in painting pixels, within its canvas (edges included), refused as CONFIG_SET_FOCUS before assemble output when invalid; only when present, `parts.json` records it with focus_source_size and `sets.json` emits it in setup-world coordinates through the actual rig resize and `src/coords.ts`. Absent focus emits no field or inferred value; changing/removing it requires reassembly
|
|
157
157
|
- **assemble.extend_below_crop[i]** — required: `part`, `run`, `tag`
|
|
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
|
-
- **assemble.take[i]** — required: `run`, `run_dir`, `st_input`; optional: `tags`, `part`, `seed`, `reference` (issues #866, #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
|
-
- **assemble.take[i].
|
|
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
|
+
- **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. 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.
|
|
161
162
|
- **assemble.editor_receipts** — required: `receipts`; optional: `required` (issue #946, additive), `trace_parts` (issue #947, additive)
|
|
162
163
|
- **assemble.editor_receipts.receipts[i]** — required: `file`, `sha256`, `from_sha256`, `editor` (issue #946)
|
|
163
164
|
- **assemble.patches[i]** — required: `name`, `box`, `alpha`, `draw`
|
|
@@ -616,6 +617,20 @@ stale evidence rather than reconstructing original art from emitted siblings.
|
|
|
616
617
|
Without the block the API reading is SKIP; CLI stdout and emitted bytes remain unchanged.
|
|
617
618
|
See [Source before scissors](AUTHORING.md#source-before-scissors).
|
|
618
619
|
|
|
620
|
+
### Scene plate editor receipts
|
|
621
|
+
|
|
622
|
+
`scene.plate.editor_receipts` (issue #966, additive) is optional and uses the
|
|
623
|
+
assemble receipt ledger shape, including `required` and `trace_parts`.
|
|
624
|
+
Receipt file paths resolve against the scene file. Declared receipts are
|
|
625
|
+
verified even without `required`; when required, the plate needs a verified
|
|
626
|
+
receipt matching its bytes. Receipt refusals occur before compose writes new
|
|
627
|
+
artifacts. As before, compose creates `--out` and clears its owned outputs,
|
|
628
|
+
including an earlier `rig/` and `scene.json`, before input validation, so a
|
|
629
|
+
refused re-run can remove earlier artifacts. Omitting the field preserves
|
|
630
|
+
exit codes and `scene.json` bytes. The existing required
|
|
631
|
+
`provenance` field is preserved. It declares pixel origin, while the receipt
|
|
632
|
+
verifies file identity and records the author's edit declaration.
|
|
633
|
+
|
|
619
634
|
### Editor receipts
|
|
620
635
|
|
|
621
636
|
The optional `assemble.editor_receipts` block (issue #946, additive) records
|
|
@@ -664,3 +679,23 @@ reads that rate (issue #965, additive for readers). Measurements in
|
|
|
664
679
|
`requirements` still require a positive `fps`, with no default. Declarations
|
|
665
680
|
whose instruments use their own rate keep that rate.
|
|
666
681
|
The output `check.json` omits `requirements.fps` when the file supplies no `fps`.
|
|
682
|
+
|
|
683
|
+
### Crop donor transport receipts (issue #973)
|
|
684
|
+
|
|
685
|
+
Whole-layer `parts[].taken_layers[]` optionally adds `transport` when its config
|
|
686
|
+
entry declares `crop`. The ordered fields are `crop`, `donor_canvas`,
|
|
687
|
+
`target_canvas`, `scale`, `translate`, `filter`, `input_rgba_sha256`,
|
|
688
|
+
`before_rgba_sha256` and `after_rgba_sha256`. Hashes bind whole-canvas row-major
|
|
689
|
+
straight RGBA before and after transport, and the donor input reconstructed from
|
|
690
|
+
the declared crop. `filter: "exact"` requires unit scale and integer translation.
|
|
691
|
+
Other maps carry `"bilinear"`. The strict reader refuses incomplete or malformed
|
|
692
|
+
transport records. Absent, the existing receipt fields and bytes are unchanged.
|
|
693
|
+
The output hash describes transport before downstream assembly, independently of
|
|
694
|
+
final part geometry. Existing no-take inputs emit no transport metadata.
|
|
695
|
+
|
|
696
|
+
### Region take source compatibility (issue #1054)
|
|
697
|
+
|
|
698
|
+
A see-through `--source` with an opaque explicit painting reference was accepted
|
|
699
|
+
when donor geometry followed the reference and is now refused with
|
|
700
|
+
`INPUTS_PAINTING_OPAQUE` before the donor is read. The reference remains a colour
|
|
701
|
+
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.12.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/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/config.ts
CHANGED
|
@@ -2501,7 +2501,7 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
|
|
|
2501
2501
|
const region = isPlainObject(v) && ('part' in v || 'seed' in v);
|
|
2502
2502
|
const o = region
|
|
2503
2503
|
? c.object(p, v, ['run', 'run_dir', 'st_input', 'part', 'seed'], ['reference'])
|
|
2504
|
-
: c.object(p, v, ['run', 'run_dir', 'st_input', 'tags'], []);
|
|
2504
|
+
: c.object(p, v, ['run', 'run_dir', 'st_input', 'tags'], ['crop']);
|
|
2505
2505
|
if (o === null) return;
|
|
2506
2506
|
if (o.run !== 'full' && o.run !== 'head') c.fail('CONFIG_FIELD_TYPE', p + '.run', '"full" or "head" is required');
|
|
2507
2507
|
for (const k of ['run_dir', 'st_input']) c.string(`${p}.${k}`, o[k]);
|
|
@@ -2526,6 +2526,14 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
|
|
|
2526
2526
|
}
|
|
2527
2527
|
return;
|
|
2528
2528
|
}
|
|
2529
|
+
if ('crop' in o) {
|
|
2530
|
+
const crop = c.object(`${p}.crop`, o.crop, ['box', 'resample'], []);
|
|
2531
|
+
if (crop !== null) {
|
|
2532
|
+
const box = crop.box;
|
|
2533
|
+
if (!(Array.isArray(box) && box.length === 4 && box.every(n => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0) && box[2] > box[0] && box[3] > box[1])) c.fail('CONFIG_FIELD_TYPE', `${p}.crop.box`, 'requires [left, top, right, bottom], nonnegative safe integers with positive width/height in source-painting pixels');
|
|
2534
|
+
if (crop.resample !== 'bilinear') c.fail('CONFIG_FIELD_TYPE', `${p}.crop.resample`, '"bilinear" is required explicitly');
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2529
2537
|
if (!c.array(p + '.tags', o.tags, true)) return;
|
|
2530
2538
|
(o.tags as Json[]).forEach((tag, j) => {
|
|
2531
2539
|
const reading = typeof tag === 'string' ? readLayerTag(tag) : null;
|
|
@@ -2537,6 +2545,13 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
|
|
|
2537
2545
|
});
|
|
2538
2546
|
}
|
|
2539
2547
|
|
|
2548
|
+
/** Shared receipt shape validation for config and scene input doors. */
|
|
2549
|
+
export function editorReceiptProblems(value: unknown, at: string): Problem[] {
|
|
2550
|
+
const c = new Check();
|
|
2551
|
+
checkEditorReceipts(c, value, at);
|
|
2552
|
+
return c.problems;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2540
2555
|
/**
|
|
2541
2556
|
* `config.assemble.editor_receipts` (issue #946): `{receipts, required?, trace_parts?}` (`trace_parts`, issue #947).
|
|
2542
2557
|
* Shape refusals are the loader's own; a receipt whose `from_sha256` equals
|
|
@@ -2544,8 +2559,7 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
|
|
|
2544
2559
|
* Whether the file exists and hashes to `sha256` is read at assemble
|
|
2545
2560
|
* (`src/editreceipt.ts`), where the file is.
|
|
2546
2561
|
*/
|
|
2547
|
-
function checkEditorReceipts(c: Check, value: Json): void {
|
|
2548
|
-
const at = 'config.assemble.editor_receipts';
|
|
2562
|
+
function checkEditorReceipts(c: Check, value: Json, at = 'config.assemble.editor_receipts'): void {
|
|
2549
2563
|
const o = c.object(at, value, ['receipts'], ['required', 'trace_parts']);
|
|
2550
2564
|
if (o === null) return;
|
|
2551
2565
|
for (const k of ['required', 'trace_parts'] as const) {
|
package/src/editreceipt.ts
CHANGED
|
@@ -89,6 +89,8 @@ export interface VerifiedReceipt extends EditorReceipt {
|
|
|
89
89
|
/** The receipts read for one build: those that verified, keyed by sha256, and the refusals of those that did not. */
|
|
90
90
|
export interface ReceiptLedger {
|
|
91
91
|
required: boolean;
|
|
92
|
+
/** Input location, defaulting to the assemble ledger. */
|
|
93
|
+
at?: string;
|
|
92
94
|
/** The field that made receipts required, as a refusal names it: `required`, else `trace_parts` (issue #947). */
|
|
93
95
|
by: 'required' | 'trace_parts';
|
|
94
96
|
bySha: ReadonlyMap<string, VerifiedReceipt>;
|
|
@@ -101,17 +103,17 @@ export interface ReceiptLedger {
|
|
|
101
103
|
* `file`). A missing file is `ASSEMBLE_EDITOR_RECEIPT_FILE`; bytes that hash
|
|
102
104
|
* to another value are `ASSEMBLE_EDITOR_RECEIPT_SHA256`, naming both values.
|
|
103
105
|
*/
|
|
104
|
-
export function readEditorReceipts(spec: EditorReceipts | undefined, configPath: string): ReceiptLedger {
|
|
106
|
+
export function readEditorReceipts(spec: EditorReceipts | undefined, configPath: string, at = AT, relativeTo: 'config' | 'scene file' = 'config'): ReceiptLedger {
|
|
105
107
|
const problems: Problem[] = [];
|
|
106
108
|
const bySha = new Map<string, VerifiedReceipt>();
|
|
107
109
|
if (spec === undefined) return { required: false, by: 'required', bySha, problems };
|
|
108
110
|
const base = dirname(resolve(configPath));
|
|
109
111
|
spec.receipts.forEach((r, i) => {
|
|
110
|
-
const
|
|
112
|
+
const receiptAt = `${at}.receipts[${i}]`;
|
|
111
113
|
const path = resolve(base, r.file);
|
|
112
|
-
const object = `${
|
|
114
|
+
const object = `${receiptAt} (file "${r.file}")`;
|
|
113
115
|
if (!existsSync(path) || !statSync(path).isFile()) {
|
|
114
|
-
problems.push({ code: 'ASSEMBLE_EDITOR_RECEIPT_FILE', object, detail: `names ${path}, which is no such file; the edited image, its path relative to the
|
|
116
|
+
problems.push({ code: 'ASSEMBLE_EDITOR_RECEIPT_FILE', object, detail: `names ${path}, which is no such file; the edited image, its path relative to the ${relativeTo}'s directory, is required` });
|
|
115
117
|
return;
|
|
116
118
|
}
|
|
117
119
|
const found = fileSha256(path);
|
|
@@ -119,10 +121,10 @@ export function readEditorReceipts(spec: EditorReceipts | undefined, configPath:
|
|
|
119
121
|
problems.push({ code: 'ASSEMBLE_EDITOR_RECEIPT_SHA256', object, detail: `the file's bytes hash to sha256 ${found}; the receipt's sha256 ${r.sha256} is required — the file changed after its receipt was written, or the receipt names another file` });
|
|
120
122
|
return;
|
|
121
123
|
}
|
|
122
|
-
if (!bySha.has(found)) bySha.set(found, { ...r, at, path });
|
|
124
|
+
if (!bySha.has(found)) bySha.set(found, { ...r, at: receiptAt, path });
|
|
123
125
|
});
|
|
124
126
|
const by = spec.required === true || spec.trace_parts !== true ? 'required' : 'trace_parts';
|
|
125
|
-
return { required: spec.required === true || spec.trace_parts === true, by, bySha, problems };
|
|
127
|
+
return { required: spec.required === true || spec.trace_parts === true, by, bySha, problems, at };
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
/** An image the input itself says was made or edited outside See-through. */
|
|
@@ -181,7 +183,7 @@ export function missingReceipts(ledger: ReceiptLedger, images: readonly EditedIm
|
|
|
181
183
|
problems.push({
|
|
182
184
|
code: 'ASSEMBLE_EDITOR_RECEIPT_MISSING',
|
|
183
185
|
object: image.object,
|
|
184
|
-
detail: `${image.path} (sha256 ${found}) carries no editor receipt; ${AT}.${ledger.by} is true, so a receipt {file, sha256, from_sha256, editor} whose sha256 is this file's is required — edit the image in an image editor and record it, never generate or patch it in code`,
|
|
186
|
+
detail: `${image.path} (sha256 ${found}) carries no editor receipt; ${ledger.at ?? AT}.${ledger.by} is true, so a receipt {file, sha256, from_sha256, editor} whose sha256 is this file's is required — edit the image in an image editor and record it, never generate or patch it in code`,
|
|
185
187
|
});
|
|
186
188
|
}
|
|
187
189
|
return problems;
|
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 zero-alpha gaps. */
|
|
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,6 +268,7 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
270
|
}
|
|
271
|
+
const fill: Array<[number, number]> = [];
|
|
269
272
|
// 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
273
|
{
|
|
271
274
|
const near: Uint8Array[] = [];
|
|
@@ -274,7 +277,6 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
|
|
|
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,29 @@ 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
|
+
for (const [p, front] of restore) {
|
|
633
|
+
const s = p * 4;
|
|
634
|
+
parts[front].data.set([srcr.data[s], srcr.data[s + 1], srcr.data[s + 2], 255], s);
|
|
635
|
+
changed[front].data[p] = 1;
|
|
636
|
+
}
|
|
637
|
+
planned.forEach((writes, i) => {
|
|
638
|
+
for (const p of writes.keys()) options.written?.(i, p);
|
|
639
|
+
});
|
|
640
|
+
for (const [p, front] of restore) if (!planned[front].has(p)) options.written?.(front, p);
|
|
616
641
|
return { changed, resolved, unseparated, skipped };
|
|
617
642
|
}
|
package/src/parts.ts
CHANGED
|
@@ -507,9 +507,26 @@ function orderedProvenance(p: PixelProvenance): PixelProvenance {
|
|
|
507
507
|
...(p.depth === undefined ? {} : { depth: { kind: p.depth.kind, values: p.depth.values.map(v => ({ group: v.group, ...(v.bone === undefined ? {} : { bone: v.bone }), value: v.value })) } }) };
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
+
function orderedTakenSource(source: TakenLayerSource): TakenLayerSource {
|
|
511
|
+
const transport = source.transport;
|
|
512
|
+
return {
|
|
513
|
+
run: source.run, tag: source.tag, run_dir: source.run_dir, st_input: source.st_input,
|
|
514
|
+
prompt_id: source.prompt_id, seed: source.seed, support_px: source.support_px,
|
|
515
|
+
checked_px: source.checked_px, differing_px: source.differing_px,
|
|
516
|
+
...(transport === undefined ? {} : { transport: {
|
|
517
|
+
crop: transport.crop, donor_canvas: transport.donor_canvas,
|
|
518
|
+
target_canvas: transport.target_canvas, scale: transport.scale,
|
|
519
|
+
translate: transport.translate, filter: transport.filter,
|
|
520
|
+
input_rgba_sha256: transport.input_rgba_sha256,
|
|
521
|
+
before_rgba_sha256: transport.before_rgba_sha256,
|
|
522
|
+
after_rgba_sha256: transport.after_rgba_sha256,
|
|
523
|
+
} }),
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
510
527
|
function serializePartList(parts: readonly PartRecord[]): Array<Record<string, unknown>> {
|
|
511
528
|
return parts.map((p) =>
|
|
512
|
-
Object.fromEntries(PART_KEYS.filter((k) => p[k] !== undefined).map((k) => [k, k === FRINGE_KEY ? (p.fringe_pushed_back ?? []).map((q) => ({ part: q.part, px: q.px })) : k === LIMB_KEY ? orderedLimb(p.limb as LimbRecord) : k === 'taken_layers' ? p.taken_layers?.map(
|
|
529
|
+
Object.fromEntries(PART_KEYS.filter((k) => p[k] !== undefined).map((k) => [k, k === FRINGE_KEY ? (p.fringe_pushed_back ?? []).map((q) => ({ part: q.part, px: q.px })) : k === LIMB_KEY ? orderedLimb(p.limb as LimbRecord) : k === 'taken_layers' ? p.taken_layers?.map(orderedTakenSource) : k === 'provenance' ? orderedProvenance(p.provenance as PixelProvenance) : p[k]])),
|
|
513
530
|
);
|
|
514
531
|
}
|
|
515
532
|
|
package/src/scene.ts
CHANGED
|
@@ -96,9 +96,10 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
96
96
|
import type { RigStop } from '@rig-c/core/rig';
|
|
97
97
|
import { checkStage, gateThroughRigc, type Log } from './build.ts';
|
|
98
98
|
import { ACCEPTABLE_BARS, barsNotMet, type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackMode, requirementsNotPass, type RigcRunner } from './check.ts';
|
|
99
|
-
import { CONSTRAINT_BONE_FIELDS, ROOT_BONE } from './config.ts';
|
|
99
|
+
import { CONSTRAINT_BONE_FIELDS, editorReceiptProblems, ROOT_BONE } from './config.ts';
|
|
100
100
|
import { cropToSpineY } from './coords.ts';
|
|
101
101
|
import { failLine, PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
102
|
+
import { missingReceipts, readEditorReceipts, type EditorReceipts } from './editreceipt.ts';
|
|
102
103
|
import type { MotionSpec } from './motion.ts';
|
|
103
104
|
import { readPng } from './raster/png.ts';
|
|
104
105
|
import { readRequirements, type RequirementsFile } from './requirements.ts';
|
|
@@ -161,6 +162,7 @@ export interface ScenePlate {
|
|
|
161
162
|
image: string;
|
|
162
163
|
imagePath: string;
|
|
163
164
|
provenance: Provenance;
|
|
165
|
+
editor_receipts?: EditorReceipts;
|
|
164
166
|
note: string | null;
|
|
165
167
|
}
|
|
166
168
|
|
|
@@ -221,7 +223,8 @@ export function acceptProblems(names: readonly string[], where: string): Problem
|
|
|
221
223
|
/**
|
|
222
224
|
* Read and shape-check a scene file. Every problem is collected before one
|
|
223
225
|
* refusal: the file, `spec`, `canvas` (two positive integers), `plate`
|
|
224
|
-
* (optional
|
|
226
|
+
* (optional, with required `image` and `provenance` and optional `note`
|
|
227
|
+
* and `editor_receipts` with the shared ledger shape), `characters` (at
|
|
225
228
|
* least one; each `id`, `build`, `offset`), `order` (a list of strings), and
|
|
226
229
|
* any key the format does not read. Resolving the ids and slots `order`
|
|
227
230
|
* names is {@link composeScene}'s, which has the builds.
|
|
@@ -270,7 +273,10 @@ export function loadScene(path: string): SceneFile {
|
|
|
270
273
|
const p = o.plate;
|
|
271
274
|
if (!isRecord(p)) fail('SCENE_FIELD_TYPE', 'scene.plate', `is ${show(p)}; {"image": "<png>", "provenance": ${PROVENANCES.map((x) => `"${x}"`).join(' | ')}} is required when the key is present`);
|
|
272
275
|
else {
|
|
273
|
-
known(p, 'scene.plate', ['image', 'provenance', 'note']);
|
|
276
|
+
known(p, 'scene.plate', ['image', 'provenance', 'note', 'editor_receipts']);
|
|
277
|
+
if ('editor_receipts' in p) {
|
|
278
|
+
problems.push(...editorReceiptProblems(p.editor_receipts, 'scene.plate.editor_receipts').map((problem) => ({ ...problem, code: 'SCENE_EDITOR_RECEIPT' })));
|
|
279
|
+
}
|
|
274
280
|
const image = p.image;
|
|
275
281
|
const prov = p.provenance;
|
|
276
282
|
if (!('image' in p)) fail('SCENE_FIELD_PRESENT', 'scene.plate.image', 'is absent and required; the plate PNG, relative to the scene file');
|
|
@@ -278,7 +284,7 @@ export function loadScene(path: string): SceneFile {
|
|
|
278
284
|
if (!('provenance' in p)) fail('SCENE_FIELD_PRESENT', 'scene.plate.provenance', `is absent and required; one of ${PROVENANCES.join(', ')} — what the plate's pixels are, which the author states and nothing judges`);
|
|
279
285
|
else if (typeof prov !== 'string' || !(PROVENANCES as readonly string[]).includes(prov)) fail('SCENE_PLATE_PROVENANCE', 'scene.plate.provenance', `is ${show(prov)}; one of ${PROVENANCES.join(', ')} is required`);
|
|
280
286
|
if (typeof image === 'string' && image !== '' && typeof prov === 'string' && (PROVENANCES as readonly string[]).includes(prov)) {
|
|
281
|
-
plate = { image, imagePath: resolve(base, image), provenance: prov as Provenance, note: typeof p.note === 'string' ? p.note : null };
|
|
287
|
+
plate = { image, imagePath: resolve(base, image), provenance: prov as Provenance, ...('editor_receipts' in p ? { editor_receipts: p.editor_receipts as EditorReceipts } : {}), note: typeof p.note === 'string' ? p.note : null };
|
|
282
288
|
}
|
|
283
289
|
}
|
|
284
290
|
}
|
|
@@ -1375,6 +1381,14 @@ export function composeFromFiles(scenePath: string, requirementsPath?: string, m
|
|
|
1375
1381
|
const builds = scene.characters.map((c) => readCharacterBuild(c, problems, accept));
|
|
1376
1382
|
let plate: PlateImage | null = null;
|
|
1377
1383
|
if (scene.plate !== null) {
|
|
1384
|
+
const ledger = readEditorReceipts(scene.plate.editor_receipts, scene.path, 'scene.plate.editor_receipts', 'scene file');
|
|
1385
|
+
const receiptCodes: Readonly<Record<string, string>> = {
|
|
1386
|
+
ASSEMBLE_EDITOR_RECEIPT_FILE: 'SCENE_EDITOR_RECEIPT_FILE',
|
|
1387
|
+
ASSEMBLE_EDITOR_RECEIPT_SHA256: 'SCENE_EDITOR_RECEIPT_SHA256',
|
|
1388
|
+
ASSEMBLE_EDITOR_RECEIPT_MISSING: 'SCENE_EDITOR_RECEIPT_MISSING',
|
|
1389
|
+
};
|
|
1390
|
+
const receiptProblems = [...ledger.problems, ...missingReceipts(ledger, [{ object: 'scene.plate.image', path: scene.plate.imagePath }])];
|
|
1391
|
+
problems.push(...receiptProblems.map((problem) => ({ ...problem, code: receiptCodes[problem.code] ?? problem.code })));
|
|
1378
1392
|
const where = `scene.plate.image (${scene.plate.image})`;
|
|
1379
1393
|
if (!existsSync(scene.plate.imagePath)) problems.push({ code: 'SCENE_PLATE_PRESENT', object: where, detail: `${scene.plate.imagePath} does not exist; a PNG of the canvas's size is required` });
|
|
1380
1394
|
else {
|
package/src/takelayers.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/** Verified replacement in an existing full/head run; never writes or forges a run manifest. */
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
3
4
|
import { dirname, resolve } from 'node:path';
|
|
4
5
|
import type { EarlyConfig, PlanEntry, Run } from './config.ts';
|
|
5
6
|
import { CORE_KERNEL, fullPlanBand } from './assemble.ts';
|
|
6
|
-
import { makeInputs } from './inputs.ts';
|
|
7
|
+
import { makeInputs, squarePad } from './inputs.ts';
|
|
7
8
|
import { OPAQUE_ALPHA_ABOVE, readLayers, type Layer, type LayerSet } from './layers.ts';
|
|
8
9
|
import { PartsError, refuseIfAny, type Problem } from './errors.ts';
|
|
9
10
|
import { dilate } from './raster/morph.ts';
|
|
10
|
-
import { newMask, type Raster } from './raster/types.ts';
|
|
11
|
+
import { newMask, newRaster, newFloatImage, type Raster } from './raster/types.ts';
|
|
11
12
|
import { readPng } from './raster/png.ts';
|
|
12
13
|
import type { TakeDeclaration } from './takeregion.ts';
|
|
13
|
-
import
|
|
14
|
+
import { crop, pad } from './raster/composite.ts';
|
|
15
|
+
import { warpAffine, type ScaleTranslate } from './raster/warp.ts';
|
|
16
|
+
import { takenTransportProblems, type TakenLayerSource, type TakenLayerTransport } from './takesource.ts';
|
|
14
17
|
|
|
15
18
|
export interface TakeLayers {
|
|
16
19
|
run: Run;
|
|
@@ -18,6 +21,8 @@ export interface TakeLayers {
|
|
|
18
21
|
/** The exact PNG supplied to See-through, resolved from the config directory. */
|
|
19
22
|
st_input: string;
|
|
20
23
|
tags: string[];
|
|
24
|
+
/** Original painting pixels, right/bottom exclusive; donor input is squarePad(crop). */
|
|
25
|
+
crop?: { box: [number, number, number, number]; resample: 'bilinear' };
|
|
21
26
|
}
|
|
22
27
|
function refuse(code: string, object: string, detail: string): never { throw new PartsError([{ code, object, detail }]); }
|
|
23
28
|
function metadata(path: string): { prompt_id: string; seed: number } {
|
|
@@ -49,6 +54,92 @@ function identity(layer: Layer, canvas: LayerSet['canvas'], donor: Raster, targe
|
|
|
49
54
|
if (differing > 0) return refuse('ASSEMBLE_TAKE_INPUT_IDENTITY', object, `${differing} differing pixel(s), bbox [${x0}, ${y0}, ${x1}, ${y1}] in st_input pixels (right/bottom exclusive); exact RGBA identity under alpha > ${OPAQUE_ALPHA_ABOVE}, grown by ${CORE_KERNEL}x${CORE_KERNEL}, is required`);
|
|
50
55
|
return { support, checked };
|
|
51
56
|
}
|
|
57
|
+
/** Hash straight RGBA, with the dimensions carried separately in the transport receipt. */
|
|
58
|
+
function rgbaHash(image: Raster): string {
|
|
59
|
+
return createHash('sha256').update(image.data).digest('hex');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function cropGeometry(d: TakeLayers, painting: Raster, target: Raster, donor: LayerSet, set: LayerSet, inputs: ReturnType<typeof makeInputs>, at: string): { expected: Raster; map: ScaleTranslate; exact: boolean } {
|
|
63
|
+
const declaration = d.crop!;
|
|
64
|
+
const [x0, y0, x1, y1] = declaration.box;
|
|
65
|
+
if (declaration.resample !== 'bilinear' || !declaration.box.every(Number.isSafeInteger) || x0 < 0 || y0 < 0 || x1 <= x0 || y1 <= y0 || x1 > painting.width || y1 > painting.height) {
|
|
66
|
+
return refuse('ASSEMBLE_TAKE_CROP', at, `crop [${declaration.box.join(', ')}] on painting ${painting.width}x${painting.height}; an inside nonempty integer box and resample "bilinear" are required`);
|
|
67
|
+
}
|
|
68
|
+
const w = x1 - x0, h = y1 - y0;
|
|
69
|
+
const donorPad = squarePad(w, h);
|
|
70
|
+
const expected = pad(crop(painting, x0, y0, w, h), donorPad.left, donorPad.top, donorPad.side - w - donorPad.left, donorPad.side - h - donorPad.top, [255, 255, 255, 255]);
|
|
71
|
+
const origin = target === painting ? [0, 0] : d.run === 'head' ? [-inputs.headBox![0], -inputs.headBox![1]] : [inputs.padLeft, inputs.padTop];
|
|
72
|
+
const scaleXUnit = BigInt(donorPad.side) * BigInt(set.canvas.w) === BigInt(donor.canvas.w) * BigInt(target.width);
|
|
73
|
+
const scaleYUnit = BigInt(donorPad.side) * BigInt(set.canvas.h) === BigInt(donor.canvas.h) * BigInt(target.height);
|
|
74
|
+
const offsetX = BigInt(x0 - donorPad.left + origin[0]) * BigInt(set.canvas.w);
|
|
75
|
+
const offsetY = BigInt(y0 - donorPad.top + origin[1]) * BigInt(set.canvas.h);
|
|
76
|
+
const integerX = offsetX % BigInt(target.width) === 0n;
|
|
77
|
+
const integerY = offsetY % BigInt(target.height) === 0n;
|
|
78
|
+
return { expected, exact: scaleXUnit && scaleYUnit && integerX && integerY, map: {
|
|
79
|
+
sx: scaleXUnit ? 1 : donorPad.side / donor.canvas.w * set.canvas.w / target.width,
|
|
80
|
+
sy: scaleYUnit ? 1 : donorPad.side / donor.canvas.h * set.canvas.h / target.height,
|
|
81
|
+
tx: integerX ? Number(offsetX / BigInt(target.width)) : (x0 - donorPad.left + origin[0]) * set.canvas.w / target.width,
|
|
82
|
+
ty: integerY ? Number(offsetY / BigInt(target.height)) : (y0 - donorPad.top + origin[1]) * set.canvas.h / target.height,
|
|
83
|
+
} };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** One full-canvas affine pass, using the same premultiplied float32 convention as layerToRig. */
|
|
87
|
+
function transportLayer(layer: Layer, donor: LayerSet, set: LayerSet, image: Raster, d: TakeLayers, map: ScaleTranslate, exact: boolean, at: string): { layer: Layer; transport: TakenLayerTransport } {
|
|
88
|
+
const canvas = newRaster(donor.canvas.w, donor.canvas.h);
|
|
89
|
+
for (let y = 0; y < layer.pixels.height; y++) {
|
|
90
|
+
canvas.data.set(layer.pixels.data.subarray(y * layer.pixels.width * 4, (y + 1) * layer.pixels.width * 4), ((y + layer.top) * canvas.width + layer.left) * 4);
|
|
91
|
+
}
|
|
92
|
+
const [x0, y0, x1, y1] = d.crop!.box;
|
|
93
|
+
const donorPad = squarePad(x1 - x0, y1 - y0);
|
|
94
|
+
for (let y = layer.top; y < layer.bottom; y++) for (let x = layer.left; x < layer.right; x++) {
|
|
95
|
+
if (canvas.data[(y * canvas.width + x) * 4 + 3] <= OPAQUE_ALPHA_ABOVE) continue;
|
|
96
|
+
const dx = x * donorPad.side / canvas.width - donorPad.left;
|
|
97
|
+
const dy = y * donorPad.side / canvas.height - donorPad.top;
|
|
98
|
+
const tx = map.sx * x + map.tx, ty = map.sy * y + map.ty;
|
|
99
|
+
if (dx < 0 || dy < 0 || (x + 1) * donorPad.side / canvas.width - donorPad.left > x1 - x0 || (y + 1) * donorPad.side / canvas.height - donorPad.top > y1 - y0 || tx < 0 || ty < 0 || tx + map.sx > set.canvas.w || ty + map.sy > set.canvas.h) {
|
|
100
|
+
return refuse('ASSEMBLE_TAKE_CROP', at, `supported donor cell [${x}, ${y}] falls outside the declared painting crop or target canvas; the whole taken support must be retained`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const out = newRaster(set.canvas.w, set.canvas.h);
|
|
104
|
+
if (exact) {
|
|
105
|
+
for (let y = 0; y < canvas.height; y++) for (let x = 0; x < canvas.width; x++) {
|
|
106
|
+
const tx = x + map.tx, ty = y + map.ty;
|
|
107
|
+
if (tx >= 0 && ty >= 0 && tx < out.width && ty < out.height) out.data.set(canvas.data.subarray((y * canvas.width + x) * 4, (y * canvas.width + x + 1) * 4), (ty * out.width + tx) * 4);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const pre = newFloatImage(canvas.width, canvas.height, 4);
|
|
111
|
+
for (let p = 0; p < canvas.width * canvas.height; p++) {
|
|
112
|
+
const a = canvas.data[p * 4 + 3];
|
|
113
|
+
for (let c = 0; c < 3; c++) pre.data[p * 4 + c] = Math.fround(canvas.data[p * 4 + c] * Math.fround(a / 255));
|
|
114
|
+
pre.data[p * 4 + 3] = a;
|
|
115
|
+
}
|
|
116
|
+
const warped = warpAffine(pre, map, out.width, out.height, 'bilinear');
|
|
117
|
+
const clip = (v: number): number => Math.max(0, Math.min(255, v));
|
|
118
|
+
for (let p = 0; p < out.width * out.height; p++) {
|
|
119
|
+
const a = Math.fround(clip(warped.data[p * 4 + 3]));
|
|
120
|
+
for (let c = 0; c < 3; c++) {
|
|
121
|
+
const value = Math.fround(clip(warped.data[p * 4 + c]));
|
|
122
|
+
const straight = Math.fround(Math.fround(value * 255) / Math.max(a, Math.fround(1e-3)));
|
|
123
|
+
out.data[p * 4 + c] = a > 0 ? Math.trunc(clip(straight)) : 0;
|
|
124
|
+
}
|
|
125
|
+
out.data[p * 4 + 3] = Math.trunc(a);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
let opaquePx = 0;
|
|
129
|
+
for (let p = 3; p < out.data.length; p += 4) if (out.data[p] > OPAQUE_ALPHA_ABOVE) opaquePx++;
|
|
130
|
+
if (opaquePx === 0) return refuse('ASSEMBLE_TAKE_SUPPORT', at, `has 0 pixels of alpha above ${OPAQUE_ALPHA_ABOVE} after the declared transport; a nonempty taken layer is required`);
|
|
131
|
+
const transport: TakenLayerTransport = {
|
|
132
|
+
crop: [...d.crop!.box], donor_canvas: [canvas.width, canvas.height], target_canvas: [out.width, out.height],
|
|
133
|
+
scale: [map.sx, map.sy], translate: [map.tx, map.ty], filter: exact ? 'exact' : 'bilinear',
|
|
134
|
+
input_rgba_sha256: rgbaHash(image), before_rgba_sha256: rgbaHash(canvas), after_rgba_sha256: rgbaHash(out),
|
|
135
|
+
};
|
|
136
|
+
refuseIfAny(takenTransportProblems(transport, out, at));
|
|
137
|
+
return {
|
|
138
|
+
layer: { ...layer, left: 0, top: 0, right: out.width, bottom: out.height, pixels: out, opaquePx },
|
|
139
|
+
transport,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
52
143
|
export function takeLayerNote(source: TakenLayerSource): string {
|
|
53
144
|
return `take ${source.run}:${source.tag} from ${source.run_dir}; prompt_id ${source.prompt_id}; seed ${source.seed}; st_input ${source.st_input}; support ${source.support_px} run px; checked ${source.checked_px} input px; differing ${source.differing_px}; alpha > ${OPAQUE_ALPHA_ABOVE}, ${CORE_KERNEL}x${CORE_KERNEL} margin`;
|
|
54
145
|
}
|
|
@@ -81,7 +172,10 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
81
172
|
const meta = metadata(resolve(base, d.run_dir, 'meta.json'));
|
|
82
173
|
let image: Raster;
|
|
83
174
|
try { image = readPng(resolve(base, d.st_input)); } catch { return refuse('ASSEMBLE_TAKE_INPUT', at, `st_input "${d.st_input}" must name the original readable PNG supplied to the donor run`); }
|
|
84
|
-
if (target === null || donor.canvas.w !== set.canvas.w || donor.canvas.h !== set.canvas.h || image.width !== target.width || image.height !== target.height) return refuse('ASSEMBLE_TAKE_GEOMETRY', at, `donor canvas ${donor.canvas.w}x${donor.canvas.h}, target canvas ${set.canvas.w}x${set.canvas.h}, donor st_input ${image.width}x${image.height}, target st_input ${target?.width ?? 0}x${target?.height ?? 0}; equal canvases and equal input dimensions are required (full uses squarePad; head uses head_box)`);
|
|
175
|
+
if (d.crop === undefined && (target === null || donor.canvas.w !== set.canvas.w || donor.canvas.h !== set.canvas.h || image.width !== target.width || image.height !== target.height)) return refuse('ASSEMBLE_TAKE_GEOMETRY', at, `donor canvas ${donor.canvas.w}x${donor.canvas.h}, target canvas ${set.canvas.w}x${set.canvas.h}, donor st_input ${image.width}x${image.height}, target st_input ${target?.width ?? 0}x${target?.height ?? 0}; equal canvases and equal input dimensions are required (full uses squarePad; head uses head_box)`);
|
|
176
|
+
if (target === null) return refuse('ASSEMBLE_TAKE_CROP', at, 'a target input is required for a declared crop');
|
|
177
|
+
const geometry = d.crop === undefined ? undefined : cropGeometry(d, painting, target, donor, set, inputs, at);
|
|
178
|
+
if (geometry !== undefined && (image.width !== geometry.expected.width || image.height !== geometry.expected.height)) return refuse('ASSEMBLE_TAKE_CROP', at, `donor st_input ${image.width}x${image.height}; declared square-padded crop requires ${geometry.expected.width}x${geometry.expected.height}`);
|
|
85
179
|
const union = new Uint8Array(image.width * image.height);
|
|
86
180
|
for (const tag of d.tags) {
|
|
87
181
|
const key = `${d.run}:${tag}`;
|
|
@@ -89,10 +183,12 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
89
183
|
seen.add(key);
|
|
90
184
|
const layer = donor.layers.find(l => l.name === tag);
|
|
91
185
|
if (layer === undefined) return refuse('ASSEMBLE_TAKE_TAG_IN_RUN', at, `tag "${tag}" is absent; a named See-through tag held by that donor is required`);
|
|
92
|
-
const checked = identity(layer, donor.canvas, image, target, `${at} tag "${tag}"`);
|
|
186
|
+
const checked = identity(layer, donor.canvas, image, geometry?.expected ?? target, `${at} tag "${tag}"`);
|
|
93
187
|
for (let p = 0; p < union.length; p++) union[p] |= checked.checked[p];
|
|
94
188
|
const source: TakenLayerSource = { run: d.run, tag, run_dir: d.run_dir, st_input: d.st_input, prompt_id: meta.prompt_id, seed: meta.seed, support_px: checked.support, checked_px: checked.checked.reduce((a, b) => a + b, 0), differing_px: 0 };
|
|
95
|
-
const
|
|
189
|
+
const transported = geometry === undefined ? undefined : transportLayer(layer, donor, set, image, d, geometry.map, geometry.exact, `${at} tag "${tag}"`);
|
|
190
|
+
if (transported !== undefined) source.transport = transported.transport;
|
|
191
|
+
const replacement: Layer = { ...(transported?.layer ?? layer), takenLayers: [source] };
|
|
96
192
|
lists[d.run] = [...lists[d.run].filter(l => l.name !== tag), replacement];
|
|
97
193
|
origins.set(replacement, resolve(base, d.run_dir));
|
|
98
194
|
notes.push(takeLayerNote(source));
|
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`);
|
package/src/takesource.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
/** Layer identity receipts, retained independently of part names and derived geometry. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import type { Raster } from './raster/types.ts';
|
|
2
4
|
import type { Problem } from './errors.ts';
|
|
3
5
|
import { readLayerTag } from './tags.ts';
|
|
6
|
+
export interface TakenLayerTransport {
|
|
7
|
+
crop: [number, number, number, number];
|
|
8
|
+
donor_canvas: [number, number];
|
|
9
|
+
target_canvas: [number, number];
|
|
10
|
+
scale: [number, number];
|
|
11
|
+
translate: [number, number];
|
|
12
|
+
filter: 'exact' | 'bilinear';
|
|
13
|
+
input_rgba_sha256: string;
|
|
14
|
+
before_rgba_sha256: string;
|
|
15
|
+
after_rgba_sha256: string;
|
|
16
|
+
}
|
|
17
|
+
/** Verify a transported run canvas against its sealed receipt before downstream assembly. */
|
|
18
|
+
export function takenTransportProblems(transport: TakenLayerTransport, image: Raster, at: string): Problem[] {
|
|
19
|
+
const actual = createHash('sha256').update(image.data).digest('hex');
|
|
20
|
+
if (image.width !== transport.target_canvas[0] || image.height !== transport.target_canvas[1] || actual !== transport.after_rgba_sha256) {
|
|
21
|
+
return [{ code: 'PARTS_TAKEN_LAYERS', object: at,
|
|
22
|
+
detail: `transported canvas ${image.width}x${image.height}, RGBA sha256 ${actual}; receipt requires ${transport.target_canvas.join('x')}, RGBA sha256 ${transport.after_rgba_sha256}` }];
|
|
23
|
+
}
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
4
26
|
export interface TakenLayerSource {
|
|
5
27
|
run: 'full' | 'head';
|
|
6
28
|
tag: string;
|
|
@@ -11,6 +33,7 @@ export interface TakenLayerSource {
|
|
|
11
33
|
support_px: number;
|
|
12
34
|
checked_px: number;
|
|
13
35
|
differing_px: 0;
|
|
36
|
+
transport?: TakenLayerTransport;
|
|
14
37
|
}
|
|
15
38
|
export function unionTakenSources(lists: readonly (readonly TakenLayerSource[] | undefined)[]): TakenLayerSource[] {
|
|
16
39
|
const out: TakenLayerSource[] = [];
|
|
@@ -28,13 +51,27 @@ export function takenSourceProblems(value: unknown, at: string): Problem[] {
|
|
|
28
51
|
if (typeof item !== 'object' || item === null || Array.isArray(item)) { fail('each source must be a complete identity receipt'); continue; }
|
|
29
52
|
const o = item as Record<string, unknown>;
|
|
30
53
|
const tag = typeof o.tag === 'string' ? readLayerTag(o.tag) : null;
|
|
31
|
-
if (Object.keys(o).some(k => !keys.includes(k)) || keys.some(k => !(k in o)) ||
|
|
54
|
+
if (Object.keys(o).some(k => !keys.includes(k) && k !== 'transport') || keys.some(k => !(k in o)) ||
|
|
32
55
|
(o.run !== 'full' && o.run !== 'head') || tag === null || tag.group === 'author' ||
|
|
33
56
|
['run_dir', 'st_input', 'prompt_id'].some(k => typeof o[k] !== 'string' || !(o[k] as string).trim()) ||
|
|
34
57
|
!Number.isSafeInteger(o.seed) || (o.seed as number) < 0 ||
|
|
35
58
|
['support_px', 'checked_px'].some(k => !Number.isSafeInteger(o[k]) || (o[k] as number) <= 0) || o.differing_px !== 0) {
|
|
36
59
|
fail('each source requires exactly run, See-through tag, run_dir, st_input, prompt_id, nonnegative safe integer seed, positive support_px/checked_px and differing_px 0'); continue;
|
|
37
60
|
}
|
|
61
|
+
if (o.transport !== undefined) {
|
|
62
|
+
const t = o.transport as Record<string, unknown> | null;
|
|
63
|
+
const fields = ['crop', 'donor_canvas', 'target_canvas', 'scale', 'translate', 'filter', 'input_rgba_sha256', 'before_rgba_sha256', 'after_rgba_sha256'];
|
|
64
|
+
const pair = (v: unknown, positive: boolean, integer: boolean): v is number[] => Array.isArray(v) && v.length === 2 && v.every(n => typeof n === 'number' && Number.isFinite(n) && (!positive || n > 0) && (!integer || Number.isSafeInteger(n)));
|
|
65
|
+
if (typeof t !== 'object' || t === null || Array.isArray(t) || Object.keys(t).length !== fields.length || fields.some(k => !(k in t)) ||
|
|
66
|
+
!Array.isArray(t.crop) || t.crop.length !== 4 || !t.crop.every(n => Number.isSafeInteger(n) && n >= 0) || t.crop[2] <= t.crop[0] || t.crop[3] <= t.crop[1] ||
|
|
67
|
+
!pair(t.donor_canvas, true, true) || !pair(t.target_canvas, true, true) || !pair(t.scale, true, false) || !pair(t.translate, false, false) ||
|
|
68
|
+
(t.filter !== 'exact' && t.filter !== 'bilinear') ||
|
|
69
|
+
['input_rgba_sha256', 'before_rgba_sha256', 'after_rgba_sha256'].some(k => typeof t[k] !== 'string' || !/^[0-9a-f]{64}$/.test(t[k] as string))) {
|
|
70
|
+
fail('transport requires exactly crop, donor_canvas, target_canvas, scale, translate, filter and three lowercase RGBA SHA-256 hashes');
|
|
71
|
+
} else if ((t.filter === 'exact') !== (t.scale[0] === 1 && t.scale[1] === 1 && t.translate.every(Number.isSafeInteger))) {
|
|
72
|
+
fail('transport filter exact requires unit scale and integer translation; every other map requires bilinear');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
38
75
|
const key = JSON.stringify([o.run, o.tag, o.run_dir]);
|
|
39
76
|
if (seen.has(key)) fail(`duplicate source ${key}; each source must appear once`);
|
|
40
77
|
seen.add(key);
|