spine-parts 2.17.0 → 2.19.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 CHANGED
@@ -794,7 +794,8 @@ Resampling establishes the declared output bytes. It does not establish equality
794
794
  between separately generated donor and target art. Omitting `crop` retains the
795
795
  existing geometry refusal and its message.
796
796
 
797
- Region take entries retain their existing geometry contract and refuse crop donors.
797
+ Region take entries accept the same optional `crop` and use this transport before
798
+ selecting the seeded component on the target run canvas.
798
799
 
799
800
  ### Residual front/back edges (`edge_residuals.json`, issue #999)
800
801
 
@@ -854,10 +855,13 @@ declared painting reference keeps the selected mask fixed when `--source`
854
855
  changes for projection. The reference governs colour only and geometry follows `--source`.
855
856
  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
857
  Its input is derived as for whole-layer take above.
857
- Both run canvases must agree, and the supplied original donor input
858
- must match the entire target input in RGBA and dimensions, establishing the same
859
- crop. Different crops await #973. Painting samples use the existing Lanczos3
860
- resize onto the run canvas. Only the 8-connected qualifying component containing
858
+ Without `crop`, both run canvases must agree, and the supplied original donor
859
+ input must match the entire target input in RGBA and dimensions. With `crop`,
860
+ the supplied input must match the declared square-padded painting crop exactly.
861
+ The whole-layer crop transport maps donor pixels onto the target run canvas
862
+ before selection; the seed remains on that target canvas. Painting samples,
863
+ including a declared reference, use the existing Lanczos3 resize onto the target
864
+ run canvas, never the donor crop grid. Only the 8-connected qualifying component containing
861
865
  the seed is copied. The base layer's depth and draw order stay in use.
862
866
  For a declared reference, its hash, binding and painting-to-run transform are logged. For
863
867
  `scale` and `origin`, run coordinates are `(painting - origin) * scale`.
@@ -5203,7 +5207,7 @@ those settings. Changing a config seed alone cannot change a no-config run.
5203
5207
  | <a id="ASSEMBLE_REGION_TAKE_REFERENCE_MATCH"></a>`ASSEMBLE_REGION_TAKE_REFERENCE_MATCH` | a reference hash or painting dimensions differ | supply the declared PNG and preserve the source geometry |
5204
5208
  | <a id="ASSEMBLE_REGION_TAKE_CONTAINMENT"></a>`ASSEMBLE_REGION_TAKE_CONTAINMENT` | a non-target part has no pre-take counterpart | retain the same neighbour part population before and after the take |
5205
5209
  | <a id="ASSEMBLE_REGION_TAKE_TOLERANCE"></a>`ASSEMBLE_REGION_TAKE_TOLERANCE` | a region take has no authored `setup_painting.rgb_tolerance` | supply the same requirements file to assemble/build and check |
5206
- | <a id="ASSEMBLE_REGION_TAKE_GEOMETRY"></a>`ASSEMBLE_REGION_TAKE_GEOMETRY` | donor and target canvases or original input RGBA differ, or the target head run is absent | supply the same crop and original input PNG. Cropped donors await #973 |
5210
+ | <a id="ASSEMBLE_REGION_TAKE_GEOMETRY"></a>`ASSEMBLE_REGION_TAKE_GEOMETRY` | without `crop`, donor and target canvases or entire input RGBA differ; with `crop`, the original input differs from its declared square-padded crop; or the target head run is absent | supply the matching original input PNG and declare `crop` for a crop donor; a head take requires a target head run |
5207
5211
  | <a id="ASSEMBLE_REGION_TAKE_PART"></a>`ASSEMBLE_REGION_TAKE_PART` | the named plan part/run or its base/donor tag is absent, or the target is taken twice | name an existing plan part and one donor holding its tag |
5208
5212
  | <a id="ASSEMBLE_REGION_TAKE_EMPTY"></a>`ASSEMBLE_REGION_TAKE_EMPTY` | the derived qualifying region has 0 pixels | supply material missing from the base that covers and matches the painting |
5209
5213
  | <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 |
@@ -5297,6 +5301,11 @@ those settings. Changing a config seed alone cannot change a no-config run.
5297
5301
  | <a id="KEYPOINTS_JOINT_KNOWN"></a><a id="KEYPOINTS_JOINT_STATE"></a><a id="KEYPOINTS_POSITION_STATED"></a><a id="KEYPOINTS_POSITION_INSIDE"></a>`KEYPOINTS_JOINT_KNOWN`, `KEYPOINTS_JOINT_STATE`, `KEYPOINTS_POSITION_STATED`, `KEYPOINTS_POSITION_INSIDE` | a joint name outside body-18, a state outside observed / occluded / missing, an observed joint with no `at` or a missing one with one, or a position outside the `width`x`height` image | that joint |
5298
5302
  | <a id="KEYPOINTS_PERSON_UNIQUE"></a><a id="KEYPOINTS_PERSON_CHOSEN"></a>`KEYPOINTS_PERSON_UNIQUE`, `KEYPOINTS_PERSON_CHOSEN` | two people share an id; or the file holds more than one person and no `--person` names one, or `--person` names none of them (the message lists the ids) | `--person <id>` |
5299
5303
  | <a id="KEYPOINTS_IMAGE_SIZE"></a>`KEYPOINTS_IMAGE_SIZE` | the file's `width`x`height` is not the `--source` painting's | a file measured on this painting |
5304
+ | <a id="PARTS_PAINTING_PRESENT"></a>`PARTS_PAINTING_PRESENT` | The declared rig-resolution painting cannot be read. | Re-run assemble; restore the declared file and manifest together. |
5305
+ | <a id="PARTS_PAINTING_SHA256"></a>`PARTS_PAINTING_SHA256` | The declared rig-resolution painting does not match its SHA-256. | Re-run assemble; restore the declared file and manifest together. |
5306
+ | <a id="PARTS_PAINTING_PNG"></a>`PARTS_PAINTING_PNG` | The declared rig-resolution painting is not a decodable PNG. | Re-run assemble; restore the declared file and manifest together. |
5307
+ | <a id="PARTS_PAINTING_SIZE"></a>`PARTS_PAINTING_SIZE` | The declared rig-resolution painting dimensions differ from rig_size. | Re-run assemble; restore the declared file and manifest together. |
5308
+ | <a id="PARTS_PAINTING_OPAQUE"></a>`PARTS_PAINTING_OPAQUE` | The declared rig-resolution painting has alpha below 255. | Re-run assemble; restore the declared file and manifest together. |
5300
5309
  | <a id="PARTS_FILE_PRESENT"></a><a id="PARTS_IS_JSON"></a><a id="PARTS_KEY_KNOWN"></a><a id="PARTS_FIELD_PRESENT"></a><a id="PARTS_FIELD_TYPE"></a><a id="PARTS_NAME_UNIQUE"></a><a id="PARTS_FROM_KNOWN"></a><a id="PARTS_CUT_FROM_KNOWN"></a><a id="PARTS_BOX_INSIDE_RIG"></a><a id="PARTS_COUNTS_ADD_UP"></a><a id="PARTS_HOLES_LARGEST_FIRST"></a><a id="PARTS_HOLE_PART_KNOWN"></a><a id="PARTS_SINGLE_RUN_PAD"></a>`PARTS_*` (`PARTS_FILE_PRESENT`, `PARTS_IS_JSON`, `PARTS_KEY_KNOWN`, `PARTS_FIELD_PRESENT`, `PARTS_FIELD_TYPE`, `PARTS_NAME_UNIQUE`, `PARTS_FROM_KNOWN`, `PARTS_CUT_FROM_KNOWN`, `PARTS_BOX_INSIDE_RIG`, `PARTS_COUNTS_ADD_UP`, `PARTS_HOLES_LARGEST_FIRST`, `PARTS_HOLE_PART_KNOWN`, `PARTS_SINGLE_RUN_PAD`) | the `parts.json` read is not assemble's contract (`PARTS_FILE_PRESENT`: no `parts.json` under `--parts`, which names the directory holding `parts.json` and `parts/` — `work/rig` from `assemble --out work`, or `out` from `build --out out`; `PARTS_COUNTS_ADD_UP`: `visible_px + occluded_px` is not `opaque_px`, `visible_not_projected_px` is above `visible_px`, or the `recomposite` block's figures disagree — more uncovered than error pixels, a hole larger than its box, the wrong number of holes listed, listed areas that do not sum to `uncovered_error_px`; the last two codes are the block's order and its border names; `PARTS_SINGLE_RUN_PAD`: the `single_run_pad` block's margins are not the centring, its file is not smaller than its square, or `rig_size` is not the file at the scale, issue #366 — §5) | pass the directory holding `parts.json` and `parts/` (`work/rig` or `out`), or re-run assemble; do not edit `parts.json`; optional value/ownership report fields follow [Source before scissors](#source-before-scissors) |
5301
5310
 
5302
5311
  ### compare
@@ -5592,7 +5601,7 @@ documents do not ship). Each is an input this package built; none is an author's
5592
5601
  | <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 |
5593
5602
  | <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 |
5594
5603
  | <a id="CHECK_BOUNDARY_COLOUR_STEP"></a>`CHECK_BOUNDARY_COLOUR_STEP` | the requirements file declares `boundary_colour.max_step_excess` and a part boundary's colour step in the rig's render exceeds the same boundary's step in the rig's own pieces by more than it; the part pair, the frame (`setup` or `idle frame <n> (t <s> s)`), the stage pixel, the excess, the declared allowance and both steps are quoted. Unlike [`CHECK_SETUP_MATCHES_PAINTING`](#CHECK_SETUP_MATCHES_PAINTING), which compares the painting per declared region at the setup pose, this compares against the rig's own flat pieces (`parts.json` placement at setup, each piece's rest colour through its art UVs on every idle frame), so a part drawn over its neighbour's line art is not a failure | the pair's rig image or mesh: `rig/images/<part>.png` (a texture stretched into its padded UVs, or a notch cut out of it), or that part's mesh in `config.json` `meshes` when the mesh cuts a corner off the art; see [Boundary colour step](#boundary-colour-step-issue-942) |
5595
- | <a id="CHECK_BOUNDARY_COLOUR_UNMEASURED"></a>`CHECK_BOUNDARY_COLOUR_UNMEASURED` | `boundary_colour` is declared and the step cannot be taken: no `parts.json` or no `idle` (refused before anything is built), or a drawn slot has no `parts.json` piece, is clipped, or its rig image is not its parts PNG with one even pad on every side (the slot and frame are named). Never a pass | make every drawn slot a `parts.json` piece, or drop `boundary_colour` from the requirements file (the bar then reports SKIP) |
5604
+ | <a id="CHECK_BOUNDARY_COLOUR_UNMEASURED"></a>`CHECK_BOUNDARY_COLOUR_UNMEASURED` | `boundary_colour` is declared and the step cannot be taken: no `parts.json`, no `idle`, or a default-skin region or mesh image without a sequence, with a parts record, whose rig image is not its parts PNG with one even pad on every side (refused before anything is built); otherwise a drawn slot has no `parts.json` piece, is clipped, or its rig image is not its parts PNG with one even pad on every side (the slot and frame are named). Never a pass | make every drawn slot a `parts.json` piece, or drop `boundary_colour` from the requirements file (the bar then reports SKIP) |
5596
5605
  | <a id="SETUP_PAINTING_REQUIRED_LIMIT"></a>`SETUP_PAINTING_REQUIRED_LIMIT` | `setup_painting.required` is `true` and a limit the check needs is absent: `rgb_tolerance`, `regions`, or a region's `max_pixels` (the object names the region). Refused when the requirements file is read, before anything is built (issue #943) | author the named limit; none is derived from the art. Without `required` the same region reports SKIP |
5597
5606
  | <a id="CHECK_SOURCE_GRID"></a>`CHECK_SOURCE_GRID` | the setup-pose still and its black-tinted twin (the coverage `SETUP_POSE_VS_SOURCE` reads) did not come back on one grid over one opaque background | a rigc problem; report it |
5598
5607
  | <a id="CHECK_RIGC_VERSION"></a>`CHECK_RIGC_VERSION` | `rigc --version` is below 1.4.0, or prints no version: its `render` has no `--geometry`, which `TEXTURE_STRETCH` reads. Refused before anything is built | `bun install` (this package depends on rig-c ^2.20.4), or put a newer `rigc` first on `PATH` |
@@ -8012,50 +8021,50 @@ Internal `SeamSupport.drawings` never enters check JSON. Named requirement
8012
8021
  <!-- check-row-table:begin -->
8013
8022
  | Row family | row_scope | row_kind | row_subjects (producer expression) | Producer |
8014
8023
  | --- | --- | --- | --- | --- |
8015
- | `ANIMATIONS_DO_NOT_FOLD.declared_not_folding` | 'part' | finding | [e.slot] | [check.ts:3479](../src/check.ts#L3479) |
8016
- | `ANIMATIONS_DO_NOT_FOLD.folding` | 'part' | finding when entry === undefined; otherwise evidence | [slot] | [check.ts:3441](../src/check.ts#L3441) |
8024
+ | `ANIMATIONS_DO_NOT_FOLD.declared_not_folding` | 'part' | finding | [e.slot] | [check.ts:3516](../src/check.ts#L3516) |
8025
+ | `ANIMATIONS_DO_NOT_FOLD.folding` | 'part' | finding when entry === undefined; otherwise evidence | [slot] | [check.ts:3478](../src/check.ts#L3478) |
8017
8026
  | `ART_JOINT_DISTANCE.joints` | 'rig' | finding when status === 'FAIL'; otherwise evidence | [] | [artjoints.ts:86](../src/artjoints.ts#L86) |
8018
- | `BOUNDARY_COLOUR_STEP.over` | 'pair' | finding | r.parts | [boundarycolour.ts:219](../src/boundarycolour.ts#L219) |
8019
- | `BOUNDARY_COLOUR_STEP.unmeasured` | 'part' | evidence | [r.slot] | [boundarycolour.ts:220](../src/boundarycolour.ts#L220) |
8020
- | `CLOTH_SETTLES.rows` | 'rig' | finding when speeds.length > 0 && s < speeds.length; otherwise evidence | [] | [check.ts:5764](../src/check.ts#L5764) |
8027
+ | `BOUNDARY_COLOUR_STEP.over` | 'pair' | finding | r.parts | [boundarycolour.ts:220](../src/boundarycolour.ts#L220) |
8028
+ | `BOUNDARY_COLOUR_STEP.unmeasured` | 'part' | evidence | [r.slot] | [boundarycolour.ts:221](../src/boundarycolour.ts#L221) |
8029
+ | `CLOTH_SETTLES.rows` | 'rig' | finding when speeds.length > 0 && s < speeds.length; otherwise evidence | [] | [check.ts:5801](../src/check.ts#L5801) |
8021
8030
  | `CUT_JOINT_MATERIAL.rows` | 'part' | finding when r.status === 'FAIL'; otherwise evidence | [r.part] | [cutmaterial.ts:280](../src/cutmaterial.ts#L280) |
8022
- | `FEET_STAY_LEVEL.feet` | 'part' | finding when row.status === 'FAIL'; otherwise evidence | [row.part] | [check.ts:3680](../src/check.ts#L3680) |
8023
- | `FEET_STAY_LEVEL.feet[].worst.through` | 'rig' | evidence | [] | [check.ts:3655](../src/check.ts#L3655) |
8024
- | `LIMB_ONE_BONE.parts` | 'part' | finding when fail; otherwise evidence | [p.name] | [check.ts:3972](../src/check.ts#L3972) |
8031
+ | `FEET_STAY_LEVEL.feet` | 'part' | finding when row.status === 'FAIL'; otherwise evidence | [row.part] | [check.ts:3717](../src/check.ts#L3717) |
8032
+ | `FEET_STAY_LEVEL.feet[].worst.through` | 'rig' | evidence | [] | [check.ts:3692](../src/check.ts#L3692) |
8033
+ | `LIMB_ONE_BONE.parts` | 'part' | finding when fail; otherwise evidence | [p.name] | [check.ts:4009](../src/check.ts#L4009) |
8025
8034
  | `PART_SUPPORT_REPORT.pairs` | 'pair' | evidence; finding when length > 0; otherwise evidence | [F.name, B.name] | [coincide.ts:114](../src/coincide.ts#L114), [coincide.ts:130](../src/coincide.ts#L130) |
8026
8035
  | `PART_SUPPORT_REPORT.raw_pairs` | 'pair' | evidence | [F.name, B.name] | [coincide.ts:110](../src/coincide.ts#L110) |
8027
8036
  | `PART_SUPPORT_REPORT.unowned.regions` | 'rig' | finding | [] | [coincide.ts:145](../src/coincide.ts#L145) |
8028
- | `SEAM_OVER_MOTION.pairs` | 'pair' | evidence | [p.a, p.b] | [check.ts:5165](../src/check.ts#L5165) |
8029
- | `SEAM_OVER_MOTION.required.pairs` | 'pair' | finding when open > 0; otherwise evidence | [p.a, p.b] | [check.ts:4573](../src/check.ts#L4573) |
8030
- | `SEAM_OVER_MOTION.roots.unmeasured` | 'part' | evidence | [root.part] | [check.ts:5142](../src/check.ts#L5142) |
8031
- | `SEAM_OVER_MOTION.rows` | 'pair' | finding when p.status === 'read' && opens.length > 0; otherwise evidence; finding when r.status === 'read' && r.opens.length > 0; otherwise evidence | [want.a, want.b]; pairs.filter(p => p.pair === r.pair).flatMap(p => [p.a, p.b]) | [check.ts:5104](../src/check.ts#L5104), [check.ts:5168](../src/check.ts#L5168) |
8032
- | `SEAM_OVER_MOTION.rows[].cells` | 'pair' | evidence | [want.a, want.b] | [check.ts:5117](../src/check.ts#L5117) |
8033
- | `SEAM_OVER_MOTION.rows[].joint_contact.reasons` | 'pair' | evidence | [want.a, want.b] | [check.ts:5107](../src/check.ts#L5107) |
8037
+ | `SEAM_OVER_MOTION.pairs` | 'pair' | evidence | [p.a, p.b] | [check.ts:5202](../src/check.ts#L5202) |
8038
+ | `SEAM_OVER_MOTION.required.pairs` | 'pair' | finding when open > 0; otherwise evidence | [p.a, p.b] | [check.ts:4610](../src/check.ts#L4610) |
8039
+ | `SEAM_OVER_MOTION.roots.unmeasured` | 'part' | evidence | [root.part] | [check.ts:5179](../src/check.ts#L5179) |
8040
+ | `SEAM_OVER_MOTION.rows` | 'pair' | finding when p.status === 'read' && opens.length > 0; otherwise evidence; finding when r.status === 'read' && r.opens.length > 0; otherwise evidence | [want.a, want.b]; pairs.filter(p => p.pair === r.pair).flatMap(p => [p.a, p.b]) | [check.ts:5141](../src/check.ts#L5141), [check.ts:5205](../src/check.ts#L5205) |
8041
+ | `SEAM_OVER_MOTION.rows[].cells` | 'pair' | evidence | [want.a, want.b] | [check.ts:5154](../src/check.ts#L5154) |
8042
+ | `SEAM_OVER_MOTION.rows[].joint_contact.reasons` | 'pair' | evidence | [want.a, want.b] | [check.ts:5144](../src/check.ts#L5144) |
8034
8043
  | `SEAM_OVER_MOTION.rows[].pose_at_worst.joints` | 'rig' | evidence | [] | [motionseampose.ts:53](../src/motionseampose.ts#L53) |
8035
- | `SEAM_OVER_MOTION.worlds.*.rows` | 'pair' | evidence | [want.a, want.b] | [check.ts:5101](../src/check.ts#L5101) |
8036
- | `SEAM_OVER_RANGE.joints` | 'part' | evidence; finding when poses.some(p => p.status === 'FAIL'); otherwise evidence | [j.part] | [check.ts:4296](../src/check.ts#L4296), [check.ts:4342](../src/check.ts#L4342) |
8037
- | `SEAM_OVER_RANGE.joints[].poses` | 'part' | finding when fail; otherwise evidence | [j.part] | [check.ts:4340](../src/check.ts#L4340) |
8044
+ | `SEAM_OVER_MOTION.worlds.*.rows` | 'pair' | evidence | [want.a, want.b] | [check.ts:5138](../src/check.ts#L5138) |
8045
+ | `SEAM_OVER_RANGE.joints` | 'part' | evidence; finding when poses.some(p => p.status === 'FAIL'); otherwise evidence | [j.part] | [check.ts:4333](../src/check.ts#L4333), [check.ts:4379](../src/check.ts#L4379) |
8046
+ | `SEAM_OVER_RANGE.joints[].poses` | 'part' | finding when fail; otherwise evidence | [j.part] | [check.ts:4377](../src/check.ts#L4377) |
8038
8047
  | `SETUP_MATCHES_PAINTING.regions` | 'rig' | finding when status === 'FAIL'; otherwise evidence | [] | [setuppainting.ts:174](../src/setuppainting.ts#L174) |
8039
8048
  | `SETUP_MATCHES_PAINTING.regions[].slots` | slot === '(uncovered)' ? 'rig' : 'part' | evidence | slot === '(uncovered)' ? [] : [slot] | [setuppainting.ts:175](../src/setuppainting.ts#L175) |
8040
- | `STILL_REGIONS_DARK.*.crossing` | 'part' | finding | [sl.name] | [check.ts:8704](../src/check.ts#L8704) |
8041
- | `STILL_REGIONS_DARK.*.still_slots` | 'part' | evidence; finding when r.max > tolerance; otherwise evidence | [slot] | [check.ts:8690](../src/check.ts#L8690), [check.ts:8695](../src/check.ts#L8695) |
8042
- | `STRESS_OFF_CHAIN.not_read` | 'part' | evidence | [r.part] | [check.ts:3900](../src/check.ts#L3900) |
8043
- | `STRESS_OFF_CHAIN.per_part` | 'part' | finding when poses.some(p => typeof p.reading === 'number' && p.reading > STRESS_RIGID); otherwise evidence | [r.part] | [check.ts:3888](../src/check.ts#L3888) |
8044
- | `STRESS_OFF_CHAIN.per_part[].off_chain` | 'part' | evidence | [r.part] | [check.ts:3888](../src/check.ts#L3888) |
8045
- | `STRESS_OFF_CHAIN.per_part[].poses` | 'part' | evidence; finding when shown > STRESS_RIGID; otherwise evidence | [r.part] | [check.ts:3856](../src/check.ts#L3856), [check.ts:3874](../src/check.ts#L3874) |
8046
- | `TEXTURE_STRETCH.per_mesh` | 'part' | evidence; finding when severity > TEXTURE_STRETCH_CEILING; otherwise evidence | [m.slot] | [check.ts:9338](../src/check.ts#L9338), [check.ts:9348](../src/check.ts#L9348) |
8047
- | `TIP_OVER_ROOT.parts` | 'part' | evidence; finding when !ok && !(!rigid && hanging.onLink && Math.max(c.root, c.tip) < TIP_TRAVEL_FLOOR); otherwise evidence | [p.name] | [check.ts:8120](../src/check.ts#L8120), [check.ts:8125](../src/check.ts#L8125), [check.ts:8146](../src/check.ts#L8146), [check.ts:8157](../src/check.ts#L8157) |
8048
- | `WIND_BAND.pairs` | 'pair' | finding when !holdsAll; otherwise evidence | [p.a, p.b] | [check.ts:6268](../src/check.ts#L6268) |
8049
- | `WIND_BAND.pairs[].steps` | 'pair' | finding when !s.holds; otherwise evidence | [p.a, p.b] | [check.ts:6279](../src/check.ts#L6279) |
8050
- | `figure_openings.openings` | 'pair' | finding | [ps.under, ps.above] | [check.ts:5585](../src/check.ts#L5585) |
8051
- | `loop_physics` | 'rig' | evidence | [] | [check.ts:7243](../src/check.ts#L7243) |
8052
- | `requirements.lines.* (bone)` | 'rig' | finding when line.status === 'FAIL'; otherwise evidence | [] | [check.ts:7539](../src/check.ts#L7539) |
8053
- | `requirements.lines.* (seam)` | 'pair' | finding when line.status === 'FAIL'; otherwise evidence | [r.part, r.neighbour] | [check.ts:7539](../src/check.ts#L7539) |
8054
- | `requirements.lines.* (stretch)` | 'part' | finding when line.status === 'FAIL'; otherwise evidence | [r.slot] | [check.ts:7539](../src/check.ts#L7539) |
8055
- | `seam_pairs` | pair[0] === SEAM_NO_ART ? 'rig' : pair[1] === SEAM_NO_ART ? 'part' : 'pair' | evidence | pair.filter(p => p !== SEAM_NO_ART) | [check.ts:2442](../src/check.ts#L2442) |
8056
- | `seam_scope.changes` | 'rig' | evidence | [] | [check.ts:1921](../src/check.ts#L1921) |
8057
- | `seam_scope.domain.states` | 'rig' | evidence | [] | [check.ts:2006](../src/check.ts#L2006) |
8058
- | `seam_scope.pairs` | row.parts[0] === SEAM_NO_ART ? 'rig' : row.parts[1] === SEAM_NO_ART ? 'part' : 'pair' | evidence | row.parts.filter(p => p !== SEAM_NO_ART) | [check.ts:7153](../src/check.ts#L7153) |
8059
- | `seam_scope.population.pairs` | 'pair' | evidence | row.parts | [check.ts:2377](../src/check.ts#L2377) |
8060
- | `seam_scope.population.single_art` | 'part' | evidence | [row.part] | [check.ts:2378](../src/check.ts#L2378) |
8049
+ | `STILL_REGIONS_DARK.*.crossing` | 'part' | finding | [sl.name] | [check.ts:8744](../src/check.ts#L8744) |
8050
+ | `STILL_REGIONS_DARK.*.still_slots` | 'part' | evidence; finding when r.max > tolerance; otherwise evidence | [slot] | [check.ts:8730](../src/check.ts#L8730), [check.ts:8735](../src/check.ts#L8735) |
8051
+ | `STRESS_OFF_CHAIN.not_read` | 'part' | evidence | [r.part] | [check.ts:3937](../src/check.ts#L3937) |
8052
+ | `STRESS_OFF_CHAIN.per_part` | 'part' | finding when poses.some(p => typeof p.reading === 'number' && p.reading > STRESS_RIGID); otherwise evidence | [r.part] | [check.ts:3925](../src/check.ts#L3925) |
8053
+ | `STRESS_OFF_CHAIN.per_part[].off_chain` | 'part' | evidence | [r.part] | [check.ts:3925](../src/check.ts#L3925) |
8054
+ | `STRESS_OFF_CHAIN.per_part[].poses` | 'part' | evidence; finding when shown > STRESS_RIGID; otherwise evidence | [r.part] | [check.ts:3893](../src/check.ts#L3893), [check.ts:3911](../src/check.ts#L3911) |
8055
+ | `TEXTURE_STRETCH.per_mesh` | 'part' | evidence; finding when severity > TEXTURE_STRETCH_CEILING; otherwise evidence | [m.slot] | [check.ts:9378](../src/check.ts#L9378), [check.ts:9388](../src/check.ts#L9388) |
8056
+ | `TIP_OVER_ROOT.parts` | 'part' | evidence; finding when !ok && !(!rigid && hanging.onLink && Math.max(c.root, c.tip) < TIP_TRAVEL_FLOOR); otherwise evidence | [p.name] | [check.ts:8160](../src/check.ts#L8160), [check.ts:8165](../src/check.ts#L8165), [check.ts:8186](../src/check.ts#L8186), [check.ts:8197](../src/check.ts#L8197) |
8057
+ | `WIND_BAND.pairs` | 'pair' | finding when !holdsAll; otherwise evidence | [p.a, p.b] | [check.ts:6305](../src/check.ts#L6305) |
8058
+ | `WIND_BAND.pairs[].steps` | 'pair' | finding when !s.holds; otherwise evidence | [p.a, p.b] | [check.ts:6316](../src/check.ts#L6316) |
8059
+ | `figure_openings.openings` | 'pair' | finding | [ps.under, ps.above] | [check.ts:5622](../src/check.ts#L5622) |
8060
+ | `loop_physics` | 'rig' | evidence | [] | [check.ts:7283](../src/check.ts#L7283) |
8061
+ | `requirements.lines.* (bone)` | 'rig' | finding when line.status === 'FAIL'; otherwise evidence | [] | [check.ts:7579](../src/check.ts#L7579) |
8062
+ | `requirements.lines.* (seam)` | 'pair' | finding when line.status === 'FAIL'; otherwise evidence | [r.part, r.neighbour] | [check.ts:7579](../src/check.ts#L7579) |
8063
+ | `requirements.lines.* (stretch)` | 'part' | finding when line.status === 'FAIL'; otherwise evidence | [r.slot] | [check.ts:7579](../src/check.ts#L7579) |
8064
+ | `seam_pairs` | pair[0] === SEAM_NO_ART ? 'rig' : pair[1] === SEAM_NO_ART ? 'part' : 'pair' | evidence | pair.filter(p => p !== SEAM_NO_ART) | [check.ts:2479](../src/check.ts#L2479) |
8065
+ | `seam_scope.changes` | 'rig' | evidence | [] | [check.ts:1958](../src/check.ts#L1958) |
8066
+ | `seam_scope.domain.states` | 'rig' | evidence | [] | [check.ts:2043](../src/check.ts#L2043) |
8067
+ | `seam_scope.pairs` | row.parts[0] === SEAM_NO_ART ? 'rig' : row.parts[1] === SEAM_NO_ART ? 'part' : 'pair' | evidence | row.parts.filter(p => p !== SEAM_NO_ART) | [check.ts:7193](../src/check.ts#L7193) |
8068
+ | `seam_scope.population.pairs` | 'pair' | evidence | row.parts | [check.ts:2414](../src/check.ts#L2414) |
8069
+ | `seam_scope.population.single_art` | 'part' | evidence | [row.part] | [check.ts:2415](../src/check.ts#L2415) |
8061
8070
  <!-- check-row-table:end -->
package/docs/STABILITY.md CHANGED
@@ -258,6 +258,18 @@ every number) are AUTHORING §3's tables, and the loader refuses any other by na
258
258
 
259
259
  ## Files this package writes
260
260
 
261
+ `assemble` and `build` declare `painting_in_rig` in parts.json as
262
+ `{ path: "painting_in_rig.png", sha256, resample: "lanczos3-rgb-opaque" }`.
263
+ The sibling PNG is the exact rig-resolution raster assemble used: source RGB
264
+ forced opaque before PIL-exact Lanczos3 resizing to `rig_size`. Package readers
265
+ verify its file hash, dimensions and opaque alpha. Legacy manifests may omit it.
266
+ Readers released through 2.17.0 refuse this new top-level key as
267
+ `PARTS_KEY_KNOWN`; use a reader that supports the declaration.
268
+ Adding the declaration makes earlier revision and depth receipts stale under
269
+ their existing whole-file parts.json identity contract; regenerate them.
270
+ Check's setup-painting comparison still flattens over its backdrop at source
271
+ resolution before resizing; it can differ for non-opaque paintings.
272
+
261
273
  | file | written by | what is stable |
262
274
  | --- | --- | --- |
263
275
  | `parts.json`, `parts/<name>.png` | `assemble`, `build` | one record per part: `from` (`<run>:<tag>` with a See-through v3 tag, `<run>:author:<label>` for a layer the author made — issue #256, read by no role rule — or `painting:<name>` for a patch), `cut_from` on a cut's piece only (the plan part it was cut from, issue #230), `limb` on a limb segment's part only (issue #349: `name`, `segment`, `of`, `bone`, and below a joint `joint`, `range` when the config segment declares one (issue #360), and `cap` — `at`, `width`, `radius`, `box`, `layer_px`, `image_px` with a cap image, `image_layer` after it when that image was a hidden-art layer — issue #359, `<run>:<layer>:hidden` — `missing_px`, `short_px` (`left`, `right`) after it only when `missing_px` is above 0 (issue #557, additive), `excluded_px` after them only on a subset set's limb part whose cap the set exclusion took a pixel of (issue #603, additive: each pixel taken out of the count it was in, so the cap's counts are the written PNG's), then `shape` and `upper_px` under the segment's `cap_shape` — `upper_px` without the shape only when the upper segment gave a pixel (issue #557, additive) — and after them `lower_px`, `lower_kept_px` and `lower_missing_px` under `cap_shape: "ball"` (issue #579, additive), and `edge`, `feather_radius` and `feathered_px` under its `edge`, and `cut_band`, `cut_offset`, `cut_at`, `cut_crossed`, `joint_crossed`, `band_px` and `stroke_luma_max` (when the band has a split) under its `cut_band`, issue #360), the box `x`, `y`, `w`, `h` (rig px), the pixel counts `src/parts.ts` documents (`opaque_px`, `visible_px`, `occluded_px`, `projected_core_px`, `source_px_taken`, `visible_not_projected_px`, `refused_drift_px`, `merged_px` — on a subset set's limb part counted after the set exclusion, issue #603 — `seam_override_px`, and `fringe_pushed_back` when not empty); per-part `provenance` (`unchanged_layer_px`, `hand_px`, `automatic_px`, `edits`, `automatic`, additive, issue #823); optional top-level `motion_seams`, `alternates` and `cut_ownership` (one row per cut, independent of RGBA equality, issue #823); `rig_size`, `scale_rig_per_source`, `ghost_px`, `recomposite`, and `scene` (`figure_alpha_above`, `figure_px`, `figure_mask`) under `config.scene` only, with the figure's mask `figure_rig.png` beside the recomposite (issue #242); `single_run_pad` (`file_size`, `side`, `left`, `top`) last, only for one run whose file is not the `seethrough.resolution` square (issue #366) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-parts",
3
- "version": "2.17.0",
3
+ "version": "2.19.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
@@ -138,6 +138,7 @@ import {
138
138
  resize,
139
139
  warpAffine,
140
140
  } from './raster/index.ts';
141
+ import { warpSupport } from './raster/warp.ts';
141
142
  import { pyRound } from './round.ts';
142
143
  import { ARM_MERGED_SPLIT_TAGS, AUTHOR_NO_ROLE, type LayerTagReading, readAuthorTag, readLayerTag } from './tags.ts';
143
144
 
@@ -3067,6 +3068,12 @@ export function pushBackFringe(
3067
3068
  * under a subset set's actual cover instead of recolouring it to the painting.
3068
3069
  * (`assemble_parts.py` `main`, "5. seam override".)
3069
3070
  */
3071
+ interface RegionSeamDecisions {
3072
+ record?: Map<string, Uint8Array>;
3073
+ baseline?: ReadonlyMap<string, Uint8Array>;
3074
+ support?: ReadonlyMap<string, Mask>;
3075
+ }
3076
+
3070
3077
  export function seamOverride(
3071
3078
  parts: PlacedPart[],
3072
3079
  srcr: Raster,
@@ -3075,6 +3082,7 @@ export function seamOverride(
3075
3082
  keep: ReadonlyArray<Mask | null> | null = null,
3076
3083
  turnMovingPair: ((a: string, b: string) => boolean) | null = null,
3077
3084
  written?: (part: number, rigPixel: number) => void,
3085
+ decisions?: RegionSeamDecisions,
3078
3086
  ): void {
3079
3087
  const { width: W } = srcr;
3080
3088
  const { top, cand } = seamCandidates(parts, srcr, rule, silhouette);
@@ -3084,6 +3092,9 @@ export function seamOverride(
3084
3092
  turnMovingPair === null
3085
3093
  ? []
3086
3094
  : parts.map((_, j) => j).filter((j) => j !== i && turnMovingPair(p.name, parts[j].record.name));
3095
+ const decided = decisions?.record === undefined ? undefined : new Uint8Array(srcr.width * srcr.height);
3096
+ if (decided !== undefined) decisions!.record!.set(p.name, decided);
3097
+ const baseline = decisions?.baseline?.get(p.name), support = decisions?.support?.get(p.from);
3087
3098
  let n = 0;
3088
3099
  for (let y = 0; y < p.h; y++) {
3089
3100
  for (let x = 0; x < p.w; x++) {
@@ -3091,8 +3102,8 @@ export function seamOverride(
3091
3102
  const ry = p.y + y;
3092
3103
  const d = ry * W + rx;
3093
3104
  const s = (y * p.w + x) * 4;
3094
- if (keep?.[i]?.data[d] === 1 || cand[d] === 0 || top[d] !== i || image.data[s + 3] < CORE_ALPHA) continue;
3095
- if (
3105
+ let admitted = !(keep?.[i]?.data[d] === 1 || cand[d] === 0 || top[d] !== i || image.data[s + 3] < CORE_ALPHA);
3106
+ if (admitted &&
3096
3107
  movingPeers.some((j) => {
3097
3108
  const pj = parts[j].record;
3098
3109
  const imgJ = parts[j].image.data;
@@ -3107,9 +3118,10 @@ export function seamOverride(
3107
3118
  }
3108
3119
  return false;
3109
3120
  })
3110
- ) {
3111
- continue;
3112
- }
3121
+ ) admitted = false;
3122
+ if (baseline !== undefined && support !== undefined && support.data[d] === 0) admitted = baseline[d] === 1;
3123
+ if (!admitted) continue;
3124
+ if (decided !== undefined) decided[d] = 1;
3113
3125
  const different = image.data[s] !== srcr.data[d * 4] || image.data[s + 1] !== srcr.data[d * 4 + 1] || image.data[s + 2] !== srcr.data[d * 4 + 2];
3114
3126
  image.data[s] = srcr.data[d * 4];
3115
3127
  image.data[s + 1] = srcr.data[d * 4 + 1];
@@ -4704,6 +4716,8 @@ export function softOcclusionLine(r: SoftOcclusionReading): string {
4704
4716
  }
4705
4717
 
4706
4718
  export interface AssembleResult {
4719
+ /** The already-resampled opaque painting used by this assembly. */
4720
+ paintingInRig: Raster;
4707
4721
  /** Report-only residual candidates, present after the visible edge pass. */
4708
4722
  edgeResiduals?: EdgeResidualReport;
4709
4723
  /** Report-only source re-take under actual soft front support (#825). */
@@ -4949,13 +4963,14 @@ export function retainRegionNeighbours(placed: PlacedPart[], before: readonly Pl
4949
4963
  export function assemble(input: AssembleInput): AssembleResult {
4950
4964
  if (input.regionTake === undefined) return assembleParts(input);
4951
4965
  const targets = regionTakeTargets(input.regionTake.targets, input.cuts, input.limbs);
4952
- const before = assembleParts({ ...input, full: input.regionTake.full, head: input.regionTake.head, regionTake: undefined }, targets);
4953
- return assembleParts(input, targets, before);
4966
+ const counterfactual = input.projectRule === 'core' ? { cleanup: new Map<string, RunLayer[]>(), seam: new Map<string, Uint8Array>() } : undefined;
4967
+ const before = assembleParts({ ...input, full: input.regionTake.full, head: input.regionTake.head, regionTake: undefined }, targets, null, counterfactual);
4968
+ return assembleParts(input, targets, before, counterfactual);
4954
4969
  }
4955
4970
 
4956
4971
  /** The counterfactual is internal and is never emitted. Empty taken targets
4957
4972
  * may be recovered by a take, so only that counterfactual permits them. */
4958
- function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, beforeTake: AssembleResult | null = null): AssembleResult {
4973
+ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, beforeTake: AssembleResult | null = null, counterfactual?: { cleanup: Map<string, RunLayer[]>; seam: Map<string, Uint8Array> }): AssembleResult {
4959
4974
  const emptyTargets = beforeTake === null ? targets : undefined;
4960
4975
  const { source, extend, patches, seamRule, projectRule } = input;
4961
4976
  const authoredDepths = input.depth === undefined ? new Map<string, AuthoredUnitDepth>() : authoredUnitDepths(input);
@@ -5058,6 +5073,23 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
5058
5073
  // A single run (issue #359) is read once: there is no head run to place, project or count ghosts for.
5059
5074
  for (const [run, set] of single ? ([['full', full]] as const) : ([['full', full], ['head', head]] as const)) {
5060
5075
  const layers = runLayers(set, input.resolution);
5076
+ if (beforeTake === null) counterfactual?.cleanup.set(run, layers);
5077
+ else if (counterfactual !== undefined) for (const layer of layers) {
5078
+ const sourceLayer = set.layers.find(q => q.name === layer.tag);
5079
+ const selection = sourceLayer?.regionSelection;
5080
+ const baseline = counterfactual.cleanup.get(run)?.find(q => q.tag === layer.tag);
5081
+ if (selection === undefined || baseline === undefined) continue;
5082
+ const raw = placeLayer(sourceLayer!, input.resolution);
5083
+ layer.opaqueRunPx = 0;
5084
+ layer.ghostPx = 0;
5085
+ const dx = single ? frame.fullPad : 0, dy = single ? frame.fullPadTop : 0;
5086
+ for (let y = 0; y < input.resolution; y++) for (let x = 0; x < input.resolution; x++) {
5087
+ const sx = x - dx, sy = y - dy, p = y * input.resolution + x;
5088
+ if (sx < 0 || sy < 0 || sx >= selection.width || sy >= selection.height || selection.data[sy * selection.width + sx] === 0) layer.canvas.data[p * 4 + 3] = baseline.canvas.data[p * 4 + 3];
5089
+ if (layer.canvas.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) layer.opaqueRunPx++;
5090
+ else if (raw.data[p * 4 + 3] > OPAQUE_ALPHA_ABOVE) layer.ghostPx++;
5091
+ }
5092
+ }
5061
5093
  if (run === 'full') fullTags.push(...layers.filter((l) => l.opaqueRunPx > 0).map((l) => l.tag));
5062
5094
  const rigLayers = layers.map((l) => layerToRig(l.canvas, frame, run));
5063
5095
  const rank = planRanks(layers.map((l) => l.tag), run, sourcePlan);
@@ -5961,7 +5993,13 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
5961
5993
  for (const p of placed) if (p.record.depth !== undefined && artFiles.has(p.record.depth.image)) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: p.record.depth.image, detail: 'collides with a part artwork filename; choose noncolliding part names before sheet emission' }]);
5962
5994
 
5963
5995
 
5964
- seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder, input.turnMovingPair ?? null, (i, p) => { writersInOrder[i][p] = AW.seamOverride; });
5996
+ const regionSupport = new Map<string, Mask>();
5997
+ if (beforeTake !== null && counterfactual !== undefined) for (const [run, set] of [['full', input.full], ['head', input.head]] as const) {
5998
+ if (single && run === 'head') continue;
5999
+ const map = runMap(frame, run), dx = single ? frame.fullPad : 0, dy = single ? frame.fullPadTop : 0;
6000
+ for (const layer of set.layers) if (layer.regionSelection !== undefined) regionSupport.set(`${run}:${layer.name}`, warpSupport(layer.regionSelection, { sx: map.sx, sy: map.sx, tx: map.tx + dx * map.sx, ty: map.ty + dy * map.sx }, W, H, map.k < 1 ? 'bilinear' : 'bicubic'));
6001
+ }
6002
+ seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder, input.turnMovingPair ?? null, (i, p) => { writersInOrder[i][p] = AW.seamOverride; }, counterfactual === undefined ? undefined : beforeTake === null ? { record: counterfactual.seam } : { baseline: counterfactual.seam, support: regionSupport });
5965
6003
  placed.forEach((p, i) => {
5966
6004
  p.record.provenance = pixelProvenance(p.image, p.record.x, p.record.y, W, writersInOrder[i], editNames, 0, valueBaselines.get(p.record.from) ?? null);
5967
6005
  const depth = authoredDepths.get(p.record.name);
@@ -6007,6 +6045,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
6007
6045
  return {
6008
6046
  ...(softOcclusion.length === 0 ? {} : { softOcclusion }),
6009
6047
  ...(!single ? { cropClipped: cropClippedLines(plan, extend, (run, tag) => rig.get(`${run}:${tag}`) ?? null, frame) } : {}),
6048
+ paintingInRig: srcr,
6010
6049
  parts: {
6011
6050
  rig_size: [W, H],
6012
6051
  scale_rig_per_source: frame.S,
@@ -33,6 +33,7 @@ import { readPng } from './raster/png.ts';
33
33
  export const BOUNDARY_COLOUR_LINE = 'BOUNDARY_COLOUR_STEP';
34
34
  export const BOUNDARY_COLOUR_CODE = 'CHECK_BOUNDARY_COLOUR_STEP';
35
35
  export const BOUNDARY_COLOUR_UNMEASURED_CODE = 'CHECK_BOUNDARY_COLOUR_UNMEASURED';
36
+ export const BOUNDARY_COLOUR_UNMEASURED_SUFFIX = "; the step against the rig's own pieces cannot be taken, and an untaken reading is never a pass — make the slot draw a parts.json piece, or drop boundary_colour from the requirements file and the bar reports SKIP";
36
37
  export const UNDECLARED_BOUNDARY_COLOUR_REASON = 'not measured, not a pass: no requirements file declares boundary_colour; declare {"boundary_colour": {"max_step_excess": <0-255>}} in the --requirements file (config.requirements under build) to hold every part boundary of the setup and every idle frame to the rig\'s own pieces';
37
38
 
38
39
  /** The one declaration: the largest step excess (0-255) the rig allows over its own pieces. No default exists. */
@@ -206,7 +207,7 @@ export function measureBoundaryColour(api: Api, input: BoundaryColourInput, decl
206
207
  readFrame(setup, 'setup', true);
207
208
  for (const frame of idle) readFrame(frame, `idle frame ${frame.index} (t ${+frame.time.toFixed(4)} s)`, false);
208
209
  const over = [...pairsWorst.entries()].sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)).map(([, v]) => v).filter((v) => v.excess > declared.max_step_excess);
209
- for (const u of unmeasured) problems.push({ code: BOUNDARY_COLOUR_UNMEASURED_CODE, object: `slot "${u.slot}" (${u.frame})`, detail: `${u.reason}; the step against the rig's own pieces cannot be taken, and an untaken reading is never a pass — make the slot draw a parts.json piece, or drop boundary_colour from the requirements file and the bar reports SKIP` });
210
+ for (const u of unmeasured) problems.push({ code: BOUNDARY_COLOUR_UNMEASURED_CODE, object: `slot "${u.slot}" (${u.frame})`, detail: `${u.reason}${BOUNDARY_COLOUR_UNMEASURED_SUFFIX}` });
210
211
  for (const o of over) problems.push({ code: BOUNDARY_COLOUR_CODE, object: `part pair "${o.parts[0]}|${o.parts[1]}"`, detail: `${o.frame}, stage pixel (${o.at[0]}, ${o.at[1]}): step excess ${o.excess} > declared max_step_excess ${declared.max_step_excess} (rendered step ${o.rendered_step}, the rig's own pieces ${o.reference_step}); a texture stretched into its padded UVs or a notch cut out of a piece shows here — fix the rig image or mesh of that pair (AUTHORING, failure map)` });
211
212
  return {
212
213
  status: over.length === 0 && unmeasured.length === 0 ? 'PASS' : 'FAIL',
package/src/build.ts CHANGED
@@ -102,7 +102,7 @@ import { CONTROL_SUFFIX, withAnimations } from './motion.ts';
102
102
  import type { PaletteError } from './palette.ts';
103
103
  import { type LayerSet, readLayers } from './layers.ts';
104
104
  import { placeBoneEntriesForSkeleton, poseBoneEntriesForDrawn, REGISTER_OFFSET_BAR, REGISTER_SCALE_BAR, registeredWithinBar, registerSkeleton, SKELETON_LIMB_BONES, skeletonDrawnLength, skeletonLimbJoints } from './limbs.ts';
105
- import { type AlternatePartsRecord, FRONT_SUFFIX, type PartRecord, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
105
+ import { type AlternatePartsRecord, PAINTING_IN_RIG_FILE, FRONT_SUFFIX, type PartRecord, readParts, type RecompositeRecord, type SingleRunPad, tagOf, writeParts } from './parts.ts';
106
106
  import { encodePngBytes, readPng, writePng } from './raster/png.ts';
107
107
  import type { Raster } from './raster/types.ts';
108
108
  import { type Mask, newMask } from './raster/types.ts';
@@ -818,6 +818,10 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
818
818
  mkdirSync(dirname(outs.partsJson), { recursive: true });
819
819
  mkdirSync(dirname(outs.recomposite), { recursive: true });
820
820
  mkdirSync(dirname(outs.errorMap), { recursive: true });
821
+ const paintingBytes = encodePngBytes(result.paintingInRig);
822
+ result.parts.painting_in_rig = { path: PAINTING_IN_RIG_FILE,
823
+ sha256: createHash('sha256').update(paintingBytes).digest('hex'), resample: 'lanczos3-rgb-opaque' };
824
+ writeFileSync(join(dirname(outs.partsJson), PAINTING_IN_RIG_FILE), paintingBytes);
821
825
  writeParts(outs.partsJson, result.parts);
822
826
  const residualPath = join(dirname(outs.partsJson), EDGE_RESIDUAL_FILE);
823
827
  if (result.edgeResiduals === undefined) rmSync(residualPath, { force: true });
@@ -2428,7 +2432,7 @@ export interface BuildRunners {
2428
2432
  }
2429
2433
 
2430
2434
  /** Every path `build` writes under `--out`, relative — and so every path it clears first. */
2431
- export const BUILD_OWNS: readonly string[] = ['parts', 'parts.json', 'recomposite_rig.png', ERROR_MAP_FILE, 'rig', 'check', 'idle.gif', 'idle.png', 'idle-indexed.png'];
2435
+ export const BUILD_OWNS: readonly string[] = ['parts', 'parts.json', PAINTING_IN_RIG_FILE, 'recomposite_rig.png', ERROR_MAP_FILE, 'rig', 'check', 'idle.gif', 'idle.png', 'idle-indexed.png'];
2432
2436
 
2433
2437
  export type BuildStage = 'assemble' | 'rig' | 'check' | 'loop' | 'artifact';
2434
2438
 
package/src/check.ts CHANGED
@@ -7,7 +7,7 @@ import { SETUP_PAINTING_LINE, UNDECLARED_SETUP_PAINTING_REASON, setupPaintingBou
7
7
  import { readMaterialSources } from './cutmaterialio.ts';
8
8
  import { CUT_MATERIAL_LINE, checkJointMaterial, type MaterialLine } from './cutmaterial.ts';
9
9
  import { ART_JOINT_LINE, artJointLine, type ArtJointLine } from './artjoints.ts';
10
- import { BOUNDARY_COLOUR_LINE, BOUNDARY_COLOUR_UNMEASURED_CODE, measureBoundaryColour, type BoundaryColourMeasured } from './boundarycolour.ts';
10
+ import { BOUNDARY_COLOUR_LINE, BOUNDARY_COLOUR_UNMEASURED_CODE, BOUNDARY_COLOUR_UNMEASURED_SUFFIX, measureBoundaryColour, type BoundaryColourMeasured } from './boundarycolour.ts';
11
11
  import { baseAnchorMoves, type AnchorRegion } from './baseanchor.ts';
12
12
  /**
13
13
  * The check stage: build a rig through rig-c, gate it under both
@@ -1858,6 +1858,43 @@ export function seamDrawingSignature(input: {
1858
1858
  return JSON.stringify(seamSourceValue({ slot: input.slot, attachment: input.attachment, source, image: input.image, vertices: input.vertices, color: input.color }));
1859
1859
  }
1860
1860
 
1861
+ /** File-only rig-image padding checks after the parts loader has validated each PNG against its record. */
1862
+ export function boundaryColourSizeProblems(inp: CheckInputs): Problem[] {
1863
+ if (inp.parts === null) return [];
1864
+ const records = new Set(inp.parts.parts.map(p => p.name));
1865
+ const imagesDir = typeof inp.rig.images === 'string' ? resolve(inp.rigDir, inp.rig.images) : join(inp.rigDir, 'images');
1866
+ const problems: Problem[] = [];
1867
+ const seen = new Set<string>();
1868
+ const skins = isRecord(inp.rig.skins) ? inp.rig.skins : null;
1869
+ const skin = skins !== null && isRecord(skins.default) ? skins.default : null;
1870
+ if (skin === null) return problems;
1871
+ for (const [slot, drawings] of Object.entries(skin)) {
1872
+ if (!isRecord(drawings)) continue;
1873
+ for (const source of Object.values(drawings)) {
1874
+ if (!seamImageSource(source) || seen.has(source.image)) continue;
1875
+ const image = source.image;
1876
+ seen.add(image);
1877
+ const name = image.replace(/\.png$/, '');
1878
+ const partPng = join(inp.partsDir, `${name}.png`), rigPng = join(imagesDir, image);
1879
+ if (!records.has(name) || !existsSync(partPng) || !existsSync(rigPng)) continue;
1880
+ let src: Raster, rigImg: Raster;
1881
+ try { src = readPng(partPng); rigImg = readPng(rigPng); }
1882
+ catch { continue; }
1883
+ const dx = rigImg.width - src.width, dy = rigImg.height - src.height;
1884
+ const reason = dx !== dy || dx < 0 || dx % 2 !== 0
1885
+ ? `the rig image "${image}" is ${rigImg.width}x${rigImg.height}, not parts/${name}.png's ${src.width}x${src.height} with one even pad on every side`
1886
+ : null;
1887
+ if (reason !== null) problems.push({ code: BOUNDARY_COLOUR_UNMEASURED_CODE, object: `slot "${slot}" (image "${image}")`, detail: `${reason}${BOUNDARY_COLOUR_UNMEASURED_SUFFIX}` });
1888
+ }
1889
+ }
1890
+ return problems;
1891
+ }
1892
+
1893
+ /** The image mapping supported by seam and boundary-colour source readers. */
1894
+ function seamImageSource(source: unknown): source is Record<string, unknown> & { image: string } {
1895
+ return isRecord(source) && ['region', 'mesh'].includes(typeof source.type === 'string' ? source.type : 'region') && typeof source.image === 'string' && source.image.length > 0 && source.sequence === undefined;
1896
+ }
1897
+
1861
1898
  /** Resolve only the actually selected default-skin identity, not a filename suffix. */
1862
1899
  export function seamSourceAttachment(rig: Record<string, unknown>, slot: string, attachment: string): Record<string, unknown> {
1863
1900
  const skins = isRecord(rig.skins) ? rig.skins : null;
@@ -1867,7 +1904,7 @@ export function seamSourceAttachment(rig: Record<string, unknown>, slot: string,
1867
1904
  const matches = Object.entries(drawings).filter(([key, value]) => isRecord(value) && (typeof value.name === 'string' ? value.name : key) === attachment);
1868
1905
  if (matches.length !== 1) throw new SeamSupportError({ code: matches.length === 0 ? 'SOURCE_ATTACHMENT_MISSING' : 'SOURCE_ATTACHMENT_AMBIGUOUS', slot, attachment });
1869
1906
  const source = matches[0][1];
1870
- if (!isRecord(source) || !['region', 'mesh'].includes(typeof source.type === 'string' ? source.type : 'region') || typeof source.image !== 'string' || source.image.length === 0 || source.sequence !== undefined) {
1907
+ if (!seamImageSource(source)) {
1871
1908
  throw new SeamSupportError({ code: 'SOURCE_MAPPING_UNSUPPORTED', slot, attachment, feature: 'sequence-or-non-image-attachment' });
1872
1909
  }
1873
1910
  return source;
@@ -6459,6 +6496,9 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
6459
6496
  ...(ready.parts === null ? [{ code: BOUNDARY_COLOUR_UNMEASURED_CODE, object: 'requirements.boundary_colour', detail: `requires parts.json and its parts/ PNGs, the rig's own pieces the step is measured against: ${ready.noParts ?? 'none was read'}; an untaken reading is never a pass` }] : []),
6460
6497
  ...(ready.idleDuration === null ? [{ code: BOUNDARY_COLOUR_UNMEASURED_CODE, object: 'requirements.boundary_colour', detail: `requires an idle animation, whose every frame is measured: ${ready.noIdle ?? 'none was read'}; an untaken reading is never a pass` }] : []),
6461
6498
  ]));
6499
+ if (file.boundary_colour !== undefined && ready.parts !== null && ready.idleDuration !== null) {
6500
+ take(() => refuseIfAny(boundaryColourSizeProblems(ready)));
6501
+ }
6462
6502
  take(() => refuseIfAny(exceptionProblems(file, ready.parts, ready.noParts)));
6463
6503
  // A seam's pairs are read off parts.json's art (issue #111); both resolvers' problems are named in one refusal.
6464
6504
  if (file.requirements.some((r) => r.kind === 'seam')) {
package/src/config.ts CHANGED
@@ -2510,11 +2510,19 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
2510
2510
  const p = `${at}[${i}]`;
2511
2511
  const region = isPlainObject(v) && ('part' in v || 'seed' in v);
2512
2512
  const o = region
2513
- ? c.object(p, v, ['run', 'run_dir', 'st_input', 'part', 'seed'], ['reference'])
2513
+ ? c.object(p, v, ['run', 'run_dir', 'st_input', 'part', 'seed'], ['reference', 'crop'])
2514
2514
  : c.object(p, v, ['run', 'run_dir', 'st_input', 'tags'], ['crop']);
2515
2515
  if (o === null) return;
2516
2516
  if (o.run !== 'full' && o.run !== 'head') c.fail('CONFIG_FIELD_TYPE', p + '.run', '"full" or "head" is required');
2517
2517
  for (const k of ['run_dir', 'st_input']) c.string(`${p}.${k}`, o[k]);
2518
+ if ('crop' in o) {
2519
+ const crop = c.object(`${p}.crop`, o.crop, ['box', 'resample'], []);
2520
+ if (crop !== null) {
2521
+ const box = crop.box;
2522
+ 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');
2523
+ if (crop.resample !== 'bilinear') c.fail('CONFIG_FIELD_TYPE', `${p}.crop.resample`, '"bilinear" is required explicitly');
2524
+ }
2525
+ }
2518
2526
  if (region) {
2519
2527
  if (o.reference !== undefined) {
2520
2528
  const r = c.object(`${p}.reference`, o.reference, ['sha256'], ['source', 'painting']);
@@ -2536,14 +2544,6 @@ function checkTakeLayers(c: Check, value: Json, plan: string[] | null = null): v
2536
2544
  }
2537
2545
  return;
2538
2546
  }
2539
- if ('crop' in o) {
2540
- const crop = c.object(`${p}.crop`, o.crop, ['box', 'resample'], []);
2541
- if (crop !== null) {
2542
- const box = crop.box;
2543
- 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');
2544
- if (crop.resample !== 'bilinear') c.fail('CONFIG_FIELD_TYPE', `${p}.crop.resample`, '"bilinear" is required explicitly');
2545
- }
2546
- }
2547
2547
  if (!c.array(p + '.tags', o.tags, true)) return;
2548
2548
  (o.tags as Json[]).forEach((tag, j) => {
2549
2549
  const reading = typeof tag === 'string' ? readLayerTag(tag) : null;
package/src/layers.ts CHANGED
@@ -38,7 +38,7 @@ import { basename, dirname, join } from 'node:path';
38
38
  import { initializeCanvas, type Layer as PsdLayer, readPsd, writePsd } from 'ag-psd';
39
39
  import { type Problem, refuseIfAny } from './errors.ts';
40
40
  import { decodePngBytes, encodePngBytes } from './raster/png.ts';
41
- import type { Raster } from './raster/types.ts';
41
+ import type { Mask, Raster } from './raster/types.ts';
42
42
  import { BODY_TAGS, HEAD_TAGS, HIDDEN_NAME_RULE, type LayerTagReading, layerTagRequirement, readHiddenTag, readLayerTag, SPLIT_TAGS } from './tags.ts';
43
43
 
44
44
  /** Alpha strictly above this counts as painted. The reference uses the same cut for its ghost clean-up and its sheets. */
@@ -54,6 +54,8 @@ export const CORE_ALPHA = 250;
54
54
  export const NEAR_WHITE_MIN = 235;
55
55
 
56
56
  export interface Layer {
57
+ /** Exact seeded component in the original run canvas; internal, never serialized. */
58
+ regionSelection?: Mask;
57
59
  /** Verified donor identities retained through generated splits. */
58
60
  takenLayers?: TakenLayerSource[];
59
61
  /** As the input names it: a v3 tag, possibly with a `-r`/`-l` side, or an author-made layer's `author:<label>`. */
package/src/parts.ts CHANGED
@@ -91,6 +91,9 @@ import { partDepthProblems, type PartDepthReference } from './depthsheets.ts';
91
91
  */
92
92
  import { motionSeamProblems, type MotionSeamDeclaration } from './motionseams.ts';
93
93
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
94
+ import { createHash } from 'node:crypto';
95
+ import { dirname, join } from 'node:path';
96
+ import { decodePngBytes } from './raster/png.ts';
94
97
  import { type Problem, refuseIfAny } from './errors.ts';
95
98
  import { KEYPOINT_NAMES, type PosePoints } from './skeleton.ts';
96
99
  import { readLayerTag } from './tags.ts';
@@ -366,7 +369,16 @@ export interface AlternatePartsRecord {
366
369
  registration?: { offset: [number, number]; scale: number };
367
370
  }
368
371
 
372
+ export const PAINTING_IN_RIG_FILE = 'painting_in_rig.png';
373
+ export interface PaintingInRig {
374
+ path: typeof PAINTING_IN_RIG_FILE;
375
+ sha256: string;
376
+ resample: 'lanczos3-rgb-opaque';
377
+ }
378
+
369
379
  export interface PartsFile {
380
+ /** Optional on legacy packages; binds the opaque RGB raster assemble actually read. */
381
+ painting_in_rig?: PaintingInRig;
370
382
  /** Structural moves, independent of per-pixel value equality. */
371
383
  cut_ownership?: CutOwnership[];
372
384
  rig_size: [number, number];
@@ -417,8 +429,8 @@ export interface SceneRecord {
417
429
  figure_mask: string;
418
430
  }
419
431
 
420
- const TOP_KEYS = ['rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
421
- const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
432
+ const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
433
+ const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
422
434
  export const SINGLE_RUN_PAD_KEYS = ['file_size', 'side', 'left', 'top'] as const;
423
435
  export const SCENE_KEYS = ['figure_alpha_above', 'figure_px', 'figure_mask'] as const;
424
436
  export const RECOMPOSITE_KEYS = ['mean_abs', 'within_limit', 'within_share', 'error_limit', 'error_px', 'covered_alpha', 'uncovered_error_px', 'hole_count', 'holes_listed', 'holes'] as const;
@@ -541,6 +553,9 @@ export function serializeParts(file: PartsFile): string {
541
553
  const ordered = {
542
554
  rig_size: file.rig_size,
543
555
  scale_rig_per_source: file.scale_rig_per_source,
556
+ ...(file.painting_in_rig === undefined ? {} : { painting_in_rig: {
557
+ path: file.painting_in_rig.path, sha256: file.painting_in_rig.sha256, resample: file.painting_in_rig.resample,
558
+ } }),
544
559
  parts: serializePartList(file.parts),
545
560
  ...(file.cut_ownership === undefined ? {} : { cut_ownership: orderedOwnership(file.cut_ownership) }),
546
561
  ...(file.motion_seams === undefined ? {} : { motion_seams: file.motion_seams.map(({ part, neighbour }) => ({ part, neighbour })) }),
@@ -593,7 +608,29 @@ export function readParts(path: string): PartsFile {
593
608
  } catch (err) {
594
609
  refuseIfAny([{ code: 'PARTS_IS_JSON', object: path, detail: `does not parse as JSON: ${(err as Error).message}` }]);
595
610
  }
596
- return checkParts(raw, path);
611
+ const file = checkParts(raw, path);
612
+ const declared = file.painting_in_rig;
613
+ if (declared !== undefined) {
614
+ const imagePath = join(dirname(path), declared.path);
615
+ const problems: Problem[] = [];
616
+ const fail = (code: string, detail: string): void => { problems.push({ code, object: imagePath, detail }); };
617
+ let bytes: Uint8Array | undefined;
618
+ try { bytes = new Uint8Array(readFileSync(imagePath)); }
619
+ catch { fail('PARTS_PAINTING_PRESENT', 'declared painting_in_rig file is not readable; re-run assemble'); }
620
+ if (bytes !== undefined) {
621
+ const actual = createHash('sha256').update(bytes).digest('hex');
622
+ if (actual !== declared.sha256) fail('PARTS_PAINTING_SHA256', `sha256 is ${actual}; declared ${declared.sha256} is required`);
623
+ let image;
624
+ try { image = decodePngBytes(bytes, imagePath); }
625
+ catch { fail('PARTS_PAINTING_PNG', 'declared painting_in_rig file is not a decodable PNG'); }
626
+ if (image !== undefined) {
627
+ if (image.width !== file.rig_size[0] || image.height !== file.rig_size[1]) fail('PARTS_PAINTING_SIZE', `is ${image.width}x${image.height}; rig_size ${file.rig_size.join('x')} is required`);
628
+ if (image.data.some((value, index) => index % 4 === 3 && value !== 255)) fail('PARTS_PAINTING_OPAQUE', 'has alpha below 255; lanczos3-rgb-opaque requires alpha 255 everywhere');
629
+ }
630
+ }
631
+ refuseIfAny(problems);
632
+ }
633
+ return file;
597
634
  }
598
635
 
599
636
  /** Additive ownership census; not another term in the value partition. */
@@ -656,6 +693,17 @@ function checkParts(raw: unknown, path: string): PartsFile {
656
693
  const o = raw as Record<string, unknown>;
657
694
  for (const k of Object.keys(o)) if (!(TOP_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${path} key "${k}"`, `is not a parts.json field; known: ${TOP_KEYS.join(', ')}`);
658
695
  for (const k of REQUIRED_TOP_KEYS) if (!(k in o)) fail('PARTS_FIELD_PRESENT', `${path} field "${k}"`, 'is absent and required');
696
+ if ('painting_in_rig' in o) {
697
+ const p = o.painting_in_rig;
698
+ if (typeof p !== 'object' || p === null || Array.isArray(p) ||
699
+ Object.keys(p).sort().join(',') !== 'path,resample,sha256' ||
700
+ (p as Record<string, unknown>).path !== PAINTING_IN_RIG_FILE ||
701
+ (p as Record<string, unknown>).resample !== 'lanczos3-rgb-opaque' ||
702
+ typeof (p as Record<string, unknown>).sha256 !== 'string' ||
703
+ !/^[a-f0-9]{64}$/.test((p as Record<string, unknown>).sha256 as string)) {
704
+ fail('PARTS_FIELD_TYPE', `${path} field "painting_in_rig"`, 'requires exactly path "painting_in_rig.png", lowercase 64-hex sha256 and resample "lanczos3-rgb-opaque"');
705
+ }
706
+ }
659
707
  const size = o.rig_size;
660
708
  const sizeOk = Array.isArray(size) && size.length === 2 && size.every((n) => Number.isInteger(n) && (n as number) > 0);
661
709
  if ('rig_size' in o && !sizeOk) fail('PARTS_FIELD_TYPE', `${path} field "rig_size"`, `is ${show(size)}; [width, height] in positive integers is required`);
@@ -1,4 +1,4 @@
1
- import { type FloatImage, newFloatImage, RasterError } from './types.ts';
1
+ import { type FloatImage, type Mask, newMask, newFloatImage, RasterError } from './types.ts';
2
2
 
3
3
  /** A forward map `dst = scale * src + translate`, per axis — the only affine the pipeline uses. */
4
4
  export interface ScaleTranslate {
@@ -119,3 +119,21 @@ export function warpAffine(src: FloatImage, map: ScaleTranslate, width: number,
119
119
  }
120
120
  return out;
121
121
  }
122
+
123
+ /** Exact nonzero quantized tap support, without cancellation between taps. */
124
+ export function warpSupport(src: Mask, map: ScaleTranslate, width: number, height: number, filter: WarpFilter): Mask {
125
+ const xs = positions(width, map.sx, map.tx, 'x'), ys = positions(height, map.sy, map.ty, 'y');
126
+ const out = newMask(width, height);
127
+ for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
128
+ const [ix, fx] = xs[x], [iy, fy] = ys[y];
129
+ const firstX = fx !== 0 && filter === 'bicubic' ? -1 : 0;
130
+ const firstY = fy !== 0 && filter === 'bicubic' ? -1 : 0;
131
+ const lastX = fx !== 0 ? filter === 'bicubic' ? 2 : 1 : 0;
132
+ const lastY = fy !== 0 ? filter === 'bicubic' ? 2 : 1 : 0;
133
+ for (let dy = firstY; dy <= lastY; dy++) for (let dx = firstX; dx <= lastX; dx++) {
134
+ const sx = ix + dx, sy = iy + dy;
135
+ if (sx >= 0 && sy >= 0 && sx < src.width && sy < src.height && src.data[sy * src.width + sx] === 1) out.data[y * width + x] = 1;
136
+ }
137
+ }
138
+ return out;
139
+ }
package/src/scene.ts CHANGED
@@ -99,6 +99,7 @@ import { ACCEPTABLE_BARS, barsNotMet, type CheckReport, DEFAULT_PACK_SHAPE, DEFA
99
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 { readParts } from './parts.ts';
102
103
  import { missingReceipts, readEditorReceipts, type EditorReceipts } from './editreceipt.ts';
103
104
  import type { MotionSpec } from './motion.ts';
104
105
  import { readPng } from './raster/png.ts';
@@ -473,6 +474,15 @@ export function readCharacterBuild(c: SceneCharacter, problems: Problem[], accep
473
474
  }
474
475
  }
475
476
  const parts = readJson(join(dir, 'parts.json'), "assemble's parts.json, which holds the rig_scale and the art's place", problems);
477
+ // Legacy scene records keep their existing checks; a declared package raster
478
+ // goes through the same file binding reader as rig, check, sheet and propose.
479
+ if (isRecord(parts) && 'painting_in_rig' in parts) {
480
+ try { readParts(join(dir, 'parts.json')); }
481
+ catch (err) {
482
+ if (!(err instanceof PartsError)) throw err;
483
+ problems.push(...err.problems);
484
+ }
485
+ }
476
486
  const rigRaw = readJson(join(dir, 'rig', 'rig.json'), "the rig stage's rig.json", problems);
477
487
  const motionRaw = readJson(join(dir, 'rig', 'motion.json'), "the rig stage's motion.json", problems);
478
488
  const unknown = (where: string, obj: unknown, keys: readonly string[]): void => {
package/src/takelayers.ts CHANGED
@@ -59,7 +59,7 @@ function rgbaHash(image: Raster): string {
59
59
  return createHash('sha256').update(image.data).digest('hex');
60
60
  }
61
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 } {
62
+ export function cropGeometry(d: Pick<TakeLayers, 'run' | 'crop'>, painting: Raster, target: Raster, donor: LayerSet, set: LayerSet, inputs: ReturnType<typeof makeInputs>, at: string): { expected: Raster; map: ScaleTranslate; exact: boolean } {
63
63
  const declaration = d.crop!;
64
64
  const [x0, y0, x1, y1] = declaration.box;
65
65
  if (declaration.resample !== 'bilinear' || !declaration.box.every(Number.isSafeInteger) || x0 < 0 || y0 < 0 || x1 <= x0 || y1 <= y0 || x1 > painting.width || y1 > painting.height) {
@@ -84,7 +84,7 @@ function cropGeometry(d: TakeLayers, painting: Raster, target: Raster, donor: La
84
84
  }
85
85
 
86
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 } {
87
+ export function transportLayer(layer: Layer, donor: LayerSet, set: LayerSet, image: Raster, d: Pick<TakeLayers, 'crop'>, map: ScaleTranslate, exact: boolean, at: string): { layer: Layer; transport: TakenLayerTransport } {
88
88
  const canvas = newRaster(donor.canvas.w, donor.canvas.h);
89
89
  for (let y = 0; y < layer.pixels.height; y++) {
90
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);
package/src/takeregion.ts CHANGED
@@ -10,13 +10,15 @@ import { readPng } from './raster/png.ts';
10
10
  import { resize } from './raster/resize.ts';
11
11
  import { newMask, newRaster, type Raster } from './raster/types.ts';
12
12
  import type { SetupPainting } from './setuppainting.ts';
13
- import type { TakeLayers } from './takelayers.ts';
13
+ import { cropGeometry, transportLayer, type TakeLayers } from './takelayers.ts';
14
14
 
15
15
  export interface TakeRegion {
16
16
  run: Run;
17
17
  run_dir: string;
18
18
  st_input: string;
19
19
  part: string;
20
+ /** Same painting-space crop and transport as a whole-layer take. */
21
+ crop?: TakeLayers['crop'];
20
22
  /** One integer pixel on the target run canvas, x right and y down. */
21
23
  seed: [number, number];
22
24
  /** PNG bytes, explicitly bound to the stage source or a separate painting. */
@@ -93,10 +95,11 @@ export function deriveTakenRegion(base: Layer, donor: Layer, painting: Raster, s
93
95
  const from = offsetAt(donor, x, y)!;
94
96
  pixels.data.set(donor.pixels.data.subarray(from, from + 4), ((y - top) * pixels.width + x - left) * 4);
95
97
  }
98
+ for (let p = 0; p < qualifying.data.length; p++) qualifying.data[p] = components.labels[p] === label ? 1 : 0;
96
99
  let opaquePx = 0;
97
100
  for (let i = 3; i < pixels.data.length; i += 4) if (pixels.data[i] > OPAQUE_ALPHA_ABOVE) opaquePx++;
98
101
  return {
99
- layer: { ...base, pixels, left, top, right, bottom, opaquePx },
102
+ layer: { ...base, pixels, left, top, right, bottom, opaquePx, regionSelection: qualifying },
100
103
  reading: { pixels: stats.area, box: [stats.left, stats.top, stats.width, stats.height], painting_match_share: 1, rgb_tolerance: tolerance },
101
104
  };
102
105
  }
@@ -152,9 +155,14 @@ export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleCon
152
155
  let supplied: Raster;
153
156
  try { supplied = readPng(resolve(dirname(resolve(configPath)), declaration.st_input)); }
154
157
  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`); }
155
- if ((declaration.run === 'head' && runs.single) || target === null || donor.canvas.w !== set.canvas.w || donor.canvas.h !== set.canvas.h || supplied.width !== target.width || supplied.height !== target.height || supplied.data.some((byte, i) => byte !== target.data[i])) {
158
+ if (declaration.crop === undefined && ((declaration.run === 'head' && runs.single) || target === null || donor.canvas.w !== set.canvas.w || donor.canvas.h !== set.canvas.h || supplied.width !== target.width || supplied.height !== target.height || supplied.data.some((byte, i) => byte !== target.data[i]))) {
156
159
  return refuse('ASSEMBLE_REGION_TAKE_GEOMETRY', at, `donor canvas ${donor.canvas.w}x${donor.canvas.h}, target canvas ${set.canvas.w}x${set.canvas.h}, donor input ${supplied.width}x${supplied.height}; equal canvases and exact target input RGBA are required to establish one crop; cropped donors await #973`);
157
160
  }
161
+ if (target === null || (declaration.run === 'head' && runs.single)) return refuse('ASSEMBLE_REGION_TAKE_GEOMETRY', at, 'a target run input is required for a declared crop');
162
+ const geometry = declaration.crop === undefined ? undefined : cropGeometry(declaration, painting, target, donor, set, inputs, at);
163
+ if (geometry !== undefined && (supplied.width !== geometry.expected.width || supplied.height !== geometry.expected.height || supplied.data.some((byte, i) => byte !== geometry.expected.data[i]))) {
164
+ return refuse('ASSEMBLE_REGION_TAKE_GEOMETRY', at, `donor input ${supplied.width}x${supplied.height}; exact declared square-padded crop RGBA ${geometry.expected.width}x${geometry.expected.height} is required`);
165
+ }
158
166
  const base = lists[declaration.run].find(layer => layer.name === plan[2]);
159
167
  const material = donor.layers.find(layer => layer.name === plan[2]);
160
168
  if (base === undefined || material === undefined) return refuse('ASSEMBLE_REGION_TAKE_PART', at, `tag "${plan[2]}" is absent from ${base === undefined ? 'the base' : 'the donor'} run; both must hold the plan part's tag`);
@@ -164,7 +172,8 @@ export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleCon
164
172
  const colourInputs = reference === undefined ? inputs : makeInputs(referencePainting, cfg, 'region take reference');
165
173
  const colourTarget = declaration.run === 'head' ? colourInputs.head! : target === painting ? referencePainting : colourInputs.full;
166
174
  const source = resize(colourTarget, set.canvas.w, set.canvas.h, 'lanczos3');
167
- const derived = deriveTakenRegion(base, material, source, declaration.seed, tolerance, at);
175
+ const transported = geometry === undefined ? material : transportLayer(material, donor, set, supplied, declaration, geometry.map, geometry.exact, at).layer;
176
+ const derived = deriveTakenRegion(base, transported, source, declaration.seed, tolerance, at);
168
177
  lists[declaration.run] = lists[declaration.run].map(layer => layer === base ? derived.layer : layer);
169
178
  const reading: RegionReading = { part: declaration.part, run: declaration.run, run_dir: declaration.run_dir, ...derived.reading };
170
179
  const pad = target === painting ? [0, 0] : declaration.run === 'head' ? inputs.headBox! : [-inputs.padLeft, -inputs.padTop];