Module Gg.Color
Colors and color profiles.
Color provides some function to operate on color values and basic support for ICC based color profiles to precisely specify how to interpret raw color samples.
References.
- Charles Poynton. Frequently asked questions about color. 2006
- Charles Poynton. A guided tour of color space. 1997
- Bruce MacEvoy. Color vision and modern color models.
- International Color Consortium. ICC.1:2010-12 Image technology colour management - Architecture, profile format, and data structure. 2010.
Constructors, accessors and constants
type t= colorThe type for colors in a device independent RGB color space with an alpha component. The color space is defined by a D65 white point and the ITU-R BT.709 primaries (corresponds to a linearized sRGB space). The alpha component represent the color's opacity ranging from
0., a fully transparent color, to1.a completly opaque one.
type stops= (float * color) listThe type for color stops. A piecewise linear color curve.
val v : float -> float -> float -> float -> colorv r g b ais the linear sRGB color(r, g, b, a)as a color value.
val v_srgb : ?a:float -> float -> float -> float -> colorv r g b ~ais the sRGB color(r, g, b, a)converted to aGgcolor value.
val v_srgbi : ?a:float -> int -> int -> int -> colorv_srgbi r g b ~ais the 24-bit sRGB color(r, g, b, a)converted to aGgcolor value by(v_srgb (float r /. 255.) (float g /. 255.) (float b /. 255.) ~a)
val r : color -> floatr cis the red component ofc.
val g : color -> floatg cis the green component ofc.
val b : color -> floatb cis the blue component ofc.
val a : color -> floata cis the alpha component ofc.
val void : colorvoidis(v 0. 0. 0. 0.)an invisible color.
val black : colorblackis(v 0. 0. 0. 1.)
val gray : ?a:float -> float -> colorgray a gis the sRGB color(g, g, g, a)converted to color a value.
val white : colorwhiteis(v 1. 1. 1. 1.)
val red : colorredis(v 1. 0. 0. 1.)
val green : colorgreenis(v 0. 1. 0. 1.)
val blue : colorblueis(v 0. 0. 1. 1.)
Functions
val blend : color -> color -> colorblend src dstissrcblended overdstusing source over destination alpha blending. See Alvy Ray Smith. Image compositing fundamentals. 1995.
Color conversions
Note. In the following conversions all color spaces carry an alpha component. The alpha component is always left untouched by the conversions.
WARNING. Converting between color spaces may result in out of gamut colors whose components are out of the destination color space expected ranges. The client is responsible to handle these; for values of type color simply clamping these is one option. Currently some conversion do not even round trip due to floating point inaccuracies, see this issue, so it is a good idea to clamp the conversions to color.
sRGB
CIE L*u*v*
type luv= v4The type for colors in the CIE L*u*v* color space with a D65 reference white point and an alpha component. The meaning and range of the components is:
- L* is lightness in the range
0.to100. - u*'s practical range is
-134.to220. - v*'s practical range is
-140.to122.
- L* is lightness in the range
CIE L*C*huv
type lch_uv= v4The type for colors in the CIE L*C*huv color space with a D65 reference white point and an alpha component. This color space is CIE L*u*v* with polar coordinates, the meaning and range of the components is:
- L* is the lightness in the range
0.to100. - C* represents chroma, in the range
0.to260.77in practice. - h represents hue in degrees in the range
0.to2pi.
- L* is the lightness in the range
CIE L*a*b*
type lab= v4The type for colors in the CIE L*a*b* color space with a D50 reference white point and an alpha component. The meaning and range of the components is:
- L* is lightness in the range
0.to100. - a* and b*'s practical range is
-128.to127.
- L* is lightness in the range
CIE L*C*hab
type lch_ab= v4The type for colors in the CIE L*C*h*ab color space with a D50 reference white point and an alpha component. This color space is CIE L*a*b* with polar coordinates, the meaning and range of the components is:
- L* is the lightness in the range
0.to100. - C* represents chroma, in the range
0.to181.02, but less in practice. - h represents hue in degrees in the range
0.to2pi.
- L* is the lightness in the range
Color spaces
type space=[|`XYZ|`Lab|`Luv|`YCbr|`Yxy|`RGB|`Gray|`HSV|`HLS|`CMYK|`CMY|`CLR2|`CLR3|`CLR4|`CLR5|`CLR6|`CLR7|`CLR8|`CLR9|`CLRA|`CLRB|`CLRC|`CLRD|`CLRE|`CLRF]The type for color spaces. These correspond to the ICC v4 supported color space, see the specification, section 7.2.6.
val space_dim : space -> intspace_dim sis the dimension of the color spaces.
val pp_space : Stdlib.Format.formatter -> space -> unitpp_space sprints a textual representation ofsonppf.
Color profiles
type profileThe type for ICC color profiles. A color profile can describe the characteristics of a color space, an input or output device and provide a mapping to a profile connection space (PCS), which is either CIE L*a*b* or XYZ with a D50 white point. For more information about ICC profile consult the ICC FAQ and the ICC v4 specification.
This module defines only a profile for the color space of
colorand a grayscale color space.
val profile_of_icc : string -> profile optionprofile_of_icc sis a profile from the ICC profile byte streams.Noneis returned ifsdoesn't seem to be a ICC profile.Note A profile value is returned if a color space can be extracted, it doesn't guarantee a correct ICC profile byte stream.
val profile_to_icc : profile -> stringprofile_to_icc pisp's ICC profile byte stream.
val profile_dim : profile -> intprofile_space pisspace_dim (profile_space d).
val p_gray_l : profilep_gray_lis a linear gray color profile