spine-parts 2.18.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 +15 -6
- package/docs/STABILITY.md +12 -0
- package/package.json +1 -1
- package/src/assemble.ts +48 -9
- package/src/build.ts +6 -2
- package/src/config.ts +9 -9
- package/src/layers.ts +3 -1
- package/src/parts.ts +51 -3
- package/src/raster/warp.ts +19 -1
- package/src/scene.ts +10 -0
- package/src/takelayers.ts +2 -2
- package/src/takeregion.ts +13 -4
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
|
|
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
|
-
|
|
858
|
-
must match the entire target input in RGBA and dimensions
|
|
859
|
-
|
|
860
|
-
|
|
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
|
|
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
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
4953
|
-
|
|
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
|
-
|
|
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,
|
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/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
|
-
|
|
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`);
|
package/src/raster/warp.ts
CHANGED
|
@@ -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
|
|
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
|
|
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];
|