Skip to content

Commit e7df394

Browse files
author
Chris Lilley
committed
[css-color-4] less woooly conversion
1 parent f45cc84 commit e7df394

File tree

1 file changed

+42
-46
lines changed

1 file changed

+42
-46
lines changed

css-color-4/Overview.bs

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,8 +2795,8 @@ Device-dependent CMYK Colors: the ''device-cmyk()'' function</h2>
27952795
it is useful to express CMYK colors
27962796
in a device-dependent way.
27972797

2798-
Note: because the actual resulting color is unknown,
2799-
CSS processors will attempt to approximate it.
2798+
Note: because the actual resulting color may be unknown,
2799+
CSS processors may attempt to approximate it.
28002800
This approximation is likely to be visually very far from the actual printed result.
28012801

28022802
The ''device-cmyk()'' function allows authors to specify a color in this way:
@@ -2823,34 +2823,51 @@ Device-dependent CMYK Colors: the ''device-cmyk()'' function</h2>
28232823

28242824
Typically, print-based applications will actually store the used colors as CMYK,
28252825
and send them to the printer in that form.
2826-
<!-- Unfortunately, CSS cannot do that;
2827-
various CSS features require an RGB color,
2828-
so that compositing/blending/etc. can be done. -->
2829-
As such, Device CMYK colors must be converted to an equivalent RGB color.
2826+
However, such colors do not have a colorimetric interpretation,
2827+
and thus cannot be used in gradients, compositing, blending and so on.
2828+
2829+
As such, Device CMYK colors must be converted to an equivalent color.
28302830
This is not trivial, like the conversion from HSL or HWB to RGB;
28312831
the precise conversion depends on the precise characteristics of the output device.
28322832

2833-
<!-- hopelessly handwavy and untestable -->
2834-
If the user agent has information about the output device such that it believes
2835-
it can accurately convert the CMYK color to a correct RGB color,
2836-
the computed value of the ''device-cmyk()'' function must be that RGBA color.
2837-
Otherwise, the computed value must be the fallback color.
2833+
<ol>
2834+
<li>If the user, author, or user-agent stylesheet
2835+
has an ''@color-profile'' definition for device-cmyk,
2836+
and the resource specified by the src descriptor can be retrieved,
2837+
and the resource is a valid CMYK ICC profile,
2838+
and the user agent can process ICC profiles,
2839+
the computed value of the ''device-cmyk()'' function
2840+
must be the Lab value of the CMYK color.</li>
2841+
<li>Otherwise, if a valid fallback color has been specified,
2842+
the computed value of the ''device-cmyk()'' function
2843+
must be that fallback color.</li>
2844+
<li>Otherwise,
2845+
the computed value of the ''device-cmyk()'' function must be
2846+
the sRGB value of the CMYK color,
2847+
as converted with the following naive conversion algorithm.
2848+
</li>
2849+
</ol>
28382850

28392851
<div class='example'>
2840-
For example, the following colors are equivalent
2841-
(under the default conversion listed above):
2852+
For example, with no ''@color-profile'' and no fallback specified,
2853+
the following colors are equivalent, using the naive conversion.
28422854

28432855
<pre class="lang-css">
2844-
color: device-cmyk(0 81% 81% 30%);
2845-
color: rgb(178 34 34);
2846-
color: firebrick;
2856+
color: <span class="swatch" style="--color: rgb(178 34 34)"></span> device-cmyk(0 81% 81% 30%);
2857+
color: <span class="swatch" style="--color: rgb(178 34 34)"></span> rgb(178 34 34);
2858+
color: <span class="swatch" style="--color: rgb(178 34 34)"></span> firebrick;
28472859
</pre>
2860+
</div>
2861+
2862+
<div class='example'>
2863+
With the ''@color-profile'' specified as in the example stylesheet,
2864+
the following colors are equivalent, using colorimetric conversion.
28482865

2849-
Note: these colors might not match precisely
2850-
if the browser knows a more precise conversion between CMYK and RGB colors.
2851-
It's recommended that if authors use <strong>any</strong> CMYK colors in their document,
2852-
that they use <strong>only</strong> CMYK colors in their document
2853-
to avoid any color-matching difficulties.
2866+
<pre class="lang-css">
2867+
color: <span class="swatch" style="--color: rgb(70.690% 26.851% 19.724%)"></span> device-cmyk(0 81% 81% 30%);
2868+
color: <span class="swatch" style="--color: rgb(70.690% 26.851% 19.724%)"></span> lab(45.060% 45.477 35.459)
2869+
color: <span class="swatch" style="--color: rgb(70.690% 26.851% 19.724%)"></span> rgb(70.690% 26.851% 19.724%);
2870+
</pre>
28542871
</div>
28552872

28562873
The naive conversion is necessarily approximate,
@@ -2862,7 +2879,7 @@ Device-dependent CMYK Colors: the ''device-cmyk()'' function</h2>
28622879
<img src="images/macbeth-naive.svg" style="width: 60vmin">
28632880
<figcaption>
28642881
A color checker, used for ensuring color fidelity
2865-
in the print and photographic inductries.
2882+
in the print and photographic industries.
28662883
Averaged measured Lab values are available for each patch.
28672884
The rectangles show the Lab values, converted to sRGB.
28682885
The circles show the Lab values, passed through an ICC profile to convert them to CMYK.
@@ -2871,40 +2888,19 @@ Device-dependent CMYK Colors: the ''device-cmyk()'' function</h2>
28712888
</figure>
28722889

28732890
<h3 id='cmyk-rgb'>
2874-
Converting Between Uncalibrated CMYK and RGB-Based Colors</h3>
2875-
2876-
While most colors defined in this specification are directly compatible with RGBA,
2877-
and thus can be mechanically and consistently converted back and forth with it,
2878-
device-CMYK colors are not directly compatible;
2879-
a given device-CMYK color
2880-
will map to various RGBA colors
2881-
depending on the physical characteristics of the output device.
2882-
2883-
Ideally, the user agent will be aware of the output device's color profiles for RGBA and device-CMYK.
2884-
If this is true,
2885-
then the user agent must convert between device-CMYK and RGBA colors (and vice versa)
2886-
by first converting the color into an appropriate device-independent color space,
2887-
such as CIELab,
2888-
and then converting into the output color space,
2889-
using the appropriate color profiles for each operation.
2890-
2891-
This is not always possible, however.
2892-
In that case, the user agent must use the following naive conversion algorithms.
2891+
Naively Converting Between Uncalibrated CMYK and sRGB-Based Colors</h3>
28932892

28942893
To <dfn export lt="naively convert from CMYK to RGBA | naively converted to RGBA">naively convert from CMYK to RGBA</dfn>:
28952894

2896-
If a fallback color was specified,
2897-
return that color
2898-
(converting it to RGB as well, if necessary).
2899-
Otherwise:
2900-
29012895
<ul class="lang-javascript">
29022896
<li><code>red = 1 - min(1, cyan * (1 - black) + black)</code>
29032897
<li><code>green = 1 - min(1, magenta * (1 - black) + black)</code>
29042898
<li><code>blue = 1 - min(1, yellow * (1 - black) + black)</code>
29052899
<li>Alpha is same as for input color.
29062900
</ul>
29072901

2902+
<!-- nice, but when is RGBA to naive CMYK convesion actually triggered? -->
2903+
29082904
To <dfn lt="naively convert from RGBA to CMYK | naively converted to CMYK">naively convert from RGBA to CMYK</dfn>:
29092905

29102906
<ul class="lang-javascript">

0 commit comments

Comments
 (0)