Magick++  7.1.2-29
Convert, Edit, Or Compose Bitmap Images
Color.cpp
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
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 
11 #define MAGICKCORE_IMPLEMENTATION
12 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
13 
14 #include "Magick++/Include.h"
15 #include <string>
16 
17 #include "Magick++/Color.h"
18 #include "Magick++/Exception.h"
19 
20 using namespace std;
21 
22 MagickPPExport int Magick::operator == (const Magick::Color &left_,
23  const Magick::Color &right_)
24 {
25 #if defined(MAGICKCORE_HDRI_SUPPORT)
26  return((left_.isValid() == right_.isValid()) &&
27  (fabs((double) left_.quantumRed()-(double) right_.quantumRed()) < MagickEpsilon) &&
28  (fabs((double) left_.quantumGreen()-(double) right_.quantumGreen()) < MagickEpsilon) &&
29  (fabs((double) left_.quantumBlue()-(double) right_.quantumBlue()) < MagickEpsilon));
30 #else
31  return((left_.isValid() == right_.isValid()) &&
32  (left_.quantumRed() == right_.quantumRed()) &&
33  (left_.quantumGreen() == right_.quantumGreen()) &&
34  (left_.quantumBlue() == right_.quantumBlue()));
35 #endif
36 }
37 
38 MagickPPExport int Magick::operator != (const Magick::Color &left_,
39  const Magick::Color &right_)
40 {
41  return(!(left_ == right_));
42 }
43 
44 MagickPPExport int Magick::operator > (const Magick::Color &left_,
45  const Magick::Color &right_)
46 {
47  return(!(left_ < right_ ) && (left_ != right_ ));
48 }
49 
50 MagickPPExport int Magick::operator < ( const Magick::Color &left_,
51  const Magick::Color &right_)
52 {
53  if(left_.quantumRed() < right_.quantumRed())
54  return(true);
55  if(left_.quantumRed() > right_.quantumRed())
56  return(false);
57  if(left_.quantumGreen() < right_.quantumGreen())
58  return(true);
59  if(left_.quantumGreen() > right_.quantumGreen())
60  return(false);
61  if(left_.quantumBlue() < right_.quantumBlue())
62  return(true);
63  return(false);
64 }
65 
66 MagickPPExport int Magick::operator >= (const Magick::Color &left_,
67  const Magick::Color &right_)
68 {
69  return((left_ > right_) || (left_ == right_));
70 }
71 
72 MagickPPExport int Magick::operator <= ( const Magick::Color &left_,
73  const Magick::Color &right_)
74 {
75  return((left_ < right_) || (left_ == right_));
76 }
77 
78 Magick::Color::Color(void)
79  : _pixel(new PixelInfo),
80  _isValid(false),
81  _pixelOwn(true),
82  _pixelType(RGBAPixel)
83 {
84  initPixel();
85 
86  setAlpha(TransparentAlpha);
87 }
88 
89 Magick::Color::Color(const Magick::Quantum red_,const Magick::Quantum green_,
90  const Quantum blue_)
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 }
104 
105 Magick::Color::Color(const Magick::Quantum red_,const Magick::Quantum green_,
106  const Magick::Quantum blue_, const Magick::Quantum alpha_)
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 }
122 
123 Magick::Color::Color(const Magick::Quantum cyan_,const Magick::Quantum magenta_,
124  const Magick::Quantum yellow_,const Magick::Quantum black_,
125  const Magick::Quantum alpha_)
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 }
141 
142 Magick::Color::Color(const char *color_)
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 }
163 
164 Magick::Color::Color(const Magick::Color &color_)
165  : _pixel(new PixelInfo),
166  _isValid(color_._isValid),
167  _pixelOwn(true),
168  _pixelType(color_._pixelType)
169 {
170  *_pixel=*color_._pixel;
171 }
172 
173 Magick::Color::Color(const PixelInfo &color_)
174  : _pixel(new PixelInfo),
175  _isValid(true),
176  _pixelOwn(true)
177 {
178  *_pixel=color_;
179  setPixelType(color_);
180 }
181 
182 Magick::Color::Color(const std::string &color_)
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 }
203 
204 Magick::Color::~Color(void)
205 {
206  if (_pixelOwn)
207  delete _pixel;
208 
209  _pixel=(PixelInfo *)NULL;
210 }
211 
212 Magick::Color& Magick::Color::operator=(const Magick::Color& color_)
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 }
228 
229 const Magick::Color& Magick::Color::operator=(const char *color_)
230 {
231  *this=std::string(color_);
232  return(*this);
233 }
234 
235 const Magick::Color& Magick::Color::operator=(const MagickCore::PixelInfo &color_)
236 {
237  *_pixel=color_;
238  setPixelType(color_);
239 
240  return(*this);
241 }
242 
243 const Magick::Color& Magick::Color::operator=(const std::string &color_)
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 }
272 
273 Magick::Color::operator MagickCore::PixelInfo() const
274 {
275  return *_pixel;
276 }
277 
278 Magick::Color::operator std::string() const
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 }
302 
303 bool Magick::Color::isFuzzyEquivalent(const Color &color_, const double fuzz_) const
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 }
315 
316 bool Magick::Color::isValid(void) const
317 {
318  return(_isValid);
319 }
320 
321 Magick::Color::PixelType Magick::Color::pixelType() const
322 {
323  return(_pixelType);
324 }
325 
326 void Magick::Color::isValid(bool valid_)
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 }
341 
342 void Magick::Color::quantumAlpha(const Magick::Quantum alpha_)
343 {
344  setAlpha(alpha_);
345  _isValid=true;
346 }
347 
348 Magick::Quantum Magick::Color::quantumAlpha(void) const
349 {
350  return((Magick::Quantum) _pixel->alpha);
351 }
352 
353 void Magick::Color::quantumBlack(const Magick::Quantum black_)
354 {
355  _pixel->black=black_;
356  _isValid=true;
357 }
358 
359 Magick::Quantum Magick::Color::quantumBlack(void) const
360 {
361  return((Magick::Quantum) _pixel->black);
362 }
363 
364 void Magick::Color::quantumBlue(const Magick::Quantum blue_)
365 {
366  _pixel->blue=blue_;
367  _isValid=true;
368 }
369 
370 Magick::Quantum Magick::Color::quantumBlue(void) const
371 {
372  return((Magick::Quantum) _pixel->blue);
373 }
374 
375 void Magick::Color::quantumGreen(const Magick::Quantum green_)
376 {
377  _pixel->green=green_;
378  _isValid=true;
379 }
380 
381 Magick::Quantum Magick::Color::quantumGreen(void) const
382 {
383  return((Magick::Quantum) _pixel->green);
384 }
385 
386 void Magick::Color::quantumRed(const Magick::Quantum red_)
387 {
388  _pixel->red=red_;
389  _isValid=true;
390 }
391 
392 Magick::Quantum Magick::Color::quantumRed(void) const
393 {
394  return((Magick::Quantum) _pixel->red);
395 }
396 
397 Magick::Color::Color(PixelType pixelType_)
398  : _pixel(new PixelInfo),
399  _isValid(false),
400  _pixelOwn(true),
401  _pixelType(pixelType_)
402 {
403  initPixel();
404 }
405 
406 Magick::Color::Color(PixelInfo* rep_,PixelType pixelType_)
407  : _pixel(rep_),
408  _isValid(true),
409  _pixelOwn(false),
410  _pixelType(pixelType_)
411 {
412 }
413 
414 void Magick::Color::pixel(PixelInfo *rep_,PixelType pixelType_)
415 {
416  if (_pixelOwn)
417  delete _pixel;
418 
419  _pixel=rep_;
420  _pixelOwn=false;
421  _isValid=true;
422  _pixelType=pixelType_;
423 }
424 
425 Magick::Quantum Magick::Color::scaleDoubleToQuantum(const double double_)
426 {
427  return(static_cast<Magick::Quantum>(double_*(double) QuantumRange));
428 }
429 
430 double Magick::Color::scaleQuantumToDouble(const Magick::Quantum quantum_)
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 }
438 
439 void Magick::Color::initPixel()
440 {
441  MagickCore::GetPixelInfo((MagickCore::Image *) NULL, _pixel);
442  if (_pixelType == CMYKPixel || _pixelType == CMYKAPixel)
443  _pixel->colorspace=CMYKColorspace;
444 }
445 
446 void Magick::Color::setAlpha(const Magick::Quantum alpha_)
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 }
466 
467 void Magick::Color::setPixelType(const PixelInfo &color_)
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 }
476 
477 Magick::ColorCMYK::ColorCMYK(void)
478  : Color(CMYKPixel)
479 {
480 }
481 
482 Magick::ColorCMYK::ColorCMYK(const Magick::Color &color_)
483  : Color(color_)
484 {
485 }
486 
487 Magick::ColorCMYK::ColorCMYK(const double cyan_,const double magenta_,
488  const double yellow_,const double black_)
489  : Color(CMYKPixel)
490 {
491  cyan(cyan_);
492  magenta(magenta_);
493  yellow(yellow_);
494  black(black_);
495 }
496 
497 Magick::ColorCMYK::ColorCMYK(const double cyan_,const double magenta_,
498  const double yellow_,const double black_,const double alpha_)
499  : Color(CMYKAPixel)
500 {
501  cyan(cyan_);
502  magenta(magenta_);
503  yellow(yellow_);
504  black(black_);
505  alpha(alpha_);
506 }
507 
508 Magick::ColorCMYK::~ColorCMYK(void)
509 {
510 }
511 
512 Magick::ColorCMYK& Magick::ColorCMYK::operator=(const Magick::Color& color_)
513 {
514  *static_cast<Magick::Color*>(this)=color_;
515  return(*this);
516 }
517 
518 void Magick::ColorCMYK::alpha(const double alpha_)
519 {
520  quantumAlpha(scaleDoubleToQuantum(alpha_));
521 }
522 
523 double Magick::ColorCMYK::alpha(void) const
524 {
525  return(scaleQuantumToDouble(quantumAlpha()));
526 }
527 
528 void Magick::ColorCMYK::black(const double black_)
529 {
530  quantumBlack(scaleDoubleToQuantum(black_));
531 }
532 
533 double Magick::ColorCMYK::black(void) const
534 {
535  return(scaleQuantumToDouble(quantumBlack()));
536 }
537 
538 void Magick::ColorCMYK::cyan(const double cyan_)
539 {
540  quantumRed(scaleDoubleToQuantum(cyan_));
541 }
542 
543 double Magick::ColorCMYK::cyan(void) const
544 {
545  return(scaleQuantumToDouble(quantumRed()));
546 }
547 
548 void Magick::ColorCMYK::magenta(const double magenta_)
549 {
550  quantumGreen(scaleDoubleToQuantum(magenta_));
551 }
552 
553 double Magick::ColorCMYK::magenta(void) const
554 {
555  return(scaleQuantumToDouble(quantumGreen()));
556 }
557 
558 void Magick::ColorCMYK::yellow(const double yellow_)
559 {
560  quantumBlue(scaleDoubleToQuantum(yellow_));
561 }
562 
563 double Magick::ColorCMYK::yellow(void) const
564 {
565  return(scaleQuantumToDouble(quantumBlue()));
566 }
567 
568 Magick::ColorCMYK::ColorCMYK(PixelInfo *rep_,PixelType pixelType_)
569  : Color(rep_,pixelType_)
570 {
571 }
572 
573 Magick::ColorGray::ColorGray(void)
574  : Color(RGBPixel)
575 {
576 }
577 
578 Magick::ColorGray::ColorGray(const Magick::Color & color_)
579  : Color(color_)
580 {
581 }
582 
583 Magick::ColorGray::ColorGray(double shade_)
584  : Color(scaleDoubleToQuantum(shade_),scaleDoubleToQuantum(shade_),
585  scaleDoubleToQuantum(shade_))
586 {
587 }
588 
589 Magick::ColorGray::~ColorGray()
590 {
591 }
592 
593 void Magick::ColorGray::shade(double shade_)
594 {
595  Quantum gray=scaleDoubleToQuantum(shade_);
596  quantumRed(gray);
597  quantumGreen(gray);
598  quantumBlue(gray);
599 }
600 
601 double Magick::ColorGray::shade(void) const
602 {
603  return(scaleQuantumToDouble(quantumGreen()));
604 }
605 
606 Magick::ColorGray& Magick::ColorGray::operator=(const Magick::Color& color_)
607 {
608  *static_cast<Magick::Color*>(this)=color_;
609  return(*this);
610 }
611 
612 Magick::ColorGray::ColorGray(PixelInfo *rep_,PixelType pixelType_)
613 : Color(rep_,pixelType_)
614 {
615 }
616 
617 Magick::ColorHSL::ColorHSL(void)
618  : Color(RGBPixel)
619 {
620 }
621 
622 Magick::ColorHSL::ColorHSL(const Magick::Color &color_)
623  : Color(color_)
624 {
625 }
626 
627 Magick::ColorHSL::ColorHSL(const double hue_,const double saturation_,
628  const double lightness_)
629  : Color(RGBPixel)
630 {
631  double
632  blue,
633  green,
634  red;
635 
636  ConvertHSLToRGB(hue_,saturation_,lightness_,&red,&green,&blue);
637 
638  quantumRed((Magick::Quantum) red);
639  quantumGreen((Magick::Quantum) green);
640  quantumBlue((Magick::Quantum) blue);
641 }
642 
643 Magick::ColorHSL::~ColorHSL()
644 {
645 }
646 
647 Magick::ColorHSL& Magick::ColorHSL::operator=(const Magick::Color& color_)
648 {
649  *static_cast<Magick::Color*>(this) = color_;
650  return(*this);
651 }
652 
653 void Magick::ColorHSL::hue(const double hue_)
654 {
655  double
656  hue,
657  lightness,
658  saturation;
659 
660  double
661  blue,
662  green,
663  red;
664 
665  ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
666  &lightness);
667 
668  hue=hue_;
669 
670  ConvertHSLToRGB(hue,saturation,lightness,&red,&green,&blue);
671 
672  quantumRed(ClampToQuantum(red));
673  quantumGreen(ClampToQuantum(green));
674  quantumBlue(ClampToQuantum(blue));
675 }
676 
677 double Magick::ColorHSL::hue(void) const
678 {
679  double
680  hue,
681  lightness,
682  saturation;
683 
684  ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
685  &lightness);
686 
687  return(hue);
688 }
689 
690 void Magick::ColorHSL::lightness (const double lightness_)
691 {
692  double
693  hue,
694  lightness,
695  saturation;
696 
697  double
698  blue,
699  green,
700  red;
701 
702  ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
703  &lightness);
704 
705  lightness=lightness_;
706 
707  ConvertHSLToRGB(hue,saturation,lightness,&red,&green,&blue);
708 
709  quantumRed(ClampToQuantum(red));
710  quantumGreen(ClampToQuantum(green));
711  quantumBlue(ClampToQuantum(blue));
712 }
713 
714 double Magick::ColorHSL::lightness (void) const
715 {
716  double
717  hue,
718  lightness,
719  saturation;
720 
721  ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
722  &lightness);
723 
724  return(lightness);
725 }
726 
727 void Magick::ColorHSL::saturation(const double saturation_)
728 {
729  double
730  hue,
731  lightness,
732  saturation;
733 
734  double
735  blue,
736  green,
737  red;
738 
739  ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
740  &lightness);
741 
742  saturation=saturation_;
743 
744  ConvertHSLToRGB(hue,saturation,lightness,&red,&green,&blue);
745 
746  quantumRed(ClampToQuantum(red));
747  quantumGreen(ClampToQuantum(green));
748  quantumBlue(ClampToQuantum(blue));
749 }
750 
751 double Magick::ColorHSL::saturation(void) const
752 {
753  double
754  hue,
755  lightness,
756  saturation;
757 
758  ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation,
759  &lightness);
760 
761  return(saturation);
762 }
763 
764 Magick::ColorMono::ColorMono(void)
765  : Color(RGBPixel)
766 {
767 }
768 
769 Magick::ColorMono::ColorMono(const bool mono_)
770  : Color((mono_ ? QuantumRange : 0),(mono_ ? QuantumRange : 0),
771  (mono_ ? QuantumRange : 0))
772 {
773 }
774 
775 Magick::ColorMono::ColorMono(const Magick::Color &color_)
776  : Color(color_)
777 {
778 }
779 
780 Magick::ColorMono::~ColorMono()
781 {
782 }
783 
784 Magick::ColorMono& Magick::ColorMono::operator=(const Magick::Color& color_)
785 {
786  *static_cast<Magick::Color*>(this)=color_;
787  return(*this);
788 }
789 
790 void Magick::ColorMono::mono(bool mono_)
791 {
792  quantumRed(mono_ ? QuantumRange : 0);
793  quantumGreen(mono_ ? QuantumRange : 0);
794  quantumBlue(mono_ ? QuantumRange : 0);
795 }
796 
797 bool Magick::ColorMono::mono(void) const
798 {
799  return(quantumGreen() == 0);
800 }
801 
802 Magick::ColorMono::ColorMono(PixelInfo *rep_,PixelType pixelType_)
803  : Color(rep_,pixelType_)
804 {
805 }
806 
807 Magick::ColorRGB::ColorRGB(void)
808  : Color(RGBPixel)
809 {
810 }
811 
812 Magick::ColorRGB::ColorRGB(const Magick::Color &color_)
813  : Color(color_)
814 {
815 }
816 
817 Magick::ColorRGB::ColorRGB(const double red_,const double green_,
818  const double blue_)
819  : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_),
820  scaleDoubleToQuantum(blue_))
821 {
822 }
823 
824 Magick::ColorRGB::ColorRGB(const double red_,const double green_,
825  const double blue_,const double alpha_)
826  : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_),
827  scaleDoubleToQuantum(blue_),scaleDoubleToQuantum(alpha_))
828 {
829 }
830 
831 Magick::ColorRGB::~ColorRGB(void)
832 {
833 }
834 
835 Magick::ColorRGB& Magick::ColorRGB::operator=(const Magick::Color& color_)
836 {
837  *static_cast<Magick::Color*>(this)=color_;
838  return(*this);
839 }
840 
841 void Magick::ColorRGB::alpha(const double alpha_)
842 {
843  quantumAlpha(scaleDoubleToQuantum(alpha_));
844 }
845 
846 double Magick::ColorRGB::alpha(void) const
847 {
848  return(scaleQuantumToDouble(quantumAlpha()));
849 }
850 
851 void Magick::ColorRGB::blue(const double blue_)
852 {
853  quantumBlue(scaleDoubleToQuantum(blue_));
854 }
855 
856 double Magick::ColorRGB::blue(void) const
857 {
858  return(scaleQuantumToDouble(quantumBlue()));
859 }
860 
861 void Magick::ColorRGB::green(const double green_)
862 {
863  quantumGreen(scaleDoubleToQuantum(green_));
864 }
865 
866 double Magick::ColorRGB::green(void) const
867 {
868  return(scaleQuantumToDouble(quantumGreen()));
869 }
870 
871 void Magick::ColorRGB::red(const double red_)
872 {
873  quantumRed(scaleDoubleToQuantum(red_));
874 }
875 
876 double Magick::ColorRGB::red(void) const
877 {
878  return(scaleQuantumToDouble(quantumRed()));
879 }
880 
881 Magick::ColorRGB::ColorRGB(PixelInfo *rep_,PixelType pixelType_)
882  : Color(rep_,pixelType_)
883 {
884 }
885 
886 Magick::ColorYUV::ColorYUV(void)
887  : Color(RGBPixel)
888 {
889 }
890 
891 Magick::ColorYUV::ColorYUV(const Magick::Color &color_)
892  : Color(color_)
893 {
894 }
895 
896 Magick::ColorYUV::ColorYUV(const double y_,const double u_,const double v_)
897  : Color(RGBPixel)
898 {
899  convert(y_, u_, v_);
900 }
901 
902 Magick::ColorYUV::~ColorYUV(void)
903 {
904 }
905 
906 Magick::ColorYUV& Magick::ColorYUV::operator=(const Magick::Color &color_)
907 {
908  *static_cast<Magick::Color*>(this)=color_;
909  return(*this);
910 }
911 
912 void Magick::ColorYUV::u(const double u_)
913 {
914  convert(y(), u_, v());
915 }
916 
917 double Magick::ColorYUV::u(void) const
918 {
919  return(scaleQuantumToDouble((Magick::Quantum) ((-0.14740 *
920  (double) quantumRed()) - (0.28950 * (double) quantumGreen()) + (0.43690 *
921  (double) quantumBlue()))));
922 }
923 
924 void Magick::ColorYUV::v(const double v_)
925 {
926  convert(y(), u(), v_);
927 }
928 
929 double Magick::ColorYUV::v(void) const
930 {
931  return(scaleQuantumToDouble((Magick::Quantum) ((0.61500 *
932  (double) quantumRed()) - (0.51500 * (double) quantumGreen()) - (0.10000 *
933  (double) quantumBlue()))));
934 }
935 
936 void Magick::ColorYUV::y(const double y_)
937 {
938  convert(y_, u(), v());
939 }
940 
941 double Magick::ColorYUV::y ( void ) const
942 {
943  return(scaleQuantumToDouble((Magick::Quantum) ((0.29900 *
944  (double) quantumRed()) + (0.58700 * (double) quantumGreen()) + (0.11400 *
945  (double) quantumBlue()))));
946 }
947 
948 void Magick::ColorYUV::convert(const double y_,const double u_,const double v_)
949 {
950  quantumRed(scaleDoubleToQuantum(y_ + 1.13980 * v_));
951  quantumGreen(scaleDoubleToQuantum(y_ - (0.39380 * u_) - (0.58050 * v_)));
952  quantumBlue(scaleDoubleToQuantum(y_ + 2.02790 * u_));
953 }
954 
955 Magick::ColorYUV::ColorYUV(PixelInfo *rep_,PixelType pixelType_)
956  : Color(rep_,pixelType_)
957 {
958 }