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