Skip to content

[css-color-4] Expose Linear-light sRGB as CSS syntax? #6087

@samweinig

Description

@samweinig

Edit 11 Oct 2021 by @svgeesus : much of this issue is now solved, see here for the remaining question. Issue title updated.


CSS Color 4 currently defines the following "RGB-ish" (meaning, using rgb channels, a transfer function to linear, and linear transform to XYZ) color spaces: 'srgb', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec2020'.

In some use cases, it can be useful to have variants of these that are "linear" (meaning, the transfer function is unapplied), "extended" (meaning they are not bounded from 0.0 - 1.0, but rather can extended to Inf in either the positive or negative direction) or "linear and extended" (meaning a combination of the both).

While we certainly could specify the full matrix of all combinations of color spaces with these characteristics, for instance:

srgb
linear-srgb
extended-srgb
linear-extended-srgb

display-p3
linear-display-p3
extended-display-p3
linear-extended-display-p3

(etc, etc...)

An alternate formulation might be to offer CSS functions to transform the color spaces, offering linearize(), extended() functions, so the above could be described as:

srgb -> srgb
linear-srgb -> linearize(srgb)
extended-srgb -> extended(srgb)
linear-extended-srgb -> linearize(extended(srgb)) or extended(linearize(srgb))

display-p3 -> display-p3
linear-display-p3 -> linearize(display-p3)
extended-display-p3 -> extended(display-p3)
linear-extended-display-p3 -> linearize(extended(display-p3)) or extended(linearize(display-p3))

(etc, etc...)

As existing precedent, CoreGraphics, the library used on Apple's platforms for graphics, exposes functions to transform these RGB-ish colorspaces to their "linear", "extended", and "linear and extended" variants via the following functions:

/* Create a linearized copy of the color space if the color space is matrix based.
   Return NULL if otherwise */
CG_EXTERN CGColorSpaceRef  __nullable CGColorSpaceCreateLinearized(CGColorSpaceRef space)
CG_AVAILABLE_STARTING(11.0, 14.0);

/* Create a copy of the color space which uses extended range [-Inf, +Inf] if the color space is
   matrix based. Return NULL if otherwise */
CG_EXTERN CGColorSpaceRef  __nullable CGColorSpaceCreateExtended(CGColorSpaceRef space)
CG_AVAILABLE_STARTING(11.0, 14.0);

/* Create a linearized copy of the color space which uses extended range [-Inf, +Inf]
   if the color space is matrix based. Return NULL if otherwise */
CG_EXTERN CGColorSpaceRef  __nullable CGColorSpaceCreateExtendedLinearized(CGColorSpaceRef space)
CG_AVAILABLE_STARTING(11.0, 14.0);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions