Color-0.3.3: Color spaces and conversions between them
Copyright(c) Alexey Kuleshevich 2019-2020
LicenseBSD3
MaintainerAlexey Kuleshevich <lehins@yandex.ru>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Graphics.Pixel.ColorSpace

Description

 
Synopsis

Documentation

newtype Pixel cs e Source #

Digital imaging is one of the most common places for a color to be used in. The smallest element in any image is a pixel, which is defined by its color.

Since: 0.1.0

Constructors

Pixel (Color cs e) 

Bundled Patterns

pattern PixelY :: e -> Pixel (Y i) e

Constructor for a pixel with Luminance

Since: 0.1.0

pattern PixelXYZ :: e -> e -> e -> Pixel (XYZ i) e

Constructor for a pixel in CIE1931 XYZ color space

Since: 0.1.0

pattern PixelLAB :: e -> e -> e -> Pixel (LAB i) e

Constructor for a pixel in CIE1976 LAB color space

Since: 0.3.0

pattern PixelRGB :: RedGreenBlue cs (i :: k) => e -> e -> e -> Pixel (cs l) e

Constructor for a pixel in RGB color space.

Since: 0.1.0

pattern PixelHSI :: e -> e -> e -> Pixel (HSI cs) e

Constructor for a pixel in HSI.

Since: 0.1.0

pattern PixelHSL :: e -> e -> e -> Pixel (HSL cs) e

Constructor for a pixel in HSL.

Since: 0.1.0

pattern PixelHSV :: e -> e -> e -> Pixel (HSV cs) e

Constructor for a pixel in HSV.

Since: 0.1.0

pattern PixelCMYK :: e -> e -> e -> e -> Pixel (CMYK cs) e

Constructor for a pixel in CMYK.

Since: 0.1.0

pattern PixelY'CbCr :: e -> e -> e -> Pixel (Y'CbCr cs) e

Constructor for a pixel in Y'CbCr.

Since: 0.1.0

pattern PixelY' :: e -> Pixel (Y' cs) e

Constructor for a pixel with Luma (not to be confused with luminance Y)

Since: 0.1.4

pattern PixelYA :: e -> e -> Pixel (Alpha (Y i)) e

Constructor for a pixel with Luminance and Alpha channel

Since: 0.1.0

pattern PixelXYZA :: e -> e -> e -> e -> Pixel (Alpha (XYZ i)) e

Constructor for a pixel in CIE1931 XYZ color space with Alpha channel

Since: 0.1.0

pattern PixelLABA :: e -> e -> e -> e -> Pixel (Alpha (LAB i)) e

Constructor for a pixel in CIE1976 LAB color space with Alpha channel

Since: 0.3.0

pattern PixelRGBA :: RedGreenBlue cs i => e -> e -> e -> e -> Pixel (Alpha (cs l)) e

Constructor for a pixel in RGB color space with Alpha channel

Since: 0.1.0

pattern PixelHSIA :: e -> e -> e -> e -> Pixel (Alpha (HSI cs)) e

Constructor for a pixel in HSI with alpha channel.

Since: 0.1.0

pattern PixelHSLA :: e -> e -> e -> e -> Pixel (Alpha (HSL cs)) e

Constructor for a pixel in HSL with alpha channel.

Since: 0.1.0

pattern PixelHSVA :: e -> e -> e -> e -> Pixel (Alpha (HSV cs)) e

Constructor for a pixel in HSV with alpha channel.

Since: 0.1.0

pattern PixelCMYKA :: e -> e -> e -> e -> e -> Pixel (Alpha (CMYK cs)) e

Constructor for a pixel in CMYK with alpha channel.

Since: 0.1.0

pattern PixelY'CbCrA :: e -> e -> e -> e -> Pixel (Alpha (Y'CbCr cs)) e

Constructor for a pixel in Y'CbCr with alpha channel.

Since: 0.1.0

pattern PixelY'A :: e -> e -> Pixel (Alpha (Y' cs)) e

Constructor for a pixel with Luma and Alpha channel (not to be confused with luminance Y)

Since: 0.1.4

Instances

Instances details
ColorModel cs e => Vector Vector (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (Pixel cs e) -> m (Vector (Pixel cs e)) #

basicUnsafeThaw :: PrimMonad m => Vector (Pixel cs e) -> m (Mutable Vector (PrimState m) (Pixel cs e)) #

basicLength :: Vector (Pixel cs e) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (Pixel cs e) -> Vector (Pixel cs e) #

basicUnsafeIndexM :: Monad m => Vector (Pixel cs e) -> Int -> m (Pixel cs e) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (Pixel cs e) -> Vector (Pixel cs e) -> m () #

elemseq :: Vector (Pixel cs e) -> Pixel cs e -> b -> b #

ColorModel cs e => MVector MVector (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

basicLength :: MVector s (Pixel cs e) -> Int #

basicUnsafeSlice :: Int -> Int -> MVector s (Pixel cs e) -> MVector s (Pixel cs e) #

basicOverlaps :: MVector s (Pixel cs e) -> MVector s (Pixel cs e) -> Bool #

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (Pixel cs e)) #

basicInitialize :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> m () #

basicUnsafeReplicate :: PrimMonad m => Int -> Pixel cs e -> m (MVector (PrimState m) (Pixel cs e)) #

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> Int -> m (Pixel cs e) #

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> Int -> Pixel cs e -> m () #

basicClear :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> m () #

basicSet :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> Pixel cs e -> m () #

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> MVector (PrimState m) (Pixel cs e) -> m () #

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> MVector (PrimState m) (Pixel cs e) -> m () #

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (Pixel cs e) -> Int -> m (MVector (PrimState m) (Pixel cs e)) #

Functor (Color cs) => Functor (Pixel cs) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

fmap :: (a -> b) -> Pixel cs a -> Pixel cs b #

(<$) :: a -> Pixel cs b -> Pixel cs a #

Applicative (Color cs) => Applicative (Pixel cs) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

pure :: a -> Pixel cs a #

(<*>) :: Pixel cs (a -> b) -> Pixel cs a -> Pixel cs b #

liftA2 :: (a -> b -> c) -> Pixel cs a -> Pixel cs b -> Pixel cs c #

(*>) :: Pixel cs a -> Pixel cs b -> Pixel cs b #

(<*) :: Pixel cs a -> Pixel cs b -> Pixel cs a #

Foldable (Color cs) => Foldable (Pixel cs) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

fold :: Monoid m => Pixel cs m -> m #

foldMap :: Monoid m => (a -> m) -> Pixel cs a -> m #

foldMap' :: Monoid m => (a -> m) -> Pixel cs a -> m #

foldr :: (a -> b -> b) -> b -> Pixel cs a -> b #

foldr' :: (a -> b -> b) -> b -> Pixel cs a -> b #

foldl :: (b -> a -> b) -> b -> Pixel cs a -> b #

foldl' :: (b -> a -> b) -> b -> Pixel cs a -> b #

foldr1 :: (a -> a -> a) -> Pixel cs a -> a #

foldl1 :: (a -> a -> a) -> Pixel cs a -> a #

toList :: Pixel cs a -> [a] #

null :: Pixel cs a -> Bool #

length :: Pixel cs a -> Int #

elem :: Eq a => a -> Pixel cs a -> Bool #

maximum :: Ord a => Pixel cs a -> a #

minimum :: Ord a => Pixel cs a -> a #

sum :: Num a => Pixel cs a -> a #

product :: Num a => Pixel cs a -> a #

Traversable (Color cs) => Traversable (Pixel cs) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

traverse :: Applicative f => (a -> f b) -> Pixel cs a -> f (Pixel cs b) #

sequenceA :: Applicative f => Pixel cs (f a) -> f (Pixel cs a) #

mapM :: Monad m => (a -> m b) -> Pixel cs a -> m (Pixel cs b) #

sequence :: Monad m => Pixel cs (m a) -> m (Pixel cs a) #

Bounded (Color cs e) => Bounded (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

minBound :: Pixel cs e #

maxBound :: Pixel cs e #

Eq (Color cs e) => Eq (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

(==) :: Pixel cs e -> Pixel cs e -> Bool #

(/=) :: Pixel cs e -> Pixel cs e -> Bool #

Floating (Color cs e) => Floating (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

pi :: Pixel cs e #

exp :: Pixel cs e -> Pixel cs e #

log :: Pixel cs e -> Pixel cs e #

sqrt :: Pixel cs e -> Pixel cs e #

(**) :: Pixel cs e -> Pixel cs e -> Pixel cs e #

logBase :: Pixel cs e -> Pixel cs e -> Pixel cs e #

sin :: Pixel cs e -> Pixel cs e #

cos :: Pixel cs e -> Pixel cs e #

tan :: Pixel cs e -> Pixel cs e #

asin :: Pixel cs e -> Pixel cs e #

acos :: Pixel cs e -> Pixel cs e #

atan :: Pixel cs e -> Pixel cs e #

sinh :: Pixel cs e -> Pixel cs e #

cosh :: Pixel cs e -> Pixel cs e #

tanh :: Pixel cs e -> Pixel cs e #

asinh :: Pixel cs e -> Pixel cs e #

acosh :: Pixel cs e -> Pixel cs e #

atanh :: Pixel cs e -> Pixel cs e #

log1p :: Pixel cs e -> Pixel cs e #

expm1 :: Pixel cs e -> Pixel cs e #

log1pexp :: Pixel cs e -> Pixel cs e #

log1mexp :: Pixel cs e -> Pixel cs e #

Fractional (Color cs e) => Fractional (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

(/) :: Pixel cs e -> Pixel cs e -> Pixel cs e #

recip :: Pixel cs e -> Pixel cs e #

fromRational :: Rational -> Pixel cs e #

Num (Color cs e) => Num (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

(+) :: Pixel cs e -> Pixel cs e -> Pixel cs e #

(-) :: Pixel cs e -> Pixel cs e -> Pixel cs e #

(*) :: Pixel cs e -> Pixel cs e -> Pixel cs e #

negate :: Pixel cs e -> Pixel cs e #

abs :: Pixel cs e -> Pixel cs e #

signum :: Pixel cs e -> Pixel cs e #

fromInteger :: Integer -> Pixel cs e #

Ord (Color cs e) => Ord (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

compare :: Pixel cs e -> Pixel cs e -> Ordering #

(<) :: Pixel cs e -> Pixel cs e -> Bool #

(<=) :: Pixel cs e -> Pixel cs e -> Bool #

(>) :: Pixel cs e -> Pixel cs e -> Bool #

(>=) :: Pixel cs e -> Pixel cs e -> Bool #

max :: Pixel cs e -> Pixel cs e -> Pixel cs e #

min :: Pixel cs e -> Pixel cs e -> Pixel cs e #

Show (Color cs e) => Show (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

showsPrec :: Int -> Pixel cs e -> ShowS #

show :: Pixel cs e -> String #

showList :: [Pixel cs e] -> ShowS #

Storable (Color cs e) => Storable (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

sizeOf :: Pixel cs e -> Int #

alignment :: Pixel cs e -> Int #

peekElemOff :: Ptr (Pixel cs e) -> Int -> IO (Pixel cs e) #

pokeElemOff :: Ptr (Pixel cs e) -> Int -> Pixel cs e -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Pixel cs e) #

pokeByteOff :: Ptr b -> Int -> Pixel cs e -> IO () #

peek :: Ptr (Pixel cs e) -> IO (Pixel cs e) #

poke :: Ptr (Pixel cs e) -> Pixel cs e -> IO () #

Default (Color cs e) => Default (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

def :: Pixel cs e #

NFData (Color cs e) => NFData (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

Methods

rnf :: Pixel cs e -> () #

ColorModel cs e => Unbox (Pixel cs e) Source #

Unboxing of a Pixel.

Instance details

Defined in Graphics.Pixel.Internal

newtype MVector s (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

newtype MVector s (Pixel cs e) = MV_Pixel (MVector s (Components cs e))
newtype Vector (Pixel cs e) Source # 
Instance details

Defined in Graphics.Pixel.Internal

newtype Vector (Pixel cs e) = V_Pixel (Vector (Components cs e))

liftPixel :: (Color cs e -> Color cs' e') -> Pixel cs e -> Pixel cs' e' Source #

Apply a function to Pixel's Color

Since: 0.1.0

pixelColor :: Pixel cs e -> Color cs e Source #

Get to the underlying Color

Since: 0.1.4

Conversion

Color space

convertPixel :: forall cs i e cs' i' e'. (ColorSpace cs' i' e', ColorSpace cs i e) => Pixel cs' e' -> Pixel cs e Source #

Convert a pixel from one color space to any other.

>>> :set -XDataKinds
>>> :set -XTypeApplications
>>> px = PixelSRGB @Float 0.0 0.5 1.0
>>> px
<SRGB 'NonLinear:( 0.00000000, 0.50000000, 1.00000000)>
>>> convertPixel @(AdobeRGB 'NonLinear) @_ @Word8 px
<AdobeRGB 'NonLinear:( 71,127,251)>

Since: 0.1.0

toPixelY :: ColorSpace cs i e => Pixel cs e -> Pixel (Y i) e Source #

Compute luminance of a pixel color

Since: 0.1.0

toPixelXYZ :: (ColorSpace cs i e, Elevator a, RealFloat a) => Pixel cs e -> Pixel (XYZ i) a Source #

Convert to CIE1931 XYZ color space, with the same illuminant as the original.

Since: 0.1.0

fromPixelXYZ :: (ColorSpace cs i e, Elevator a, RealFloat a) => Pixel (XYZ i) a -> Pixel cs e Source #

Convert from CIE1931 XYZ color space, with the same illuminant as the target color space.

Since: 0.1.0

toPixelBaseSpace :: (ColorSpace cs i e, bcs ~ BaseSpace cs, ColorSpace bcs i e) => Pixel cs e -> Pixel bcs e Source #

Convert pixel in an alternative representation of color space, to its base color space. Example from CMYK to SRGB

Since: 0.1.0

fromPixelBaseSpace :: (ColorSpace cs i e, bcs ~ BaseSpace cs, ColorSpace bcs i e) => Pixel bcs e -> Pixel cs e Source #

Covert a color space of a pixel into it's alternative representation. Example AdobeRGB to HSI.

Since: 0.1.0

Color model

toPixelBaseModel :: ColorSpace cs i e => Pixel cs e -> Pixel (BaseModel cs) e Source #

Drop all color space information and only keep the values encoded in the fitting color model, which the color space is backed by.

Since: 0.1.0

fromPixelBaseModel :: ColorSpace cs i e => Pixel (BaseModel cs) e -> Pixel cs e Source #

Promote a pixel without color space information to a color space that is backed by the fitting color model

Since: 0.1.0

Precision

toPixel8 :: ColorModel cs e => Pixel cs e -> Pixel cs Word8 Source #

Convert all channels of a pixel to 8bits each, while doing appropriate scaling. See Elevator.

Since: 0.1.0

toPixel16 :: ColorModel cs e => Pixel cs e -> Pixel cs Word16 Source #

Convert all channels of a pixel to 16bits each, while appropriate scaling. See Elevator.

Since: 0.1.0

toPixel32 :: ColorModel cs e => Pixel cs e -> Pixel cs Word32 Source #

Convert all channels of a pixel to 32bits each, while doing appropriate scaling. See Elevator.

Since: 0.1.0

toPixel64 :: ColorModel cs e => Pixel cs e -> Pixel cs Word64 Source #

Convert all channels of a pixel to 64bits each, while doing appropriate scaling. See Elevator.

Since: 0.1.0

toPixelF :: ColorModel cs e => Pixel cs e -> Pixel cs Float Source #

Convert all channels of a pixel to 32bit floating point numers each, while doing appropriate scaling. See Elevator.

Since: 0.1.0

toPixelD :: ColorModel cs e => Pixel cs e -> Pixel cs Double Source #

Convert all channels of a pixel to 64bit floating point numers each, while doing appropriate scaling. See Elevator.

Since: 0.1.0

RGB

toPixelLinearRGB :: (RedGreenBlue cs i, RealFloat e) => Pixel (cs 'NonLinear) e -> Pixel (cs 'Linear) e Source #

Convert non-linear RGB color space into linear one

Since: 0.2.0

fromPixelLinearRGB :: (RedGreenBlue cs i, RealFloat e) => Pixel (cs 'Linear) e -> Pixel (cs 'NonLinear) e Source #

Convert linear RGB color space into a non-linear one

Since: 0.2.0

sRGB color space

pattern PixelSRGB :: e -> e -> e -> Pixel (SRGB 'NonLinear) e Source #

Constructor for a pixel in sRGB color space

Since: 0.1.0

pattern PixelSRGBA :: e -> e -> e -> e -> Pixel (Alpha (SRGB 'NonLinear)) e Source #

Constructor for a pixel in sRGB color space with Alpha channel

Since: 0.1.0

Luma

rgbPixelLuma :: forall cs i e' e. (Luma cs, RedGreenBlue cs i, Elevator e', Elevator e, RealFloat e) => Pixel (cs 'NonLinear) e' -> Pixel (Y' cs) e Source #

Convert an RGB pixel to Y` if it has the weights specified with Luma.

Since: 0.1.4

Re-export of color space