Magick++ 7.1.2-24
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 <string>
16
17#include "Magick++/Color.h"
18#include "Magick++/Exception.h"
19
20using namespace std;
21
22MagickPPExport 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
38MagickPPExport int Magick::operator != (const Magick::Color &left_,
39 const Magick::Color &right_)
40{
41 return(!(left_ == right_));
42}
43
44MagickPPExport int Magick::operator > (const Magick::Color &left_,
45 const Magick::Color &right_)
46{
47 return(!(left_ < right_ ) && (left_ != right_ ));
48}
49
50MagickPPExport 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
66MagickPPExport int Magick::operator >= (const Magick::Color &left_,
67 const Magick::Color &right_)
68{
69 return((left_ > right_) || (left_ == right_));
70}
71
72MagickPPExport int Magick::operator <= ( const Magick::Color &left_,
73 const Magick::Color &right_)
74{
75 return((left_ < right_) || (left_ == right_));
76}
77
78Magick::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
89Magick::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
105Magick::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
123Magick::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
142Magick::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
164Magick::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
173Magick::Color::Color(const PixelInfo &color_)
174 : _pixel(new PixelInfo),
175 _isValid(true),
176 _pixelOwn(true)
177{
178 *_pixel=color_;
179 setPixelType(color_);
180}
181
182Magick::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
204Magick::Color::~Color(void)
205{
206 if (_pixelOwn)
207 delete _pixel;
208
209 _pixel=(PixelInfo *)NULL;
210}
211
212Magick::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
229const Magick::Color& Magick::Color::operator=(const char *color_)
230{
231 *this=std::string(color_);
232 return(*this);
233}
234
235const Magick::Color& Magick::Color::operator=(const MagickCore::PixelInfo &color_)
236{
237 *_pixel=color_;
238 setPixelType(color_);
239
240 return(*this);
241}
242
243const 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
273Magick::Color::operator MagickCore::PixelInfo() const
274{
275 return *_pixel;
276}
277
278Magick::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
303bool 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
316bool Magick::Color::isValid(void) const
317{
318 return(_isValid);
319}
320
321Magick::Color::PixelType Magick::Color::pixelType() const
322{
323 return(_pixelType);
324}
325
326void 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
342void Magick::Color::quantumAlpha(const Magick::Quantum alpha_)
343{
344 setAlpha(alpha_);
345 _isValid=true;
346}
347
348Magick::Quantum Magick::Color::quantumAlpha(void) const
349{
350 return((Magick::Quantum) _pixel->alpha);
351}
352
353void Magick::Color::quantumBlack(const Magick::Quantum black_)
354{
355 _pixel->black=black_;
356 _isValid=true;
357}
358
359Magick::Quantum Magick::Color::quantumBlack(void) const
360{
361 return((Magick::Quantum) _pixel->black);
362}
363
364void Magick::Color::quantumBlue(const Magick::Quantum blue_)
365{
366 _pixel->blue=blue_;
367 _isValid=true;
368}
369
370Magick::Quantum Magick::Color::quantumBlue(void) const
371{
372 return((Magick::Quantum) _pixel->blue);
373}
374
375void Magick::Color::quantumGreen(const Magick::Quantum green_)
376{
377 _pixel->green=green_;
378 _isValid=true;
379}
380
381Magick::Quantum Magick::Color::quantumGreen(void) const
382{
383 return((Magick::Quantum) _pixel->green);
384}
385
386void Magick::Color::quantumRed(const Magick::Quantum red_)
387{
388 _pixel->red=red_;
389 _isValid=true;
390}
391
392Magick::Quantum Magick::Color::quantumRed(void) const
393{
394 return((Magick::Quantum) _pixel->red);
395}
396
397Magick::Color::Color(PixelType pixelType_)
398 : _pixel(new PixelInfo),
399 _isValid(false),
400 _pixelOwn(true),
401 _pixelType(pixelType_)
402{
403 initPixel();
404}
405
406Magick::Color::Color(PixelInfo* rep_,PixelType pixelType_)
407 : _pixel(rep_),
408 _isValid(true),
409 _pixelOwn(false),
410 _pixelType(pixelType_)
411{
412}
413
414void 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
425Magick::Quantum Magick::Color::scaleDoubleToQuantum(const double double_)
426{
427 return(static_cast<Magick::Quantum>(double_*(double) QuantumRange));
428}
429
430double 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
439void Magick::Color::initPixel()
440{
441 MagickCore::GetPixelInfo((MagickCore::Image *) NULL, _pixel);
442 if (_pixelType == CMYKPixel || _pixelType == CMYKAPixel)
443 _pixel->colorspace=CMYKColorspace;
444}
445
446void 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
467void 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
477Magick::ColorCMYK::ColorCMYK(void)
478 : Color(CMYKPixel)
479{
480}
481
482Magick::ColorCMYK::ColorCMYK(const Magick::Color &color_)
483 : Color(color_)
484{
485}
486
487Magick::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
497Magick::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
508Magick::ColorCMYK::~ColorCMYK(void)
509{
510}
511
512Magick::ColorCMYK& Magick::ColorCMYK::operator=(const Magick::Color& color_)
513{
514 *static_cast<Magick::Color*>(this)=color_;
515 return(*this);
516}
517
518void Magick::ColorCMYK::alpha(const double alpha_)
519{
520 quantumAlpha(scaleDoubleToQuantum(alpha_));
521}
522
523double Magick::ColorCMYK::alpha(void) const
524{
525 return(scaleQuantumToDouble(quantumAlpha()));
526}
527
528void Magick::ColorCMYK::black(const double black_)
529{
530 quantumBlack(scaleDoubleToQuantum(black_));
531}
532
533double Magick::ColorCMYK::black(void) const
534{
535 return(scaleQuantumToDouble(quantumBlack()));
536}
537
538void Magick::ColorCMYK::cyan(const double cyan_)
539{
540 quantumRed(scaleDoubleToQuantum(cyan_));
541}
542
543double Magick::ColorCMYK::cyan(void) const
544{
545 return(scaleQuantumToDouble(quantumRed()));
546}
547
548void Magick::ColorCMYK::magenta(const double magenta_)
549{
550 quantumGreen(scaleDoubleToQuantum(magenta_));
551}
552
553double Magick::ColorCMYK::magenta(void) const
554{
555 return(scaleQuantumToDouble(quantumGreen()));
556}
557
558void Magick::ColorCMYK::yellow(const double yellow_)
559{
560 quantumBlue(scaleDoubleToQuantum(yellow_));
561}
562
563double Magick::ColorCMYK::yellow(void) const
564{
565 return(scaleQuantumToDouble(quantumBlue()));
566}
567
568Magick::ColorCMYK::ColorCMYK(PixelInfo *rep_,PixelType pixelType_)
569 : Color(rep_,pixelType_)
570{
571}
572
573Magick::ColorGray::ColorGray(void)
574 : Color(RGBPixel)
575{
576}
577
578Magick::ColorGray::ColorGray(const Magick::Color & color_)
579 : Color(color_)
580{
581}
582
583Magick::ColorGray::ColorGray(double shade_)
584 : Color(scaleDoubleToQuantum(shade_),scaleDoubleToQuantum(shade_),
585 scaleDoubleToQuantum(shade_))
586{
587}
588
589Magick::ColorGray::~ColorGray()
590{
591}
592
593void Magick::ColorGray::shade(double shade_)
594{
595 Quantum gray=scaleDoubleToQuantum(shade_);
596 quantumRed(gray);
597 quantumGreen(gray);
598 quantumBlue(gray);
599}
600
601double Magick::ColorGray::shade(void) const
602{
603 return(scaleQuantumToDouble(quantumGreen()));
604}
605
606Magick::ColorGray& Magick::ColorGray::operator=(const Magick::Color& color_)
607{
608 *static_cast<Magick::Color*>(this)=color_;
609 return(*this);
610}
611
612Magick::ColorGray::ColorGray(PixelInfo *rep_,PixelType pixelType_)
613: Color(rep_,pixelType_)
614{
615}
616
617Magick::ColorHSL::ColorHSL(void)
618 : Color(RGBPixel)
619{
620}
621
622Magick::ColorHSL::ColorHSL(const Magick::Color &color_)
623 : Color(color_)
624{
625}
626
627Magick::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
643Magick::ColorHSL::~ColorHSL()
644{
645}
646
647Magick::ColorHSL& Magick::ColorHSL::operator=(const Magick::Color& color_)
648{
649 *static_cast<Magick::Color*>(this) = color_;
650 return(*this);
651}
652
653void 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
677double 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
690void 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
714double 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
727void 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
751double 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
764Magick::ColorMono::ColorMono(void)
765 : Color(RGBPixel)
766{
767}
768
769Magick::ColorMono::ColorMono(const bool mono_)
770 : Color((mono_ ? QuantumRange : 0),(mono_ ? QuantumRange : 0),
771 (mono_ ? QuantumRange : 0))
772{
773}
774
775Magick::ColorMono::ColorMono(const Magick::Color &color_)
776 : Color(color_)
777{
778}
779
780Magick::ColorMono::~ColorMono()
781{
782}
783
784Magick::ColorMono& Magick::ColorMono::operator=(const Magick::Color& color_)
785{
786 *static_cast<Magick::Color*>(this)=color_;
787 return(*this);
788}
789
790void Magick::ColorMono::mono(bool mono_)
791{
792 quantumRed(mono_ ? QuantumRange : 0);
793 quantumGreen(mono_ ? QuantumRange : 0);
794 quantumBlue(mono_ ? QuantumRange : 0);
795}
796
797bool Magick::ColorMono::mono(void) const
798{
799 return(quantumGreen() == 0);
800}
801
802Magick::ColorMono::ColorMono(PixelInfo *rep_,PixelType pixelType_)
803 : Color(rep_,pixelType_)
804{
805}
806
807Magick::ColorRGB::ColorRGB(void)
808 : Color(RGBPixel)
809{
810}
811
812Magick::ColorRGB::ColorRGB(const Magick::Color &color_)
813 : Color(color_)
814{
815}
816
817Magick::ColorRGB::ColorRGB(const double red_,const double green_,
818 const double blue_)
819 : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_),
820 scaleDoubleToQuantum(blue_))
821{
822}
823
824Magick::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
831Magick::ColorRGB::~ColorRGB(void)
832{
833}
834
835Magick::ColorRGB& Magick::ColorRGB::operator=(const Magick::Color& color_)
836{
837 *static_cast<Magick::Color*>(this)=color_;
838 return(*this);
839}
840
841void Magick::ColorRGB::alpha(const double alpha_)
842{
843 quantumAlpha(scaleDoubleToQuantum(alpha_));
844}
845
846double Magick::ColorRGB::alpha(void) const
847{
848 return(scaleQuantumToDouble(quantumAlpha()));
849}
850
851void Magick::ColorRGB::blue(const double blue_)
852{
853 quantumBlue(scaleDoubleToQuantum(blue_));
854}
855
856double Magick::ColorRGB::blue(void) const
857{
858 return(scaleQuantumToDouble(quantumBlue()));
859}
860
861void Magick::ColorRGB::green(const double green_)
862{
863 quantumGreen(scaleDoubleToQuantum(green_));
864}
865
866double Magick::ColorRGB::green(void) const
867{
868 return(scaleQuantumToDouble(quantumGreen()));
869}
870
871void Magick::ColorRGB::red(const double red_)
872{
873 quantumRed(scaleDoubleToQuantum(red_));
874}
875
876double Magick::ColorRGB::red(void) const
877{
878 return(scaleQuantumToDouble(quantumRed()));
879}
880
881Magick::ColorRGB::ColorRGB(PixelInfo *rep_,PixelType pixelType_)
882 : Color(rep_,pixelType_)
883{
884}
885
886Magick::ColorYUV::ColorYUV(void)
887 : Color(RGBPixel)
888{
889}
890
891Magick::ColorYUV::ColorYUV(const Magick::Color &color_)
892 : Color(color_)
893{
894}
895
896Magick::ColorYUV::ColorYUV(const double y_,const double u_,const double v_)
897 : Color(RGBPixel)
898{
899 convert(y_, u_, v_);
900}
901
902Magick::ColorYUV::~ColorYUV(void)
903{
904}
905
906Magick::ColorYUV& Magick::ColorYUV::operator=(const Magick::Color &color_)
907{
908 *static_cast<Magick::Color*>(this)=color_;
909 return(*this);
910}
911
912void Magick::ColorYUV::u(const double u_)
913{
914 convert(y(), u_, v());
915}
916
917double 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
924void Magick::ColorYUV::v(const double v_)
925{
926 convert(y(), u(), v_);
927}
928
929double 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
936void Magick::ColorYUV::y(const double y_)
937{
938 convert(y_, u(), v());
939}
940
941double 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
948void 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
955Magick::ColorYUV::ColorYUV(PixelInfo *rep_,PixelType pixelType_)
956 : Color(rep_,pixelType_)
957{
958}