This module defines and operates on standard color spaces.
This module implements the packed RGB _color type.
This module implements the RGB _color type.
8 bit alpha-only color type.
24 bit BGR color type with 8 bits per channel.
32 bit BGR + alpha color type with 8 bits per channel.
32 bit BGR color type with 8 bits per channel.
8 bit luminance-only color type.
16 bit luminance + alpha color type with 8 bits per channel.
24 bit RGB color type with 8 bits per channel.
32 bit RGB + alpha color type with 8 bits per channel.
Floating point RGB + alpha color type.
32 bit RGB color type with 8 bits per channel.
Floating point RGB color type.
16 bit signed UV color type with 8 bits per channel.
24 bit signed UVW color type with 8 bits per channel.
Set of colors defined by X11, adopted by the W3C, SVG, and other popular libraries.
Detect whether T is a color type compatible with std.experimental.color.
Detect whether T is a valid color component type.
Detect whether T can represent a color component.
Create a color from a string.
Create a color from a string.
Convert between color types.
Expressing images:
Images may be expressed in a variety of ways, but a simple way may be to use std.experimental.ndslice to produce simple n-dimensional images.
import std.experimental.color; import std.experimental.ndslice; auto imageBuffer = new RGB8[height*width]; auto image = imageBuffer.sliced(height, width); foreach(ref row; image) { foreach(ref pixel; row) { pixel = Colors.white; } }
Use of ndslice this way allows the use of n-dimentional slices to produce sub-images.
Implement custom color type:
The library is extensible such that users or libraries can easily supply their own custom color formats and expect comprehensive conversion and interaction with any other libraries or code that makes use of std.experimental.color.
The requirement for a user color type is to specify a 'parent' color space, and expose at least a set of conversion functions to/from that parent.
For instance, HSV is a cylindrical representation of RGB colors, so the 'parent' color type in this case is said to be RGB. If your custom color space is not derivative of an existing color space, then you should provide conversion between CIE XYZ, which can most simply express all of human-visible color.
struct HueOnlyColor { alias ParentColor = HSV!float; static To convertColorImpl(To, From)(From color) if (is(From == HueOnlyColor) && isHSx!To) { return To(color.hue, 1.0, 1.0); // assume maximum saturation, maximum lightness } static To convertColorImpl(To, From)(From color) if (isHSx!From && is(To == HueOnlyColor)) { return HueOnlyColor(color.h); // just keep the hue } private: float hue; } static assert(isColor!HueOnlyColor == true, "This is all that is required to create a valid color type");
If your color type has template args, it may also be necessary to produce a third convertColorImpl function that converts between instantiations with different template args.
Copyright (c) 2015, Manu Evans.
This package defines human-visible colors in various formats.
RGB color formats are particularly flexible to express typical RGB image data in a wide variety of common formats without having to write adapters.
It is intended that this library facilitate a common API that allows a variety of image and multimedia libraries to interact more seamlessly, without need for constant conversions between custom, library-defined color data types.
This package pays very careful attention to correctness with respect to color space definitions, and correct handling of color space conversions. For best results, users should also pay careful attention to color space selection when working with color data, and the rest will follow. A crash course on understanding color space can be found at wikipedia.
More information regarding specific color spaces can be found in their respective modules.
All types and functions offered in this package are pure, nothrow, @safe and @nogc. It is intended to be useful by realtime or memory-contrained systems such as video games, games consoles or mobile devices.