Krita Uniform Flat-Colouring Skill
Transform clean, finished Krita lineart into an editable, production-ready Krita illustration organized into semantic, uniform single-hex flat-colour layers ready for immediate human artist handoff.
This skill is agent-agnostic: topological segmentation, contour polygon extraction, and uniformity validation are decoupled from Krita transport inside scripts/krita_adapter.py.
Hard Production Scope Boundaries (Stop at Flats)
- Strict Flat-Only Guarantee: Outputs exactly one single target hex RGB per leaf layer (
alpha == 255,opacity = 1.0). - Strictly Forbidden Operations (enforced by
configs/default_config.jsonandKritaAdapter):- NO shading, shadows, ambient occlusion, highlights, rim light, or subsurface blush.
- NO gradients, soft airbrushing, painterly blending (Atsunuri), or specular eye catchlights.
- NO global lighting layer stacks (
multiply,lighten,overlay,add,screen,soft_light,color_dodge). - NO lineart colour-hold recolouring.
- Lineart Preservation: Clones original lineart to a locked, hidden backup layer before adding colour groups. When solid-black garment/accessory silhouettes contain flat interior colours, uses a reversible
transparencymaskrather than erasing or redrawing lineart pixels.
Core Pipeline Workflow
-
Lineart Ingestion & Connected-Component Labeling (
scripts/region_segmentation.py):- Thresholds ink (
gray < 200), closes 1-px stroke pinholes (3x3binary closing), and labels interior regions. - Identifies the exterior silhouette automatically from border-touching background labels (or declarative
exterior_bg_labelsin--spec).
- Thresholds ink (
-
Semantic & Topological Partitioning (
scripts/region_segmentation.py):- Ink-Corridor Material Regions: Isolates dark apparel/accessory bands/straps bounded by
ink & geometry & silhouette, optionally eroding2 pxto produce a reversibleFill_Windowtransparency mask over dark interiors. - Pre/Post Overlays: Isolates bounded sclera, iris, or small cap regions.
- Voronoi EDT Competition: Resolves borderline shadow pockets between adjacent materials (e.g., hair vs. skin, main hair vs. back braid) via Euclidean distance transform.
- 1-px Ink Trapping: Dilates fills
1 pxunderneath bordering ink contours so anti-aliased stroke edges leave zero white halos. - Generic Fallback: Without a semantic
--spec, auto-labels enclosed interior components>= 16 pxinto isolatedFlats/Region_NNlayers and logs smaller/unmapped regions.
- Ink-Corridor Material Regions: Isolates dark apparel/accessory bands/straps bounded by
-
Non-Destructive Hierarchy & Polygon-Contained Brush Sweeps (
scripts/layer_setup.py,scripts/polygon_selection.py,scripts/flat_fill_planner.py):- Builds independent
blending_mode = "normal",inherit_alpha = falselayer groups underneathLineart/. - Converts masks into Krita
select_polygonouter (replace/add) + hole (subtract) calls using the calibrated+0.58 pxshift (SUBPX = 0.58). - Paints solid full-pressure (
1.0), full-opacity (1.0) serpentine brush sweeps using"b) Basic-5 Size"packed into<= 60-editedit_batchchunks (under Krita's64-edit cap). - Sets
alpha_locked = trueon leaf flat layers after filling so artists can immediately shade within boundaries.
- Builds independent
-
Validation & Artist Handoff Report (
scripts/validate_flat_color.py):- Confirms 100% single-hex RGB uniformity across exported opaque pixels.
- Verifies zero exterior spill outside the character silhouette.
- Documents any semi-open or ambiguous anatomical regions (e.g., faint unenclosed fingernails, semi-open tiny nail rims) for manual artist review instead of guessing.
Quick CLI Invocation
python3 skills/krita-flat-colouring/scripts/apply_flat_colors.py \
--lineart path/to/clean_lineart.png \
--spec skills/krita-flat-colouring/examples/sample_region_spec.json \
--batch-dir work/flat_batches \
--diag-out work/flat_diag.png \
--audit-out work/flat_audit.json \
--setup-layers \
--mode dry_run
Execute directly against a live Krita 6.0.4 document:
python3 skills/krita-flat-colouring/scripts/apply_flat_colors.py \
--lineart path/to/clean_lineart.png \
--spec skills/krita-flat-colouring/examples/sample_region_spec.json \
--batch-dir work/flat_batches \
--setup-layers \
--mode http_bridge
Reference Guides & Configs
references/architecture.md— Scope boundaries, module separation, and artist-handoff layer structure.references/region-segmentation.md— Connected-component isolation, Voronoi EDT ties, ink trapping, and declarativeregion_spec.jsonDSL.references/flat-execution-and-layers.md— Polygon hole subtraction,+0.58 pxsweeps,edit_batchpacking, andtransparencymaskwindowing.references/krita-interface.md— Krita 6.0.4 native bridge limits, schema validation, and non-flat runtime guards.references/validation.md— Single-hex uniformity checks, spill containment, and unresolved pocket logging.references/troubleshooting.md— Fixing semi-open leaks, polygon vertex overflows, and bridge errors.configs/default_config.json&configs/layer_hierarchy_template.jsonexamples/workflow_example.md