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