Magick++ 7.1.2-25
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
Magick::Color Class Reference
Inheritance diagram for Magick::Color:
Magick::ColorCMYK Magick::ColorGray Magick::ColorHSL Magick::ColorMono Magick::ColorRGB Magick::ColorYUV

Public Types

enum  PixelType { CMYKPixel , CMYKAPixel , RGBPixel , RGBAPixel }
 

Public Member Functions

 Color (const Magick::Quantum red_, const Magick::Quantum green_, const Magick::Quantum blue_)
 
 Color (const Magick::Quantum red_, const Magick::Quantum green_, const Magick::Quantum blue_, const Magick::Quantum alpha_)
 
 Color (const Magick::Quantum cyan_, const Magick::Quantum magenta_, const Magick::Quantum yellow_, const Magick::Quantum black_, const Magick::Quantum alpha_)
 
 Color (const char *color_)
 
 Color (const Color &color_)
 
 Color (const PixelInfo &color_)
 
 Color (const std::string &color_)
 
Coloroperator= (const Color &color_)
 
const Coloroperator= (const char *color)
 
const Coloroperator= (const PixelInfo &color_)
 
const Coloroperator= (const std::string &color)
 
 operator PixelInfo () const
 
 operator std::string () const
 
bool isFuzzyEquivalent (const Color &color_, const double fuzz_) const
 
void isValid (const bool valid_)
 
bool isValid (void) const
 
Magick::Color::PixelType pixelType (void) const
 
void quantumAlpha (const Quantum alpha_)
 
Quantum quantumAlpha (void) const
 
void quantumBlack (const Quantum black_)
 
Quantum quantumBlack (void) const
 
void quantumBlue (const Quantum blue_)
 
Quantum quantumBlue (void) const
 
void quantumGreen (const Quantum green_)
 
Quantum quantumGreen (void) const
 
void quantumRed (const Quantum red_)
 
Quantum quantumRed (void) const
 

Protected Member Functions

 Color (PixelInfo *rep_, PixelType pixelType_)
 
 Color (PixelType pixelType_)
 
void pixel (PixelInfo *rep_, PixelType pixelType_)
 

Static Protected Member Functions

static Quantum scaleDoubleToQuantum (const double double_)
 
static double scaleQuantumToDouble (const Quantum quantum_)
 

Protected Attributes

PixelInfo * _pixel
 

Private Member Functions

void initPixel ()
 
void setAlpha (const Magick::Quantum alpha_)
 
void setPixelType (const PixelInfo &color_)
 

Private Attributes

bool _isValid
 
bool _pixelOwn
 
PixelType _pixelType
 

Detailed Description

Definition at line 36 of file Color.h.

Member Enumeration Documentation

◆ PixelType

enum Magick::Color::PixelType

Definition at line 61 of file Color.h.

62 {
63 CMYKPixel,
64 CMYKAPixel,
65 RGBPixel,
66 RGBAPixel
67 };

Constructor & Destructor Documentation

◆ Color() [1/10]

Magick::Color::Color ( void  )

Definition at line 78 of file Color.cpp.

79 : _pixel(new PixelInfo),
80 _isValid(false),
81 _pixelOwn(true),
82 _pixelType(RGBAPixel)
83{
84 initPixel();
85
86 setAlpha(TransparentAlpha);
87}

◆ Color() [2/10]

Magick::Color::Color ( const Magick::Quantum  red_,
const Magick::Quantum  green_,
const Magick::Quantum  blue_ 
)

Definition at line 89 of file Color.cpp.

91 : _pixel(new PixelInfo),
92 _isValid(true),
93 _pixelOwn(true),
94 _pixelType(RGBPixel)
95{
96 initPixel();
97
98 quantumAlpha(OpaqueAlpha);
99 quantumBlack(0);
100 quantumBlue(blue_);
101 quantumGreen(green_);
102 quantumRed(red_);
103}

◆ Color() [3/10]

Magick::Color::Color ( const Magick::Quantum  red_,
const Magick::Quantum  green_,
const Magick::Quantum  blue_,
const Magick::Quantum  alpha_ 
)

Definition at line 105 of file Color.cpp.

107 : _pixel(new PixelInfo),
108 _isValid(true),
109 _pixelOwn(true),
110 _pixelType(RGBPixel)
111{
112 initPixel();
113
114 quantumAlpha(alpha_);
115 quantumBlack(0);
116 quantumBlue(blue_);
117 quantumGreen(green_);
118 quantumRed(red_);
119 if (alpha_ != OpaqueAlpha)
120 _pixelType=RGBAPixel;
121}

◆ Color() [4/10]

Magick::Color::Color ( const Magick::Quantum  cyan_,
const Magick::Quantum  magenta_,
const Magick::Quantum  yellow_,
const Magick::Quantum  black_,
const Magick::Quantum  alpha_ 
)

Definition at line 123 of file Color.cpp.

126 : _pixel(new PixelInfo),
127 _isValid(true),
128 _pixelOwn(true),
129 _pixelType(CMYKPixel)
130{
131 initPixel();
132
133 quantumAlpha(alpha_);
134 quantumBlack(black_);
135 quantumBlue(yellow_);
136 quantumGreen(magenta_);
137 quantumRed(cyan_);
138 if (alpha_ != OpaqueAlpha)
139 _pixelType=CMYKAPixel;
140}

◆ Color() [5/10]

Magick::Color::Color ( const char *  color_)

Definition at line 142 of file Color.cpp.

143 : _pixel(new PixelInfo),
144 _isValid(true),
145 _pixelOwn(true),
146 _pixelType(RGBPixel)
147{
148 initPixel();
149
150 // Use operator = implementation
151 try
152 {
153 *this=color_;
154 }
155 catch (...)
156 {
157 if (_pixelOwn)
158 delete _pixel;
159 _pixel=(PixelInfo *)NULL;
160 throw;
161 }
162}

◆ Color() [6/10]

Magick::Color::Color ( const Color color_)

Definition at line 164 of file Color.cpp.

165 : _pixel(new PixelInfo),
166 _isValid(color_._isValid),
167 _pixelOwn(true),
168 _pixelType(color_._pixelType)
169{
170 *_pixel=*color_._pixel;
171}

◆ Color() [7/10]

Magick::Color::Color ( const PixelInfo &  color_)

Definition at line 173 of file Color.cpp.

174 : _pixel(new PixelInfo),
175 _isValid(true),
176 _pixelOwn(true)
177{
178 *_pixel=color_;
179 setPixelType(color_);
180}

◆ Color() [8/10]

Magick::Color::Color ( const std::string &  color_)

Definition at line 182 of file Color.cpp.

183 : _pixel(new PixelInfo),
184 _isValid(true),
185 _pixelOwn(true),
186 _pixelType(RGBPixel)
187{
188 initPixel();
189
190 // Use operator = implementation
191 try
192 {
193 *this=color_;
194 }
195 catch (...)
196 {
197 if (_pixelOwn)
198 delete _pixel;
199 _pixel=(PixelInfo *)NULL;
200 throw;
201 }
202}

◆ ~Color()

Magick::Color::~Color ( void  )
virtual

Definition at line 204 of file Color.cpp.

205{
206 if (_pixelOwn)
207 delete _pixel;
208
209 _pixel=(PixelInfo *)NULL;
210}

◆ Color() [9/10]

Magick::Color::Color ( PixelInfo *  rep_,
PixelType  pixelType_ 
)
protected

Definition at line 406 of file Color.cpp.

407 : _pixel(rep_),
408 _isValid(true),
409 _pixelOwn(false),
410 _pixelType(pixelType_)
411{
412}

◆ Color() [10/10]

Magick::Color::Color ( PixelType  pixelType_)
protected

Definition at line 397 of file Color.cpp.

398 : _pixel(new PixelInfo),
399 _isValid(false),
400 _pixelOwn(true),
401 _pixelType(pixelType_)
402{
403 initPixel();
404}

Member Function Documentation

◆ initPixel()

void Magick::Color::initPixel ( )
private

Definition at line 439 of file Color.cpp.

440{
441 MagickCore::GetPixelInfo((MagickCore::Image *) NULL, _pixel);
442 if (_pixelType == CMYKPixel || _pixelType == CMYKAPixel)
443 _pixel->colorspace=CMYKColorspace;
444}

◆ isFuzzyEquivalent()

bool Magick::Color::isFuzzyEquivalent ( const Color color_,
const double  fuzz_ 
) const

Definition at line 303 of file Color.cpp.

304{
305 PixelInfo
306 p,
307 q;
308
309 p=*_pixel;
310 p.fuzz=fuzz_;
311 q=*color_._pixel;
312 q.fuzz=fuzz_;
313 return (IsFuzzyEquivalencePixelInfo(&p, &q) != MagickFalse);
314}

◆ isValid() [1/2]

void Magick::Color::isValid ( const bool  valid_)

Definition at line 326 of file Color.cpp.

327{
328 if (bool(valid_) == bool(isValid()))
329 return;
330
331 if (!_pixelOwn)
332 {
333 _pixel=new PixelInfo;
334 _pixelOwn=true;
335 }
336
337 _isValid=valid_;
338
339 initPixel();
340}

◆ isValid() [2/2]

bool Magick::Color::isValid ( void  ) const

Definition at line 316 of file Color.cpp.

317{
318 return(_isValid);
319}

◆ operator std::string()

Magick::Color::operator std::string ( ) const

Definition at line 278 of file Color.cpp.

279{
280 char
281 colorbuf[MagickPathExtent];
282
283 PixelInfo
284 pixel;
285
286 if (!isValid())
287 return std::string("none");
288
289 pixel.colorspace=(_pixelType == RGBPixel || _pixelType == RGBAPixel) ?
290 sRGBColorspace : CMYKColorspace;
291 pixel.depth=MAGICKCORE_QUANTUM_DEPTH;
292 pixel.alpha=_pixel->alpha;
293 pixel.alpha_trait=_pixel->alpha_trait;
294 pixel.black=_pixel->black;
295 pixel.blue=_pixel->blue;
296 pixel.green=_pixel->green;
297 pixel.red=_pixel->red;
298 GetColorTuple(&pixel,MagickTrue,colorbuf);
299
300 return(std::string(colorbuf));
301}

◆ operator=() [1/3]

const Magick::Color & Magick::Color::operator= ( const char *  color)

Definition at line 229 of file Color.cpp.

230{
231 *this=std::string(color_);
232 return(*this);
233}

◆ operator=() [2/3]

Magick::Color & Magick::Color::operator= ( const Color color_)

Definition at line 212 of file Color.cpp.

213{
214 // If not being set to ourself
215 if (this != &color_)
216 {
217 // Copy pixel value
218 *_pixel=*color_._pixel;
219
220 // Validity
221 _isValid=color_._isValid;
222
223 // Copy pixel type
224 _pixelType=color_._pixelType;
225 }
226 return(*this);
227}

◆ operator=() [3/3]

const Magick::Color & Magick::Color::operator= ( const std::string &  color)

Definition at line 243 of file Color.cpp.

244{
245 PixelInfo
246 target_color;
247
248 initPixel();
249 GetPPException;
250 if (QueryColorCompliance(color_.c_str(),AllCompliance,&target_color,
251 exceptionInfo))
252 {
253 quantumAlpha((Magick::Quantum ) target_color.alpha);
254 quantumBlack((Magick::Quantum ) target_color.black);
255 quantumBlue((Magick::Quantum ) target_color.blue);
256 quantumGreen((Magick::Quantum ) target_color.green);
257 quantumRed((Magick::Quantum ) target_color.red);
258
259 setPixelType(target_color);
260 }
261 else
262 {
263 _isValid = false;
264 _pixelOwn = false;
265 delete _pixel;
266 _pixel = (PixelInfo *)NULL;
267 }
268 ThrowPPException(true);
269
270 return(*this);
271}

◆ pixel()

void Magick::Color::pixel ( PixelInfo *  rep_,
PixelType  pixelType_ 
)
protected

Definition at line 414 of file Color.cpp.

415{
416 if (_pixelOwn)
417 delete _pixel;
418
419 _pixel=rep_;
420 _pixelOwn=false;
421 _isValid=true;
422 _pixelType=pixelType_;
423}

◆ pixelType()

Magick::Color::PixelType Magick::Color::pixelType ( void  ) const

Definition at line 321 of file Color.cpp.

322{
323 return(_pixelType);
324}

◆ quantumAlpha() [1/2]

void Magick::Color::quantumAlpha ( const Quantum  alpha_)

Definition at line 342 of file Color.cpp.

343{
344 setAlpha(alpha_);
345 _isValid=true;
346}

◆ quantumAlpha() [2/2]

Magick::Quantum Magick::Color::quantumAlpha ( void  ) const

Definition at line 348 of file Color.cpp.

349{
350 return((Magick::Quantum) _pixel->alpha);
351}

◆ quantumBlack() [1/2]

void Magick::Color::quantumBlack ( const Quantum  black_)

Definition at line 353 of file Color.cpp.

354{
355 _pixel->black=black_;
356 _isValid=true;
357}

◆ quantumBlack() [2/2]

Magick::Quantum Magick::Color::quantumBlack ( void  ) const

Definition at line 359 of file Color.cpp.

360{
361 return((Magick::Quantum) _pixel->black);
362}

◆ quantumBlue() [1/2]

void Magick::Color::quantumBlue ( const Quantum  blue_)

Definition at line 364 of file Color.cpp.

365{
366 _pixel->blue=blue_;
367 _isValid=true;
368}

◆ quantumBlue() [2/2]

Magick::Quantum Magick::Color::quantumBlue ( void  ) const

Definition at line 370 of file Color.cpp.

371{
372 return((Magick::Quantum) _pixel->blue);
373}

◆ quantumGreen() [1/2]

void Magick::Color::quantumGreen ( const Quantum  green_)

Definition at line 375 of file Color.cpp.

376{
377 _pixel->green=green_;
378 _isValid=true;
379}

◆ quantumGreen() [2/2]

Magick::Quantum Magick::Color::quantumGreen ( void  ) const

Definition at line 381 of file Color.cpp.

382{
383 return((Magick::Quantum) _pixel->green);
384}

◆ quantumRed() [1/2]

void Magick::Color::quantumRed ( const Quantum  red_)

Definition at line 386 of file Color.cpp.

387{
388 _pixel->red=red_;
389 _isValid=true;
390}

◆ quantumRed() [2/2]

Magick::Quantum Magick::Color::quantumRed ( void  ) const

Definition at line 392 of file Color.cpp.

393{
394 return((Magick::Quantum) _pixel->red);
395}

◆ scaleDoubleToQuantum()

Magick::Quantum Magick::Color::scaleDoubleToQuantum ( const double  double_)
staticprotected

Definition at line 425 of file Color.cpp.

426{
427 return(static_cast<Magick::Quantum>(double_*(double) QuantumRange));
428}

◆ scaleQuantumToDouble()

double Magick::Color::scaleQuantumToDouble ( const Quantum  quantum_)
staticprotected

Definition at line 430 of file Color.cpp.

431{
432#if (MAGICKCORE_QUANTUM_DEPTH < 32) && (MAGICKCORE_SIZEOF_FLOAT_T != MAGICKCORE_SIZEOF_DOUBLE || !defined(MAGICKCORE_HDRI_SUPPORT))
433 return(static_cast<double>(QuantumScale*(double) quantum_));
434#else
435 return(QuantumScale*quantum_);
436#endif
437}

◆ setAlpha()

void Magick::Color::setAlpha ( const Magick::Quantum  alpha_)
private

Definition at line 446 of file Color.cpp.

447{
448 _pixel->alpha=alpha_;
449 if (alpha_ == OpaqueAlpha)
450 {
451 _pixel->alpha_trait=UndefinedPixelTrait;
452 if (_pixelType == RGBAPixel)
453 _pixelType=RGBPixel;
454 else if (_pixelType == CMYKAPixel)
455 _pixelType=CMYKPixel;
456 }
457 else
458 {
459 _pixel->alpha_trait=BlendPixelTrait;
460 if (_pixelType == RGBPixel)
461 _pixelType=RGBAPixel;
462 else if (_pixelType == CMYKPixel)
463 _pixelType=CMYKAPixel;
464 }
465}

◆ setPixelType()

void Magick::Color::setPixelType ( const PixelInfo &  color_)
private

Definition at line 467 of file Color.cpp.

468{
469 if (color_.colorspace == CMYKColorspace)
470 _pixelType=color_.alpha_trait != UndefinedPixelTrait ? CMYKAPixel :
471 CMYKPixel;
472 else
473 _pixelType=color_.alpha_trait != UndefinedPixelTrait ? RGBAPixel :
474 RGBPixel;
475}

Field Documentation

◆ _isValid

bool Magick::Color::_isValid
private

Definition at line 178 of file Color.h.

◆ _pixel

PixelInfo* Magick::Color::_pixel
protected

Definition at line 174 of file Color.h.

◆ _pixelOwn

bool Magick::Color::_pixelOwn
private

Definition at line 179 of file Color.h.

◆ _pixelType

PixelType Magick::Color::_pixelType
private

Definition at line 180 of file Color.h.


The documentation for this class was generated from the following files: