@rig-c/parts 2.33.0 → 2.35.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/cli.ts +23 -10
- package/docs/AUTHORING.md +79 -5
- package/docs/STABILITY.md +6 -5
- package/package.json +1 -1
- package/src/assemble.ts +369 -38
- package/src/build.ts +162 -11
- package/src/config.ts +106 -27
- package/src/editreceipt.ts +3 -3
- package/src/occluders.ts +92 -1
- package/src/occluderstage.ts +19 -8
- package/src/paintingowner.ts +7 -4
- package/src/parts.ts +76 -14
- package/src/partsource.ts +2 -0
- package/src/provenance.ts +10 -0
- package/src/remesh.ts +10 -5
- package/src/retune.ts +4 -4
- package/src/takelayers.ts +114 -7
- package/src/takeregion.ts +16 -3
- package/src/takesource.ts +20 -1
package/src/occluderstage.ts
CHANGED
|
@@ -50,15 +50,15 @@ export interface OccluderPlateBindInput {
|
|
|
50
50
|
fullPath: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
export interface OccluderInput {
|
|
54
|
+
declaration: OccluderDeclaration;
|
|
55
|
+
image: Raster;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function readOccluderInputs(occluders: readonly OccluderDeclaration[], configPath: string, source: Raster): OccluderInput[] {
|
|
59
|
+
return occluders.map((d, i) => {
|
|
60
60
|
const at = `config.assemble.occluders[${i}]`;
|
|
61
|
-
const path = resolve(dirname(resolve(
|
|
61
|
+
const path = resolve(dirname(resolve(configPath)), d.image);
|
|
62
62
|
const bytes = new Uint8Array(readFileSync(path));
|
|
63
63
|
const found = createHash('sha256').update(bytes).digest('hex');
|
|
64
64
|
if (found !== d.sha256) refuse('CONFIG_OCCLUDER_SHA256', `${at}.sha256`, `is ${d.sha256}; ${d.image} has sha256 ${found} — declare the bytes the occluder image holds`);
|
|
@@ -66,6 +66,17 @@ export function occluderStageWarnings(input: OccluderStageInput): string[] {
|
|
|
66
66
|
if (image.width !== source.width || image.height !== source.height) {
|
|
67
67
|
refuse('ASSEMBLE_OCCLUDER_GRID', `${at}.image`, `is ${image.width}x${image.height}; the painting's ${source.width}x${source.height} is required — the occluder is read on the painting's grid and never fitted`);
|
|
68
68
|
}
|
|
69
|
+
return { declaration: d, image };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function occluderStageWarnings(input: OccluderStageInput): string[] {
|
|
74
|
+
const { source, runs } = input;
|
|
75
|
+
const frame = checkGeometry({ sourceW: source.width, sourceH: source.height, resolution: input.resolution, headBox: input.headBox, rigScale: input.rigScale, ...(runs.single ? { single: true } : {}) }, { full: runs.full, head: runs.head });
|
|
76
|
+
const full = runs.single ? padSingleRun(runs.full, frame, input.resolution) : runs.full;
|
|
77
|
+
const painting = sourceInRig(source, frame.W, frame.H);
|
|
78
|
+
const lines: string[] = [];
|
|
79
|
+
readOccluderInputs(input.occluders, input.configPath, source).forEach(({ declaration: d, image }, i) => {
|
|
69
80
|
// A rig pixel reads the occluder at the source pixel its centre falls in.
|
|
70
81
|
const sx = (x: number): number => Math.min(source.width - 1, Math.floor((x + 0.5) * source.width / frame.W));
|
|
71
82
|
const sy = (y: number): number => Math.min(source.height - 1, Math.floor((y + 0.5) * source.height / frame.H));
|
package/src/paintingowner.ts
CHANGED
|
@@ -15,11 +15,14 @@ export interface PaintingReceivers extends PaintingOwner {
|
|
|
15
15
|
faults: Array<{ receiver: string; reason: string }>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/** Owner (a), the last raw plan layer at alpha >=128 on the rig canvas. */
|
|
19
|
-
export function rawPaintingOwner(raw: ReadonlyArray<{ name: string; raster: Raster }>, pixels: number): PaintingOwner {
|
|
18
|
+
/** Owner (a), the last raw plan layer at alpha >=128 on the rig canvas (cleared where an occluder keep mask holds). */
|
|
19
|
+
export function rawPaintingOwner(raw: ReadonlyArray<{ name: string; raster: Raster; keep?: Mask | null }>, pixels: number): PaintingOwner {
|
|
20
20
|
const owner = new Int32Array(pixels).fill(-1);
|
|
21
|
-
raw.forEach(({ raster }, i) => {
|
|
22
|
-
for (let p = 0; p < pixels; p++)
|
|
21
|
+
raw.forEach(({ raster, keep }, i) => {
|
|
22
|
+
for (let p = 0; p < pixels; p++) {
|
|
23
|
+
if (raster.data[p * 4 + 3] < 128) continue;
|
|
24
|
+
owner[p] = keep?.data[p] === 1 ? -1 : i;
|
|
25
|
+
}
|
|
23
26
|
});
|
|
24
27
|
return { supplier: 'owner-a/raw-plan-alpha>=128', names: raw.map(q => q.name), pixels: owner };
|
|
25
28
|
}
|
package/src/parts.ts
CHANGED
|
@@ -392,6 +392,19 @@ export interface OccluderPlateRecord {
|
|
|
392
392
|
mask_sha256: string;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
export interface OccluderGrowRecord {
|
|
396
|
+
/** Zero-based index into `config.assemble.occluders`. */
|
|
397
|
+
occluder: number;
|
|
398
|
+
/** The declared `config.assemble.occluders[occluder].image` path. */
|
|
399
|
+
image: string;
|
|
400
|
+
/** The declared positive integer `config.assemble.occluders[occluder].grow` radius in rig px. */
|
|
401
|
+
grow: number;
|
|
402
|
+
/** Rig pixels of the occluder core (`alpha > 128`) before the dilation. */
|
|
403
|
+
covered_px_before: number;
|
|
404
|
+
/** Rig pixels of the occluder core (`alpha > 128`) after the `(2 * grow + 1)^2` dilation. */
|
|
405
|
+
covered_px_after: number;
|
|
406
|
+
}
|
|
407
|
+
|
|
395
408
|
export interface PartsFile {
|
|
396
409
|
/** Optional on legacy packages; binds the opaque RGB raster assemble actually read. */
|
|
397
410
|
painting_in_rig?: PaintingInRig;
|
|
@@ -411,6 +424,8 @@ export interface PartsFile {
|
|
|
411
424
|
single_run_pad?: SingleRunPad;
|
|
412
425
|
/** Written only when an `assemble.occluders` entry declares `plate` (issue #1237); absent otherwise. */
|
|
413
426
|
occluder_plates?: OccluderPlateRecord[];
|
|
427
|
+
/** Written only when an `assemble.occluders` entry declares `grow > 0` (issue #1251); absent otherwise. */
|
|
428
|
+
occluder_grow?: OccluderGrowRecord[];
|
|
414
429
|
/** Written only when alternate painting sets were assembled (issue #454); absent otherwise. */
|
|
415
430
|
alternates?: AlternatePartsRecord[];
|
|
416
431
|
}
|
|
@@ -447,9 +462,10 @@ export interface SceneRecord {
|
|
|
447
462
|
figure_mask: string;
|
|
448
463
|
}
|
|
449
464
|
|
|
450
|
-
const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'occluder_plates', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
|
|
451
|
-
const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'occluder_plates' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
|
|
465
|
+
const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'occluder_plates', 'occluder_grow', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
|
|
466
|
+
const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'occluder_plates' && k !== 'occluder_grow' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
|
|
452
467
|
export const OCCLUDER_PLATE_KEYS = ['receipt', 'receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const;
|
|
468
|
+
export const OCCLUDER_GROW_KEYS = ['occluder', 'image', 'grow', 'covered_px_before', 'covered_px_after'] as const;
|
|
453
469
|
export const SINGLE_RUN_PAD_KEYS = ['file_size', 'side', 'left', 'top'] as const;
|
|
454
470
|
export const SCENE_KEYS = ['figure_alpha_above', 'figure_px', 'figure_mask'] as const;
|
|
455
471
|
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;
|
|
@@ -512,20 +528,45 @@ export function tagOf(from: string): string | null {
|
|
|
512
528
|
return f === null || f.run === 'painting' ? null : f.tag;
|
|
513
529
|
}
|
|
514
530
|
|
|
515
|
-
const OWNERSHIP_KEYS = ['edit', 'from', 'into', 'moved_in_opaque_px', 'retained_band_opaque_px', 'cleared_opaque_px', 'under_filled_px', 'under_filled_opaque_px', 'net_cleared_opaque_px'] as const;
|
|
531
|
+
const OWNERSHIP_KEYS = ['edit', 'from', 'into', 'moved_in_opaque_px', 'retained_band_opaque_px', 'cleared_opaque_px', 'under_filled_px', 'under_filled_opaque_px', 'net_cleared_opaque_px', 'under_plate'] as const;
|
|
532
|
+
const REQUIRED_OWNERSHIP_KEYS = OWNERSHIP_KEYS.filter((k) => k !== 'under_plate');
|
|
516
533
|
function orderedOwnership(rows: readonly CutOwnership[]): Array<Record<string, unknown>> {
|
|
517
|
-
return rows.map(r =>
|
|
534
|
+
return rows.map((r) => ({
|
|
535
|
+
...Object.fromEntries(REQUIRED_OWNERSHIP_KEYS.map((k) => [k, r[k]])),
|
|
536
|
+
...(r.under_plate === undefined
|
|
537
|
+
? {}
|
|
538
|
+
: {
|
|
539
|
+
under_plate: Object.fromEntries(OCCLUDER_PLATE_KEYS.map((k) => [k, r.under_plate![k]])),
|
|
540
|
+
}),
|
|
541
|
+
}));
|
|
542
|
+
}
|
|
543
|
+
function checkOccluderPlateEntry(entry: unknown, at: string, fail: (code: string, object: string, detail: string) => void): void {
|
|
544
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
545
|
+
fail('PARTS_FIELD_TYPE', at, `is ${show(entry)}; an object is required`);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const r = entry as Record<string, unknown>;
|
|
549
|
+
for (const k of Object.keys(r)) if (!(OCCLUDER_PLATE_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${at} key "${k}"`, `is not an occluder_plates field; known: ${OCCLUDER_PLATE_KEYS.join(', ')}`);
|
|
550
|
+
for (const k of OCCLUDER_PLATE_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${at} field "${k}"`, 'is absent and required');
|
|
551
|
+
if ('receipt' in r && (typeof r.receipt !== 'string' || r.receipt.length === 0)) fail('PARTS_FIELD_TYPE', `${at} field "receipt"`, `is ${show(r.receipt)}; a non-empty string path is required`);
|
|
552
|
+
for (const k of ['receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const) {
|
|
553
|
+
if (k in r && (typeof r[k] !== 'string' || !/^[a-f0-9]{64}$/.test(r[k] as string))) {
|
|
554
|
+
fail('PARTS_FIELD_TYPE', `${at} field "${k}"`, `is ${show(r[k])}; 64 lowercase hex characters are required`);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
518
557
|
}
|
|
519
558
|
function checkOwnership(raw: unknown, object: string, fail: (code: string, object: string, detail: string) => void): void {
|
|
520
559
|
if (!Array.isArray(raw)) { fail('PARTS_FIELD_TYPE', object, `is ${show(raw)}; an array of indexed cut ownership records is required`); return; }
|
|
521
560
|
const seen = new Set<string>();
|
|
522
561
|
raw.forEach((row, i) => {
|
|
523
562
|
const r = row as CutOwnership | null;
|
|
524
|
-
const
|
|
563
|
+
const keys = r !== null && typeof r === 'object' && !Array.isArray(r) ? Object.keys(r).filter((k) => k !== 'under_plate').sort().join(',') : '';
|
|
564
|
+
const shape = r !== null && typeof r === 'object' && !Array.isArray(r) && keys === [...REQUIRED_OWNERSHIP_KEYS].sort().join(',') &&
|
|
525
565
|
typeof r.edit === 'string' && /^cuts\[\d+\]$/.test(r.edit) && !seen.has(r.edit) && typeof r.from === 'string' && r.from !== '' && typeof r.into === 'string' && r.into !== '' &&
|
|
526
|
-
|
|
566
|
+
REQUIRED_OWNERSHIP_KEYS.slice(3).every(k => Number.isSafeInteger(r[k]) && (k === 'net_cleared_opaque_px' || (r[k] as number) >= 0));
|
|
527
567
|
if (!shape) { fail('PARTS_FIELD_TYPE', `${object}[${i}]`, `is ${show(row)}; a distinct cuts[i] with from/into names, nonnegative move/clear/fill counts and signed net_cleared_opaque_px is required`); return; }
|
|
528
568
|
const q = r as CutOwnership; seen.add(q.edit);
|
|
569
|
+
if ('under_plate' in q && q.under_plate !== undefined) checkOccluderPlateEntry(q.under_plate, `${object}[${i}].under_plate`, fail);
|
|
529
570
|
if (q.moved_in_opaque_px - q.retained_band_opaque_px !== q.cleared_opaque_px || q.cleared_opaque_px - q.under_filled_opaque_px !== q.net_cleared_opaque_px || q.under_filled_opaque_px > q.under_filled_px) {
|
|
530
571
|
fail('PARTS_COUNTS_ADD_UP', `${object}[${i}]`, `moved ${q.moved_in_opaque_px} - retained ${q.retained_band_opaque_px} = ${q.moved_in_opaque_px - q.retained_band_opaque_px} (gross cleared ${q.cleared_opaque_px} required); cleared - opaque fill ${q.under_filled_opaque_px} = ${q.cleared_opaque_px - q.under_filled_opaque_px} (net ${q.net_cleared_opaque_px} required); opaque fill must be at most total fill ${q.under_filled_px}`);
|
|
531
572
|
}
|
|
@@ -540,6 +581,7 @@ function orderedProvenance(p: PixelProvenance): PixelProvenance {
|
|
|
540
581
|
|
|
541
582
|
function orderedTakenSource(source: TakenLayerSource): TakenLayerSource {
|
|
542
583
|
const transport = source.transport;
|
|
584
|
+
const split = source.split;
|
|
543
585
|
return {
|
|
544
586
|
run: source.run, tag: source.tag, run_dir: source.run_dir, st_input: source.st_input,
|
|
545
587
|
prompt_id: source.prompt_id, seed: source.seed, support_px: source.support_px,
|
|
@@ -552,6 +594,10 @@ function orderedTakenSource(source: TakenLayerSource): TakenLayerSource {
|
|
|
552
594
|
before_rgba_sha256: transport.before_rgba_sha256,
|
|
553
595
|
after_rgba_sha256: transport.after_rgba_sha256,
|
|
554
596
|
} }),
|
|
597
|
+
...(split === undefined ? {} : { split: {
|
|
598
|
+
occluder: split.occluder, image: split.image, sha256: split.sha256,
|
|
599
|
+
covered_px: split.covered_px, visible_px: split.visible_px,
|
|
600
|
+
} }),
|
|
555
601
|
};
|
|
556
602
|
}
|
|
557
603
|
|
|
@@ -582,6 +628,7 @@ export function serializeParts(file: PartsFile): string {
|
|
|
582
628
|
...(file.recomposite === undefined ? {} : { recomposite: serializeRecomposite(file.recomposite) }),
|
|
583
629
|
...(file.scene === undefined ? {} : { scene: Object.fromEntries(SCENE_KEYS.map((k) => [k, (file.scene as SceneRecord)[k]])) }),
|
|
584
630
|
...(file.occluder_plates === undefined ? {} : { occluder_plates: file.occluder_plates.map((p) => Object.fromEntries(OCCLUDER_PLATE_KEYS.map((k) => [k, p[k]]))) }),
|
|
631
|
+
...(file.occluder_grow === undefined ? {} : { occluder_grow: file.occluder_grow.map((g) => Object.fromEntries(OCCLUDER_GROW_KEYS.map((k) => [k, g[k]]))) }),
|
|
585
632
|
...(file.single_run_pad === undefined ? {} : { single_run_pad: Object.fromEntries(SINGLE_RUN_PAD_KEYS.map((k) => [k, (file.single_run_pad as SingleRunPad)[k]])) }),
|
|
586
633
|
...(file.alternates === undefined
|
|
587
634
|
? {}
|
|
@@ -925,19 +972,34 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
925
972
|
if (!Array.isArray(o.occluder_plates) || o.occluder_plates.length === 0) {
|
|
926
973
|
fail('PARTS_FIELD_TYPE', `${path} field "occluder_plates"`, `is ${show(o.occluder_plates)}; a non-empty array of occluder plate records is required`);
|
|
927
974
|
} else {
|
|
928
|
-
o.occluder_plates.forEach((entry, i) => {
|
|
929
|
-
|
|
975
|
+
o.occluder_plates.forEach((entry, i) => checkOccluderPlateEntry(entry, `${path} occluder_plates[${i}]`, fail));
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
if ('occluder_grow' in o) {
|
|
979
|
+
if (!Array.isArray(o.occluder_grow) || o.occluder_grow.length === 0) {
|
|
980
|
+
fail('PARTS_FIELD_TYPE', `${path} field "occluder_grow"`, `is ${show(o.occluder_grow)}; a non-empty array of occluder grow records is required`);
|
|
981
|
+
} else {
|
|
982
|
+
o.occluder_grow.forEach((entry, i) => {
|
|
983
|
+
const at = `${path} occluder_grow[${i}]`;
|
|
930
984
|
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
931
985
|
fail('PARTS_FIELD_TYPE', at, `is ${show(entry)}; an object is required`);
|
|
932
986
|
return;
|
|
933
987
|
}
|
|
934
988
|
const r = entry as Record<string, unknown>;
|
|
935
|
-
for (const k of Object.keys(r)) if (!(
|
|
936
|
-
for (const k of
|
|
937
|
-
if ('
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
989
|
+
for (const k of Object.keys(r)) if (!(OCCLUDER_GROW_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${at} key "${k}"`, `is not an occluder_grow field; known: ${OCCLUDER_GROW_KEYS.join(', ')}`);
|
|
990
|
+
for (const k of OCCLUDER_GROW_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${at} field "${k}"`, 'is absent and required');
|
|
991
|
+
if ('occluder' in r && !(typeof r.occluder === 'number' && Number.isInteger(r.occluder) && r.occluder >= 0)) {
|
|
992
|
+
fail('PARTS_FIELD_TYPE', `${at} field "occluder"`, `is ${show(r.occluder)}; a non-negative integer index is required`);
|
|
993
|
+
}
|
|
994
|
+
if ('image' in r && (typeof r.image !== 'string' || r.image.length === 0)) {
|
|
995
|
+
fail('PARTS_FIELD_TYPE', `${at} field "image"`, `is ${show(r.image)}; a non-empty string path is required`);
|
|
996
|
+
}
|
|
997
|
+
if ('grow' in r && !(typeof r.grow === 'number' && Number.isInteger(r.grow) && r.grow > 0)) {
|
|
998
|
+
fail('PARTS_FIELD_TYPE', `${at} field "grow"`, `is ${show(r.grow)}; a positive integer is required`);
|
|
999
|
+
}
|
|
1000
|
+
for (const k of ['covered_px_before', 'covered_px_after'] as const) {
|
|
1001
|
+
if (k in r && !(typeof r[k] === 'number' && Number.isInteger(r[k]) && (r[k] as number) >= 0)) {
|
|
1002
|
+
fail('PARTS_FIELD_TYPE', `${at} field "${k}"`, `is ${show(r[k])}; a non-negative integer is required`);
|
|
941
1003
|
}
|
|
942
1004
|
}
|
|
943
1005
|
});
|
package/src/partsource.ts
CHANGED
|
@@ -62,10 +62,12 @@ export function untracedPartSources(cfg: Pick<AssembleConfig, 'assemble' | 'seet
|
|
|
62
62
|
};
|
|
63
63
|
const a = cfg.assemble;
|
|
64
64
|
(a.cuts ?? []).forEach((q, i) => {
|
|
65
|
+
if (typeof q.under === 'object' && q.under !== null) return;
|
|
65
66
|
refuse(`part "${q.into}" (config.assemble.cuts[${i}])`, `its pixels are carved out of part "${q.from}" by a hand-drawn ${q.polygon.length}-point polygon`);
|
|
66
67
|
});
|
|
67
68
|
(a.alternates ?? []).forEach((set, j) => {
|
|
68
69
|
(set.cuts ?? []).forEach((q, i) => {
|
|
70
|
+
if (typeof q.under === 'object' && q.under !== null) return;
|
|
69
71
|
refuse(`part "${q.into}" (config.assemble.alternates[${j}].cuts[${i}], alternate set "${set.name}")`, `its pixels are carved out of part "${q.from}" by a hand-drawn ${q.polygon.length}-point polygon`);
|
|
70
72
|
});
|
|
71
73
|
});
|
package/src/provenance.ts
CHANGED
|
@@ -137,6 +137,15 @@ export function provenanceLines(parts: readonly PartRecord[]): string[] {
|
|
|
137
137
|
return lines;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
export interface CutUnderPlateRecord {
|
|
141
|
+
receipt: string;
|
|
142
|
+
receipt_sha256: string;
|
|
143
|
+
occluder_sha256: string;
|
|
144
|
+
painting_sha256: string;
|
|
145
|
+
output_sha256: string;
|
|
146
|
+
mask_sha256: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
140
149
|
/** Structural cut census, independent of the value partition. Counts are from
|
|
141
150
|
* the original parent partition before limb/fringe/seam processing. */
|
|
142
151
|
export interface CutOwnership {
|
|
@@ -149,6 +158,7 @@ export interface CutOwnership {
|
|
|
149
158
|
under_filled_px: number;
|
|
150
159
|
under_filled_opaque_px: number;
|
|
151
160
|
net_cleared_opaque_px: number;
|
|
161
|
+
under_plate?: CutUnderPlateRecord;
|
|
152
162
|
}
|
|
153
163
|
export function ownershipLines(rows: readonly CutOwnership[]): string[] {
|
|
154
164
|
return rows.map(r => ` ownership: ${r.edit} "${r.from}" -> "${r.into}" moved in ${r.moved_in_opaque_px} opaque px; retained band ${r.retained_band_opaque_px}; gross cleared ${r.cleared_opaque_px} before refill; under filled ${r.under_filled_px} px (${r.under_filled_opaque_px} opaque); net cleared ${r.net_cleared_opaque_px}; independent of RGBA equality`);
|
package/src/remesh.ts
CHANGED
|
@@ -134,6 +134,8 @@ export interface RemeshPlant {
|
|
|
134
134
|
unexpandedStops?: boolean;
|
|
135
135
|
/** Issue #617's mutant: run just before check-input reads the input, after the first snapshot, to change a file under it. */
|
|
136
136
|
beforeInputCheck?: () => void;
|
|
137
|
+
/** Issue #1256's mutant: hand every non-`images/` entry of the tree to `gateThroughRigc` as text, as before. */
|
|
138
|
+
unfilteredGateTexts?: boolean;
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
/** The versions the provenance names: this package's and the rigc that gated the revision (its `--version` line). */
|
|
@@ -866,10 +868,13 @@ export function inputTreeProblems(tree: FileTree, root: string, op: 'remesh' | '
|
|
|
866
868
|
return out;
|
|
867
869
|
}
|
|
868
870
|
|
|
871
|
+
/** The two text files `gateThroughRigc`'s `rigc build` reads (`src/build.ts`), in `readTree` sort order. */
|
|
872
|
+
export const GATE_TEXT_FILES = ['motion.json', 'rig.json'] as const;
|
|
869
873
|
/** A tree's images as the gate takes them (name under `images/`, bytes). */
|
|
870
|
-
const pngsOf = (tree: FileTree): Array<readonly [string, Uint8Array]> => [...tree].filter(([k]) => k.startsWith('images/')).map(([k, b]) => [k.slice('images/'.length), b] as const);
|
|
871
|
-
/** A tree's
|
|
872
|
-
const textsOf = (tree: FileTree): Array<readonly [string, string]> =>
|
|
874
|
+
export const pngsOf = (tree: FileTree): Array<readonly [string, Uint8Array]> => [...tree].filter(([k]) => k.startsWith('images/')).map(([k, b]) => [k.slice('images/'.length), b] as const);
|
|
875
|
+
/** A tree's text inputs for the gate (`rig.json` and `motion.json`; `unfiltered` is the pre-#1256 plant). */
|
|
876
|
+
export const textsOf = (tree: FileTree, unfiltered = false): Array<readonly [string, string]> =>
|
|
877
|
+
[...tree].filter(([k]) => (unfiltered ? !k.startsWith('images/') : (GATE_TEXT_FILES as readonly string[]).includes(k))).map(([k, b]) => [k, text(b)] as const);
|
|
873
878
|
|
|
874
879
|
/**
|
|
875
880
|
* The delta's `mesh_report.json` row (issue #526): the input's row, key for key, with `vertices`, `triangles`, `hull`,
|
|
@@ -973,7 +978,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
|
|
|
973
978
|
refuseIfAny(deltaSourceProblems(doc, part, inAtt, deltaPath));
|
|
974
979
|
log(`rig-parts remesh: ${part} of ${input.rig}, ${tree.size} file(s); the request is a mesh edit of ${doc.ops.length} op(s), the baseline is the input itself`);
|
|
975
980
|
let model = null as string | null;
|
|
976
|
-
const inGate = gateThroughRigc(pngsOf(tree), textsOf(tree), rigc, join(scratch, 'gate-input'), { pageEdges, packShape }, (dir) => {
|
|
981
|
+
const inGate = gateThroughRigc(pngsOf(tree), textsOf(tree, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate-input'), { pageEdges, packShape }, (dir) => {
|
|
977
982
|
const p = join(dir, RIGC_MODEL_DOCUMENT);
|
|
978
983
|
model = existsSync(p) ? readFileSync(p, 'utf8') : null;
|
|
979
984
|
});
|
|
@@ -1010,7 +1015,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
|
|
|
1010
1015
|
log(` ${part}: v=${before.vertices} t=${before.triangles} hull=${before.hull} -> v=${after.vertices} t=${after.triangles} hull=${after.hull}`);
|
|
1011
1016
|
log(` preserved: ${identical.filter((p) => p !== PROVENANCE_FILE && !(input.recordInputCheck === true && p === INPUT_CHECK_FILE)).length} file(s) byte-identical to the input; rig.json identical outside skins.default.${part}.${part}; mesh_report.json identical but the "${part}" row`);
|
|
1012
1017
|
// 7. The gate and check.
|
|
1013
|
-
const gate = gateThroughRigc(pngsOf(revision), textsOf(revision), rigc, join(scratch, 'gate'), { pageEdges, packShape });
|
|
1018
|
+
const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), { pageEdges, packShape });
|
|
1014
1019
|
for (const g of gate) {
|
|
1015
1020
|
log(` rigc ${g.label}, the revision: exit ${g.status}`);
|
|
1016
1021
|
for (const l of g.lines) log(` ${l.trim()}`);
|
package/src/retune.ts
CHANGED
|
@@ -40,7 +40,7 @@ import { dirname, join, resolve, sep } from 'node:path';
|
|
|
40
40
|
import { checkStage, gateThroughRigc, type Log, rigStage } from './build.ts';
|
|
41
41
|
import { type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackShape, type PageEdges, rigcRanClause, type RigcRunner } from './check.ts';
|
|
42
42
|
import { PartsError, type Problem, problemLine, refuseIfAny } from './errors.ts';
|
|
43
|
-
import { type CheckSide, carryProvenance, type ParentProvenance, checkHeldProblems, checkSide, checkScope, type FileTree, firstDifference, type HashRow, hashRows, INPUT_CHECK_FILE, type InputCheckBinding, inputCheckHashes, inputCheckMovedProblems, inputCheckOf, inputCheckReusedLine, inputCheckText, inputTreeProblems, perturbed, readTree, sha256 } from './remesh.ts';
|
|
43
|
+
import { type CheckSide, carryProvenance, type ParentProvenance, checkHeldProblems, checkSide, checkScope, type FileTree, firstDifference, type HashRow, hashRows, INPUT_CHECK_FILE, type InputCheckBinding, inputCheckHashes, inputCheckMovedProblems, inputCheckOf, inputCheckReusedLine, inputCheckText, inputTreeProblems, perturbed, pngsOf, readTree, sha256, textsOf } from './remesh.ts';
|
|
44
44
|
import { DEFAULT_IDLE_KEYS, type IdleKeys, rigJsonText } from './rig.ts';
|
|
45
45
|
|
|
46
46
|
/** The provenance file's spec. */
|
|
@@ -89,6 +89,8 @@ export interface RetunePlant {
|
|
|
89
89
|
skipHold?: boolean;
|
|
90
90
|
/** Issue #617's mutant: run just before check-input reads the input, after the first snapshot, to change a file under it. */
|
|
91
91
|
beforeInputCheck?: () => void;
|
|
92
|
+
/** Issue #1256's mutant: hand every non-`images/` entry of the tree to `gateThroughRigc` as text, as before. */
|
|
93
|
+
unfilteredGateTexts?: boolean;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
/** One constraint the request changed: its name and type, and each field whose value moved, in the rebuild's order. */
|
|
@@ -377,9 +379,7 @@ export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: stri
|
|
|
377
379
|
log(` idle: ${changed.idle.tracks_changed} track(s) changed, duration ${changed.idle.duration[0]} -> ${changed.idle.duration[1]}`);
|
|
378
380
|
log(` preserved: ${identical.filter((p) => p !== RETUNE_FILE && !(input.recordInputCheck === true && p === INPUT_CHECK_FILE)).length} file(s) byte-identical to the input; rig.json identical outside constraints and invariants.detached; motion.json identical outside animations.idle`);
|
|
379
381
|
// 6. The gate and check.
|
|
380
|
-
const
|
|
381
|
-
const texts = [...revision].filter(([k]) => !k.startsWith('images/')).map(([k, b]) => [k, text(b)] as const);
|
|
382
|
-
const gate = gateThroughRigc(pngs, texts, rigc, join(scratch, 'gate'), { pageEdges, packShape });
|
|
382
|
+
const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), { pageEdges, packShape });
|
|
383
383
|
for (const g of gate) {
|
|
384
384
|
log(` rigc ${g.label}, the revision: exit ${g.status}`);
|
|
385
385
|
for (const l of g.lines) log(` ${l.trim()}`);
|
package/src/takelayers.ts
CHANGED
|
@@ -7,15 +7,18 @@ import { CORE_KERNEL, fullPlanBand } from './assemble.ts';
|
|
|
7
7
|
import { makeInputs, squarePad } from './inputs.ts';
|
|
8
8
|
import { OPAQUE_ALPHA_ABOVE, readLayers, type Layer, type LayerSet } from './layers.ts';
|
|
9
9
|
import { PartsError, refuseIfAny, type Problem } from './errors.ts';
|
|
10
|
-
import { declaredOccluderPair, occluderDrawCycleProblems, occluderDrawOrderProblems, occluderOverTakenProblems, type OccluderDeclaration } from './occluders.ts';
|
|
10
|
+
import { COPIED_ALPHA_ABOVE, declaredOccluderPair, occluderDrawCycleProblems, occluderDrawOrderProblems, occluderOverTakenProblems, type OccluderDeclaration } from './occluders.ts';
|
|
11
11
|
import { dilate } from './raster/morph.ts';
|
|
12
12
|
import { newMask, newRaster, newFloatImage, type Raster } from './raster/types.ts';
|
|
13
13
|
import { readPng } from './raster/png.ts';
|
|
14
|
-
import type { TakeDeclaration } from './takeregion.ts';
|
|
14
|
+
import type { TakeDeclaration, TakeOccluderSplit } from './takeregion.ts';
|
|
15
15
|
import { crop, pad } from './raster/composite.ts';
|
|
16
16
|
import { warpAffine, type ScaleTranslate } from './raster/warp.ts';
|
|
17
17
|
import { takenTransportProblems, type TakenLayerSource, type TakenLayerTransport } from './takesource.ts';
|
|
18
18
|
|
|
19
|
+
export const TAKE_SPLIT_OCCLUDER = 'ASSEMBLE_TAKE_SPLIT_OCCLUDER';
|
|
20
|
+
export const TAKE_SPLIT_EMPTY = 'ASSEMBLE_TAKE_SPLIT_EMPTY';
|
|
21
|
+
|
|
19
22
|
export interface TakeLayers {
|
|
20
23
|
run: Run;
|
|
21
24
|
run_dir: string;
|
|
@@ -142,7 +145,10 @@ export function transportLayer(layer: Layer, donor: LayerSet, set: LayerSet, ima
|
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
export function takeLayerNote(source: TakenLayerSource): string {
|
|
145
|
-
|
|
148
|
+
const splitClause = source.split === undefined
|
|
149
|
+
? ''
|
|
150
|
+
: `; split occluder[${source.split.occluder}] ${source.split.image} (${source.split.sha256.slice(0, 12)}) covered ${source.split.covered_px} run px, visible ${source.split.visible_px} run px`;
|
|
151
|
+
return `take ${source.run}:${source.tag} from ${source.run_dir}; prompt_id ${source.prompt_id}; seed ${source.seed}; st_input ${source.st_input}; support ${source.support_px} run px; checked ${source.checked_px} input px; differing ${source.differing_px}; alpha > ${OPAQUE_ALPHA_ABOVE}, ${CORE_KERNEL}x${CORE_KERNEL} margin${splitClause}`;
|
|
146
152
|
}
|
|
147
153
|
/** Intersection of original alpha supports in the common target-run canvas; no bbox or dilation proxy. */
|
|
148
154
|
function supportOverlap(a: Layer, b: Layer): number {
|
|
@@ -156,8 +162,29 @@ function supportOverlap(a: Layer, b: Layer): number {
|
|
|
156
162
|
}
|
|
157
163
|
/** Apply every declaration together, so replacing all tied layers from one run can retain its known order. */
|
|
158
164
|
export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single: boolean }, painting: Raster, cfg: Pick<EarlyConfig, 'seethrough' | 'depth'> & { assemble: { take?: TakeDeclaration[]; plan?: PlanEntry[]; occluders?: OccluderDeclaration[] } }, configPath: string): { full: LayerSet; head: LayerSet; single: boolean; notes: string[] } {
|
|
159
|
-
const
|
|
165
|
+
const wholeDeclarations = (cfg.assemble.take ?? []).filter((item): item is TakeLayers => 'tags' in item);
|
|
166
|
+
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeLayers | TakeOccluderSplit => 'tags' in item || 'occluder' in item);
|
|
160
167
|
const occluders = cfg.assemble.occluders ?? [];
|
|
168
|
+
for (const d of declarations) {
|
|
169
|
+
if ('occluder' in d) {
|
|
170
|
+
const partAt = `config.assemble.take run "${d.run_dir}" (${d.run}) part "${d.part}"`;
|
|
171
|
+
const occEntry = Number.isSafeInteger(d.occluder) && d.occluder >= 0 ? occluders[d.occluder] : undefined;
|
|
172
|
+
if (occEntry === undefined) {
|
|
173
|
+
return refuse(TAKE_SPLIT_OCCLUDER, partAt, `occluder index ${d.occluder} does not exist in config.assemble.occluders (${occluders.length} declared); a valid occluder index is required`);
|
|
174
|
+
}
|
|
175
|
+
if ((occEntry.over ?? []).includes(d.part)) {
|
|
176
|
+
return refuse(TAKE_SPLIT_OCCLUDER, partAt, `part "${d.part}" is in config.assemble.occluders[${d.occluder}].over; a split take is for a part under the occluder, not in its over`);
|
|
177
|
+
}
|
|
178
|
+
if (!occEntry.under.includes(d.part)) {
|
|
179
|
+
return refuse(TAKE_SPLIT_OCCLUDER, partAt, `part "${d.part}" is not in config.assemble.occluders[${d.occluder}].under; a part declared under that occluder is required`);
|
|
180
|
+
}
|
|
181
|
+
if (cfg.assemble.plan !== undefined) {
|
|
182
|
+
const row = cfg.assemble.plan.find(([part]) => part === d.part);
|
|
183
|
+
if (row === undefined) return refuse('CONFIG_NAME_RESOLVES', partAt, `names "${d.part}"; a part named in assemble.plan is required`);
|
|
184
|
+
if (row[1] !== d.run || row[2] !== d.tag) return refuse('CONFIG_NAME_RESOLVES', partAt, `declares ${d.run}:${d.tag} for part "${d.part}"; assemble.plan declares ["${row[0]}", "${row[1]}", "${row[2]}"]`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
161
188
|
if (occluders.length > 0) {
|
|
162
189
|
const cycles = occluderDrawCycleProblems(occluders);
|
|
163
190
|
refuseIfAny([
|
|
@@ -165,7 +192,7 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
165
192
|
...(cfg.assemble.plan === undefined
|
|
166
193
|
? []
|
|
167
194
|
: [
|
|
168
|
-
...occluderOverTakenProblems(occluders, cfg.assemble.plan,
|
|
195
|
+
...occluderOverTakenProblems(occluders, cfg.assemble.plan, wholeDeclarations),
|
|
169
196
|
...(cycles.length > 0 ? [] : occluderDrawOrderProblems(occluders, cfg.assemble.plan)),
|
|
170
197
|
]),
|
|
171
198
|
]);
|
|
@@ -190,6 +217,85 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
190
217
|
if (target === null) return refuse('ASSEMBLE_TAKE_CROP', at, 'a target input is required for a declared crop');
|
|
191
218
|
const geometry = d.crop === undefined ? undefined : cropGeometry(d, painting, target, donor, set, inputs, at);
|
|
192
219
|
if (geometry !== undefined && (image.width !== geometry.expected.width || image.height !== geometry.expected.height)) return refuse('ASSEMBLE_TAKE_CROP', at, `donor st_input ${image.width}x${image.height}; declared square-padded crop requires ${geometry.expected.width}x${geometry.expected.height}`);
|
|
220
|
+
if ('occluder' in d) {
|
|
221
|
+
const partAt = `${at} part "${d.part}"`;
|
|
222
|
+
const tagAt = `${at} tag "${d.tag}"`;
|
|
223
|
+
const key = `${d.run}:${d.tag}`;
|
|
224
|
+
if (seen.has(key)) return refuse('ASSEMBLE_TAKE_UNIQUE', at, `tag "${d.tag}" replaces ${key} twice; declare one donor per target tag`);
|
|
225
|
+
seen.add(key);
|
|
226
|
+
const baseLayer = lists[d.run].find(l => l.name === d.tag);
|
|
227
|
+
if (baseLayer === undefined) return refuse('ASSEMBLE_TAKE_TAG_IN_RUN', at, `tag "${d.tag}" is absent from the base ${d.run} run; both base and donor must hold the split tag`);
|
|
228
|
+
const donorLayer = donor.layers.find(l => l.name === d.tag);
|
|
229
|
+
if (donorLayer === undefined) return refuse('ASSEMBLE_TAKE_TAG_IN_RUN', at, `tag "${d.tag}" is absent; a named See-through tag held by that donor is required`);
|
|
230
|
+
const occEntry = occluders[d.occluder]!;
|
|
231
|
+
let occPng: Raster;
|
|
232
|
+
try { occPng = readPng(resolve(base, occEntry.image)); } catch { return refuse('CONFIG_FILE_PRESENT', `config.assemble.occluders[${d.occluder}].image`, `names "${occEntry.image}", which is not a readable PNG`); }
|
|
233
|
+
if (occPng.width !== painting.width || occPng.height !== painting.height) {
|
|
234
|
+
return refuse('ASSEMBLE_OCCLUDER_GRID', `config.assemble.occluders[${d.occluder}].image`, `is ${occPng.width}x${occPng.height}; the painting's dimensions ${painting.width}x${painting.height} are required`);
|
|
235
|
+
}
|
|
236
|
+
const occTarget = d.run === 'head'
|
|
237
|
+
? crop(occPng, inputs.headBox![0], inputs.headBox![1], inputs.headBox![2] - inputs.headBox![0], inputs.headBox![3] - inputs.headBox![1])
|
|
238
|
+
: target === painting
|
|
239
|
+
? occPng
|
|
240
|
+
: pad(occPng, inputs.padLeft, inputs.padTop, target.width - painting.width - inputs.padLeft, target.height - painting.height - inputs.padTop, [0, 0, 0, 0]);
|
|
241
|
+
const isCovered = (x: number, y: number): boolean => {
|
|
242
|
+
const ox = Math.min(occTarget.width - 1, Math.max(0, Math.floor((x + 0.5) * occTarget.width / set.canvas.w)));
|
|
243
|
+
const oy = Math.min(occTarget.height - 1, Math.max(0, Math.floor((y + 0.5) * occTarget.height / set.canvas.h)));
|
|
244
|
+
return occTarget.data[(oy * occTarget.width + ox) * 4 + 3] > COPIED_ALPHA_ABOVE;
|
|
245
|
+
};
|
|
246
|
+
const transported = geometry === undefined ? undefined : transportLayer(donorLayer, donor, set, image, d, geometry.map, geometry.exact, tagAt);
|
|
247
|
+
const donorOnSet = transported?.layer ?? donorLayer;
|
|
248
|
+
const merged = newRaster(set.canvas.w, set.canvas.h);
|
|
249
|
+
let coveredPx = 0, visiblePx = 0, opaquePx = 0;
|
|
250
|
+
for (let y = 0; y < set.canvas.h; y++) for (let x = 0; x < set.canvas.w; x++) {
|
|
251
|
+
const p = (y * set.canvas.w + x) * 4;
|
|
252
|
+
if (isCovered(x, y)) {
|
|
253
|
+
if (x >= baseLayer.left && x < baseLayer.right && y >= baseLayer.top && y < baseLayer.bottom) {
|
|
254
|
+
const bp = ((y - baseLayer.top) * baseLayer.pixels.width + (x - baseLayer.left)) * 4;
|
|
255
|
+
merged.data.set(baseLayer.pixels.data.subarray(bp, bp + 4), p);
|
|
256
|
+
if (baseLayer.pixels.data[bp + 3] > OPAQUE_ALPHA_ABOVE) { coveredPx++; opaquePx++; }
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
if (x >= donorOnSet.left && x < donorOnSet.right && y >= donorOnSet.top && y < donorOnSet.bottom) {
|
|
260
|
+
const dp = ((y - donorOnSet.top) * donorOnSet.pixels.width + (x - donorOnSet.left)) * 4;
|
|
261
|
+
merged.data.set(donorOnSet.pixels.data.subarray(dp, dp + 4), p);
|
|
262
|
+
if (donorOnSet.pixels.data[dp + 3] > OPAQUE_ALPHA_ABOVE) { visiblePx++; opaquePx++; }
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (coveredPx === 0 || visiblePx === 0) {
|
|
267
|
+
return refuse('ASSEMBLE_TAKE_SPLIT_EMPTY', partAt, `covered_px is ${coveredPx} (base ${d.run}:${d.tag} under occluder[${d.occluder}] alpha > ${COPIED_ALPHA_ABOVE}) and visible_px is ${visiblePx} (donor ${d.run}:${d.tag} outside occluder[${d.occluder}]); both regions require at least 1 pixel of alpha > ${OPAQUE_ALPHA_ABOVE}`);
|
|
268
|
+
}
|
|
269
|
+
const donorVisiblePixels = newRaster(donorLayer.pixels.width, donorLayer.pixels.height);
|
|
270
|
+
let donorVisibleOpaque = 0;
|
|
271
|
+
for (let y = 0; y < donorLayer.pixels.height; y++) for (let x = 0; x < donorLayer.pixels.width; x++) {
|
|
272
|
+
const dx = donorLayer.left + x, dy = donorLayer.top + y;
|
|
273
|
+
const tx = geometry === undefined ? dx : Math.floor(geometry.map.sx * dx + geometry.map.tx);
|
|
274
|
+
const ty = geometry === undefined ? dy : Math.floor(geometry.map.sy * dy + geometry.map.ty);
|
|
275
|
+
if (tx >= 0 && tx < set.canvas.w && ty >= 0 && ty < set.canvas.h && !isCovered(tx, ty)) {
|
|
276
|
+
const dp = (y * donorLayer.pixels.width + x) * 4;
|
|
277
|
+
donorVisiblePixels.data.set(donorLayer.pixels.data.subarray(dp, dp + 4), dp);
|
|
278
|
+
if (donorLayer.pixels.data[dp + 3] > OPAQUE_ALPHA_ABOVE) donorVisibleOpaque++;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const donorVisible: Layer = { ...donorLayer, pixels: donorVisiblePixels, opaquePx: donorVisibleOpaque };
|
|
282
|
+
const checked = identity(donorVisible, donor.canvas, image, geometry?.expected ?? target, tagAt);
|
|
283
|
+
const source: TakenLayerSource = {
|
|
284
|
+
run: d.run, tag: d.tag, run_dir: d.run_dir, st_input: d.st_input,
|
|
285
|
+
prompt_id: meta.prompt_id, seed: meta.seed,
|
|
286
|
+
support_px: checked.support,
|
|
287
|
+
checked_px: checked.checked.reduce((a, b) => a + b, 0),
|
|
288
|
+
differing_px: 0,
|
|
289
|
+
...(transported === undefined ? {} : { transport: transported.transport }),
|
|
290
|
+
split: { occluder: d.occluder, image: occEntry.image, sha256: occEntry.sha256, covered_px: coveredPx, visible_px: visiblePx },
|
|
291
|
+
};
|
|
292
|
+
const replacement: Layer = { ...baseLayer, left: 0, top: 0, right: set.canvas.w, bottom: set.canvas.h, pixels: merged, opaquePx, takenLayers: [source] };
|
|
293
|
+
lists[d.run] = [...lists[d.run].filter(l => l.name !== d.tag), replacement];
|
|
294
|
+
origins.set(replacement, resolve(base, d.run_dir));
|
|
295
|
+
notes.push(takeLayerNote(source));
|
|
296
|
+
notes.push(`take union ${d.run} from ${d.run_dir}: checked ${checked.checked.reduce((a, b) => a + b, 0)} input px; differing 0`);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
193
299
|
const union = new Uint8Array(image.width * image.height);
|
|
194
300
|
for (const tag of d.tags) {
|
|
195
301
|
const key = `${d.run}:${tag}`;
|
|
@@ -232,8 +338,9 @@ export function applyTakenLayers(runs: { full: LayerSet; head: LayerSet; single:
|
|
|
232
338
|
if (reversed) problems.push({ code: 'ASSEMBLE_TAKE_PLAN_ORDER', object: `${run} plan parts "${a.part}" / "${b.part}"`, detail: `plan order reverses ${band === 0 ? `mixed-run depths ${a.layer.depth} / ${b.layer.depth}; put the larger depth behind` : `two-run full-layer roles "${a.layer.name}" / "${b.layer.name}"; order back hair, body, headwear/earwear, face, head details, front hair`}; supports overlap at ${overlap} run px (alpha > ${OPAQUE_ALPHA_ABOVE}); use assemble --propose-plan` });
|
|
233
339
|
}
|
|
234
340
|
refuseIfAny(problems);
|
|
235
|
-
const
|
|
236
|
-
|
|
341
|
+
const tagsOf = (d: TakeLayers | TakeOccluderSplit): readonly string[] => 'tags' in d ? d.tags : [d.tag];
|
|
342
|
+
const replaced = new Set(declarations.filter(d => d.run === run).flatMap(tagsOf));
|
|
343
|
+
if (runs[run].hidden.some(l => replaced.has(l.of)) || declarations.some(d => d.run === run && readLayers(resolve(base, d.run_dir)).hidden.some(l => tagsOf(d).includes(l.of)))) return refuse('ASSEMBLE_TAKE_HIDDEN', run, 'a replaced layer has hidden companion art; separate hidden provenance is not declared, so the combination is refused');
|
|
237
344
|
}
|
|
238
345
|
const full = { ...runs.full, layers: lists.full }, head = runs.single ? full : { ...runs.head, layers: lists.head };
|
|
239
346
|
return { full, head, single: runs.single, notes };
|
package/src/takeregion.ts
CHANGED
|
@@ -24,7 +24,20 @@ export interface TakeRegion {
|
|
|
24
24
|
/** PNG bytes, explicitly bound to the stage source or a separate painting. */
|
|
25
25
|
reference?: { source: true; sha256: string } | { painting: string; sha256: string };
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export interface TakeOccluderSplit {
|
|
28
|
+
run: Run;
|
|
29
|
+
run_dir: string;
|
|
30
|
+
st_input: string;
|
|
31
|
+
/** Same painting-space crop and transport as a whole-layer take. */
|
|
32
|
+
crop?: TakeLayers['crop'];
|
|
33
|
+
/** Plan part on `run`; must be in `occluders[occluder].under`, not in `over`. */
|
|
34
|
+
part: string;
|
|
35
|
+
/** The plan row's See-through tag for `part` on `run`. */
|
|
36
|
+
tag: string;
|
|
37
|
+
/** Zero-based index into `config.assemble.occluders`; its image is the split mask. */
|
|
38
|
+
occluder: number;
|
|
39
|
+
}
|
|
40
|
+
export type TakeDeclaration = TakeLayers | TakeRegion | TakeOccluderSplit;
|
|
28
41
|
export interface RegionReading {
|
|
29
42
|
part: string;
|
|
30
43
|
run: Run;
|
|
@@ -106,7 +119,7 @@ export function deriveTakenRegion(base: Layer, donor: Layer, painting: Raster, s
|
|
|
106
119
|
|
|
107
120
|
/** Called beside whole-layer take, before assembly or any output emission. */
|
|
108
121
|
export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleConfig, configPath: string, setup: SetupPainting | undefined, receipts: ReceiptLedger, sourcePath?: string): Runs {
|
|
109
|
-
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeRegion => '
|
|
122
|
+
const declarations = (cfg.assemble.take ?? []).filter((item): item is TakeRegion => 'seed' in item);
|
|
110
123
|
if (declarations.length === 0) return runs;
|
|
111
124
|
const tolerance = setup?.rgb_tolerance;
|
|
112
125
|
if (typeof tolerance !== 'number' || !Number.isSafeInteger(tolerance) || tolerance < 0 || tolerance > 255) {
|
|
@@ -126,7 +139,7 @@ export function applyTakenRegions(runs: Runs, painting: Raster, cfg: AssembleCon
|
|
|
126
139
|
const plan = cfg.assemble.plan.find(entry => entry[0] === declaration.part && entry[1] === declaration.run);
|
|
127
140
|
if (plan === undefined) return refuse('ASSEMBLE_REGION_TAKE_PART', at, `requires a plan part named "${declaration.part}" in target run "${declaration.run}"`);
|
|
128
141
|
const key = `${plan[1]}:${plan[2]}`;
|
|
129
|
-
if (seen.has(key) || (cfg.assemble.take ?? []).some(item => 'tags' in item && item.run === plan[1] && item.tags.includes(plan[2]))) {
|
|
142
|
+
if (seen.has(key) || (cfg.assemble.take ?? []).some(item => ('tags' in item && item.run === plan[1] && item.tags.includes(plan[2])) || ('occluder' in item && item.run === plan[1] && (item.tag === plan[2] || item.part === declaration.part)))) {
|
|
130
143
|
return refuse('ASSEMBLE_REGION_TAKE_PART', at, `target ${key} is taken more than once; one region donor or whole-layer donor per target is required`);
|
|
131
144
|
}
|
|
132
145
|
seen.add(key);
|
package/src/takesource.ts
CHANGED
|
@@ -23,6 +23,13 @@ export function takenTransportProblems(transport: TakenLayerTransport, image: Ra
|
|
|
23
23
|
}
|
|
24
24
|
return [];
|
|
25
25
|
}
|
|
26
|
+
export interface TakenLayerSplit {
|
|
27
|
+
occluder: number;
|
|
28
|
+
image: string;
|
|
29
|
+
sha256: string;
|
|
30
|
+
covered_px: number;
|
|
31
|
+
visible_px: number;
|
|
32
|
+
}
|
|
26
33
|
export interface TakenLayerSource {
|
|
27
34
|
run: 'full' | 'head';
|
|
28
35
|
tag: string;
|
|
@@ -34,6 +41,7 @@ export interface TakenLayerSource {
|
|
|
34
41
|
checked_px: number;
|
|
35
42
|
differing_px: 0;
|
|
36
43
|
transport?: TakenLayerTransport;
|
|
44
|
+
split?: TakenLayerSplit;
|
|
37
45
|
}
|
|
38
46
|
export function unionTakenSources(lists: readonly (readonly TakenLayerSource[] | undefined)[]): TakenLayerSource[] {
|
|
39
47
|
const out: TakenLayerSource[] = [];
|
|
@@ -51,7 +59,7 @@ export function takenSourceProblems(value: unknown, at: string): Problem[] {
|
|
|
51
59
|
if (typeof item !== 'object' || item === null || Array.isArray(item)) { fail('each source must be a complete identity receipt'); continue; }
|
|
52
60
|
const o = item as Record<string, unknown>;
|
|
53
61
|
const tag = typeof o.tag === 'string' ? readLayerTag(o.tag) : null;
|
|
54
|
-
if (Object.keys(o).some(k => !keys.includes(k) && k !== 'transport') || keys.some(k => !(k in o)) ||
|
|
62
|
+
if (Object.keys(o).some(k => !keys.includes(k) && k !== 'transport' && k !== 'split') || keys.some(k => !(k in o)) ||
|
|
55
63
|
(o.run !== 'full' && o.run !== 'head') || tag === null || tag.group === 'author' ||
|
|
56
64
|
['run_dir', 'st_input', 'prompt_id'].some(k => typeof o[k] !== 'string' || !(o[k] as string).trim()) ||
|
|
57
65
|
!Number.isSafeInteger(o.seed) || (o.seed as number) < 0 ||
|
|
@@ -72,6 +80,17 @@ export function takenSourceProblems(value: unknown, at: string): Problem[] {
|
|
|
72
80
|
fail('transport filter exact requires unit scale and integer translation; every other map requires bilinear');
|
|
73
81
|
}
|
|
74
82
|
}
|
|
83
|
+
if (o.split !== undefined) {
|
|
84
|
+
const s = o.split as Record<string, unknown> | null;
|
|
85
|
+
const splitFields = ['occluder', 'image', 'sha256', 'covered_px', 'visible_px'];
|
|
86
|
+
if (typeof s !== 'object' || s === null || Array.isArray(s) || Object.keys(s).length !== splitFields.length || splitFields.some(k => !(k in s)) ||
|
|
87
|
+
!Number.isSafeInteger(s.occluder) || (s.occluder as number) < 0 ||
|
|
88
|
+
typeof s.image !== 'string' || !s.image.trim() ||
|
|
89
|
+
typeof s.sha256 !== 'string' || !/^[0-9a-f]{64}$/.test(s.sha256) ||
|
|
90
|
+
['covered_px', 'visible_px'].some(k => !Number.isSafeInteger(s[k]) || (s[k] as number) <= 0)) {
|
|
91
|
+
fail('split requires exactly nonnegative safe integer occluder, nonempty image, lowercase SHA-256 sha256, and positive safe integers covered_px and visible_px');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
75
94
|
const key = JSON.stringify([o.run, o.tag, o.run_dir]);
|
|
76
95
|
if (seen.has(key)) fail(`duplicate source ${key}; each source must appear once`);
|
|
77
96
|
seen.add(key);
|