Skip to content

Commit 73f4d65

Browse files
committed
[css-color-5] Added sample javascript code for naively converting from device-cmyk
1 parent 6a93bd8 commit 73f4d65

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

css-color-5/Overview.bs

+24
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,30 @@ unless trailing zeroes have been omitted.
35083508
}
35093509
</pre>
35103510

3511+
<!--
3512+
██████ ███████ ████████ ████████
3513+
██ ██ ██ ██ ██ ██ ██
3514+
██ ██ ██ ██ ██ ██
3515+
██ ██ ██ ██ ██ ██████
3516+
██ ██ ██ ██ ██ ██
3517+
██ ██ ██ ██ ██ ██ ██
3518+
██████ ███████ ████████ ████████
3519+
-->
3520+
3521+
<h2 id="color-conversion-code">
3522+
Sample code for Color Conversions</h2>
3523+
3524+
<em>This section is not normative.</em>
3525+
3526+
The naive conversion from device-cmyk is trivial:
3527+
3528+
<pre class="include-code lang-javascript">
3529+
path: naive.js
3530+
highlight: js
3531+
</pre>
3532+
3533+
3534+
35113535
<!--
35123536
██████ ████████ ██████ ██ ██ ████████ ████ ████████ ██ ██
35133537
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██

css-color-5/naive.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function naive(cmyk) {
2+
// naively convert an array of CMYK values
3+
// to sRGB
4+
let [cyan, magenta, yellow, black] = cmyk;
5+
let red = 1 - Math.min(1, cyan * (1 - black) + black);
6+
let green = 1 - Math.min(1, magenta * (1 - black) + black);
7+
let blue = 1 - Math.min(1, yellow * (1 - black) + black);
8+
return [red, green, blue];
9+
}

0 commit comments

Comments
 (0)