Skip to content

Commit 376cf1e

Browse files
committed
[css-color] Fix the CMYK -> RGB naive conversion algo.
1 parent 166f4cd commit 376cf1e

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

css-color/Overview.bs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,19 +1732,19 @@ Converting Between CMYK and RGB-Based Colors</h3>
17321732
Otherwise:
17331733

17341734
<ul>
1735-
<li><code>red = 1.0 - min(1.0, cyan + black)</code>
1736-
<li><code>green = 1.0 - min(1.0, magenta + black)</code>
1737-
<li><code>blue = 1.0 - min(1.0, yellow + black)</code>
1735+
<li><code>red = 1 - min(1, cyan * (1 - black) + black)</code>
1736+
<li><code>green = 1 - min(1, magenta * (1 - black) + black)</code>
1737+
<li><code>blue = 1 - min(1, yellow * (1 - black) + black)</code>
17381738
<li>Alpha is same as for input color.
17391739
</ul>
17401740

17411741
To <dfn title="naively convert from RGBA to CMYK | naively converted to CMYK">naively convert from RGBA to CMYK</dfn>:
17421742

17431743
<ul>
1744-
<li>k = 1 - max(r, g, b)
1745-
<li>c = (1 - r - k) / (1 - k), or 0 if k is 1
1746-
<li>m = (1 - g - k) / (1 - k), or 0 if k is 1
1747-
<li>y = (1 - b - k) / (1 - k), or 0 if k is 1
1744+
<li>black = 1 - max(red, green, blue)
1745+
<li>cyan = (1 - red - black) / (1 - black), or 0 if black is 1
1746+
<li>magenta = (1 - green - black) / (1 - black), or 0 if black is 1
1747+
<li>yellow = (1 - blue - black) / (1 - black), or 0 if black is 1
17481748
<li>alpha is the same as the input color
17491749
<li>fallback color must be set to the input color
17501750
</ul>
@@ -2990,9 +2990,10 @@ The CMYKColor Class</h3>
29902990

29912991
<pre>
29922992
function() {
2993-
const r = 1 - Math.min(1, this.c + this.k);
2994-
const g = 1 - Math.min(1, this.m + this.k);
2995-
const b = 1 - Math.min(1, this.y + this.k);
2993+
const k_ = 1 - this.k;
2994+
const r = 1 - Math.min(1, this.c * k_ + this.k);
2995+
const g = 1 - Math.min(1, this.m * k_ + this.k);
2996+
const b = 1 - Math.min(1, this.y * k_ + this.k);
29962997
return new RGBColor(r, g, b, this.a);
29972998
}
29982999
</pre>

css-color/Overview.html

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</p>
8383
<h1 class="p-name no-ref" id=title>CSS Color Module Level 4</h1>
8484
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>Editor’s Draft,
85-
<span class=dt-updated><span class=value-title title=20140714>14 July 2014</span></span></span></h2>
85+
<span class=dt-updated><span class=value-title title=20140715>15 July 2014</span></span></span></h2>
8686
<div data-fill-with=spec-metadata><dl>
8787
<dt>This version:
8888
<dd><a class=u-url href=http://dev.w3.org/csswg/css-color/>http://dev.w3.org/csswg/css-color/</a>
@@ -1884,19 +1884,19 @@ <h3 class="heading settled heading" data-level=9.1 id=cmyk-rgb><span class=secno
18841884
Otherwise:</p>
18851885

18861886
<ul>
1887-
<li><code>red = 1.0 - min(1.0, cyan + black)</code>
1888-
<li><code>green = 1.0 - min(1.0, magenta + black)</code>
1889-
<li><code>blue = 1.0 - min(1.0, yellow + black)</code>
1887+
<li><code>red = 1 - min(1, cyan * (1 - black) + black)</code>
1888+
<li><code>green = 1 - min(1, magenta * (1 - black) + black)</code>
1889+
<li><code>blue = 1 - min(1, yellow * (1 - black) + black)</code>
18901890
<li>Alpha is same as for input color.
18911891
</ul>
18921892

18931893
<p>To <dfn data-dfn-type=dfn data-noexport="" id=naively-convert-from-rgba-to-cmyk title="naively convert from RGBA to CMYK | naively converted to CMYK">naively convert from RGBA to CMYK<a class=self-link href=#naively-convert-from-rgba-to-cmyk></a></dfn>:</p>
18941894

18951895
<ul>
1896-
<li>k = 1 - max(r, g, b)
1897-
<li>c = (1 - r - k) / (1 - k), or 0 if k is 1
1898-
<li>m = (1 - g - k) / (1 - k), or 0 if k is 1
1899-
<li>y = (1 - b - k) / (1 - k), or 0 if k is 1
1896+
<li>black = 1 - max(red, green, blue)
1897+
<li>cyan = (1 - red - black) / (1 - black), or 0 if black is 1
1898+
<li>magenta = (1 - green - black) / (1 - black), or 0 if black is 1
1899+
<li>yellow = (1 - blue - black) / (1 - black), or 0 if black is 1
19001900
<li>alpha is the same as the input color
19011901
<li>fallback color must be set to the input color
19021902
</ul>
@@ -3098,9 +3098,10 @@ <h3 class="heading settled heading" data-level=15.4 id=api-CMYKColor><span class
30983098
Defined as follows in ECMAScript:
30993099

31003100
<pre>function() {
3101-
const r = 1 - Math.min(1, this.c + this.k);
3102-
const g = 1 - Math.min(1, this.m + this.k);
3103-
const b = 1 - Math.min(1, this.y + this.k);
3101+
const k_ = 1 - this.k;
3102+
const r = 1 - Math.min(1, this.c * k_ + this.k);
3103+
const g = 1 - Math.min(1, this.m * k_ + this.k);
3104+
const b = 1 - Math.min(1, this.y * k_ + this.k);
31043105
return new RGBColor(r, g, b, this.a);
31053106
}
31063107
</pre>

0 commit comments

Comments
 (0)