{-# OPTIONS_HADDOCK not-home #-}
{-
Copyright (c) 2008, 2009
Russell O'Connor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-}
-- |Provides a /linear/ colour space with the same gamut as
-- "Data.Colour.SRGB".
module Data.Colour.SRGB.Linear
 (Colour, RGB(..)
 ,rgb, toRGB
 ,sRGBGamut
 )
where

import qualified Data.Colour.Internal as Internal(Colour(RGB))
import Data.Colour.Internal (Colour)
import Data.Colour.Chan
import Data.Colour.RGB
import Data.Colour.CIE.Chromaticity
import Data.Colour.CIE.Illuminant (d65)

-- |Constructs a 'Colour' from RGB values using the /linear/ RGB colour
-- with the same gamut as sRGB.
rgb :: Fractional a => a -> a -> a -> Colour a
rgb :: a -> a -> a -> Colour a
rgb a
r a
g a
b = Chan Red a -> Chan Green a -> Chan Blue a -> Colour a
forall a. Chan Red a -> Chan Green a -> Chan Blue a -> Colour a
Internal.RGB (a -> Chan Red a
forall p a. a -> Chan p a
Chan a
r) (a -> Chan Green a
forall p a. a -> Chan p a
Chan a
g) (a -> Chan Blue a
forall p a. a -> Chan p a
Chan a
b)

-- |Return RGB values using the /linear/ RGB colour with the same gamut
-- as sRGB.
toRGB :: Fractional a => Colour a -> RGB a
toRGB :: Colour a -> RGB a
toRGB (Internal.RGB (Chan a
r) (Chan a
g) (Chan a
b)) = a -> a -> a -> RGB a
forall a. a -> a -> a -> RGB a
RGB a
r a
g a
b

-- |This is the gamut for the sRGB colour space.
sRGBGamut :: RGBGamut
sRGBGamut :: RGBGamut
sRGBGamut = RGB (Chromaticity Rational) -> Chromaticity Rational -> RGBGamut
RGBGamut (Chromaticity Rational
-> Chromaticity Rational
-> Chromaticity Rational
-> RGB (Chromaticity Rational)
forall a. a -> a -> a -> RGB a
RGB (Rational -> Rational -> Chromaticity Rational
forall a. Fractional a => a -> a -> Chromaticity a
mkChromaticity Rational
0.64 Rational
0.33)
                         (Rational -> Rational -> Chromaticity Rational
forall a. Fractional a => a -> a -> Chromaticity a
mkChromaticity Rational
0.30 Rational
0.60)
                         (Rational -> Rational -> Chromaticity Rational
forall a. Fractional a => a -> a -> Chromaticity a
mkChromaticity Rational
0.15 Rational
0.06))
                    Chromaticity Rational
forall a. Fractional a => Chromaticity a
d65