AC-Colour-1.1.4: Efficient RGB colour types.

Data.Colour

Description

This module exports all the main interesting parts of the various colour modules. It also provides functions for converting between Colour and Colour8.

It is the general intention that "most" work will be done with Colour, with values converted to Colour8 only as a final step. However, full arithmetic on Colour8 is supported anyway, in case anybody wants to work that way. It is slightly less efficient and flexible, however.

Note that most colour values from external sources are typically colour values in the non-linear sRGB colour space, rather than the linear RGB values handled here. See Data.Colour.Nonlinear for conversion functions.

Synopsis

Documentation

data Colour Source

The main colour type. It stores three channels (red, green and blue) as linear Double values normally ranging from 0 to 1. (0 represents minimum intensity, 1 represents maximum. Black is therefore Colour 0 0 0 and white is Colour 1 1 1.)

The channel values are stored as strict, unboxed fields, so operating on Colours should be quite efficient in time and space.

The Num and Fractional instances provide arithmetic for Colours. Note that (*) acts channel-wise; this is usually what is wanted.

Constructors

Colour 

Fields

red :: !Double
 
green :: !Double
 
blue :: !Double
 

grey :: Double -> ColourSource

Turn a Double into a shade of grey.

cscale :: Double -> Colour -> ColourSource

Scale a Colour by a specified amount. (That is, change the brightness while not affecting the shade.)

clip :: Colour -> ColourSource

Take a Colour and clip all channels to the range 0--1 inclusive. Any value outside that range will be replaced with the nearest endpoint (i.e., 0 for negative numbers, 1 for positive numbers higher than 1). Values inside the range are unaffected.

pack :: (Double, Double, Double) -> ColourSource

Convert a tuple into a Colour.

unpack :: Colour -> (Double, Double, Double)Source

Convert a Colour into a tuple.

cBlack :: ColourSource

Constant: Black.

cWhite :: ColourSource

Constant: White.

cRed :: ColourSource

Constant: Red.

cYellow :: ColourSource

Constant: Yellow.

cGreen :: ColourSource

Constant: Green.

cCyan :: ColourSource

Constant: Cyan.

cBlue :: ColourSource

Constant: Blue.

cMagenta :: ColourSource

Constant: Magenta.

data Colour8 Source

The integral colour. It stores three channels (red, green and blue) as linear Word8 values ranging from 0 to 255. (0 represents minimum intensity, 255 represents maximum. Black is therefore Colour8 0 0 0 and white is Colour8 255 255 255.)

The channel values are stored as strict, unboxed fields, so operating on Colour8s should be quite efficient in time and space.

The Num and Fractional instances provide arithmetic for Colour8s. Note that (*) acts channel-wise; this is usually what is wanted.

Constructors

Colour8 

Fields

red8 :: !Word8
 
green8 :: !Word8
 
blue8 :: !Word8
 

grey8 :: Word8 -> Colour8Source

Convert a Word8 into a shade of grey.

c8scale :: Word8 -> Colour8 -> Colour8Source

Scale a Colour8 by the specified amount. Recall that 0x00 means zero, and 0xFF means one. This means that it is impossible to make a colour brighter, only darker. It also means this operation is modestly inefficient due to the renormalisation steps.

pack8 :: (Word8, Word8, Word8) -> Colour8Source

Convert a tuple to a Colour8.

unpack8 :: Colour8 -> (Word8, Word8, Word8)Source

Convert a Colour8 to a tuple.

c8Black :: Colour8Source

Constant: Black.

c8White :: Colour8Source

Constant: White.

c8Red :: Colour8Source

Constant: Red.

c8Yellow :: Colour8Source

Constant: Yellow.

c8Green :: Colour8Source

Constant: Green.

c8Cyan :: Colour8Source

Constant: Cyan.

c8Blue :: Colour8Source

Constant: Blue.

c8Magenta :: Colour8Source

Constant: Magenta.

cpromote :: Colour8 -> ColourSource

Convert a Colour8 into a Colour. Recall that 0x00 means zero and 0xFF means one; this function will remap such values appropriately.

cdemote :: Colour -> Colour8Source

Convert a Colour into a Colour8. Any values outside the range 0--1 will be wrapped to that range. You may want to run clip before calling this function to prevent this behaviour (unless you know the values can't be outside the permitted range). This function is the exact inverse of cpromote; 0 is mapped to 0x00 and 1 is mapped to 0xFF.