Skip to content

Commit 014a459

Browse files
committed
[css-color-4] update inlined copy of sample code
1 parent b4ff5d0 commit 014a459

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

css-color-4/Overview.bs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,11 @@ Default Style Rules</h2>
25342534
<em>This section is not normative.</em>
25352535

25362536
<pre class="lang-javascript">
2537-
<!-- imported 4 Mar 2019-->
2537+
<!-- imported 30 Oct 2019-->
2538+
// Sample code for color conversions
2539+
// Conversion can also be done using ICC profiles and a Color Management System
2540+
// For clarity, a library is used for matrix manipulations
2541+
25382542
// sRGB-related functions
25392543

25402544
function lin_sRGB(RGB) {
@@ -2591,21 +2595,21 @@ Default Style Rules</h2>
25912595

25922596

25932597
function lin_P3(RGB) {
2594-
// convert an array of display-p3 RGB values in the range 0.0 - 1.0
2598+
// convert an array of image-p3 RGB values in the range 0.0 - 1.0
25952599
// to linear light (un-companded) form.
25962600

25972601
return lin_sRGB(RGB); // same as sRGB
25982602
}
25992603

26002604
function gam_P3(RGB) {
2601-
// convert an array of linear-light display-p3 RGB in the range 0.0-1.0
2605+
// convert an array of linear-light image-p3 RGB in the range 0.0-1.0
26022606
// to gamma corrected form
26032607

26042608
return gam_sRGB(RGB); // same as sRGB
26052609
}
26062610

26072611
function lin_P3_to_XYZ(rgb) {
2608-
// convert an array of linear-light display-p3 values to CIE XYZ
2612+
// convert an array of linear-light image-p3 values to CIE XYZ
26092613
// using D65 (no chromatic adaptation)
26102614
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
26112615
var M = math.matrix([
@@ -2634,7 +2638,7 @@ Default Style Rules</h2>
26342638
function lin_ProPhoto(RGB) {
26352639
// convert an array of prophoto-rgb values in the range 0.0 - 1.0
26362640
// to linear light (un-companded) form.
2637-
// Transfer curve is gamma 1.0 with a small linear portion
2641+
// Transfer curve is gamma 1.8 with a small linear portion
26382642
return RGB.map(function (val) {
26392643
if (val < 0.031248) {
26402644
return val / 16;
@@ -2647,7 +2651,7 @@ Default Style Rules</h2>
26472651
function gam_ProPhoto(RGB) {
26482652
// convert an array of linear-light prophoto-rgb in the range 0.0-1.0
26492653
// to gamma corrected form
2650-
// Transfer curve is gamma 1.0 with a small linear portion
2654+
// Transfer curve is gamma 1.8 with a small linear portion
26512655
return RGB.map(function (val) {
26522656
if (val > 0.001953) {
26532657
return Math.pow(val, 1/1.8);
@@ -2673,36 +2677,38 @@ Default Style Rules</h2>
26732677
function XYZ_to_lin_ProPhoto(XYZ) {
26742678
// convert XYZ to linear-light prophoto-rgb
26752679
var M = Math.matrix([
2676-
[ 1.3457989731028281, -0.25558010007997534, -0.05110628506753401 ],
2677-
[ -0.5446224939028347, 1.5082327413132781, 0.02053603239147973 ],
2678-
[ 0.0, 0.0, 1.2119675456389454 ]
2680+
[ 1.3457989731028281, -0.25558010007997534, -0.05110628506753401 ],
2681+
[ -0.5446224939028347, 1.5082327413132781, 0.02053603239147973 ],
2682+
[ 0.0, 0.0, 1.2119675456389454 ]
26792683
]);
26802684

26812685
return Math.multiply(M, XYZ).valueOf();
26822686
}
26832687

26842688
// a98-rgb functions
26852689

2686-
function lin_a98-rgb(RGB) {
2690+
function lin_a98rgb(RGB) {
26872691
// convert an array of a98-rgb values in the range 0.0 - 1.0
26882692
// to linear light (un-companded) form.
26892693
return RGB.map(function (val) {
2690-
return Math.pow(val, 563/256);
2694+
return Math.pow(val, 563/256);
26912695
});
26922696
}
26932697

2694-
function gam_a98-rgb(RGB) {
2698+
function gam_a98rgb(RGB) {
26952699
// convert an array of linear-light a98-rgb in the range 0.0-1.0
26962700
// to gamma corrected form
26972701
return RGB.map(function (val) {
26982702
return Math.pow(val, 256/563);
26992703
});
27002704
}
27012705

2702-
function lin_a98-rgb_to_XYZ(rgb) {
2703-
// convert an array of linear-light prophoto-rgb values to CIE XYZ
2706+
function lin_a98rgb_to_XYZ(rgb) {
2707+
// convert an array of linear-light a98-rgb values to CIE XYZ
27042708
// using D50 (so no chromatic adaptation needed afterwards)
27052709
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
2710+
// which has greater numerical precsion than section 4.3.5.3 of
2711+
// https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
27062712
var M = Math.matrix([
27072713
[ 0.5766690429101305, 0.1855582379065463, 0.1882286462349947 ],
27082714
[ 0.29734497525053605, 0.6273635662554661, 0.07529145849399788 ],
@@ -2712,8 +2718,8 @@ Default Style Rules</h2>
27122718
return Math.multiply(M, rgb).valueOf();
27132719
}
27142720

2715-
function XYZ_to_lin_a98-rgb(XYZ) {
2716-
// convert XYZ to linear-light prophoto-rgb
2721+
function XYZ_to_lin_a98rgb(XYZ) {
2722+
// convert XYZ to linear-light a98-rgb
27172723
var M = Math.matrix([
27182724
[ 2.0415879038107465, -0.5650069742788596, -0.34473135077832956 ],
27192725
[ -0.9692436362808795, 1.8759675015077202, 0.04155505740717557 ],
@@ -2726,7 +2732,7 @@ Default Style Rules</h2>
27262732
//Rec. 2020-related functions
27272733

27282734
function lin_2020(RGB) {
2729-
// convert an array of Rec. 2020 RGB values in the range 0.0 - 1.0
2735+
// convert an array of rec-2020 RGB values in the range 0.0 - 1.0
27302736
// to linear light (un-companded) form.
27312737
const α = 1.09929682680944 ;
27322738
const β = 0.018053968510807;
@@ -2742,7 +2748,7 @@ Default Style Rules</h2>
27422748
//check with standard this really is 2.4 and 1/2.4, not 0.45 was wikipedia claims
27432749

27442750
function gam_2020(RGB) {
2745-
// convert an array of linear-light Rec. 2020 RGB in the range 0.0-1.0
2751+
// convert an array of linear-light rec-2020 RGB in the range 0.0-1.0
27462752
// to gamma corrected form
27472753
const α = 1.09929682680944 ;
27482754
const β = 0.018053968510807;
@@ -2757,7 +2763,7 @@ Default Style Rules</h2>
27572763
}
27582764

27592765
function lin_2020_to_XYZ(rgb) {
2760-
// convert an array of linear-light Rec. 2020 values to CIE XYZ
2766+
// convert an array of linear-light rec-2020 values to CIE XYZ
27612767
// using D65 (no chromatic adaptation)
27622768
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
27632769
var M = math.matrix([
@@ -2771,7 +2777,7 @@ Default Style Rules</h2>
27712777
}
27722778

27732779
function XYZ_to_lin_2020(XYZ) {
2774-
// convert XYZ to linear-light Rec. 2020
2780+
// convert XYZ to linear-light rec-2020
27752781
var M = math.matrix([
27762782
[1.7166511879712674, -0.35567078377639233, -0.25336628137365974],
27772783
[-0.6666843518324892, 1.6164812366349395, 0.01576854581391113],

0 commit comments

Comments
 (0)