Color-0.4.0: Color spaces and conversions between them
Copyright(c) Alexey Kuleshevich 2018-2025
LicenseBSD3
MaintainerAlexey Kuleshevich <lehins@yandex.ru>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Graphics.Color.Space.CIE1976.LAB

Description

 
Synopsis

Constructors for an CIE L*a*b* color space.

pattern LAB :: V3 e -> Color (LAB i) e Source #

pattern ColorLAB :: e -> e -> e -> Color (LAB i) e Source #

pattern ColorLABA :: e -> e -> e -> e -> Color (Alpha (LAB i)) e Source #

Constructor for LAB with alpha channel.

data LAB (i :: k) Source #

CIE L*a*b* color space

It is customary to have CIELAB color channels to be in range of [0, 100], however in this library all values for consistency are kept in a [0, 1] range for floating point precision.

Conversion from XYZ (xyz2lab):

\[ \begin{align} L^\star &= 1.16 \ f\!\left(\frac{Y}{Y_{\mathrm{n}}}\right) - 0.16\\ a^\star &= 5.0 \left(f\!\left(\frac{X}{X_{\mathrm{n}}}\right) - f\!\left(\frac{Y}{Y_{\mathrm{n}}}\right)\right)\\ b^\star &= 2.0 \left(f\!\left(\frac{Y}{Y_{\mathrm{n}}}\right) - f\!\left(\frac{Z}{Z_{\mathrm{n}}}\right)\right) \end{align} \]

Where ft is defined as:

\[ \begin{align} f(t) &= \begin{cases} \sqrt[3]{t} & \text{if } t > \delta^3 \\ \dfrac{t}{3 \delta^2} + \frac{4}{29} & \text{otherwise} \end{cases} \\ \delta &= \tfrac{6}{29} \end{align} \]

Conversion to XYZ (lab2xyz):

\[ \begin{align} X &= X_{\mathrm{n}} f^{-1}\left(\frac{L^\star+0.16}{1.16} + \frac{a^\star}{5.0}\right)\\ Y &= Y_{\mathrm{n}} f^{-1}\left(\frac{L^\star+0.16}{1.16}\right)\\ Z &= Z_{\mathrm{n}} f^{-1}\left(\frac{L^\star+0.16}{1.16} - \frac{b^\star}{2.0}\right)\\ \end{align} \]

Where ift is defined as:

\[ f^{-1}(t) = \begin{cases} t^3 & \text{if } t > \delta \\ 3\delta^2\left(t - \tfrac{4}{29}\right) & \text{otherwise} \end{cases} \]

Instances

Instances details
(Illuminant i, Elevator e, RealFloat e) => ColorSpace (LAB i) (i :: k) e Source # 
Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Associated Types

type BaseModel (LAB i) Source #

type BaseSpace (LAB i) Source #

Methods

toBaseModel :: Color (LAB i) e -> Color (BaseModel (LAB i)) e Source #

fromBaseModel :: Color (BaseModel (LAB i)) e -> Color (LAB i) e Source #

toBaseSpace :: Color (LAB i) e -> Color (BaseSpace (LAB i)) e Source #

fromBaseSpace :: Color (BaseSpace (LAB i)) e -> Color (LAB i) e Source #

luminance :: (Elevator a, RealFloat a) => Color (LAB i) e -> Color (Y i) a Source #

grayscale :: Color (LAB i) e -> Color X e Source #

replaceGrayscale :: Color (LAB i) e -> Color X e -> Color (LAB i) e Source #

applyGrayscale :: Color (LAB i) e -> (Color X e -> Color X e) -> Color (LAB i) e Source #

toColorXYZ :: (Elevator a, RealFloat a) => Color (LAB i) e -> Color (XYZ i) a Source #

fromColorXYZ :: (Elevator a, RealFloat a) => Color (XYZ i) a -> Color (LAB i) e Source #

Foldable (Color (LAB i)) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

fold :: Monoid m => Color (LAB i) m -> m #

foldMap :: Monoid m => (a -> m) -> Color (LAB i) a -> m #

foldMap' :: Monoid m => (a -> m) -> Color (LAB i) a -> m #

foldr :: (a -> b -> b) -> b -> Color (LAB i) a -> b #

foldr' :: (a -> b -> b) -> b -> Color (LAB i) a -> b #

foldl :: (b -> a -> b) -> b -> Color (LAB i) a -> b #

foldl' :: (b -> a -> b) -> b -> Color (LAB i) a -> b #

foldr1 :: (a -> a -> a) -> Color (LAB i) a -> a #

foldl1 :: (a -> a -> a) -> Color (LAB i) a -> a #

toList :: Color (LAB i) a -> [a] #

null :: Color (LAB i) a -> Bool #

length :: Color (LAB i) a -> Int #

elem :: Eq a => a -> Color (LAB i) a -> Bool #

maximum :: Ord a => Color (LAB i) a -> a #

minimum :: Ord a => Color (LAB i) a -> a #

sum :: Num a => Color (LAB i) a -> a #

product :: Num a => Color (LAB i) a -> a #

Traversable (Color (LAB i)) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

traverse :: Applicative f => (a -> f b) -> Color (LAB i) a -> f (Color (LAB i) b) #

sequenceA :: Applicative f => Color (LAB i) (f a) -> f (Color (LAB i) a) #

mapM :: Monad m => (a -> m b) -> Color (LAB i) a -> m (Color (LAB i) b) #

sequence :: Monad m => Color (LAB i) (m a) -> m (Color (LAB i) a) #

Applicative (Color (LAB i)) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

pure :: a -> Color (LAB i) a #

(<*>) :: Color (LAB i) (a -> b) -> Color (LAB i) a -> Color (LAB i) b #

liftA2 :: (a -> b -> c) -> Color (LAB i) a -> Color (LAB i) b -> Color (LAB i) c #

(*>) :: Color (LAB i) a -> Color (LAB i) b -> Color (LAB i) b #

(<*) :: Color (LAB i) a -> Color (LAB i) b -> Color (LAB i) a #

Functor (Color (LAB i)) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

fmap :: (a -> b) -> Color (LAB i) a -> Color (LAB i) b #

(<$) :: a -> Color (LAB i) b -> Color (LAB i) a #

Storable e => Storable (Color (LAB i) e) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

sizeOf :: Color (LAB i) e -> Int #

alignment :: Color (LAB i) e -> Int #

peekElemOff :: Ptr (Color (LAB i) e) -> Int -> IO (Color (LAB i) e) #

pokeElemOff :: Ptr (Color (LAB i) e) -> Int -> Color (LAB i) e -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Color (LAB i) e) #

pokeByteOff :: Ptr b -> Int -> Color (LAB i) e -> IO () #

peek :: Ptr (Color (LAB i) e) -> IO (Color (LAB i) e) #

poke :: Ptr (Color (LAB i) e) -> Color (LAB i) e -> IO () #

(Illuminant i, Elevator e) => Show (Color (LAB i) e) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

showsPrec :: Int -> Color (LAB i) e -> ShowS #

show :: Color (LAB i) e -> String #

showList :: [Color (LAB i) e] -> ShowS #

Eq e => Eq (Color (LAB i) e) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

(==) :: Color (LAB i) e -> Color (LAB i) e -> Bool #

(/=) :: Color (LAB i) e -> Color (LAB i) e -> Bool #

Ord e => Ord (Color (LAB i) e) Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Methods

compare :: Color (LAB i) e -> Color (LAB i) e -> Ordering #

(<) :: Color (LAB i) e -> Color (LAB i) e -> Bool #

(<=) :: Color (LAB i) e -> Color (LAB i) e -> Bool #

(>) :: Color (LAB i) e -> Color (LAB i) e -> Bool #

(>=) :: Color (LAB i) e -> Color (LAB i) e -> Bool #

max :: Color (LAB i) e -> Color (LAB i) e -> Color (LAB i) e #

min :: Color (LAB i) e -> Color (LAB i) e -> Color (LAB i) e #

(Illuminant i, Elevator e) => ColorModel (LAB i) e Source #

CIE1976 LAB color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

Associated Types

type Components (LAB i) e Source #

type ChannelCount (LAB i) :: Nat Source #

type ChannelCount (LAB i) Source # 
Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

type ChannelCount (LAB i) = 3
newtype Color (LAB i) e Source #

Color in CIE L*a*b* color space

Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

newtype Color (LAB i) e = LAB (V3 e)
type BaseModel (LAB i) Source # 
Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

type BaseModel (LAB i) = LAB i
type BaseSpace (LAB i) Source # 
Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

type BaseSpace (LAB i) = LAB i
type Components (LAB i) e Source # 
Instance details

Defined in Graphics.Color.Space.CIE1976.LAB

type Components (LAB i) e = (e, e, e)

Helpers

XYZ to L*a*b*

xyz2lab :: forall i a e. (Illuminant i, Elevator a, Elevator e, RealFloat e) => Color (XYZ i) a -> Color (LAB i) e Source #

ft :: RealFloat a => a -> a Source #

L*a*b* to XYZ

lab2xyz :: forall i a e. (Illuminant i, Elevator e, Elevator a, RealFloat a) => Color (LAB i) e -> Color (XYZ i) a Source #

ift :: (Fractional a, Ord a) => a -> a Source #