File: Color.html

package info (click to toggle)
imagemagick 8%3A7.1.2.8%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,412 kB
  • sloc: ansic: 372,773; cpp: 22,661; xml: 11,570; sh: 6,618; perl: 6,285; makefile: 3,497; tcl: 459
file content (260 lines) | stat: -rw-r--r-- 10,326 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Magick++ API: Working with Color</title>
<link rel="stylesheet" href="magick.css" type="text/css" />
</head>
<body>
<div class="doc-section">
<h1 align="center">Magick::Color</h1>
<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>
<h4>Quantum</h4>

The 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.

<h4>Quantum</h4>

Quantum 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.
<p align="center" style="margin-bottom: 0cm"><b>Effect Of QuantumDepth Values</b></p>
<center>
<table width="361" border="1" cellpadding="2" cellspacing="3">
<col width="102" />
<col width="121" />
<col width="111" />
<tr>
<td width="102">
<p align="center"><b>QuantumDepth</b></p></td>
<td width="121">
<p align="center"><b>Quantum Typedef</b></p></td>
<td width="111">
<p align="center"><b>Quantum Size</b></p></td></tr>
<tr>
<td width="102">
<p align="center">8</p></td>
<td width="121">
<p align="center">unsigned char</p></td>
<td width="111">
<p align="center">32 bits</p></td></tr>
<tr>
<td width="102">
<p align="center">16</p></td>
<td width="121">
<p align="center">unsigned short</p></td>
<td width="111">
<p align="center">64 bits</p></td></tr>
<tr>
<td width="102">
<p align="center">32</p></td>
<td width="121">
<p align="center">unsigned int</p></td>
<td width="111">
<p align="center">128 bits</p></td></tr>
</table></center>
<h3><a name="Color"></a>Color Class</h3>
<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>
<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>
<div class="viewport">
class Color 
{ 
  public: 
    Color ( Quantum red_, 
     Quantum green_, 
     Quantum blue_ ); 
    Color ( Quantum red_, 
     Quantum green_, 
     Quantum blue_, 
     Quantum alpha_ ); 
    Color ( const std::string &amp;svgColor_ ); 
    Color ( const char * svgColor_ ); 
    Color ( void ); 
    virtual        ~Color ( void ); 
    Color ( const Color &amp; color_ );

    // Red color (range 0 to MaxRGB) 
    void           redQuantum ( Quantum red_ ); 
    Quantum        redQuantum ( void ) const;

    // Green color (range 0 to MaxRGB) 
    void           greenQuantum ( Quantum green_ ); 
    Quantum        greenQuantum ( void ) const;

    // Blue color (range 0 to MaxRGB) 
    void           blueQuantum ( Quantum blue_ ); 
    Quantum        blueQuantum ( void ) const;

    // Alpha level (range OpaqueOpacity=0 to TransparentOpacity=MaxRGB) 
    void           alphaQuantum ( Quantum alpha_ ); 
    Quantum        alphaQuantum ( void ) const;

    // Scaled (to 1.0) version of alpha for use in sub-classes 
    // (range opaque=0 to transparent=1.0) 
    void           alpha ( double alpha_ ); 
    double         alpha ( void ) const; 
  
    // Does object contain valid color? 
    void           isValid ( bool valid_ ); 
    bool           isValid ( void ) const; 
  
    // Set color via SVG color specification string 
    const Color&amp; operator= ( const std::string &amp; svgColor_ ); 
    const Color&amp; operator= ( const char * svgColor_ );

    // Assignment operator 
    Color&amp; operator= ( const Color&amp; color_ ); 
  
    // Return SVG color specification string 
    /* virtual */ operator std::string() const;

    // Return ImageMagick Quantum 
    operator Quantum() const;

    // Construct color via ImageMagick Quantum 
    Color ( const Quantum &amp;color_ );

    // Set color via ImageMagick Quantum 
    const Color&amp; operator= ( Quantum &amp;color_ ); 
};
</div>
<p align="center" style="margin-bottom: 0cm"><b>Color Derived Classes</b></p>
<table width="90%" border="1" cellpadding="2" cellspacing="3">
<col width="29*" />
<col width="227*" />
<tr>
<td width="12%">
<p><a href="Color.html#ColorRGB">ColorRGB</a></p></td>
<td width="88%">
<p>Representation of RGB color with red, green, and blue specified as ratios (0 to 1)</p></td></tr>
<tr>
<td width="12%">
<p><a href="Color.html#ColorGray">ColorGray</a></p></td>
<td width="88%">
<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>
<tr>
<td width="12%">
<p><a href="Color.html#ColorMono">ColorMono</a></p></td>
<td width="88%">
<p>Representation of a black/white color (true/false)</p></td></tr>
<tr>
<td width="12%">
<p><a href="Color.html#ColorYUV">ColorYUV</a></p></td>
<td width="88%">
<p>Representation of a color in the YUV <span lang="en-US">colorspace</span></p></td></tr></table>
<h3><a name="ColorRGB"></a>ColorRGB</h3>
<p>Representation of an sRGB color. All color arguments have a valid range of 0.0 - 1.0.</p>
<pre class="code">
class ColorRGB : public Color 
{ 
  public: 
    ColorRGB ( double red_, double green_, double blue_ ); 
    ColorRGB ( void ); 
    ColorRGB ( const Color &amp; color_ ); 
    /* virtual */  ~ColorRGB ( void ); 
  
    void           red ( double red_ ); 
    double         red ( void ) const; 
  
    void           green ( double green_ ); 
    double         green ( void ) const; 
  
    void           blue ( double blue_ ); 
    double         blue ( void ) const;

    // Assignment operator from base class 
    ColorRGB&amp; operator= ( const Color&amp; color_ ); 
}; 
</pre>
<h3><a name="ColorGray"></a>ColorGray</h3>
<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>
<pre class="code">
class ColorGray : public Color 
{ 
  public: 
    ColorGray ( double shade_ ); 
    ColorGray ( void ); 
    ColorGray ( const Color &amp; color_ ); 
    /* virtual */ ~ColorGray ();

    void           shade ( double shade_ ); 
    double         shade ( void ) const;

    // Assignment operator from base class 
    ColorGray&amp; operator= ( const Color&amp; color_ ); 
}; 
</pre>
<h3><a name="ColorMono"></a>ColorMono</h3>
<p>Representation of a black/white pixel (in RGB colorspace). Color arguments are constrained to 'false' (black pixel) and 'true' (white pixel).</p>
<pre class="code">
class ColorMono : public Color 
{ 
  public: 
    ColorMono ( bool mono_ ); 
    ColorMono ( void ); 
    ColorMono ( const Color &amp; color_ ); 
    /* virtual */ ~ColorMono (); 
  
    void           mono ( bool mono_ ); 
    bool           mono ( void ) const;

    // Assignment operator from base class 
    ColorMono&amp; operator= ( const Color&amp; color_ ); 
}; 
</pre>
<h3><a name="ColorHSL"></a>ColorHSL</h3>
<p>Representation of a color in Hue/Saturation/Luminosity (HSL) colorspace.</p>
<pre class="code">
class ColorHSL : public Color 
{ 
  public: 
    ColorHSL ( double hue_, double saturation_, double luminosity_ ); 
    ColorHSL ( void ); 
    ColorHSL ( const Color &amp; color_ ); 
    /* virtual */  ~ColorHSL ( ); 
  
    void           hue ( double hue_ ); 
    double         hue ( void ) const; 
  
    void           saturation ( double saturation_ ); 
    double         saturation ( void ) const; 
  
    void           luminosity ( double luminosity_ ); 
    double         luminosity ( void ) const;

    // Assignment operator from base class 
    ColorHSL&amp; operator= ( const Color&amp; color_ ); 
}; 
</pre>
<h3><a name="ColorYUV"></a>ColorYUV</h3>
<p>Representation of a color in YUV colorspace (used to encode color for television transmission).</p>
<p>Argument ranges:</p>
<dl>
<dd> Y: 0.0 through 1.0</dd>
<dd> U: -0.5 through 0.5</dd>
<dd> V: -0.5 through 0.5</dd>
</dl>
<pre class="code">
class ColorYUV : public Color 
{ 
  public: 
    ColorYUV ( double y_, double u_, double v_ ); 
    ColorYUV ( void ); 
    ColorYUV ( const Color &amp; color_ ); 
    /* virtual */ ~ColorYUV ( void ); 
  
    void           u ( double u_ ); 
    double         u ( void ) const; 
  
    void           v ( double v_ ); 
    double         v ( void ) const; 
  
    void           y ( double y_ ); 
    double         y ( void ) const;

    // Assignment operator from base class 
    ColorYUV&amp; operator= ( const Color&amp; color_ ); 
}; 
</pre>
</div>
</body>
</html>