/usr/share/doc/libghc-colour-doc/html/src/Data-Colour-CIE.html is in libghc-colour-doc 2.3.3-10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>Data/Colour/CIE.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-
<a name="line-2"></a>Copyright (c) 2008, 2009
<a name="line-3"></a>Russell O'Connor
<a name="line-4"></a>
<a name="line-5"></a>Permission is hereby granted, free of charge, to any person obtaining a copy
<a name="line-6"></a>of this software and associated documentation files (the "Software"), to deal
<a name="line-7"></a>in the Software without restriction, including without limitation the rights
<a name="line-8"></a>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
<a name="line-9"></a>copies of the Software, and to permit persons to whom the Software is
<a name="line-10"></a>furnished to do so, subject to the following conditions:
<a name="line-11"></a>
<a name="line-12"></a>The above copyright notice and this permission notice shall be included in
<a name="line-13"></a>all copies or substantial portions of the Software.
<a name="line-14"></a>
<a name="line-15"></a>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
<a name="line-16"></a>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
<a name="line-17"></a>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
<a name="line-18"></a>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
<a name="line-19"></a>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
<a name="line-20"></a>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
<a name="line-21"></a>THE SOFTWARE.
<a name="line-22"></a>-}</span>
<a name="line-23"></a><span class='hs-comment'>-- |Colour operations defined by the International Commission on </span>
<a name="line-24"></a><span class='hs-comment'>-- Illumination (CIE).</span>
<a name="line-25"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Colour</span><span class='hs-varop'>.</span><span class='hs-conid'>CIE</span>
<a name="line-26"></a> <span class='hs-layout'>(</span><span class='hs-conid'>Colour</span>
<a name="line-27"></a> <span class='hs-layout'>,</span><span class='hs-varid'>cieXYZ</span><span class='hs-layout'>,</span> <span class='hs-varid'>cieXYZView</span><span class='hs-layout'>,</span> <span class='hs-varid'>luminance</span>
<a name="line-28"></a> <span class='hs-layout'>,</span><span class='hs-varid'>toCIEXYZ</span> <span class='hs-comment'>-- depricated</span>
<a name="line-29"></a>
<a name="line-30"></a> <span class='hs-layout'>,</span><span class='hs-conid'>Chromaticity</span>
<a name="line-31"></a> <span class='hs-layout'>,</span><span class='hs-varid'>mkChromaticity</span><span class='hs-layout'>,</span> <span class='hs-varid'>chromaCoords</span>
<a name="line-32"></a> <span class='hs-layout'>,</span><span class='hs-varid'>chromaX</span><span class='hs-layout'>,</span> <span class='hs-varid'>chromaY</span><span class='hs-layout'>,</span> <span class='hs-varid'>chromaZ</span>
<a name="line-33"></a> <span class='hs-layout'>,</span><span class='hs-varid'>chromaConvert</span>
<a name="line-34"></a> <span class='hs-layout'>,</span><span class='hs-varid'>chromaColour</span>
<a name="line-35"></a>
<a name="line-36"></a> <span class='hs-layout'>,</span><span class='hs-varid'>lightness</span><span class='hs-layout'>,</span> <span class='hs-varid'>cieLABView</span><span class='hs-layout'>,</span> <span class='hs-varid'>cieLAB</span> <span class='hs-varop'>--cieLuv</span>
<a name="line-37"></a> <span class='hs-layout'>)</span>
<a name="line-38"></a><span class='hs-keyword'>where</span>
<a name="line-39"></a>
<a name="line-40"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>List</span>
<a name="line-41"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Colour</span>
<a name="line-42"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Colour</span><span class='hs-varop'>.</span><span class='hs-conid'>RGB</span>
<a name="line-43"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Colour</span><span class='hs-varop'>.</span><span class='hs-conid'>SRGB</span><span class='hs-varop'>.</span><span class='hs-conid'>Linear</span>
<a name="line-44"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Colour</span><span class='hs-varop'>.</span><span class='hs-conid'>CIE</span><span class='hs-varop'>.</span><span class='hs-conid'>Chromaticity</span>
<a name="line-45"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Colour</span><span class='hs-varop'>.</span><span class='hs-conid'>Matrix</span>
<a name="line-46"></a>
<a name="line-47"></a><a name="cieXYZ"></a><span class='hs-comment'>-- |Construct a 'Colour' from XYZ coordinates for the 2&#176; standard</span>
<a name="line-48"></a><span class='hs-comment'>-- (colourimetric) observer.</span>
<a name="line-49"></a><span class='hs-definition'>cieXYZ</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Fractional</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span>
<a name="line-50"></a><span class='hs-definition'>cieXYZ</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-varid'>z</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>rgb</span> <span class='hs-varid'>r</span> <span class='hs-varid'>g</span> <span class='hs-varid'>b</span>
<a name="line-51"></a> <span class='hs-keyword'>where</span>
<a name="line-52"></a> <span class='hs-keyglyph'>[</span><span class='hs-varid'>r</span><span class='hs-layout'>,</span><span class='hs-varid'>g</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mult</span> <span class='hs-varid'>matrix</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-keyglyph'>]</span>
<a name="line-53"></a> <span class='hs-varid'>matrix</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>map</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>fromRational</span><span class='hs-layout'>)</span> <span class='hs-varid'>xyz2rgb709</span>
<a name="line-54"></a>
<a name="line-55"></a><a name="cieXYZView"></a><span class='hs-comment'>-- |Returns the XYZ colour coordinates for the 2&#176; standard</span>
<a name="line-56"></a><span class='hs-comment'>-- (colourimetric) observer.</span>
<a name="line-57"></a><span class='hs-definition'>cieXYZView</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Fractional</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-58"></a><span class='hs-definition'>cieXYZView</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span>
<a name="line-59"></a> <span class='hs-keyword'>where</span>
<a name="line-60"></a> <span class='hs-conid'>RGB</span> <span class='hs-varid'>r</span> <span class='hs-varid'>g</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toRGB</span> <span class='hs-varid'>c</span>
<a name="line-61"></a> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mult</span> <span class='hs-varid'>matrix</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>r</span><span class='hs-layout'>,</span><span class='hs-varid'>g</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span>
<a name="line-62"></a> <span class='hs-varid'>matrix</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>map</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>fromRational</span><span class='hs-layout'>)</span> <span class='hs-varid'>rgb7092xyz</span>
<a name="line-63"></a>
<a name="line-64"></a><a name="toCIEXYZ"></a><span class='hs-comment'>{-# DEPRECATED toCIEXYZ "`toCIEXYZ' has been renamed `cieXYZView'" #-}</span>
<a name="line-65"></a><span class='hs-definition'>toCIEXYZ</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>cieXYZView</span> <span class='hs-varid'>x</span>
<a name="line-66"></a>
<a name="line-67"></a><a name="luminance"></a><span class='hs-comment'>{- CIE luminance -}</span>
<a name="line-68"></a><span class='hs-comment'>-- |Returns the Y colour coordinate (luminance) for the 2&#176; standard</span>
<a name="line-69"></a><span class='hs-comment'>-- (colourimetric) observer.</span>
<a name="line-70"></a><span class='hs-definition'>luminance</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Fractional</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span>
<a name="line-71"></a><span class='hs-definition'>luminance</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>y</span>
<a name="line-72"></a> <span class='hs-keyword'>where</span>
<a name="line-73"></a> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toCIEXYZ</span> <span class='hs-varid'>c</span>
<a name="line-74"></a>
<a name="line-75"></a><a name="instance%20AffineSpace%20Chromaticity"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>AffineSpace</span> <span class='hs-conid'>Chromaticity</span> <span class='hs-keyword'>where</span>
<a name="line-76"></a> <span class='hs-varid'>affineCombo</span> <span class='hs-varid'>l</span> <span class='hs-varid'>z</span> <span class='hs-keyglyph'>=</span>
<a name="line-77"></a> <span class='hs-varid'>foldl1'</span> <span class='hs-varid'>chromaAdd</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>chromaScale</span> <span class='hs-varid'>w</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-varid'>w</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-layout'>(</span><span class='hs-num'>1</span><span class='hs-comment'>-</span><span class='hs-varid'>total</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span><span class='hs-conop'>:</span><span class='hs-varid'>l</span><span class='hs-keyglyph'>]</span>
<a name="line-78"></a> <span class='hs-keyword'>where</span>
<a name="line-79"></a> <span class='hs-varid'>total</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>sum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>map</span> <span class='hs-varid'>fst</span> <span class='hs-varid'>l</span>
<a name="line-80"></a> <span class='hs-layout'>(</span><span class='hs-conid'>Chroma</span> <span class='hs-varid'>x0</span> <span class='hs-varid'>y0</span><span class='hs-layout'>)</span> <span class='hs-varop'>`chromaAdd`</span> <span class='hs-layout'>(</span><span class='hs-conid'>Chroma</span> <span class='hs-varid'>x1</span> <span class='hs-varid'>y1</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Chroma</span> <span class='hs-layout'>(</span><span class='hs-varid'>x0</span><span class='hs-varop'>+</span><span class='hs-varid'>x1</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>y0</span><span class='hs-varop'>+</span><span class='hs-varid'>y1</span><span class='hs-layout'>)</span>
<a name="line-81"></a> <span class='hs-varid'>s</span> <span class='hs-varop'>`chromaScale`</span> <span class='hs-layout'>(</span><span class='hs-conid'>Chroma</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Chroma</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-varop'>*</span><span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-varop'>*</span><span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-82"></a>
<a name="line-83"></a><a name="chromaColour"></a><span class='hs-comment'>-- |Constructs a colour from the given 'Chromaticity' and 'luminance'.</span>
<a name="line-84"></a><span class='hs-definition'>chromaColour</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Fractional</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span>
<a name="line-85"></a> <span class='hs-conid'>Chromaticity</span> <span class='hs-varid'>a</span>
<a name="line-86"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^ 'luminance'</span>
<a name="line-87"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span>
<a name="line-88"></a><span class='hs-definition'>chromaColour</span> <span class='hs-varid'>ch</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>cieXYZ</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-varop'>*</span><span class='hs-varid'>ch_x</span><span class='hs-layout'>)</span> <span class='hs-varid'>y</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-varop'>*</span><span class='hs-varid'>ch_z</span><span class='hs-layout'>)</span>
<a name="line-89"></a> <span class='hs-keyword'>where</span>
<a name="line-90"></a> <span class='hs-layout'>(</span><span class='hs-varid'>ch_x</span><span class='hs-layout'>,</span> <span class='hs-varid'>ch_y</span><span class='hs-layout'>,</span> <span class='hs-varid'>ch_z</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>chromaCoords</span> <span class='hs-varid'>ch</span>
<a name="line-91"></a> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>y</span><span class='hs-varop'>/</span><span class='hs-varid'>ch_y</span>
<a name="line-92"></a>
<a name="line-93"></a><a name="lightness"></a><span class='hs-comment'>-- |Returns the lightness of a colour with respect to a given white point.</span>
<a name="line-94"></a><span class='hs-comment'>-- Lightness is a perceptually uniform measure.</span>
<a name="line-95"></a><span class='hs-definition'>lightness</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Floating</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Chromaticity</span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^White point</span>
<a name="line-96"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span>
<a name="line-97"></a><span class='hs-definition'>lightness</span> <span class='hs-varid'>white_ch</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-num'>6</span><span class='hs-varop'>/</span><span class='hs-num'>29</span><span class='hs-layout'>)</span><span class='hs-varop'>^</span><span class='hs-num'>3</span> <span class='hs-varop'><</span> <span class='hs-varid'>y'</span> <span class='hs-keyglyph'>=</span> <span class='hs-num'>116</span><span class='hs-varop'>*</span><span class='hs-varid'>y'</span><span class='hs-varop'>**</span><span class='hs-layout'>(</span><span class='hs-num'>1</span><span class='hs-varop'>/</span><span class='hs-num'>3</span><span class='hs-layout'>)</span> <span class='hs-comment'>-</span> <span class='hs-num'>16</span>
<a name="line-98"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-num'>29</span><span class='hs-varop'>/</span><span class='hs-num'>3</span><span class='hs-layout'>)</span><span class='hs-varop'>^</span><span class='hs-num'>3</span><span class='hs-varop'>*</span><span class='hs-varid'>y'</span>
<a name="line-99"></a> <span class='hs-keyword'>where</span>
<a name="line-100"></a> <span class='hs-varid'>white</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>chromaColour</span> <span class='hs-varid'>white_ch</span> <span class='hs-num'>1.0</span>
<a name="line-101"></a> <span class='hs-varid'>y'</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>luminance</span> <span class='hs-varid'>c</span><span class='hs-varop'>/</span><span class='hs-varid'>luminance</span> <span class='hs-varid'>white</span><span class='hs-layout'>)</span>
<a name="line-102"></a>
<a name="line-103"></a><a name="cieLABView"></a><span class='hs-comment'>-- |Returns the CIELAB coordinates of a colour, which is a</span>
<a name="line-104"></a><span class='hs-comment'>-- perceptually uniform colour space.</span>
<a name="line-105"></a><span class='hs-comment'>-- The first coordinate is 'lightness'.</span>
<a name="line-106"></a><span class='hs-comment'>-- If you don't know what white point to use, use</span>
<a name="line-107"></a><span class='hs-comment'>-- 'Data.Colour.CIE.Illuminant.d65'.</span>
<a name="line-108"></a><span class='hs-definition'>cieLABView</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Floating</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Chromaticity</span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^White point</span>
<a name="line-109"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-110"></a><span class='hs-definition'>cieLABView</span> <span class='hs-varid'>white_ch</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>lightness</span> <span class='hs-varid'>white_ch</span> <span class='hs-varid'>c</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span>
<a name="line-111"></a> <span class='hs-keyword'>where</span>
<a name="line-112"></a> <span class='hs-varid'>white</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>chromaColour</span> <span class='hs-varid'>white_ch</span> <span class='hs-num'>1.0</span>
<a name="line-113"></a> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toCIEXYZ</span> <span class='hs-varid'>c</span>
<a name="line-114"></a> <span class='hs-layout'>(</span><span class='hs-varid'>xn</span><span class='hs-layout'>,</span><span class='hs-varid'>yn</span><span class='hs-layout'>,</span><span class='hs-varid'>zn</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toCIEXYZ</span> <span class='hs-varid'>white</span>
<a name="line-115"></a> <span class='hs-layout'>(</span><span class='hs-varid'>fx</span><span class='hs-layout'>,</span> <span class='hs-varid'>fy</span><span class='hs-layout'>,</span> <span class='hs-varid'>fz</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-varop'>/</span><span class='hs-varid'>xn</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-varop'>/</span><span class='hs-varid'>yn</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>z</span><span class='hs-varop'>/</span><span class='hs-varid'>zn</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-116"></a> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-num'>500</span><span class='hs-varop'>*</span><span class='hs-layout'>(</span><span class='hs-varid'>fx</span> <span class='hs-comment'>-</span> <span class='hs-varid'>fy</span><span class='hs-layout'>)</span>
<a name="line-117"></a> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-num'>200</span><span class='hs-varop'>*</span><span class='hs-layout'>(</span><span class='hs-varid'>fy</span> <span class='hs-comment'>-</span> <span class='hs-varid'>fz</span><span class='hs-layout'>)</span>
<a name="line-118"></a> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-num'>6</span><span class='hs-varop'>/</span><span class='hs-num'>29</span><span class='hs-layout'>)</span><span class='hs-varop'>^</span><span class='hs-num'>3</span> <span class='hs-varop'><</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span><span class='hs-varop'>**</span><span class='hs-layout'>(</span><span class='hs-num'>1</span><span class='hs-varop'>/</span><span class='hs-num'>3</span><span class='hs-layout'>)</span>
<a name="line-119"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-num'>841</span><span class='hs-varop'>/</span><span class='hs-num'>108</span><span class='hs-varop'>*</span><span class='hs-varid'>x</span> <span class='hs-varop'>+</span> <span class='hs-num'>4</span><span class='hs-varop'>/</span><span class='hs-num'>29</span>
<a name="line-120"></a>
<a name="line-121"></a><a name="cieLAB"></a><span class='hs-comment'>-- |Returns the colour for given CIELAB coordinates, which is a</span>
<a name="line-122"></a><span class='hs-comment'>-- perceptually uniform colour space.</span>
<a name="line-123"></a><span class='hs-comment'>-- If you don't know what white point to use, use</span>
<a name="line-124"></a><span class='hs-comment'>-- 'Data.Colour.CIE.Illuminant.d65'.</span>
<a name="line-125"></a><span class='hs-definition'>cieLAB</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Floating</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Chromaticity</span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^White point</span>
<a name="line-126"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^L* coordinate (lightness)</span>
<a name="line-127"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^a* coordinate</span>
<a name="line-128"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^b* coordinate</span>
<a name="line-129"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span>
<a name="line-130"></a><span class='hs-definition'>cieLAB</span> <span class='hs-varid'>white_ch</span> <span class='hs-varid'>l</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>cieXYZ</span> <span class='hs-layout'>(</span><span class='hs-varid'>xn</span><span class='hs-varop'>*</span><span class='hs-varid'>transform</span> <span class='hs-varid'>fx</span><span class='hs-layout'>)</span>
<a name="line-131"></a> <span class='hs-layout'>(</span><span class='hs-varid'>yn</span><span class='hs-varop'>*</span><span class='hs-varid'>transform</span> <span class='hs-varid'>fy</span><span class='hs-layout'>)</span>
<a name="line-132"></a> <span class='hs-layout'>(</span><span class='hs-varid'>zn</span><span class='hs-varop'>*</span><span class='hs-varid'>transform</span> <span class='hs-varid'>fz</span><span class='hs-layout'>)</span>
<a name="line-133"></a> <span class='hs-keyword'>where</span>
<a name="line-134"></a> <span class='hs-varid'>white</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>chromaColour</span> <span class='hs-varid'>white_ch</span> <span class='hs-num'>1.0</span>
<a name="line-135"></a> <span class='hs-layout'>(</span><span class='hs-varid'>xn</span><span class='hs-layout'>,</span><span class='hs-varid'>yn</span><span class='hs-layout'>,</span><span class='hs-varid'>zn</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toCIEXYZ</span> <span class='hs-varid'>white</span>
<a name="line-136"></a> <span class='hs-varid'>fx</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fy</span> <span class='hs-varop'>+</span> <span class='hs-varid'>a</span><span class='hs-varop'>/</span><span class='hs-num'>500</span>
<a name="line-137"></a> <span class='hs-varid'>fy</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-varop'>+</span> <span class='hs-num'>16</span><span class='hs-layout'>)</span><span class='hs-varop'>/</span><span class='hs-num'>116</span>
<a name="line-138"></a> <span class='hs-varid'>fz</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fy</span> <span class='hs-comment'>-</span> <span class='hs-varid'>b</span><span class='hs-varop'>/</span><span class='hs-num'>200</span>
<a name="line-139"></a> <span class='hs-varid'>delta</span> <span class='hs-keyglyph'>=</span> <span class='hs-num'>6</span><span class='hs-varop'>/</span><span class='hs-num'>29</span>
<a name="line-140"></a> <span class='hs-varid'>transform</span> <span class='hs-varid'>fa</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>fa</span> <span class='hs-varop'>></span> <span class='hs-varid'>delta</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fa</span><span class='hs-varop'>^</span><span class='hs-num'>3</span>
<a name="line-141"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>fa</span> <span class='hs-comment'>-</span> <span class='hs-num'>16</span><span class='hs-varop'>/</span><span class='hs-num'>116</span><span class='hs-layout'>)</span><span class='hs-varop'>*</span><span class='hs-num'>3</span><span class='hs-varop'>*</span><span class='hs-varid'>delta</span><span class='hs-varop'>^</span><span class='hs-num'>2</span>
<a name="line-142"></a>
<a name="line-143"></a><a name="cieLuv"></a><span class='hs-comment'>-- |Returns the CIELUV coordinates of a colour, which is a</span>
<a name="line-144"></a><span class='hs-comment'>-- perceptually uniform colour space.</span>
<a name="line-145"></a><span class='hs-comment'>-- If you don't know what white point to use, use</span>
<a name="line-146"></a><span class='hs-comment'>-- 'Data.Colour.CIE.Illuminant.d65'.</span>
<a name="line-147"></a><span class='hs-definition'>cieLuv</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Floating</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Chromaticity</span> <span class='hs-varid'>a</span> <span class='hs-comment'>-- ^White point</span>
<a name="line-148"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-149"></a><span class='hs-definition'>cieLuv</span> <span class='hs-varid'>white_ch</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span><span class='hs-layout'>,</span> <span class='hs-num'>13</span><span class='hs-varop'>*</span><span class='hs-varid'>l</span><span class='hs-varop'>*</span><span class='hs-layout'>(</span><span class='hs-varid'>u'</span><span class='hs-comment'>-</span><span class='hs-varid'>un'</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-num'>13</span><span class='hs-varop'>*</span><span class='hs-varid'>l</span><span class='hs-varop'>*</span><span class='hs-layout'>(</span><span class='hs-varid'>v'</span><span class='hs-comment'>-</span><span class='hs-varid'>vn'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-150"></a> <span class='hs-keyword'>where</span>
<a name="line-151"></a> <span class='hs-varid'>white</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>chromaColour</span> <span class='hs-varid'>white_ch</span> <span class='hs-num'>1.0</span>
<a name="line-152"></a> <span class='hs-layout'>(</span><span class='hs-varid'>u'</span><span class='hs-layout'>,</span> <span class='hs-varid'>v'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>u'v'</span> <span class='hs-varid'>c</span>
<a name="line-153"></a> <span class='hs-layout'>(</span><span class='hs-varid'>un'</span><span class='hs-layout'>,</span> <span class='hs-varid'>vn'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>u'v'</span> <span class='hs-varid'>white</span>
<a name="line-154"></a> <span class='hs-varid'>l</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>lightness</span> <span class='hs-varid'>white_ch</span> <span class='hs-varid'>c</span>
<a name="line-155"></a><a name="u'v'"></a><span class='hs-comment'>--------------------------------------------------------------------------</span>
<a name="line-156"></a><span class='hs-comment'>{- not for export -}</span>
<a name="line-157"></a><span class='hs-definition'>u'v'</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Floating</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Colour</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-158"></a><span class='hs-definition'>u'v'</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-num'>4</span><span class='hs-varop'>*</span><span class='hs-varid'>x</span><span class='hs-varop'>/</span><span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-varop'>+</span><span class='hs-num'>15</span><span class='hs-varop'>*</span><span class='hs-varid'>y</span><span class='hs-varop'>+</span><span class='hs-num'>3</span><span class='hs-varop'>*</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-num'>9</span><span class='hs-varop'>*</span><span class='hs-varid'>y</span><span class='hs-varop'>/</span><span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-varop'>+</span><span class='hs-num'>15</span><span class='hs-varop'>*</span><span class='hs-varid'>y</span><span class='hs-varop'>+</span><span class='hs-num'>3</span><span class='hs-varop'>*</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-159"></a> <span class='hs-keyword'>where</span>
<a name="line-160"></a> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toCIEXYZ</span> <span class='hs-varid'>c</span>
<a name="line-161"></a>
<a name="line-162"></a><a name="rgb7092xyz"></a><span class='hs-definition'>rgb7092xyz</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>rgb2xyz</span> <span class='hs-varid'>sRGBGamut</span><span class='hs-layout'>)</span>
<a name="line-163"></a>
<a name="line-164"></a><a name="xyz2rgb709"></a><span class='hs-definition'>xyz2rgb709</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>inverse</span> <span class='hs-varid'>rgb7092xyz</span>
</pre></body>
</html>
|