Magick++
7.1.2-29
Convert, Edit, Or Compose Bitmap Images
Toggle main menu visibility
Loading...
Searching...
No Matches
Color.h
1
// This may look like C code, but it is really -*- C++ -*-
2
//
3
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003, 2008
4
//
5
// Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
6
// dedicated to making software imaging solutions freely available.
7
//
8
// Color Implementation
9
//
10
#if !defined (Magick_Color_header)
11
#define Magick_Color_header
12
13
#include "Magick++/Include.h"
14
#include <string>
15
16
namespace
Magick
17
{
18
class
MagickPPExport
Color
;
19
20
// Compare two Color objects regardless of LHS/RHS
21
MagickPPExport
int
operator
==
22
(
const
Magick::Color& left_,
const
Magick::Color& right_);
23
MagickPPExport
int
operator
!=
24
(
const
Magick::Color& left_,
const
Magick::Color& right_);
25
MagickPPExport
int
operator
>
26
(
const
Magick::Color& left_,
const
Magick::Color& right_);
27
MagickPPExport
int
operator
<
28
(
const
Magick::Color& left_,
const
Magick::Color& right_);
29
MagickPPExport
int
operator
>=
30
(
const
Magick::Color& left_,
const
Magick::Color& right_);
31
MagickPPExport
int
operator
<=
32
(
const
Magick::Color& left_,
const
Magick::Color& right_);
33
34
// Base color class stores RGBA components scaled to fit Quantum
35
// All double arguments have a valid range of 0.0 - 1.0.
36
class
MagickPPExport Color
37
{
38
public
:
39
40
// PixelType specifies the interpretation of PixelInfo members
41
// CMYKPixel:
42
// Cyan = red
43
// Magenta = green
44
// Yellow = blue
45
// Black(K) = black
46
// CMYKPixel:
47
// Cyan = red
48
// Magenta = green
49
// Yellow = blue
50
// Black(K) = black
51
// Alpha = alpha
52
// RGBPixel:
53
// Red = red;
54
// Green = green;
55
// Blue = blue;
56
// RGBAPixel:
57
// Red = red;
58
// Green = green;
59
// Blue = blue;
60
// Alpha = alpha;
61
enum
PixelType
62
{
63
CMYKPixel,
64
CMYKAPixel,
65
RGBPixel,
66
RGBAPixel
67
};
68
69
// Default constructor
70
Color(
void
);
71
72
// Construct Color using the specified RGB values
73
Color(
const
Magick::Quantum red_,
const
Magick::Quantum green_,
74
const
Magick::Quantum blue_);
75
76
// Construct Color using the specified RGBA values
77
Color(
const
Magick::Quantum red_,
const
Magick::Quantum green_,
78
const
Magick::Quantum blue_,
const
Magick::Quantum alpha_);
79
80
// Construct Color using the specified CMYKA values
81
Color(
const
Magick::Quantum cyan_,
const
Magick::Quantum magenta_,
82
const
Magick::Quantum yellow_,
const
Magick::Quantum black_,
83
const
Magick::Quantum alpha_);
84
85
// Construct Color using the specified color string
86
Color(
const
char
*color_);
87
88
// Copy constructor
89
Color(
const
Color &color_);
90
91
// Construct color via ImageMagick PixelInfo
92
Color(
const
PixelInfo &color_);
93
94
// Constructor Color using the specified color string
95
Color(
const
std::string &color_);
96
97
// Destructor
98
virtual
~Color(
void
);
99
100
// Assignment operator
101
Color& operator=(
const
Color &color_);
102
103
// Set color via X11 color specification string
104
const
Color& operator=(
const
char
*color);
105
106
// Set color via ImageMagick PixelInfo
107
const
Color& operator=(
const
PixelInfo &color_);
108
109
// Set color via color specification string
110
const
Color& operator=(
const
std::string &color);
111
112
// Return ImageMagick PixelInfo
113
operator
PixelInfo()
const
;
114
115
// Return color specification string
116
operator
std::string()
const
;
117
118
// Returns true if the distance between the other color is less than the
119
// specified distance in a linear three(or four) % dimensional color space.
120
bool
isFuzzyEquivalent(
const
Color &color_,
const
double
fuzz_)
const
;
121
122
// Does object contain valid color?
123
void
isValid(
const
bool
valid_);
124
bool
isValid(
void
)
const
;
125
126
// Returns pixel type of the color
127
Magick::Color::PixelType pixelType(
void
)
const
;
128
129
// Alpha level (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange)
130
void
quantumAlpha(
const
Quantum alpha_);
131
Quantum quantumAlpha(
void
)
const
;
132
133
// Black color (range 0 to QuantumRange)
134
void
quantumBlack(
const
Quantum black_);
135
Quantum quantumBlack(
void
)
const
;
136
137
// Blue/Yellow color (range 0 to QuantumRange)
138
void
quantumBlue(
const
Quantum blue_);
139
Quantum quantumBlue(
void
)
const
;
140
141
// Green/Magenta color (range 0 to QuantumRange)
142
void
quantumGreen(
const
Quantum green_);
143
Quantum quantumGreen(
void
)
const
;
144
145
// Red/Cyan color (range 0 to QuantumRange)
146
void
quantumRed(
const
Quantum red_);
147
Quantum quantumRed(
void
)
const
;
148
149
protected
:
150
151
// Constructor to construct with PixelInfo*
152
// Used to point Color at a pixel in an image
153
Color(PixelInfo *rep_,PixelType pixelType_);
154
155
// Constructor to construct with PixelType
156
Color(PixelType pixelType_);
157
158
// Set pixel
159
// Used to point Color at a pixel in an image
160
void
pixel(PixelInfo *rep_,PixelType pixelType_);
161
162
// Scale a value expressed as a double (0-1) to Quantum range (0-QuantumRange)
163
static
Quantum scaleDoubleToQuantum(
const
double
double_);
164
165
// Scale a value expressed as a Quantum (0-QuantumRange) to double range (0-1)
166
static
double
scaleQuantumToDouble(
const
Quantum quantum_);
167
168
// PixelInfo represents a color pixel:
169
// red = red (range 0 to QuantumRange)
170
// green = green (range 0 to QuantumRange)
171
// blue = blue (range 0 to QuantumRange)
172
// alpha = alpha (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange)
173
// index = PseudoColor colormap index
174
PixelInfo *_pixel;
175
176
private
:
177
178
bool
_isValid;
// Set true if pixel is "valid"
179
bool
_pixelOwn;
// Set true if we allocated pixel
180
PixelType _pixelType;
// Color type supported by _pixel
181
182
// Common initializer for PixelInfo representation
183
void
initPixel();
184
185
void
setAlpha(
const
Magick::Quantum alpha_);
186
187
// Sets the pixel type using the specified PixelInfo.
188
void
setPixelType(
const
PixelInfo &color_);
189
};
190
191
class
MagickPPExport ColorCMYK:
public
Color
192
{
193
public
:
194
195
// Default constructor
196
ColorCMYK(
void
);
197
198
// Copy constructor
199
ColorCMYK(
const
Color &color_);
200
201
// Construct ColorCMYK using the specified CMYK values
202
ColorCMYK(
const
double
cyan_,
const
double
magenta_,
const
double
yellow_,
203
const
double
black_);
204
205
// Construct ColorCMYK using the specified CMYKA values
206
ColorCMYK(
const
double
cyan_,
const
double
magenta_,
const
double
yellow_,
207
const
double
black_,
const
double
alpha_);
208
209
// Destructor
210
~ColorCMYK(
void
);
211
212
// Assignment operator from base class
213
ColorCMYK& operator=(
const
Color& color_);
214
215
// Alpha level (range 0 to 1.0)
216
void
alpha(
const
double
alpha_);
217
double
alpha(
void
)
const
;
218
219
// Black/Key color (range 0 to 1.0)
220
void
black(
const
double
black_);
221
double
black(
void
)
const
;
222
223
// Black/Key color (range 0.0 to 1.0)
224
void
cyan(
const
double
cyan_);
225
double
cyan(
void
)
const
;
226
227
// Magenta color (range 0 to 1.0)
228
void
magenta(
const
double
magenta_);
229
double
magenta(
void
)
const
;
230
231
// Yellow color (range 0 to 1.0)
232
void
yellow(
const
double
yellow_);
233
double
yellow(
void
)
const
;
234
235
protected
:
236
237
// Constructor to construct with PixelInfo*
238
ColorCMYK(PixelInfo *rep_,PixelType pixelType_);
239
};
240
241
//
242
// Grayscale RGB color
243
//
244
// Grayscale is simply RGB with equal parts of red, green, and blue
245
// All double arguments have a valid range of 0.0 - 1.0.
246
class
MagickPPExport ColorGray:
public
Color
247
{
248
public
:
249
250
// Default constructor
251
ColorGray(
void
);
252
253
// Copy constructor
254
ColorGray(
const
Color &color_);
255
256
// Construct ColorGray using the specified shade
257
ColorGray(
const
double
shade_);
258
259
// Destructor
260
~ColorGray();
261
262
// Shade
263
void
shade(
const
double
shade_);
264
double
shade(
void
)
const
;
265
266
// Assignment operator from base class
267
ColorGray& operator=(
const
Color& color_);
268
269
protected
:
270
271
// Constructor to construct with PixelInfo*
272
ColorGray(PixelInfo *rep_,PixelType pixelType_);
273
};
274
275
//
276
// HSL Colorspace colors
277
//
278
// All double arguments have a valid range of 0.0 - 1.0.
279
class
MagickPPExport ColorHSL:
public
Color
280
{
281
public
:
282
283
// Default constructor
284
ColorHSL(
void
);
285
286
// Copy constructor
287
ColorHSL(
const
Color &color_);
288
289
// Construct ColorHSL using the specified HSL values
290
ColorHSL(
const
double
hue_,
const
double
saturation_,
291
const
double
lightness_);
292
293
// Destructor
294
~ColorHSL();
295
296
// Assignment operator from base class
297
ColorHSL& operator=(
const
Color& color_);
298
299
// Hue color
300
void
hue(
const
double
hue_);
301
double
hue(
void
)
const
;
302
303
// Lightness color
304
void
lightness(
const
double
lightness_);
305
double
lightness(
void
)
const
;
306
307
// Saturation color
308
void
saturation(
const
double
saturation_);
309
double
saturation(
void
)
const
;
310
311
protected
:
312
313
// Constructor to construct with PixelInfo*
314
ColorHSL(PixelInfo *rep_,PixelType pixelType_);
315
};
316
317
//
318
// Monochrome color
319
//
320
// Color arguments are constrained to 'false' (black pixel) and 'true'
321
// (white pixel)
322
class
MagickPPExport ColorMono:
public
Color
323
{
324
public
:
325
326
// Default constructor
327
ColorMono(
void
);
328
329
// Construct ColorMono (false=black, true=white)
330
ColorMono(
const
bool
mono_);
331
332
// Copy constructor
333
ColorMono(
const
Color &color_);
334
335
// Destructor
336
~ColorMono();
337
338
// Assignment operator from base class
339
ColorMono& operator=(
const
Color& color_);
340
341
// Mono color
342
void
mono(
const
bool
mono_);
343
bool
mono(
void
)
const
;
344
345
protected
:
346
347
// Constructor to construct with PixelInfo*
348
ColorMono(PixelInfo* rep_,PixelType pixelType_);
349
};
350
351
class
MagickPPExport ColorRGB:
public
Color
352
{
353
public
:
354
355
// Default constructor
356
ColorRGB(
void
);
357
358
// Copy constructor
359
ColorRGB(
const
Color &color_);
360
361
// Construct ColorRGB using the specified RGB values
362
ColorRGB(
const
double
red_,
const
double
green_,
const
double
blue_);
363
364
// Construct ColorRGB using the specified RGBA values
365
ColorRGB(
const
double
red_,
const
double
green_,
const
double
blue_,
366
const
double
alpha_);
367
368
// Destructor
369
~ColorRGB(
void
);
370
371
// Assignment operator from base class
372
ColorRGB& operator=(
const
Color& color_);
373
374
// Alpha level (range 0 to 1.0)
375
void
alpha(
const
double
alpha_);
376
double
alpha(
void
)
const
;
377
378
// Blue color (range 0.0 to 1.0)
379
void
blue(
const
double
blue_);
380
double
blue(
void
)
const
;
381
382
// Green color (range 0 to 1.0)
383
void
green(
const
double
green_);
384
double
green(
void
)
const
;
385
386
// Red color (range 0 to 1.0)
387
void
red(
const
double
red_);
388
double
red(
void
)
const
;
389
390
protected
:
391
392
// Constructor to construct with PixelInfo*
393
ColorRGB(PixelInfo *rep_,PixelType pixelType_);
394
};
395
396
//
397
// YUV Colorspace color
398
//
399
// Argument ranges:
400
// Y: 0.0 through 1.0
401
// U: -0.5 through 0.5
402
// V: -0.5 through 0.5
403
class
MagickPPExport ColorYUV:
public
Color
404
{
405
public
:
406
407
// Default constructor
408
ColorYUV(
void
);
409
410
// Copy constructor
411
ColorYUV(
const
Color &color_);
412
413
// Construct ColorYUV using the specified YUV values
414
ColorYUV(
const
double
y_,
const
double
u_,
const
double
v_);
415
416
// Destructor
417
~ColorYUV(
void
);
418
419
// Assignment operator from base class
420
ColorYUV& operator=(
const
Color& color_);
421
422
// Color U (0.0 through 1.0)
423
void
u(
const
double
u_);
424
double
u(
void
)
const
;
425
426
// Color V (-0.5 through 0.5)
427
void
v(
const
double
v_);
428
double
v(
void
)
const
;
429
430
// Color Y (-0.5 through 0.5)
431
void
y(
const
double
y_);
432
double
y(
void
)
const
;
433
434
protected
:
435
436
// Constructor to construct with PixelInfo*
437
ColorYUV(PixelInfo *rep_,PixelType pixelType_);
438
439
private
:
440
441
void
convert(
const
double
y_,
const
double
u_,
const
double
v_);
442
443
};
444
}
// namespace Magick
445
446
#endif
// Magick_Color_header
Magick::Color
Definition
Color.h:37
Magick++
lib
Magick++
Color.h
Generated by
1.17.0