Skip to content

feat(color): minimal cross-codec CICP/ICC emission policy#19

Closed
lilith wants to merge 1 commit into
feat/metadata-policyfrom
feat/color-signaling
Closed

feat(color): minimal cross-codec CICP/ICC emission policy#19
lilith wants to merge 1 commit into
feat/metadata-policyfrom
feat/color-signaling

Conversation

@lilith
Copy link
Copy Markdown
Member

@lilith lilith commented Jun 1, 2026

Stacked on #17 (feat/metadata-policy). The diff here is color-only — base it on #17, retarget to main after #17 merges.

What

A minimal cross-codec color-signaling production policy in zencodec::color:

  • resolve_color_emit(&SourceColor, &EncodeCapabilities, ColorPolicy) -> ColorPlan — reconciles a source's color description against a target's capabilities and returns ColorPlan { cicp: Option<Cicp>, icc: IccDisposition }.
  • ColorPolicy { Compatibility, Balanced (default), Compact, Verbatim, Custom(ColorFields) } — intent presets; the same meaning whether encoding from pixels or transcoding.
  • Two capability flags split the conflated notion of "CICP works": EncodeCapabilities::cicp_is_format_authority (a conformant decoder honors CICP) vs cicp_safe_sole_carrier (safe to ship CICP-only and drop the ICC — JXL today, per libjxl's want_icc=false; false for AVIF/HEIC/PNG per 2026 ecosystem support).
  • IccRetention gains DropIfCicpRepresentable / DropIfCicpSafeSoleCarrier.

Behavior: under Balanced, derive CICP from an ICC and drop the redundant profile only where CICP is the format's authority and safe as the sole carrier (→ JXL); else keep the ICC (AVIF/PNG keep both). Grayscale and CMYK suppress CICP entirely (an RGB CICP over gray/CMYK pixels would recolor them) and keep the ICC.

Deliberately minimal surface

Only what current transcode (JPEG→JXL) needs. HDR/gain-map/range/rendering-intent dispositions and a warnings-channel notes list were trimmed — every type is #[non_exhaustive], so they re-land additively when a consumer needs them. No cargo feature: gating struct fields the crate constructs itself would fork resolve_color_emit's body; removal is cleaner pre-publish.

Consumers (separate PRs)

  • zenjxl: wired — Metadata::cicp drives the codestream enum color; redundant ICC stripped; the decoder synthesizes an ICC back from the enum (so a profile is still present after decode). End-to-end Display-P3 round-trip test added.
  • zenavif: already emits nclx from meta.cicp.
  • JPEG-in-JXL (lossless recompress) preserves color verbatim via a separate jbrd path — unaffected.
  • HEIC: decode-only (no encoder).

Tests

zencodec lib 466 pass (8 new color), zenjxl 48 (incl. CICP round-trip), zencodecs metadata_conformance 15 (JXL cicp promoted Gap → Ok).

@lilith
Copy link
Copy Markdown
Member Author

lilith commented Jun 1, 2026

Superseded by #21 — the unified scenario-driven encode-emit model replaces this scenario-blind resolve_color_emit surface (the color logic here is ported into emit::resolve_emit, now driven by EmitFacts and reconciled with orientation + metadata in one plan). Branch left on origin for reference.

@lilith lilith closed this Jun 1, 2026
lilith added a commit that referenced this pull request Jun 2, 2026
A pure no_std color-carrier policy: resolve_color_emit(&SourceColor,
&EncodeCapabilities, ColorPolicy) -> ColorPlan{cicp, icc} — no CMS, no codec deps.

Replaces the over-built EmitFacts/EmitIntent/EmitPlan "scenario" model and the
TranscodeEncoder trait, which a 5-codec dogfood + adversarial review + a full
read of zenpixels/zenpipe showed (a) nothing in the pipeline produces the facts
for (decode attaches no color to the buffer; the carrier is a flat Metadata), and
(b) would have forced every codec to depend on every other. The grounded surface
is the shipped #19 shape + the four surviving red-team fixes.

- ColorPolicy { Compatibility, Balanced(default), Compact, Verbatim, Custom };
  ColorPlan { cicp, icc: IccDisposition{KeepSource, SynthesizeFrom, Drop} }.
- EncodeCapabilities: cicp_is_valid_carrier (standardized carrier incl. PNG cICP),
  cicp_safe_sole_carrier (JXL only). IccRetention +DropIfCicpRepresentable,
  +DropIfCicpSafeSoleCarrier. ColorFields::new makes Custom constructible.
- No redundant SynthesizeFrom(sRGB). Lowers to zenpixels_convert::
  finalize_for_output_with; SynthesizeFrom -> icc_profile_for_primaries const-fn
  table (no CMS, no silent drop; sRGB -> None).
- helpers::set_exif_orientation closes the double-rotation hazard (pipeline-applied).

472 lib tests + 16 doctests pass, clippy + fmt clean. Design + rejected
alternatives recorded in docs/color-emit-model.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant