1<?xml version="1.0" encoding="utf-8" ?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 4<head> 5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6<title>Magick++ API: Working with Color</title> 7<link rel="stylesheet" href="magick.css" type="text/css" /> 8</head> 9<body> 10<div class="doc-section"> 11<h1 align="center">Magick::Color</h1> 12<p><a href="Color.html#Color">Color</a> is the base color class in Magick++. It is a simple container class for the pixel red, green, blue, and alpha values scaled to fit ImageMagick's Quantum size. Normally users will instantiate a class derived from Color which supports the color model that fits the needs of the application. The Color class may be constructed directly from an SVG-style color string.</p> 13<h4>Quantum</h4> 14 15The base type used to represent color samples in ImageMagick is the Quantum type. Pixels are represented by a structure of Quantum values. For example, an RGB pixel contains red, green, and blue quantums, while an RGBA pixel contains red, green, blue, and opacity quantums. The maximum value that a Quantum can attain is specified by a constant value represented by the MaxRGB define, which is itself determined by the number of bits in a Quantum. The QuantumDepth build option determines the number of bits in a Quantum. 16 17<h4>Quantum</h4> 18 19Quantum is the internal representation of a pixel in ImageMagick. ImageMagick may be compiled to support 32, 64, or 128 bit pixels of type Quantum. This is controlled by the value of the QuantumDepth define. The default is 32 bit pixels (QuantumDepth=8), which provides the best performance and the least resource consumption. If additional color precision or range is desired, then ImageMagick may be compiled with QuantumDepth=16 or QuantumDepth=32. The following table shows the relationship between QuantumDepth, the type of Quantum, and the overall Quantum size. 20<p align="center" style="margin-bottom: 0cm"><b>Effect Of QuantumDepth Values</b></p> 21<center> 22<table width="361" border="1" cellpadding="2" cellspacing="3"> 23<col width="102" /> 24<col width="121" /> 25<col width="111" /> 26<tr> 27<td width="102"> 28<p align="center"><b>QuantumDepth</b></p></td> 29<td width="121"> 30<p align="center"><b>Quantum Typedef</b></p></td> 31<td width="111"> 32<p align="center"><b>Quantum Size</b></p></td></tr> 33<tr> 34<td width="102"> 35<p align="center">8</p></td> 36<td width="121"> 37<p align="center">unsigned char</p></td> 38<td width="111"> 39<p align="center">32 bits</p></td></tr> 40<tr> 41<td width="102"> 42<p align="center">16</p></td> 43<td width="121"> 44<p align="center">unsigned short</p></td> 45<td width="111"> 46<p align="center">64 bits</p></td></tr> 47<tr> 48<td width="102"> 49<p align="center">32</p></td> 50<td width="121"> 51<p align="center">unsigned int</p></td> 52<td width="111"> 53<p align="center">128 bits</p></td></tr> 54</table></center> 55<h3><a name="Color"></a>Color Class</h3> 56<p>The Color base class is not intended to be used directly. Normally a user will construct a derived class or inherit from this class. Color arguments are must be scaled to fit the Quantum size. The Color class contains a pointer to a Quantum, which may be allocated by the Color class, or may refer to an existing pixel in an image.</p> 57<p>An alternate way to construct the class is via an SVG-compatible color specification string (e.g. Color("red") or Color ("#FF0000")). Since the class may be constructed from a string, convenient strings may be passed in place of an explicit Color object in methods which accept a reference to Color. Color may also be converted to a std::string for convenience in user interfaces, and for saving settings to a text file.</p> 58<div class="viewport"> 59class Color 60{ 61 public: 62 Color ( Quantum red_, 63 Quantum green_, 64 Quantum blue_ ); 65 Color ( Quantum red_, 66 Quantum green_, 67 Quantum blue_, 68 Quantum alpha_ ); 69 Color ( const std::string &svgColor_ ); 70 Color ( const char * svgColor_ ); 71 Color ( void ); 72 virtual ~Color ( void ); 73 Color ( const Color & color_ ); 74 75 // Red color (range 0 to MaxRGB) 76 void redQuantum ( Quantum red_ ); 77 Quantum redQuantum ( void ) const; 78 79 // Green color (range 0 to MaxRGB) 80 void greenQuantum ( Quantum green_ ); 81 Quantum greenQuantum ( void ) const; 82 83 // Blue color (range 0 to MaxRGB) 84 void blueQuantum ( Quantum blue_ ); 85 Quantum blueQuantum ( void ) const; 86 87 // Alpha level (range OpaqueOpacity=0 to TransparentOpacity=MaxRGB) 88 void alphaQuantum ( Quantum alpha_ ); 89 Quantum alphaQuantum ( void ) const; 90 91 // Scaled (to 1.0) version of alpha for use in sub-classes 92 // (range opaque=0 to transparent=1.0) 93 void alpha ( double alpha_ ); 94 double alpha ( void ) const; 95 96 // Does object contain valid color? 97 void isValid ( bool valid_ ); 98 bool isValid ( void ) const; 99 100 // Set color via SVG color specification string 101 const Color& operator= ( const std::string & svgColor_ ); 102 const Color& operator= ( const char * svgColor_ ); 103 104 // Assignment operator 105 Color& operator= ( const Color& color_ ); 106 107 // Return SVG color specification string 108 /* virtual */ operator std::string() const; 109 110 // Return ImageMagick Quantum 111 operator Quantum() const; 112 113 // Construct color via ImageMagick Quantum 114 Color ( const Quantum &color_ ); 115 116 // Set color via ImageMagick Quantum 117 const Color& operator= ( Quantum &color_ ); 118}; 119</div> 120<p align="center" style="margin-bottom: 0cm"><b>Color Derived Classes</b></p> 121<table width="90%" border="1" cellpadding="2" cellspacing="3"> 122<col width="29*" /> 123<col width="227*" /> 124<tr> 125<td width="12%"> 126<p><a href="Color.html#ColorRGB">ColorRGB</a></p></td> 127<td width="88%"> 128<p>Representation of RGB color with red, green, and blue specified as ratios (0 to 1)</p></td></tr> 129<tr> 130<td width="12%"> 131<p><a href="Color.html#ColorGray">ColorGray</a></p></td> 132<td width="88%"> 133<p>Representation of <span lang="en-US">grayscale</span> sRGB color (equal parts red, green, and blue) specified as a ratio (0 to 1)</p></td></tr> 134<tr> 135<td width="12%"> 136<p><a href="Color.html#ColorMono">ColorMono</a></p></td> 137<td width="88%"> 138<p>Representation of a black/white color (true/false)</p></td></tr> 139<tr> 140<td width="12%"> 141<p><a href="Color.html#ColorYUV">ColorYUV</a></p></td> 142<td width="88%"> 143<p>Representation of a color in the YUV <span lang="en-US">colorspace</span></p></td></tr></table> 144<h3><a name="ColorRGB"></a>ColorRGB</h3> 145<p>Representation of an sRGB color. All color arguments have a valid range of 0.0 - 1.0.</p> 146<pre class="code"> 147class ColorRGB : public Color 148{ 149 public: 150 ColorRGB ( double red_, double green_, double blue_ ); 151 ColorRGB ( void ); 152 ColorRGB ( const Color & color_ ); 153 /* virtual */ ~ColorRGB ( void ); 154 155 void red ( double red_ ); 156 double red ( void ) const; 157 158 void green ( double green_ ); 159 double green ( void ) const; 160 161 void blue ( double blue_ ); 162 double blue ( void ) const; 163 164 // Assignment operator from base class 165 ColorRGB& operator= ( const Color& color_ ); 166}; 167</pre> 168<h3><a name="ColorGray"></a>ColorGray</h3> 169<p>Representation of a grayscale color (in linear colorspace). <span lang="en-US">Grayscale</span> is simply RGB with equal parts of red, green, and blue. All double arguments have a valid range of 0.0 - 1.0.</p> 170<pre class="code"> 171class ColorGray : public Color 172{ 173 public: 174 ColorGray ( double shade_ ); 175 ColorGray ( void ); 176 ColorGray ( const Color & color_ ); 177 /* virtual */ ~ColorGray (); 178 179 void shade ( double shade_ ); 180 double shade ( void ) const; 181 182 // Assignment operator from base class 183 ColorGray& operator= ( const Color& color_ ); 184}; 185</pre> 186<h3><a name="ColorMono"></a>ColorMono</h3> 187<p>Representation of a black/white pixel (in RGB colorspace). Color arguments are constrained to 'false' (black pixel) and 'true' (white pixel).</p> 188<pre class="code"> 189class ColorMono : public Color 190{ 191 public: 192 ColorMono ( bool mono_ ); 193 ColorMono ( void ); 194 ColorMono ( const Color & color_ ); 195 /* virtual */ ~ColorMono (); 196 197 void mono ( bool mono_ ); 198 bool mono ( void ) const; 199 200 // Assignment operator from base class 201 ColorMono& operator= ( const Color& color_ ); 202}; 203</pre> 204<h3><a name="ColorHSL"></a>ColorHSL</h3> 205<p>Representation of a color in Hue/Saturation/Luminosity (HSL) colorspace.</p> 206<pre class="code"> 207class ColorHSL : public Color 208{ 209 public: 210 ColorHSL ( double hue_, double saturation_, double luminosity_ ); 211 ColorHSL ( void ); 212 ColorHSL ( const Color & color_ ); 213 /* virtual */ ~ColorHSL ( ); 214 215 void hue ( double hue_ ); 216 double hue ( void ) const; 217 218 void saturation ( double saturation_ ); 219 double saturation ( void ) const; 220 221 void luminosity ( double luminosity_ ); 222 double luminosity ( void ) const; 223 224 // Assignment operator from base class 225 ColorHSL& operator= ( const Color& color_ ); 226}; 227</pre> 228<h3><a name="ColorYUV"></a>ColorYUV</h3> 229<p>Representation of a color in YUV colorspace (used to encode color for television transmission).</p> 230<p>Argument ranges:</p> 231<dl> 232<dd> Y: 0.0 through 1.0</dd> 233<dd> U: -0.5 through 0.5</dd> 234<dd> V: -0.5 through 0.5</dd> 235</dl> 236<pre class="code"> 237class ColorYUV : public Color 238{ 239 public: 240 ColorYUV ( double y_, double u_, double v_ ); 241 ColorYUV ( void ); 242 ColorYUV ( const Color & color_ ); 243 /* virtual */ ~ColorYUV ( void ); 244 245 void u ( double u_ ); 246 double u ( void ) const; 247 248 void v ( double v_ ); 249 double v ( void ) const; 250 251 void y ( double y_ ); 252 double y ( void ) const; 253 254 // Assignment operator from base class 255 ColorYUV& operator= ( const Color& color_ ); 256}; 257</pre> 258</div> 259</body> 260</html> 261