1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4 // Copyright Dirk Lemstra 2013-2015
5 //
6 // Color Implementation
7 //
8 
9 #define MAGICKCORE_IMPLEMENTATION
10 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11 
12 #include "Magick++/Include.h"
13 #include <string>
14 
15 using namespace std;
16 
17 #include "Magick++/Color.h"
18 #include "Magick++/Exception.h"
19 
operator ==(const Magick::Color & left_,const Magick::Color & right_)20 MagickPPExport int Magick::operator == (const Magick::Color &left_,
21   const Magick::Color &right_)
22 {
23   return((left_.isValid() == right_.isValid()) &&
24     (left_.quantumRed() == right_.quantumRed()) &&
25     (left_.quantumGreen() == right_.quantumGreen()) &&
26     (left_.quantumBlue() == right_.quantumBlue()));
27 }
28 
operator !=(const Magick::Color & left_,const Magick::Color & right_)29 MagickPPExport int Magick::operator != (const Magick::Color &left_,
30   const Magick::Color &right_)
31 {
32   return(!(left_ == right_));
33 }
34 
operator >(const Magick::Color & left_,const Magick::Color & right_)35 MagickPPExport int Magick::operator > (const Magick::Color &left_,
36   const Magick::Color &right_)
37 {
38   return(!(left_ < right_ ) && (left_ != right_ ));
39 }
40 
operator <(const Magick::Color & left_,const Magick::Color & right_)41 MagickPPExport int Magick::operator < ( const Magick::Color &left_,
42   const Magick::Color &right_)
43 {
44   if(left_.quantumRed() < right_.quantumRed())
45     return(true);
46   if(left_.quantumRed() > right_.quantumRed())
47     return(false);
48   if(left_.quantumGreen() < right_.quantumGreen())
49     return(true);
50   if(left_.quantumGreen() > right_.quantumGreen())
51     return(false);
52   if(left_.quantumBlue() < right_.quantumBlue())
53     return(true);
54   return(false);
55 }
56 
operator >=(const Magick::Color & left_,const Magick::Color & right_)57 MagickPPExport int Magick::operator >= (const Magick::Color &left_,
58   const Magick::Color &right_)
59 {
60   return((left_ > right_) || (left_ == right_));
61 }
62 
operator <=(const Magick::Color & left_,const Magick::Color & right_)63 MagickPPExport int Magick::operator <= ( const Magick::Color &left_,
64   const Magick::Color &right_)
65 {
66   return((left_ < right_) || (left_ == right_));
67 }
68 
Color(void)69 Magick::Color::Color(void)
70   : _pixel(new PixelInfo),
71     _isValid(false),
72     _pixelOwn(true),
73     _pixelType(RGBPixel)
74 {
75   initPixel();
76 }
77 
Color(const Quantum red_,const Quantum green_,const Quantum blue_)78 Magick::Color::Color(const Quantum red_,const Quantum green_,
79   const Quantum blue_)
80   : _pixel(new PixelInfo),
81     _isValid(true),
82     _pixelOwn(true),
83     _pixelType(RGBPixel)
84 {
85   initPixel();
86 
87   quantumAlpha(OpaqueAlpha);
88   quantumBlack(0);
89   quantumBlue(blue_);
90   quantumGreen(green_);
91   quantumRed(red_);
92 }
93 
Color(const Quantum red_,const Quantum green_,const Quantum blue_,const Quantum alpha_)94 Magick::Color::Color(const Quantum red_,const Quantum green_,
95   const Quantum blue_, const Quantum alpha_)
96   : _pixel(new PixelInfo),
97     _isValid(true),
98     _pixelOwn(true),
99     _pixelType(RGBPixel)
100 {
101   initPixel();
102 
103   quantumAlpha(alpha_);
104   quantumBlack(0);
105   quantumBlue(blue_);
106   quantumGreen(green_);
107   quantumRed(red_);
108   if (alpha_ != OpaqueAlpha)
109     _pixelType=RGBAPixel;
110 }
111 
Color(const Quantum cyan_,const Quantum magenta_,const Quantum yellow_,const Quantum black_,const Quantum alpha_)112 Magick::Color::Color(const Quantum cyan_,const Quantum magenta_,
113   const Quantum yellow_,const Quantum black_,const Quantum alpha_)
114   : _pixel(new PixelInfo),
115     _isValid(true),
116     _pixelOwn(true),
117     _pixelType(CMYKPixel)
118 {
119   initPixel();
120 
121   quantumAlpha(alpha_);
122   quantumBlack(black_);
123   quantumBlue(yellow_);
124   quantumGreen(magenta_);
125   quantumRed(cyan_);
126   if (alpha_ != OpaqueAlpha)
127     _pixelType=CMYKAPixel;
128 }
129 
Color(const char * color_)130 Magick::Color::Color(const char *color_)
131   : _pixel(new PixelInfo),
132     _isValid(true),
133     _pixelOwn(true),
134     _pixelType(RGBPixel)
135 {
136   initPixel();
137 
138   // Use operator = implementation
139   *this=color_;
140 }
141 
Color(const Magick::Color & color_)142 Magick::Color::Color(const Magick::Color &color_)
143   : _pixel(new PixelInfo),
144     _isValid(color_._isValid),
145     _pixelOwn(true),
146     _pixelType(color_._pixelType)
147 {
148   *_pixel=*color_._pixel;
149 }
150 
Color(const PixelInfo & color_)151 Magick::Color::Color(const PixelInfo &color_)
152   : _pixel(new PixelInfo),
153     _isValid(true),
154     _pixelOwn(true)
155 {
156   *_pixel=color_;
157   setPixelType(color_);
158 }
159 
Color(const std::string & color_)160 Magick::Color::Color(const std::string &color_)
161   : _pixel(new PixelInfo),
162     _isValid(true),
163     _pixelOwn(true),
164     _pixelType(RGBPixel)
165 {
166   initPixel();
167 
168   // Use operator = implementation
169   *this=color_;
170 }
171 
~Color(void)172 Magick::Color::~Color(void)
173 {
174   if (_pixelOwn)
175     delete _pixel;
176 
177   _pixel=(PixelInfo *)NULL;
178 }
179 
operator =(const Magick::Color & color_)180 Magick::Color& Magick::Color::operator=(const Magick::Color& color_)
181 {
182   // If not being set to ourself
183   if (this != &color_)
184     {
185       // Copy pixel value
186       *_pixel=*color_._pixel;
187 
188       // Validity
189       _isValid=color_._isValid;
190 
191       // Copy pixel type
192       _pixelType=color_._pixelType;
193     }
194   return(*this);
195 }
196 
operator =(const char * color_)197 const Magick::Color& Magick::Color::operator=(const char *color_)
198 {
199   *this=std::string(color_);
200   return(*this);
201 }
202 
operator =(const MagickCore::PixelInfo & color_)203 const Magick::Color& Magick::Color::operator=(const MagickCore::PixelInfo &color_)
204 {
205   *_pixel=color_;
206   setPixelType(color_);
207 
208   return(*this);
209 }
210 
operator =(const std::string & color_)211 const Magick::Color& Magick::Color::operator=(const std::string &color_)
212 {
213   PixelInfo
214     target_color;
215 
216   initPixel();
217   GetPPException;
218   if (QueryColorCompliance(color_.c_str(),AllCompliance,&target_color,
219       exceptionInfo))
220     {
221       quantumAlpha(target_color.alpha);
222       quantumBlack(target_color.black);
223       quantumBlue(target_color.blue);
224       quantumGreen(target_color.green);
225       quantumRed(target_color.red);
226 
227       setPixelType(target_color);
228     }
229   else
230     _isValid = false;
231   ThrowPPException(false);
232 
233   return(*this);
234 }
235 
operator MagickCore::PixelInfo() const236 Magick::Color::operator MagickCore::PixelInfo() const
237 {
238   return *_pixel;
239 }
240 
operator std::string() const241 Magick::Color::operator std::string() const
242 {
243   char
244     colorbuf[MagickPathExtent];
245 
246   PixelInfo
247     pixel;
248 
249   if (!isValid())
250     return std::string("none");
251 
252   pixel.colorspace=(_pixelType == RGBPixel || _pixelType == RGBAPixel) ?
253     RGBColorspace : CMYKColorspace;
254   pixel.alpha_trait=(_pixelType == RGBAPixel || _pixelType == CMYKAPixel) ?
255     BlendPixelTrait : UndefinedPixelTrait;
256   pixel.depth=MAGICKCORE_QUANTUM_DEPTH;
257   pixel.alpha=_pixel->alpha;
258   pixel.alpha_trait=_pixel->alpha_trait;
259   pixel.black=_pixel->black;
260   pixel.blue=_pixel->blue;
261   pixel.green=_pixel->green;
262   pixel.red=_pixel->red;
263   GetColorTuple(&pixel,MagickTrue,colorbuf);
264 
265   return(std::string(colorbuf));
266 }
267 
isFuzzyEquivalent(const Color & color_,const double fuzz_) const268 bool Magick::Color::isFuzzyEquivalent(const Color &color_, const double fuzz_) const
269 {
270   PixelInfo
271     p,
272     q;
273 
274   p=*_pixel;
275   p.fuzz=fuzz_;
276   q=*color_._pixel;
277   q.fuzz=fuzz_;
278   return (IsFuzzyEquivalencePixelInfo(&p, &q) != MagickFalse);
279 }
280 
isValid(void) const281 bool Magick::Color::isValid(void) const
282 {
283   return(_isValid);
284 }
285 
pixelType() const286 Magick::Color::PixelType Magick::Color::pixelType() const
287 {
288   return(_pixelType);
289 }
290 
isValid(bool valid_)291 void Magick::Color::isValid(bool valid_)
292 {
293   if ((valid_ && isValid()) || (!valid_ && !isValid()))
294     return;
295 
296   if (!_pixelOwn)
297     {
298       _pixel=new PixelInfo;
299       _pixelOwn=true;
300     }
301 
302   _isValid=valid_;
303 
304   initPixel();
305 }
306 
quantumAlpha(const Magick::Quantum alpha_)307 void Magick::Color::quantumAlpha(const Magick::Quantum alpha_)
308 {
309   _pixel->alpha=alpha_;
310   if (alpha_ == QuantumRange)
311     {
312       _pixel->alpha_trait=UndefinedPixelTrait;
313       if (_pixelType == RGBAPixel)
314         _pixelType=RGBPixel;
315       else if (_pixelType == CMYKAPixel)
316         _pixelType=CMYKPixel;
317     }
318   else
319     {
320       _pixel->alpha_trait=BlendPixelTrait;
321       if (_pixelType == RGBPixel)
322         _pixelType=RGBAPixel;
323       else if (_pixelType == CMYKPixel)
324         _pixelType=CMYKAPixel;
325     }
326   _isValid=true;
327 }
328 
quantumAlpha(void) const329 Magick::Quantum Magick::Color::quantumAlpha(void) const
330 {
331   return(_pixel->alpha);
332 }
333 
quantumBlack(const Magick::Quantum black_)334 void Magick::Color::quantumBlack(const Magick::Quantum black_)
335 {
336   _pixel->black=black_;
337   _isValid=true;
338 }
339 
quantumBlack(void) const340 Magick::Quantum Magick::Color::quantumBlack(void) const
341 {
342   return(_pixel->black);
343 }
344 
quantumBlue(const Magick::Quantum blue_)345 void Magick::Color::quantumBlue(const Magick::Quantum blue_)
346 {
347   _pixel->blue=blue_;
348   _isValid=true;
349 }
350 
quantumBlue(void) const351 Magick::Quantum Magick::Color::quantumBlue(void) const
352 {
353   return(_pixel->blue);
354 }
355 
quantumGreen(const Magick::Quantum green_)356 void Magick::Color::quantumGreen(const Magick::Quantum green_)
357 {
358   _pixel->green=green_;
359   _isValid=true;
360 }
361 
quantumGreen(void) const362 Magick::Quantum Magick::Color::quantumGreen(void) const
363 {
364   return(_pixel->green);
365 }
366 
quantumRed(const Magick::Quantum red_)367 void Magick::Color::quantumRed(const Magick::Quantum red_)
368 {
369   _pixel->red=red_;
370   _isValid=true;
371 }
372 
quantumRed(void) const373 Magick::Quantum Magick::Color::quantumRed(void) const
374 {
375   return _pixel->red;
376 }
377 
Color(PixelType pixelType_)378 Magick::Color::Color(PixelType pixelType_)
379   : _pixel(new PixelInfo),
380     _isValid(false),
381     _pixelOwn(true),
382     _pixelType(pixelType_)
383 {
384   initPixel();
385 }
386 
Color(PixelInfo * rep_,PixelType pixelType_)387 Magick::Color::Color(PixelInfo* rep_,PixelType pixelType_)
388   : _pixel(rep_),
389     _isValid(true),
390     _pixelOwn(false),
391     _pixelType(pixelType_)
392 {
393 }
394 
pixel(PixelInfo * rep_,PixelType pixelType_)395 void Magick::Color::pixel(PixelInfo *rep_,PixelType pixelType_)
396 {
397   if (_pixelOwn)
398     delete _pixel;
399 
400   _pixel=rep_;
401   _pixelOwn=false;
402   _isValid=true;
403   _pixelType=pixelType_;
404 }
405 
scaleDoubleToQuantum(const double double_)406 Magick::Quantum Magick::Color::scaleDoubleToQuantum(const double double_)
407 {
408   return(static_cast<Magick::Quantum>(double_*QuantumRange));
409 }
410 
scaleQuantumToDouble(const Magick::Quantum quantum_)411 double Magick::Color::scaleQuantumToDouble(const Magick::Quantum quantum_)
412 {
413 #if (MAGICKCORE_QUANTUM_DEPTH < 32)
414   return(static_cast<double>(quantum_)/QuantumRange);
415 #else
416   return(quantum_/QuantumRange);
417 #endif
418 }
419 
initPixel()420 void Magick::Color::initPixel()
421 {
422   MagickCore::GetPixelInfo((MagickCore::Image *) NULL, _pixel);
423   if (_pixelType == CMYKPixel || _pixelType == CMYKAPixel)
424     _pixel->colorspace=CMYKColorspace;
425 }
426 
setPixelType(const PixelInfo & color_)427 void Magick::Color::setPixelType(const PixelInfo &color_)
428 {
429   if (color_.colorspace == CMYKColorspace)
430     _pixelType=color_.alpha_trait != UndefinedPixelTrait ? CMYKAPixel :
431       CMYKPixel;
432   else
433     _pixelType=color_.alpha_trait != UndefinedPixelTrait ? RGBAPixel :
434       RGBPixel;
435 }
436 
ColorCMYK(void)437 Magick::ColorCMYK::ColorCMYK(void)
438   : Color(CMYKPixel)
439 {
440 }
441 
ColorCMYK(const Magick::Color & color_)442 Magick::ColorCMYK::ColorCMYK(const Magick::Color &color_)
443   : Color(color_)
444 {
445 }
446 
ColorCMYK(const double cyan_,const double magenta_,const double yellow_,const double black_)447 Magick::ColorCMYK::ColorCMYK(const double cyan_,const double magenta_,
448   const double yellow_,const double black_)
449   : Color(CMYKPixel)
450 {
451   cyan(cyan_);
452   magenta(magenta_);
453   yellow(yellow_);
454   black(black_);
455 }
456 
ColorCMYK(const double cyan_,const double magenta_,const double yellow_,const double black_,const double alpha_)457 Magick::ColorCMYK::ColorCMYK(const double cyan_,const double magenta_,
458   const double yellow_,const double black_,const double alpha_)
459   : Color(CMYKAPixel)
460 {
461   cyan(cyan_);
462   magenta(magenta_);
463   yellow(yellow_);
464   black(black_);
465   alpha(alpha_);
466 }
467 
~ColorCMYK(void)468 Magick::ColorCMYK::~ColorCMYK(void)
469 {
470 }
471 
operator =(const Magick::Color & color_)472 Magick::ColorCMYK& Magick::ColorCMYK::operator=(const Magick::Color& color_)
473 {
474   *static_cast<Magick::Color*>(this)=color_;
475   return(*this);
476 }
477 
alpha(const double alpha_)478 void Magick::ColorCMYK::alpha(const double alpha_)
479 {
480   quantumAlpha(scaleDoubleToQuantum(alpha_));
481 }
482 
alpha(void) const483 double Magick::ColorCMYK::alpha(void) const
484 {
485   return(scaleQuantumToDouble(quantumAlpha()));
486 }
487 
black(const double black_)488 void Magick::ColorCMYK::black(const double black_)
489 {
490   quantumBlack(scaleDoubleToQuantum(black_));
491 }
492 
black(void) const493 double Magick::ColorCMYK::black(void) const
494 {
495   return(scaleQuantumToDouble(quantumBlack()));
496 }
497 
cyan(const double cyan_)498 void Magick::ColorCMYK::cyan(const double cyan_)
499 {
500   quantumRed(scaleDoubleToQuantum(cyan_));
501 }
502 
cyan(void) const503 double Magick::ColorCMYK::cyan(void) const
504 {
505   return(scaleQuantumToDouble(quantumRed()));
506 }
507 
magenta(const double magenta_)508 void Magick::ColorCMYK::magenta(const double magenta_)
509 {
510   quantumGreen(scaleDoubleToQuantum(magenta_));
511 }
512 
magenta(void) const513 double Magick::ColorCMYK::magenta(void) const
514 {
515   return(scaleQuantumToDouble(quantumGreen()));
516 }
517 
yellow(const double yellow_)518 void Magick::ColorCMYK::yellow(const double yellow_)
519 {
520   quantumBlue(scaleDoubleToQuantum(yellow_));
521 }
522 
yellow(void) const523 double Magick::ColorCMYK::yellow(void) const
524 {
525   return(scaleQuantumToDouble(quantumBlue()));
526 }
527 
ColorCMYK(PixelInfo * rep_,PixelType pixelType_)528 Magick::ColorCMYK::ColorCMYK(PixelInfo *rep_,PixelType pixelType_)
529   : Color(rep_,pixelType_)
530 {
531 }
532 
ColorGray(void)533 Magick::ColorGray::ColorGray(void)
534   : Color()
535 {
536 }
537 
ColorGray(const Magick::Color & color_)538 Magick::ColorGray::ColorGray(const Magick::Color & color_)
539   : Color(color_)
540 {
541 }
542 
ColorGray(double shade_)543 Magick::ColorGray::ColorGray(double shade_)
544   : Color(scaleDoubleToQuantum(shade_),scaleDoubleToQuantum(shade_),
545           scaleDoubleToQuantum(shade_))
546 {
547 }
548 
~ColorGray()549 Magick::ColorGray::~ColorGray()
550 {
551 }
552 
shade(double shade_)553 void Magick::ColorGray::shade(double shade_)
554 {
555   Quantum gray=scaleDoubleToQuantum(shade_);
556   quantumRed(gray);
557   quantumGreen(gray);
558   quantumBlue(gray);
559 }
560 
shade(void) const561 double Magick::ColorGray::shade(void) const
562 {
563   return(scaleQuantumToDouble(quantumGreen()));
564 }
565 
operator =(const Magick::Color & color_)566 Magick::ColorGray& Magick::ColorGray::operator=(const Magick::Color& color_)
567 {
568   *static_cast<Magick::Color*>(this)=color_;
569   return(*this);
570 }
571 
ColorGray(PixelInfo * rep_,PixelType pixelType_)572 Magick::ColorGray::ColorGray(PixelInfo *rep_,PixelType pixelType_)
573 : Color(rep_,pixelType_)
574 {
575 }
576 
ColorHSL(void)577 Magick::ColorHSL::ColorHSL(void)
578   : Color()
579 {
580 }
581 
ColorHSL(const Magick::Color & color_)582 Magick::ColorHSL::ColorHSL(const Magick::Color &color_)
583   : Color(color_)
584 {
585 }
586 
ColorHSL(const double hue_,const double saturation_,const double lightness_)587 Magick::ColorHSL::ColorHSL(const double hue_,const double saturation_,
588   const double lightness_)
589   : Color()
590 {
591   double
592     blue,
593     green,
594     red;
595 
596   ConvertHSLToRGB(hue_,saturation_,lightness_,&red,&green,&blue);
597 
598   quantumRed(red);
599   quantumGreen(green);
600   quantumBlue(blue);
601 }
602 
~ColorHSL()603 Magick::ColorHSL::~ColorHSL()
604 {
605 }
606 
operator =(const Magick::Color & color_)607 Magick::ColorHSL& Magick::ColorHSL::operator=(const Magick::Color& color_)
608 {
609   *static_cast<Magick::Color*>(this) = color_;
610   return(*this);
611 }
612 
hue(const double hue_)613 void Magick::ColorHSL::hue(const double hue_)
614 {
615   double
616     hue,
617     lightness,
618     saturation;
619 
620   double
621     blue,
622     green,
623     red;
624 
625   ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
626     &lightness);
627 
628   hue=hue_;
629 
630   ConvertHSLToRGB(hue,saturation,lightness,&red,&green,&blue);
631 
632   quantumRed(ClampToQuantum(red));
633   quantumGreen(ClampToQuantum(green));
634   quantumBlue(ClampToQuantum(blue));
635 }
636 
hue(void) const637 double Magick::ColorHSL::hue(void) const
638 {
639   double
640     hue,
641     lightness,
642     saturation;
643 
644   ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
645     &lightness);
646 
647   return(hue);
648 }
649 
lightness(const double lightness_)650 void Magick::ColorHSL::lightness (const double lightness_)
651 {
652   double
653     hue,
654     lightness,
655     saturation;
656 
657   double
658     blue,
659     green,
660     red;
661 
662   ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
663     &lightness);
664 
665   lightness=lightness_;
666 
667   ConvertHSLToRGB(hue,saturation,lightness,&red,&green,&blue);
668 
669   quantumRed(ClampToQuantum(red));
670   quantumGreen(ClampToQuantum(green));
671   quantumBlue(ClampToQuantum(blue));
672 }
673 
lightness(void) const674 double Magick::ColorHSL::lightness (void) const
675 {
676   double
677     hue,
678     lightness,
679     saturation;
680 
681   ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
682     &lightness);
683 
684   return(lightness);
685 }
686 
saturation(const double saturation_)687 void Magick::ColorHSL::saturation(const double saturation_)
688 {
689   double
690     hue,
691     lightness,
692     saturation;
693 
694   double
695     blue,
696     green,
697     red;
698 
699   ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
700     &lightness);
701 
702   saturation=saturation_;
703 
704   ConvertHSLToRGB(hue,saturation,lightness,&red,&green,&blue);
705 
706   quantumRed(ClampToQuantum(red));
707   quantumGreen(ClampToQuantum(green));
708   quantumBlue(ClampToQuantum(blue));
709 }
710 
saturation(void) const711 double Magick::ColorHSL::saturation(void) const
712 {
713   double
714     hue,
715     lightness,
716     saturation;
717 
718   ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
719     &lightness);
720 
721   return(saturation);
722 }
723 
ColorMono(void)724 Magick::ColorMono::ColorMono(void)
725   : Color()
726 {
727 }
728 
ColorMono(const bool mono_)729 Magick::ColorMono::ColorMono(const bool mono_)
730   : Color((mono_ ? QuantumRange : 0),(mono_ ? QuantumRange : 0),
731           (mono_ ? QuantumRange : 0))
732 {
733 }
734 
ColorMono(const Magick::Color & color_)735 Magick::ColorMono::ColorMono(const Magick::Color &color_)
736   : Color(color_)
737 {
738 }
739 
~ColorMono()740 Magick::ColorMono::~ColorMono()
741 {
742 }
743 
operator =(const Magick::Color & color_)744 Magick::ColorMono& Magick::ColorMono::operator=(const Magick::Color& color_)
745 {
746   *static_cast<Magick::Color*>(this)=color_;
747   return(*this);
748 }
749 
mono(bool mono_)750 void Magick::ColorMono::mono(bool mono_)
751 {
752   quantumRed(mono_ ? QuantumRange : 0);
753   quantumGreen(mono_ ? QuantumRange : 0);
754   quantumBlue(mono_ ? QuantumRange : 0);
755 }
756 
mono(void) const757 bool Magick::ColorMono::mono(void) const
758 {
759   return(quantumGreen() == 0);
760 }
761 
ColorMono(PixelInfo * rep_,PixelType pixelType_)762 Magick::ColorMono::ColorMono(PixelInfo *rep_,PixelType pixelType_)
763   : Color(rep_,pixelType_)
764 {
765 }
766 
ColorRGB(void)767 Magick::ColorRGB::ColorRGB(void)
768   : Color()
769 {
770 }
771 
ColorRGB(const Magick::Color & color_)772 Magick::ColorRGB::ColorRGB(const Magick::Color &color_)
773   : Color(color_)
774 {
775 }
776 
ColorRGB(const double red_,const double green_,const double blue_)777 Magick::ColorRGB::ColorRGB(const double red_,const double green_,
778   const double blue_)
779   : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_),
780           scaleDoubleToQuantum(blue_))
781 {
782 }
783 
ColorRGB(const double red_,const double green_,const double blue_,const double alpha_)784 Magick::ColorRGB::ColorRGB(const double red_,const double green_,
785   const double blue_,const double alpha_)
786   : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_),
787           scaleDoubleToQuantum(blue_),scaleDoubleToQuantum(alpha_))
788 {
789 }
790 
~ColorRGB(void)791 Magick::ColorRGB::~ColorRGB(void)
792 {
793 }
794 
operator =(const Magick::Color & color_)795 Magick::ColorRGB& Magick::ColorRGB::operator=(const Magick::Color& color_)
796 {
797   *static_cast<Magick::Color*>(this)=color_;
798   return(*this);
799 }
800 
alpha(const double alpha_)801 void Magick::ColorRGB::alpha(const double alpha_)
802 {
803   quantumAlpha(scaleDoubleToQuantum(alpha_));
804 }
805 
alpha(void) const806 double Magick::ColorRGB::alpha(void) const
807 {
808   return(scaleQuantumToDouble(quantumAlpha()));
809 }
810 
blue(const double blue_)811 void Magick::ColorRGB::blue(const double blue_)
812 {
813   quantumBlue(scaleDoubleToQuantum(blue_));
814 }
815 
blue(void) const816 double Magick::ColorRGB::blue(void) const
817 {
818   return(scaleQuantumToDouble(quantumBlue()));
819 }
820 
green(const double green_)821 void Magick::ColorRGB::green(const double green_)
822 {
823   quantumGreen(scaleDoubleToQuantum(green_));
824 }
825 
green(void) const826 double Magick::ColorRGB::green(void) const
827 {
828   return(scaleQuantumToDouble(quantumGreen()));
829 }
830 
red(const double red_)831 void Magick::ColorRGB::red(const double red_)
832 {
833   quantumRed(scaleDoubleToQuantum(red_));
834 }
835 
red(void) const836 double Magick::ColorRGB::red(void) const
837 {
838   return(scaleQuantumToDouble(quantumRed()));
839 }
840 
ColorRGB(PixelInfo * rep_,PixelType pixelType_)841 Magick::ColorRGB::ColorRGB(PixelInfo *rep_,PixelType pixelType_)
842   : Color(rep_,pixelType_)
843 {
844 }
845 
ColorYUV(void)846 Magick::ColorYUV::ColorYUV(void)
847   : Color()
848 {
849 }
850 
ColorYUV(const Magick::Color & color_)851 Magick::ColorYUV::ColorYUV(const Magick::Color &color_)
852   : Color(color_)
853 {
854 }
855 
ColorYUV(const double y_,const double u_,const double v_)856 Magick::ColorYUV::ColorYUV(const double y_,const double u_,const double v_)
857   : Color()
858 {
859   convert(y_, u_, v_);
860 }
861 
~ColorYUV(void)862 Magick::ColorYUV::~ColorYUV(void)
863 {
864 }
865 
operator =(const Magick::Color & color_)866 Magick::ColorYUV& Magick::ColorYUV::operator=(const Magick::Color &color_)
867 {
868   *static_cast<Magick::Color*>(this)=color_;
869   return(*this);
870 }
871 
u(const double u_)872 void Magick::ColorYUV::u(const double u_)
873 {
874   convert(y(), u_, v());
875 }
876 
u(void) const877 double Magick::ColorYUV::u(void) const
878 {
879   return(scaleQuantumToDouble((-0.14740 * quantumRed()) - (0.28950 *
880     quantumGreen()) + (0.43690 * quantumBlue())));
881 }
882 
v(const double v_)883 void Magick::ColorYUV::v(const double v_)
884 {
885   convert(y(), u(), v_);
886 }
887 
v(void) const888 double Magick::ColorYUV::v(void) const
889 {
890   return(scaleQuantumToDouble((0.61500 * quantumRed()) - (0.51500 *
891     quantumGreen()) - (0.10000 * quantumBlue())));
892 }
893 
y(const double y_)894 void Magick::ColorYUV::y(const double y_)
895 {
896   convert(y_, u(), v());
897 }
898 
y(void) const899 double Magick::ColorYUV::y ( void ) const
900 {
901   return(scaleQuantumToDouble((0.29900 * quantumRed()) + (0.58700 *
902     quantumGreen()) + (0.11400 * quantumBlue())));
903 }
904 
convert(const double y_,const double u_,const double v_)905 void Magick::ColorYUV::convert(const double y_,const double u_,const double v_)
906 {
907   quantumRed(scaleDoubleToQuantum(y_ + 1.13980 * v_));
908   quantumGreen(scaleDoubleToQuantum(y_ - (0.39380 * u_) - (0.58050 * v_)));
909   quantumBlue(scaleDoubleToQuantum(y_ + 2.02790 * u_));
910 }
911 
ColorYUV(PixelInfo * rep_,PixelType pixelType_)912 Magick::ColorYUV::ColorYUV(PixelInfo *rep_,PixelType pixelType_)
913   : Color(rep_,pixelType_)
914 {
915 }
916