AC-Colour-1.1.3: 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.

Synopsis

Documentation

data Colour Source

The Colour type. Stores a red, a green and a blue component as strict, unboxed Double values. (So it should be quite efficient in time and space.) Also provides various class instances for arithmetic, etc. It is generally assumed that each channel will have a value somewhere between 0 and 1 at all times.

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.

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 Colour type. Stores a red, a green and a blue component as strict, unboxed Word8 values. (So it should be quite efficient in time and space.) Also provides various class instances for arithmetic, etc.

Note that 0x00 is assumed to mean zero, and 0xFF to mean one. That means that (*) is slightly slower than you might expect due to the extra steps required for renormalisation; (+) and (-) are still efficient, however.

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.

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.