| """Node-map ownership mask (``docs/02`` §9, ``docs/07`` §8 P6). |
| |
| ``node_map.uint32.png`` records, per pixel, the index of the semantic node that |
| owns it (``0`` = background / unowned). The encoding is little-endian ``uint32`` |
| packed into the RGBA channels of a standard PNG — lossless and renderer-version |
| independent. Anti-alias boundaries are resolved by an alpha-aware ownership mask |
| (the highest-alpha node wins, ties break to the lower index), built in the same |
| draw pass as the RGBA canvas in :mod:`renderers.base`. |
| |
| This module exposes the encode/decode helpers and a coverage verdict the P6 gate |
| ("every visible semantic node has node-map coverage") consumes. |
| """ |
|
|
| from __future__ import annotations |
|
|
| from collections.abc import Mapping, Sequence |
|
|
| from .base import ( |
| _encode_uint32_png, |
| decode_uint32_png, |
| ) |
|
|
|
|
| def coverage_verdict( |
| visible_node_ids: Sequence[str], node_pixel_counts: Mapping[str, int] |
| ) -> tuple[bool, list[str]]: |
| """``(all_covered, missing)`` — every visible node needs ≥1 node-map pixel.""" |
| missing = [nid for nid in visible_node_ids if node_pixel_counts.get(nid, 0) <= 0] |
| return (not missing, missing) |
|
|
|
|
| def read_owners(png: bytes) -> object: |
| """Decode a node-map PNG to its ``uint32`` owner-index array.""" |
| return decode_uint32_png(png) |
|
|
|
|
| def index_table(visible_node_ids: Sequence[str]) -> list[str]: |
| """The index→node-id table (index 0 is the background sentinel).""" |
| return ["__background__", *visible_node_ids] |
|
|
|
|
| __all__ = [ |
| "coverage_verdict", |
| "decode_uint32_png", |
| "index_table", |
| "read_owners", |
| ] |
|
|