Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
refactor(decontam): the decontam modes off, auto and palette and the --chroma-mode paths rgb and ycbcr are declared once in frames/extract.py as OFF, AUTO, PALETTE = DECONTAM_MODES and CHROMA_RGB, CHROMA_YCBCR = CHROMA_MODES, decontam.DECONTAM_MODES and video.frames.DECONTAM_MODES the same tuple by import, and every --decontam and --chroma-mode choice set, membership check, default, branch and emitted mode reads those names
Soohong Kim009495fb3780
diff --git a/sprite_gen/cli.py b/sprite_gen/cli.pyindex a651353..4e843a7 100644--- a/sprite_gen/cli.py+++ b/sprite_gen/cli.py@@ -73,7 +73,7 @@ def _add_extract(p: argparse.ArgumentParser) -> None:p.add_argument("--fringe-delta", type=float, default=18.0)p.add_argument("--fringe-unmix-reach", type=int, default=None)p.add_argument("--spill-max-fraction", type=float, default=None)- p.add_argument("--decontam", choices=("off", "auto", "palette"), default=None)+ p.add_argument("--decontam", choices=extract.DECONTAM_MODES, default=None)p.add_argument("--segmentation", choices=("components", "projection"), default=None)p.add_argument("--allow-slot-fallback", action="store_true")p.add_argument("--min-used-pixels", type=int, default=None)@@ -179,8 +179,8 @@ def _add_inspect(p: argparse.ArgumentParser) -> None:p.add_argument("--fringe-delta", type=float, default=18.0)p.add_argument("--fringe-unmix-reach", type=int, default=None)p.add_argument("--spill-max-fraction", type=float, default=None)- p.add_argument("--chroma-mode", choices=("rgb", "ycbcr"), default=None)- p.add_argument("--decontam", choices=("off", "auto", "palette"), default=None)+ p.add_argument("--chroma-mode", choices=extract.CHROMA_MODES, default=None)+ p.add_argument("--decontam", choices=extract.DECONTAM_MODES, default=None)p.add_argument("--no-write", action="store_true")diff --git a/sprite_gen/frames/cutout.py b/sprite_gen/frames/cutout.pyindex 83f0c57..023029b 100644--- a/sprite_gen/frames/cutout.py+++ b/sprite_gen/frames/cutout.py@@ -43,6 +43,8 @@ from typing import Anyfrom PIL import Image+from sprite_gen.frames import extract as extract_mod+# Matte defaults converged on a 4-icon reference set (tree/bench/flower/lamp, ivory bg).STRENGTH_DEFAULT = 45 # LO: colour distance at/below which a border pixel is fully backgroundHI_OFFSET = 60 # HI = STRENGTH + HI_OFFSET: distance at/above which a pixel is fully opaque@@ -316,7 +318,7 @@ def _measured_route(image: Image.Image, decontam: str, requested: str) -> tuple["""The measured matte, its stats carrying what was asked for and what the edge pass did."""from sprite_gen.frames.measured_matte import measured_matte- if decontam == "palette":+ if decontam == extract_mod.PALETTE:raise SystemExit(f"cutout: --decontam palette needs a chroma key background (magenta/green); "f"the background was keyed as measured (asked: {requested})")result, stats = measured_matte(image)@@ -324,15 +326,15 @@ def _measured_route(image: Image.Image, decontam: str, requested: str) -> tuple[if requested in KEY_TARGETS:stats["chroma_key"] = list(KEY_TARGETS[requested])stats["chroma_key_painted"] = list(stats["background"])- if decontam == "auto":- stats["decontam"] = {"mode": "auto", "applied": False,+ if decontam == extract_mod.AUTO:+ stats["decontam"] = {"mode": extract_mod.AUTO, "applied": False,"reason": "the measured matte unmixes its own edge against the measured background"}return result, statsdef extract_route(image: Image.Image, kind: str, *, spill_max_fraction: float | None = None,spill_min_tint: float | None = None,- spill_require_hue: bool = False, decontam: str = "off", decontam_fit: str = "still",+ spill_require_hue: bool = False, decontam: str = extract_mod.OFF, decontam_fit: str = "still",decontam_palette: dict[str, Any] | None = None, decontam_edge_band: int = 0,background_key: tuple[int, int, int] | None = None,decontam_history: dict[str, Any] | None = None,@@ -376,7 +378,7 @@ def extract_route(image: Image.Image, kind: str, *, spill_max_fraction: float |if spill_require_hue:extra["spill_require_hue"] = Truedecontam_stats: dict[str, Any] = {}- if decontam != "off":+ if decontam != extract_mod.OFF:extra.update(decontam=decontam, decontam_fit=decontam_fit, decontam_palette=decontam_palette,decontam_stats=decontam_stats, decontam_edge_band=decontam_edge_band,decontam_history=decontam_history)@@ -390,7 +392,7 @@ def extract_route(image: Image.Image, kind: str, *, spill_max_fraction: float |"chroma_key": list(target),"chroma_key_painted": list(painted),}- if decontam != "off":+ if decontam != extract_mod.OFF:stats["decontam"] = decontam_statsreturn result.convert("RGBA"), stats@@ -408,7 +410,7 @@ def cutout(spill_max_fraction: float | None = None,spill_min_tint: float | None = None,spill_require_hue: bool = False,- decontam: str = "off",+ decontam: str = extract_mod.OFF,decontam_fit: str = "still",decontam_palette: dict[str, Any] | None = None,decontam_edge_band: int = 0,@@ -439,7 +441,7 @@ def cutout("""if key not in KEYS:raise SystemExit(f"cutout: unknown key {key!r}; expected one of auto|white|magenta|green|measured")- if decontam not in ("off", "auto", "palette"):+ if decontam not in extract_mod.DECONTAM_MODES:raise SystemExit(f"cutout: unknown decontam {decontam!r}; expected off|auto|palette")image = Image.open(input_path).convert("RGBA")@@ -457,12 +459,12 @@ def cutout(decontam_palette=decontam_palette, decontam_edge_band=decontam_edge_band,decontam_history=decontam_history, measure_unrecognised=measure_unrecognised)else:- if decontam == "palette":+ if decontam == extract_mod.PALETTE:raise SystemExit(f"cutout: --decontam {decontam} needs a chroma key background (magenta/green); "f"{input_path} routed to the white matte, which has no key colour to remove")result, route_stats = _matte_route(image, input_path, strength, band, erode, tolerance)- if decontam == "auto":- route_stats["decontam"] = {"mode": "auto", "applied": False,+ if decontam == extract_mod.AUTO:+ route_stats["decontam"] = {"mode": extract_mod.AUTO, "applied": False,"reason": "the white matte has no key colour to remove"}out_path.parent.mkdir(parents=True, exist_ok=True)@@ -545,8 +547,8 @@ def add_arguments(p: Any) -> None:)p.add_argument("--decontam",- choices=["off", "auto", "palette"],- default="off",+ choices=extract_mod.DECONTAM_MODES,+ default=extract_mod.OFF,help="edge decontamination on chroma routes: re-explain key-tinted edges (hair strands, outlines) ""with the subject's own colours. off (default) keeps the chroma engine's output; auto runs it ""where it applies and records why not elsewhere; palette demands it",@@ -567,7 +569,7 @@ def run(**kwargs: object) -> int:erode=float(kwargs.get("erode", ERODE_DEFAULT)), # type: ignore[arg-type]tolerance=int(kwargs.get("tolerance", CHROMA_TOLERANCE)), # type: ignore[arg-type]white_check_dir=out_path.parent if white_check else None,- decontam=str(kwargs.get("decontam") or "off"),+ decontam=str(kwargs.get("decontam") or extract_mod.OFF),)import jsondiff --git a/sprite_gen/frames/decontam.py b/sprite_gen/frames/decontam.pyindex ed347a0..c2eb38e 100644--- a/sprite_gen/frames/decontam.py+++ b/sprite_gen/frames/decontam.py@@ -135,12 +135,9 @@ from __future__ import annotationsfrom typing import Anyfrom sprite_gen._deps import np-from sprite_gen.frames.extract import (_IN_BAND_UNMIX_KEY_DEPTH, _grow_chebyshev, _grow_into, _key_channel_split,- _key_excess_field)+from sprite_gen.frames.extract import (_IN_BAND_UNMIX_KEY_DEPTH, DECONTAM_MODES, OFF, PALETTE, _grow_chebyshev,+ _grow_into, _key_channel_split, _key_excess_field)-# "palette" runs the pass and fails loud when it cannot; "auto" runs it wherever it applies (a-# chroma key, a subject interior to learn from) and otherwise reports why it did not.-DECONTAM_MODES = ("off", "auto", "palette")DECONTAM_FITS = ("still", "video")BAND_PX = 6 # subject pixels this close (Chebyshev) to the keyed background are re-examined@@ -517,7 +514,7 @@ def palette_from_stats(stats: dict[str, Any]) -> dict[str, Any]:def decontaminate(source_rgb: np.ndarray, keyed: np.ndarray, keyed_mask: np.ndarray,chroma_key: tuple[int, int, int], *, fit: str = "still", alpha_depth: int = 4,- palette: dict[str, Any] | None = None, mode: str = "palette",+ palette: dict[str, Any] | None = None, mode: str = PALETTE,source_alpha: np.ndarray | None = None, edge_band: int = 0,history: dict[str, Any] | None = None) -> tuple[np.ndarray, dict[str, Any]]:"""Re-explain the edge of an already keyed image. Returns (RGBA uint8, stats).@@ -536,12 +533,12 @@ def decontaminate(source_rgb: np.ndarray, keyed: np.ndarray, keyed_mask: np.ndarpass does not apply; `mode="palette"` raises SystemExit there instead."""validate(mode, fit)- if mode == "off":+ if mode == OFF:raise SystemExit("decontam: decontaminate() called with mode 'off'")if palette is None:reason = not_applicable(keyed, keyed_mask, chroma_key)if reason is not None:- if mode == "palette":+ if mode == PALETTE:raise SystemExit(f"decontam: {reason}; run without decontam")if history is not None:history.clear() # a frame left as keyed: the next one has no last frame to hold todiff --git a/sprite_gen/frames/extract.py b/sprite_gen/frames/extract.pyindex 3049774..dac3fcd 100644--- a/sprite_gen/frames/extract.py+++ b/sprite_gen/frames/extract.py@@ -529,6 +529,12 @@ _SPILL_MIN_TINT = 40.0# reference at this same threshold before choosing full correction._SPILL_FULL_MIN_TINT = 8.0DEFAULT_UNMIX_REACH = 4+# The edge decontamination pass after the matte (`sprite_gen.frames.decontam`): "palette" runs the pass and fails loud+# when it cannot; "auto" runs it wherever it applies (a chroma key, a subject interior to learn from) and otherwise+# reports why it did not; "off" leaves the matte as it is.+OFF, AUTO, PALETTE = DECONTAM_MODES = ("off", "auto", "palette")+# The background matting path (`--chroma-mode`, the request's chroma.mode): the RGB engine or chrominance-plane matting.+CHROMA_RGB, CHROMA_YCBCR = CHROMA_MODES = ("rgb", "ycbcr")def hard_key_mask(source_rgb: np.ndarray, alpha: np.ndarray, chroma_key: tuple[int, int, int],@@ -656,7 +662,7 @@ def remove_chroma_background(spill_min_tint: float = _SPILL_MIN_TINT,spill_require_hue: bool = False,background_key: tuple[int, int, int] | None = None,- decontam: str = "off",+ decontam: str = OFF,decontam_fit: str = "still",decontam_palette: dict[str, Any] | None = None,decontam_stats: dict[str, Any] | None = None,@@ -678,14 +684,14 @@ def remove_chroma_background(`decontam_edge_band` keeps the frame edge as the matte left it (`decontaminate`'s `edge_band`),and `decontam_history` is a clip's record of its last frame for the video fit (`decontaminate`'s `history`)."""- if decontam != "off":+ if decontam != OFF:from sprite_gen.frames import decontam as decontam_moduledecontam_module.validate(decontam, decontam_fit)rgba = image.convert("RGBA")width, height = rgba.sizedata = np.array(rgba, dtype=np.uint8) # (H, W, 4); written back at the endsource_rgb = data[..., :3].astype(np.int32)- source_alpha = data[..., 3].copy() if decontam != "off" else None # coverage decontam may give back+ source_alpha = data[..., 3].copy() if decontam != OFF else None # coverage decontam may give backkeyed_channels, unkeyed_channels = _key_channel_split(chroma_key)unseen = 255@@ -840,7 +846,7 @@ def remove_chroma_background()if coverage > 0:data[y, x] = (*despilled, alpha)- if decontam != "off":+ if decontam != OFF:data, stats = decontam_module.decontaminate(source_rgb, data, keyed_mask, chroma_key, fit=decontam_fit,alpha_depth=unmix_reach, palette=decontam_palette, mode=decontam,source_alpha=source_alpha, edge_band=decontam_edge_band,@@ -1180,7 +1186,7 @@ def remove_chroma_background_ycbcr(chroma_key: tuple[int, int, int],warnings: list[str] | None = None,*,- decontam: str = "off",+ decontam: str = OFF,decontam_fit: str = "still",decontam_palette: dict[str, Any] | None = None,decontam_stats: dict[str, Any] | None = None,@@ -1199,7 +1205,7 @@ def remove_chroma_background_ycbcr(over this matte's output; its geometry is the RGB path's hard cut at thedefault `--key-threshold`, so both mattes share one definition of the edge."""- if decontam != "off":+ if decontam != OFF:from sprite_gen.frames import decontam as decontam_moduledecontam_module.validate(decontam, decontam_fit)@@ -1244,7 +1250,7 @@ def remove_chroma_background_ycbcr(out = retry_cleanup_alpha_ycc(out)- if decontam != "off":+ if decontam != OFF:source = np.array(rgba, dtype=np.uint8)source_rgb = source[..., :3].astype(np.int32)painted = detect_background_key_rgb(rgba, chroma_key, DEFAULT_KEY_THRESHOLD)@@ -2844,7 +2850,7 @@ def _build_parser() -> argparse.ArgumentParser:)parser.add_argument("--chroma-mode",- choices=("rgb", "ycbcr"),+ choices=CHROMA_MODES,default=None,help="background matting path; overrides request chroma.mode ""(ycbcr = chrominance-plane matting with border-mode key detection, "@@ -2852,7 +2858,7 @@ def _build_parser() -> argparse.ArgumentParser:)parser.add_argument("--decontam",- choices=("off", "auto", "palette"),+ choices=DECONTAM_MODES,default=None,help="edge decontamination after the matte; overrides request chroma.decontam ""(palette = re-explain key-tinted edges with the subject's own colours, auto = where it "@@ -3206,16 +3212,16 @@ def _run_locked(args: argparse.Namespace, run_dir: Path):chroma_mode = (args.chroma_modeif args.chroma_mode is not None- else str(chroma_config.get("mode", "rgb"))+ else str(chroma_config.get("mode", CHROMA_RGB)))- if chroma_mode not in ("rgb", "ycbcr"):+ if chroma_mode not in CHROMA_MODES:raise SystemExit("chroma.mode must be 'rgb' or 'ycbcr'")decontam_mode = (args.decontamif args.decontam is not None- else str(chroma_config.get("decontam", "off"))+ else str(chroma_config.get("decontam", OFF)))- if decontam_mode not in ("off", "auto", "palette"):+ if decontam_mode not in DECONTAM_MODES:raise SystemExit("chroma.decontam must be 'off', 'auto' or 'palette'")effective_chroma = {**chroma_config,@@ -3224,9 +3230,9 @@ def _run_locked(args: argparse.Namespace, run_dir: Path):"spill_max_fraction": spill_max_fraction,}# Recorded once it is in play, so a run keyed before decontam existed keeps its request bytes.- if decontam_mode != "off" or "decontam" in chroma_config:+ if decontam_mode != OFF or "decontam" in chroma_config:effective_chroma["decontam"] = decontam_mode- decontam_kwargs = {} if decontam_mode == "off" else {"decontam": decontam_mode}+ decontam_kwargs = {} if decontam_mode == OFF else {"decontam": decontam_mode}if effective_chroma != chroma_config:request["chroma"] = effective_chromaatomic_write_text(@@ -3390,7 +3396,7 @@ def _run_locked(args: argparse.Namespace, run_dir: Path):all_errors.append(f"{tag}: missing raw strip {raw_path}")return Nonewith Image.open(raw_path) as opened:- if chroma_mode == "ycbcr":+ if chroma_mode == CHROMA_YCBCR:ycc_notes: list[str] = []strip = remove_chroma_background_ycbcr(opened, chroma_key, ycc_notes, **decontam_kwargs)all_warnings.extend(f"{tag}: {note}" for note in ycc_notes)diff --git a/sprite_gen/gen/__init__.py b/sprite_gen/gen/__init__.pyindex 2bfc803..b09db74 100644--- a/sprite_gen/gen/__init__.py+++ b/sprite_gen/gen/__init__.py@@ -46,6 +46,7 @@ import tempfilefrom pathlib import Pathfrom typing import Any, Callable+from sprite_gen.frames import extract as extract_modfrom sprite_gen.frames.cutout import MAGENTAfrom sprite_gen.spec.runio import atomic_write_textfrom sprite_gen.util.cli_kwargs import namespace_from_kwargs@@ -450,7 +451,7 @@ def generate_image(trim_alpha: bool = False,keep_session: bool = False,workdir: Path | None = None,- decontam: str = "off",+ decontam: str = extract_mod.OFF,layout_guide: bool | str | None = False,) -> GenResult:"""Generate one image and return a GenResult. Raises SystemExit on any failure.@@ -459,9 +460,9 @@ def generate_image(guide_kind = layout_guide_kind(layout_guide)if guide_kind == "ui-kit":ui_kit_guide_size(aspect_ratio)- if decontam not in ("off", "auto", "palette"):+ if decontam not in extract_mod.DECONTAM_MODES:raise SystemExit(f"gen: unknown --decontam {decontam!r}; expected off|auto|palette")- if decontam == "palette" and not transparent:+ if decontam == extract_mod.PALETTE and not transparent:raise SystemExit("gen: --decontam applies to the chroma key of a --transparent image; add --transparent")prompt = (prompt or "").strip()if not prompt:@@ -484,7 +485,7 @@ def generate_image(# The layout guide is an attached image as much as a --ref is: the same step down applies.attached_for_strategy = [*refs, Path(LAYOUT_GUIDE_NAME)] if guide_kind else refsstrategy, strategy_source = resolve_transparency_strategy(backend, alpha_mode, refs=attached_for_strategy)- if decontam == "palette" and strategy != TRANSPARENCY_CHROMA:+ if decontam == extract_mod.PALETTE and strategy != TRANSPARENCY_CHROMA:# before the provider is called: a paid generation must not end in this refusalraise SystemExit(f"gen: --decontam removes a chroma key; this image would use {strategy} alpha ""(pass --alpha-mode chroma to key it instead)")@@ -560,7 +561,7 @@ def generate_image(if strategy_source == STRATEGY_SOURCE_REFS:raw_alpha = chroma_mod.classify_raw_alpha(raw)if raw_alpha["verdict"] == chroma_mod.RAW_ALPHA_REAL:- if decontam != "off":+ if decontam != extract_mod.OFF:# The generation is paid for and its alpha is good: decontam has no key to# remove, so it is skipped and said, not refused (see the refusal before the call).decontam_skipped = {@@ -568,7 +569,7 @@ def generate_image("skipped": f"the raw came back with a transparent background "f"({raw_alpha['alpha_zero_pct']}% alpha 0) and has no key to remove",}- print(f"[gen] {'warning: ' if decontam == 'palette' else ''}--decontam {decontam} skipped: "+ print(f"[gen] {'warning: ' if decontam == extract_mod.PALETTE else ''}--decontam {decontam} skipped: "f"{decontam_skipped['skipped']}", file=sys.stderr)strategy, strategy_source = TRANSPARENCY_NATIVE, STRATEGY_SOURCE_REFS_RAW_ALPHAprint(@@ -734,7 +735,7 @@ def _run(args: argparse.Namespace) -> int:trim_alpha=bool(getattr(args, "trim_alpha", False)),keep_session=args.keep_session,workdir=args.workdir,- decontam=str(getattr(args, "decontam", None) or "off"),+ decontam=str(getattr(args, "decontam", None) or extract_mod.OFF),layout_guide=getattr(args, "layout_guide", None),))payload = result.to_dict()@@ -826,8 +827,8 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:)parser.add_argument("--decontam",- choices=("off", "auto", "palette"),- default="off",+ choices=extract_mod.DECONTAM_MODES,+ default=extract_mod.OFF,help="chroma keying: re-explain key-tinted edges (hair strands, outlines) with the subject's own ""colours after the matte. off (default) publishes the matte as it is; auto runs it where it ""applies (chroma strategy, a subject interior); palette demands it",diff --git a/sprite_gen/gen/chroma.py b/sprite_gen/gen/chroma.pyindex 8a4ed3f..3425fa2 100644--- a/sprite_gen/gen/chroma.py+++ b/sprite_gen/gen/chroma.py@@ -23,6 +23,7 @@ from typing import Anyfrom PIL import Imagefrom sprite_gen._deps import np+from sprite_gen.frames import extract as extract_modfrom sprite_gen.frames.cutout import KEY_TARGETS, MAGENTAfrom sprite_gen.frames.extract import remove_chroma_background_ycbcrfrom sprite_gen.spec.runio import atomic_save_image@@ -193,7 +194,7 @@ def key_transparent(*,key: str = MAGENTA,white_check: Path | None = None,- decontam: str = "off",+ decontam: str = extract_mod.OFF,) -> dict[str, Any]:"""Key a chroma-background PNG to a clean transparent RGBA PNG.@@ -220,7 +221,7 @@ def key_transparent(warnings: list[str] = []decontam_stats: dict[str, Any] = {}# the default call keeps its pre-decontam signature, so a caller's matte stand-in still fits- extra = {} if decontam == "off" else {"decontam": decontam, "decontam_stats": decontam_stats}+ extra = {} if decontam == extract_mod.OFF else {"decontam": decontam, "decontam_stats": decontam_stats}image = remove_chroma_background_ycbcr(source, KEYS[key]["target"], warnings, **extra)pixels = image.load()width, height = image.size@@ -260,7 +261,7 @@ def key_transparent(}if warnings:stats["warnings"] = warnings- if decontam != "off":+ if decontam != extract_mod.OFF:stats["decontam"] = decontam_statsif white_check is not None:stats["white_check"] = str(white_check)diff --git a/sprite_gen/qa/inspect.py b/sprite_gen/qa/inspect.pyindex fc12158..a3232ab 100644--- a/sprite_gen/qa/inspect.py+++ b/sprite_gen/qa/inspect.py@@ -41,8 +41,8 @@ def _build_parser() -> argparse.ArgumentParser:parser.add_argument("--fringe-delta", type=float, default=18.0)parser.add_argument("--fringe-unmix-reach", type=int, default=None)parser.add_argument("--spill-max-fraction", type=float, default=None)- parser.add_argument("--chroma-mode", choices=("rgb", "ycbcr"), default=None)- parser.add_argument("--decontam", choices=("off", "auto", "palette"), default=None)+ parser.add_argument("--chroma-mode", choices=extract.CHROMA_MODES, default=None)+ parser.add_argument("--decontam", choices=extract.DECONTAM_MODES, default=None)parser.add_argument("--no-write", action="store_true")return parser@@ -88,7 +88,7 @@ def _strip_for_state(run_dir: Path, request: dict[str, Any], state: str, args: aif not raw_path.is_file():return Nonechroma_config = dict(request.get("chroma") or {})- chroma_mode = args.chroma_mode if args.chroma_mode is not None else str(chroma_config.get("mode", "rgb"))+ chroma_mode = args.chroma_mode if args.chroma_mode is not None else str(chroma_config.get("mode", extract.CHROMA_RGB))chroma_key = tuple(int(value) for value in request["chroma_key"]["rgb"])unmix_reach = (args.fringe_unmix_reach@@ -100,10 +100,10 @@ def _strip_for_state(run_dir: Path, request: dict[str, Any], state: str, args: aif args.spill_max_fraction is not Noneelse float(chroma_config.get("spill_max_fraction", 0.005)))- decontam = args.decontam if args.decontam is not None else str(chroma_config.get("decontam", "off"))- decontam_kwargs = {} if decontam == "off" else {"decontam": decontam}+ decontam = args.decontam if args.decontam is not None else str(chroma_config.get("decontam", extract.OFF))+ decontam_kwargs = {} if decontam == extract.OFF else {"decontam": decontam}with Image.open(raw_path) as opened:- if chroma_mode == "ycbcr":+ if chroma_mode == extract.CHROMA_YCBCR:notes: list[str] = []return extract.remove_chroma_background_ycbcr(opened, chroma_key, notes, **decontam_kwargs)return extract.remove_chroma_background(diff --git a/sprite_gen/video/effect.py b/sprite_gen/video/effect.pyindex a8346f9..9801fb0 100644--- a/sprite_gen/video/effect.py+++ b/sprite_gen/video/effect.py@@ -27,6 +27,7 @@ def brightness_alpha(image: Image.Image) -> Image.Image:def key_frames(files: list[Path], directory: Path) -> dict[str, Any]:+ from sprite_gen.frames import extractif not files:raise SystemExit("video-frames: no frames to convert")directory.mkdir(parents=True, exist_ok=True)@@ -43,7 +44,7 @@ def key_frames(files: list[Path], directory: Path) -> dict[str, Any]:"alpha_zero_pct_min": min(r["alpha_zero_pct"] for r in rows),"alpha_zero_pct_max": max(r["alpha_zero_pct"] for r in rows),"specks": {"dropped": 0, "frames": 0, "policy": "off"},- "edge_contacts": [], "edge_policy": "off", "decontam": {"mode": "off", "applied_frames": 0},+ "edge_contacts": [], "edge_policy": "off", "decontam": {"mode": extract.OFF, "applied_frames": 0},"warnings": ["Brightness alpha represents emitted light. Dark smoke becomes faint; ""black cannot occlude the scene. Use chroma alpha for opaque smoke."]}diff --git a/sprite_gen/video/frames.py b/sprite_gen/video/frames.pyindex 2fe475c..e12371d 100644--- a/sprite_gen/video/frames.py+++ b/sprite_gen/video/frames.py@@ -125,7 +125,7 @@ SPECK_APART = 0.1# (olive on green), and the pass gives it the subject's colour back. Where it cannot run (a white# key, a subject with no interior) the frames keep the matte's bytes and the report says why;# brightness alpha has no key, so `auto` is off there.-DECONTAM_MODES = ("off", "auto", "palette")+from sprite_gen.frames.extract import DECONTAM_MODES # noqa: E402 — the one declaration, under the name video-set readsDECONTAM_DEFAULT = "auto"DECONTAM_FIT = "video"DECONTAM_STAT_KEYS = ("changed_px", "refit_px", "tint_px", "recovered_px", "unexplained_px", "restored_px", "key_hue_capped_px",diff --git a/tests/frames/test_chroma_decontam.py b/tests/frames/test_chroma_decontam.pyindex 4199823..3068fec 100644--- a/tests/frames/test_chroma_decontam.py+++ b/tests/frames/test_chroma_decontam.py@@ -496,11 +496,42 @@ def test_cli_exposes_the_flag_on_every_entry_point():for argv in (["cutout", "x.png", "--decontam", "palette"],["gen", "--out", "x.png", "--transparent", "--decontam", "palette"],["video-frames", "--clip", "c.mp4", "--out-dir", "o", "--decontam", "palette"],+ ["video-set", "--out-dir", "o", "--decontam", "palette"],["extract", "--run-dir", "r", "--decontam", "palette"],["inspect", "--run-dir", "r", "--decontam", "palette"]):assert parser.parse_args(argv).decontam == "palette"+def _choices_of(flag: str) -> dict[str, object]:+ """`flag`'s choices on every verb and module parser that has it, by parser name."""+ import argparse++ from sprite_gen import cli+ from sprite_gen.frames import extract+ from sprite_gen.qa import inspect++ verbs = next(a for a in cli._build_parser()._actions if isinstance(a, argparse._SubParsersAction)).choices+ parsers = {**verbs, "frames.extract module": extract._build_parser(), "qa.inspect module": inspect._build_parser()}+ return {name: action.choices for name, parser in parsers.items()+ for action in parser._actions if flag in action.option_strings}+++def test_every_decontam_flag_reads_the_one_declaration():+ """Every `--decontam` takes its choices from the one tuple, and the names other modules read it by are that tuple."""+ from sprite_gen.frames import extract++ readers = _choices_of("--decontam")+ assert [name for name, choices in readers.items() if choices is not decontam.DECONTAM_MODES] == [], sorted(readers)+ assert decontam.DECONTAM_MODES is extract.DECONTAM_MODES and frames_mod.DECONTAM_MODES is extract.DECONTAM_MODES+++def test_every_chroma_mode_flag_reads_the_one_declaration():+ from sprite_gen.frames import extract++ readers = _choices_of("--chroma-mode")+ assert [name for name, choices in readers.items() if choices is not extract.CHROMA_MODES] == [], sorted(readers)++# --------------------------------------------------------------------------- gen (YCbCr matte)class _FakeKeyProvider: