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.
- data Colour = Colour {}
- grey :: Double -> Colour
- cscale :: Double -> Colour -> Colour
- clip :: Colour -> Colour
- pack :: (Double, Double, Double) -> Colour
- unpack :: Colour -> (Double, Double, Double)
- cBlack :: Colour
- cWhite :: Colour
- cRed :: Colour
- cYellow :: Colour
- cGreen :: Colour
- cCyan :: Colour
- cBlue :: Colour
- cMagenta :: Colour
- data Colour8 = Colour8 {}
- grey8 :: Word8 -> Colour8
- c8scale :: Word8 -> Colour8 -> Colour8
- pack8 :: (Word8, Word8, Word8) -> Colour8
- unpack8 :: Colour8 -> (Word8, Word8, Word8)
- c8Black :: Colour8
- c8White :: Colour8
- c8Red :: Colour8
- c8Yellow :: Colour8
- c8Green :: Colour8
- c8Cyan :: Colour8
- c8Blue :: Colour8
- c8Magenta :: Colour8
- cpromote :: Colour8 -> Colour
- cdemote :: Colour -> Colour8
Documentation
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 Colour
s should be quite efficient in time and space.
The Num
and Fractional
instances provide arithmetic for
Colour
s. Note that (*)
acts channel-wise; this is usually what
is wanted.
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.
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 Colour8
s should be quite efficient in time and
space.
The Num
and Fractional
instances provide arithmetic for
Colour8
s. Note that (*)
acts channel-wise; this is usually what
is wanted.
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.
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.