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