Skip to content

Extend convert_to_srgb to Display P3 and Rec. 2020 #66

Description

@justin13888

transforms::convert_to_srgb handles the sRGB and linear transfers on BT.709 primaries and returns RawError::Unsupported for anything wider:

requires a color-management engine (not yet implemented)

That gap became reachable now that decode reports a container's real colour space (see the colour-tagging work on feat/gallery-roundtrip-gui). Before, every standard decode was forced to SRGB and this branch was effectively dead; an AVIF or HEIC with a colr nclx box now legitimately decodes as DISPLAY_P3 or REC2020, and a caller asking for sRGB pixels gets an error rather than a conversion.

The conversion itself is short — matrix::rgb_to_xyz_matrix, matrix::bradford_adapt, and transfer::eotf_for all exist in gamut-color 2.0.0 — but two pieces are missing upstream:

  • a ColourPrimaries → chromaticities accessor, needed to build the source matrix from a CICP code point;
  • an oetf_for(TransferCharacteristics) inverse, to encode into the destination transfer.

Both are asked for in visualcommons/gamut#376. Blocked on that; per the Upstream-First Policy the primaries table must not be duplicated into rawshift in the meantime.

Related, not blocked

Encode has the mirror-image gap, which needs no upstream work and can be done independently: an image tagged DISPLAY_P3 or REC2020 is written with a synthesised sRGB profile, because rawshift can only synthesise sRGB and the source carried code points rather than a profile. The right fix is to write the code points through to the output container — a PNG cICP chunk, an AVIF colr nclx box — rather than converting or mislabelling. Documented on profile_to_embed in crates/rawshift-image/src/formats/encode.rs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked-upstreamBlocked on a gamut upstream issueenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions