/usr/share/doc/libghc-colour-doc/html/src/Data-Colour-RGBSpace-HSL.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 | <?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/RGBSpace/HSL.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>
<a name="line-24"></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'>RGBSpace</span><span class='hs-varop'>.</span><span class='hs-conid'>HSL</span>
<a name="line-25"></a> <span class='hs-layout'>(</span><span class='hs-conid'>RGB</span>
<a name="line-26"></a> <span class='hs-layout'>,</span><span class='hs-varid'>hslView</span>
<a name="line-27"></a> <span class='hs-layout'>,</span><span class='hs-varid'>hue</span><span class='hs-layout'>,</span> <span class='hs-varid'>saturation</span><span class='hs-layout'>,</span> <span class='hs-varid'>lightness</span>
<a name="line-28"></a> <span class='hs-layout'>,</span><span class='hs-varid'>hsl</span>
<a name="line-29"></a> <span class='hs-layout'>)</span>
<a name="line-30"></a><span class='hs-keyword'>where</span>
<a name="line-31"></a>
<a name="line-32"></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-33"></a>
<a name="line-34"></a><a name="hslView"></a><span class='hs-comment'>-- |Returns the HSL (hue-saturation-lightness) coordinates of an 'RGB' triple.</span>
<a name="line-35"></a><span class='hs-comment'>-- See 'hue', 'saturation', and 'lightness'.</span>
<a name="line-36"></a><span class='hs-definition'>hslView</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-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>RGB</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-37"></a><span class='hs-definition'>hslView</span> <span class='hs-varid'>rgb</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>h</span><span class='hs-layout'>,</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span><span class='hs-varid'>l</span><span class='hs-layout'>)</span>
<a name="line-38"></a> <span class='hs-keyword'>where</span>
<a name="line-39"></a> <span class='hs-layout'>(</span><span class='hs-varid'>h</span><span class='hs-layout'>,</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span><span class='hs-varid'>l</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hslsv</span> <span class='hs-varid'>rgb</span>
<a name="line-40"></a>
<a name="line-41"></a><a name="saturation"></a><span class='hs-comment'>-- |Returns the saturation coordinate of an 'RGB' triple for the HSL</span>
<a name="line-42"></a><span class='hs-comment'>-- (hue-saturation-lightness) system.</span>
<a name="line-43"></a><span class='hs-comment'>-- Note: This is different from 'Data.Colour.RGBSpace.HSV.saturation' for</span>
<a name="line-44"></a><span class='hs-comment'>-- the "Data.Colour.RGBSpace.HSV"</span>
<a name="line-45"></a><span class='hs-definition'>saturation</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-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>RGB</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span>
<a name="line-46"></a><span class='hs-definition'>saturation</span> <span class='hs-varid'>rgb</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>s</span>
<a name="line-47"></a> <span class='hs-keyword'>where</span>
<a name="line-48"></a> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hslsv</span> <span class='hs-varid'>rgb</span>
<a name="line-49"></a>
<a name="line-50"></a><a name="lightness"></a><span class='hs-comment'>-- |Returns the lightness coordinate of an 'RGB' triple for the HSL</span>
<a name="line-51"></a><span class='hs-comment'>-- (hue-saturation-lightness) system.</span>
<a name="line-52"></a><span class='hs-definition'>lightness</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-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>RGB</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span>
<a name="line-53"></a><span class='hs-definition'>lightness</span> <span class='hs-varid'>rgb</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span>
<a name="line-54"></a> <span class='hs-keyword'>where</span>
<a name="line-55"></a> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-varid'>l</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span><span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hslsv</span> <span class='hs-varid'>rgb</span>
<a name="line-56"></a>
<a name="line-57"></a><a name="hsl"></a><span class='hs-comment'>-- |Convert HSL (hue-saturation-lightness) coordinates to an 'RGB' value.</span>
<a name="line-58"></a><span class='hs-comment'>-- Hue is expected to be measured in degrees.</span>
<a name="line-59"></a><span class='hs-definition'>hsl</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>RealFrac</span> <span class='hs-varid'>a</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-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'>RGB</span> <span class='hs-varid'>a</span>
<a name="line-60"></a><span class='hs-definition'>hsl</span> <span class='hs-varid'>h</span> <span class='hs-varid'>s</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-varid'>component</span> <span class='hs-varid'>t</span>
<a name="line-61"></a> <span class='hs-keyword'>where</span>
<a name="line-62"></a> <span class='hs-varid'>hk</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>h</span><span class='hs-varop'>/</span><span class='hs-num'>360</span>
<a name="line-63"></a> <span class='hs-varid'>tr</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mod1</span> <span class='hs-layout'>(</span><span class='hs-varid'>hk</span> <span class='hs-varop'>+</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-64"></a> <span class='hs-varid'>tg</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mod1</span> <span class='hs-varid'>hk</span>
<a name="line-65"></a> <span class='hs-varid'>tb</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mod1</span> <span class='hs-layout'>(</span><span class='hs-varid'>hk</span> <span class='hs-comment'>-</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-66"></a> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>RGB</span> <span class='hs-varid'>tr</span> <span class='hs-varid'>tg</span> <span class='hs-varid'>tb</span>
<a name="line-67"></a> <span class='hs-varid'>q</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>l</span> <span class='hs-varop'><</span> <span class='hs-num'>0.5</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</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-varid'>s</span><span class='hs-layout'>)</span>
<a name="line-68"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varop'>+</span> <span class='hs-varid'>s</span> <span class='hs-comment'>-</span> <span class='hs-varid'>l</span><span class='hs-varop'>*</span><span class='hs-varid'>s</span>
<a name="line-69"></a> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>=</span> <span class='hs-num'>2</span><span class='hs-varop'>*</span><span class='hs-varid'>l</span> <span class='hs-comment'>-</span> <span class='hs-varid'>q</span>
<a name="line-70"></a> <span class='hs-varid'>component</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>t</span> <span class='hs-varop'><</span> <span class='hs-num'>1</span><span class='hs-varop'>/</span><span class='hs-num'>6</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>p</span> <span class='hs-varop'>+</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>q</span><span class='hs-comment'>-</span><span class='hs-varid'>p</span><span class='hs-layout'>)</span><span class='hs-varop'>*</span><span class='hs-num'>6</span><span class='hs-varop'>*</span><span class='hs-varid'>t</span><span class='hs-layout'>)</span>
<a name="line-71"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>t</span> <span class='hs-varop'><</span> <span class='hs-num'>1</span><span class='hs-varop'>/</span><span class='hs-num'>2</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>q</span>
<a name="line-72"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>t</span> <span class='hs-varop'><</span> <span class='hs-num'>2</span><span class='hs-varop'>/</span><span class='hs-num'>3</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>p</span> <span class='hs-varop'>+</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>q</span><span class='hs-comment'>-</span><span class='hs-varid'>p</span><span class='hs-layout'>)</span><span class='hs-varop'>*</span><span class='hs-num'>6</span><span class='hs-varop'>*</span><span class='hs-layout'>(</span><span class='hs-num'>2</span><span class='hs-varop'>/</span><span class='hs-num'>3</span><span class='hs-comment'>-</span><span class='hs-varid'>t</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-73"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>p</span>
</pre></body>
</html>
|