Abstract

Colour manipulation library.

Adapted from the Gloss library by Ben Lippmeier.

Synopsis

module type colour = {
type colour
val from_rgba: f32 -> f32 -> f32 -> f32 -> colour
val to_rgba: colour -> (f32, f32, f32, f32)
}
module argb_colour: colour with colour = u32
module type colourspace = {
include colour
val add: colour -> colour -> colour
val add_linear: colour -> colour -> colour
val mult: colour -> colour -> colour
val scale: colour -> f32 -> colour
val mix: f32 -> colour -> f32 -> colour -> colour
val bright: colour -> colour
val dim: colour -> colour
val light: colour -> colour
val dark: colour -> colour
val black: colour
val red: colour
val green: colour
val blue: colour
val white: colour
val brown: colour
val yellow: colour
val orange: colour
val magenta: colour
val violet: colour
val gray: f32 -> colour
}
module colourspace: (C: colour) -> colourspace with colour = C.colour
module argb: colourspace with colour = argb_colour.colour

Description

module type colour

A colour that can be converted back and forth between an RGBA representation. Not very useful by itself, but using just this interface one can generate a lot of other useful functions via the colourspace parametric module.

type colour
val from_rgba: f32 -> f32 -> f32 -> f32 -> colour

Construct a colour from R, G, B and A channels, each of which must be a floating-point number between 0.0 and 1.0. The concrete representation need not be able to handle the full precision of each channel. Thus, from_rgba and to_rgba need not be inverse of each other (but should be close).

val to_rgba: colour -> (f32, f32, f32, f32)

Convert a colour to four R, G, B and A channels, each of which is a floating-point number between 0.0 and 1.0.

module argb_colour

A colour representation that encodes the four RGBA channels as a byte each in a 32-bit word, using the order A-R-G-B.

module type colourspace

A colour representation and a host of useful functions and constants.

include colour
val add: colour -> colour -> colour

Add RGB components of a color component-wise, then normalise them to the highest resulting one. The alpha components are averaged.

val add_linear: colour -> colour -> colour

Add RGBA components of a color component-wise, capping them at the maximum.

val mult: colour -> colour -> colour
val scale: colour -> f32 -> colour
val mix: f32 -> colour -> f32 -> colour -> colour
val bright: colour -> colour

Brighten 20%.

val dim: colour -> colour

Dim 20%.

val light: colour -> colour

20% lighter.

val dark: colour -> colour

20% darker.

val black: colour
val red: colour
val green: colour
val blue: colour
val white: colour
val brown: colour
val yellow: colour
val orange: colour
val magenta: colour
val violet: colour
val gray: f32 -> colour

Grayness from 0-1.

module colourspace

Given a colour representation, construct a colourspace with all the handy functions and constants.

module argb

An ARGB colour space - simply colourspace applied to argb_colour.