Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:17

0001 // This may look like C code, but it is really -*- C++ -*-
0002 //
0003 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003, 2008
0004 //
0005 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
0006 // dedicated to making software imaging solutions freely available.
0007 //
0008 // Color Implementation
0009 //
0010 #if !defined (Magick_Color_header)
0011 #define Magick_Color_header
0012 
0013 #include "Magick++/Include.h"
0014 #include <string>
0015 
0016 namespace Magick
0017 {
0018   class MagickPPExport Color;
0019 
0020   // Compare two Color objects regardless of LHS/RHS
0021   MagickPPExport int operator ==
0022     (const Magick::Color& left_,const Magick::Color& right_);
0023   MagickPPExport int operator !=
0024     (const Magick::Color& left_,const Magick::Color& right_);
0025   MagickPPExport int operator >
0026     (const Magick::Color& left_,const Magick::Color& right_);
0027   MagickPPExport int operator <
0028     (const Magick::Color& left_,const Magick::Color& right_);
0029   MagickPPExport int operator >=
0030     (const Magick::Color& left_,const Magick::Color& right_);
0031   MagickPPExport int operator <=
0032     (const Magick::Color& left_,const Magick::Color& right_);
0033 
0034   // Base color class stores RGBA components scaled to fit Quantum
0035   // All double arguments have a valid range of 0.0 - 1.0.
0036   class MagickPPExport Color
0037   {
0038   public:
0039 
0040     // PixelType specifies the interpretation of PixelInfo members
0041     // CMYKPixel:
0042     //   Cyan     = red
0043     //   Magenta  = green
0044     //   Yellow   = blue
0045     //   Black(K) = black
0046     // CMYKPixel:
0047     //   Cyan     = red
0048     //   Magenta  = green
0049     //   Yellow   = blue
0050     //   Black(K) = black
0051     //   Alpha    = alpha
0052     // RGBPixel:
0053     //   Red      = red;
0054     //   Green    = green;
0055     //   Blue     = blue;
0056     // RGBAPixel:
0057     //   Red      = red;
0058     //   Green    = green;
0059     //   Blue     = blue;
0060     //   Alpha    = alpha;
0061     enum PixelType
0062     {
0063       CMYKPixel,
0064       CMYKAPixel,
0065       RGBPixel,
0066       RGBAPixel
0067     };
0068 
0069     // Default constructor
0070     Color(void);
0071 
0072     // Construct Color using the specified RGB values
0073     Color(const Magick::Quantum red_,const Magick::Quantum green_,
0074       const Magick::Quantum blue_);
0075 
0076     // Construct Color using the specified RGBA values
0077     Color(const Magick::Quantum red_,const Magick::Quantum green_,
0078       const Magick::Quantum blue_,const Magick::Quantum alpha_);
0079 
0080     // Construct Color using the specified CMYKA values
0081     Color(const Magick::Quantum cyan_,const Magick::Quantum magenta_,
0082       const Magick::Quantum yellow_,const Magick::Quantum black_,
0083       const Magick::Quantum alpha_);
0084 
0085     // Construct Color using the specified color string
0086     Color(const char *color_);
0087 
0088     // Copy constructor
0089     Color(const Color &color_);
0090 
0091     // Construct color via ImageMagick PixelInfo
0092     Color(const PixelInfo &color_);
0093 
0094     // Constructor Color using the specified color string
0095     Color(const std::string &color_);
0096 
0097     // Destructor
0098     virtual ~Color(void);
0099 
0100     // Assignment operator
0101     Color& operator=(const Color &color_);
0102 
0103     // Set color via X11 color specification string
0104     const Color& operator=(const char *color);
0105 
0106     // Set color via ImageMagick PixelInfo
0107     const Color& operator=(const PixelInfo &color_);
0108 
0109     // Set color via color specification string
0110     const Color& operator=(const std::string &color);
0111 
0112     // Return ImageMagick PixelInfo
0113     operator PixelInfo() const;
0114 
0115     // Return color specification string
0116     operator std::string() const;
0117 
0118     // Returns true if the distance between the other color is less than the
0119     // specified distance in a linear three(or four) % dimensional color space.
0120     bool isFuzzyEquivalent(const Color &color_,const double fuzz_) const;
0121 
0122     // Does object contain valid color?
0123     void isValid(const bool valid_);
0124     bool isValid(void) const;
0125 
0126     // Returns pixel type of the color
0127     Magick::Color::PixelType pixelType(void) const;
0128 
0129     // Alpha level (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange)
0130     void quantumAlpha(const Quantum alpha_);
0131     Quantum quantumAlpha(void) const;
0132 
0133     // Black color (range 0 to QuantumRange)
0134     void quantumBlack(const Quantum black_);
0135     Quantum quantumBlack(void) const;
0136 
0137     // Blue/Yellow color (range 0 to QuantumRange)
0138     void quantumBlue(const Quantum blue_);
0139     Quantum quantumBlue(void) const;
0140 
0141     // Green/Magenta color (range 0 to QuantumRange)
0142     void quantumGreen(const Quantum green_);
0143     Quantum quantumGreen(void) const;
0144 
0145     // Red/Cyan color (range 0 to QuantumRange)
0146     void quantumRed(const Quantum red_);
0147     Quantum quantumRed(void) const;
0148 
0149   protected:
0150 
0151     // Constructor to construct with PixelInfo*
0152     // Used to point Color at a pixel in an image
0153     Color(PixelInfo *rep_,PixelType pixelType_);
0154 
0155     // Constructor to construct with PixelType
0156     Color(PixelType pixelType_);
0157 
0158     // Set pixel
0159     // Used to point Color at a pixel in an image
0160     void pixel(PixelInfo *rep_,PixelType pixelType_);
0161 
0162     // Scale a value expressed as a double (0-1) to Quantum range (0-QuantumRange)
0163     static Quantum scaleDoubleToQuantum(const double double_);
0164 
0165     // Scale a value expressed as a Quantum (0-QuantumRange) to double range (0-1)
0166     static double scaleQuantumToDouble(const Quantum quantum_);
0167 
0168     // PixelInfo represents a color pixel:
0169     //  red     = red   (range 0 to QuantumRange)
0170     //  green   = green (range 0 to QuantumRange)
0171     //  blue    = blue  (range 0 to QuantumRange)
0172     //  alpha   = alpha (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange)
0173     //  index   = PseudoColor colormap index
0174     PixelInfo *_pixel;
0175 
0176   private:
0177 
0178     bool _isValid; // Set true if pixel is "valid"
0179     bool _pixelOwn; // Set true if we allocated pixel
0180     PixelType _pixelType; // Color type supported by _pixel
0181 
0182     // Common initializer for PixelInfo representation
0183     void initPixel();
0184 
0185     void setAlpha(const Magick::Quantum alpha_);
0186 
0187     // Sets the pixel type using the specified PixelInfo.
0188     void setPixelType(const PixelInfo &color_);
0189   };
0190 
0191   class MagickPPExport ColorCMYK: public Color
0192   {
0193   public:
0194 
0195     // Default constructor
0196     ColorCMYK(void);
0197 
0198     // Copy constructor
0199     ColorCMYK(const Color &color_);
0200 
0201     // Construct ColorCMYK using the specified CMYK values
0202     ColorCMYK(const double cyan_,const double magenta_,const double yellow_,
0203       const double black_);
0204 
0205     // Construct ColorCMYK using the specified CMYKA values
0206     ColorCMYK(const double cyan_,const double magenta_,const double yellow_,
0207       const double black_,const double alpha_);
0208 
0209     // Destructor
0210     ~ColorCMYK(void);
0211 
0212     // Assignment operator from base class
0213     ColorCMYK& operator=(const Color& color_);
0214 
0215     // Alpha level (range 0 to 1.0)
0216     void alpha(const double alpha_);
0217     double alpha(void) const;
0218 
0219     // Black/Key color (range 0 to 1.0)
0220     void black(const double black_);
0221     double black(void) const;
0222 
0223     // Black/Key color (range 0.0 to 1.0)
0224     void cyan(const double cyan_);
0225     double cyan(void) const;
0226 
0227     // Magenta color (range 0 to 1.0)
0228     void magenta(const double magenta_);
0229     double magenta(void) const;
0230 
0231     // Yellow color (range 0 to 1.0)
0232     void yellow(const double yellow_);
0233     double yellow(void) const;
0234 
0235   protected:
0236 
0237     // Constructor to construct with PixelInfo*
0238     ColorCMYK(PixelInfo *rep_,PixelType pixelType_);
0239   };
0240 
0241   //
0242   // Grayscale RGB color
0243   //
0244   // Grayscale is simply RGB with equal parts of red, green, and blue
0245   // All double arguments have a valid range of 0.0 - 1.0.
0246   class MagickPPExport ColorGray: public Color
0247   {
0248   public:
0249 
0250     // Default constructor
0251     ColorGray(void);
0252 
0253     // Copy constructor
0254     ColorGray(const Color &color_);
0255 
0256     // Construct ColorGray using the specified shade
0257     ColorGray(const double shade_);
0258 
0259     // Destructor
0260     ~ColorGray();
0261 
0262     // Shade
0263     void shade(const double shade_);
0264     double shade(void) const;
0265 
0266     // Assignment operator from base class
0267     ColorGray& operator=(const Color& color_);
0268 
0269   protected:
0270 
0271     // Constructor to construct with PixelInfo*
0272     ColorGray(PixelInfo *rep_,PixelType pixelType_);
0273   };
0274 
0275   //
0276   // HSL Colorspace colors
0277   //
0278   // All double arguments have a valid range of 0.0 - 1.0.
0279   class MagickPPExport ColorHSL: public Color
0280   {
0281   public:
0282 
0283     // Default constructor
0284     ColorHSL(void);
0285 
0286     // Copy constructor
0287     ColorHSL(const Color &color_);
0288 
0289     // Construct ColorHSL using the specified HSL values
0290     ColorHSL(const double hue_,const double saturation_,
0291       const double lightness_);
0292 
0293     // Destructor
0294     ~ColorHSL();
0295 
0296     // Assignment operator from base class
0297     ColorHSL& operator=(const Color& color_);
0298 
0299     // Hue color
0300     void hue(const double hue_);
0301     double hue(void) const;
0302 
0303     // Lightness color
0304     void lightness(const double lightness_);
0305     double lightness(void) const;
0306 
0307     // Saturation color
0308     void saturation(const double saturation_);
0309     double saturation(void) const;
0310 
0311   protected:
0312 
0313     // Constructor to construct with PixelInfo*
0314     ColorHSL(PixelInfo *rep_,PixelType pixelType_);
0315   };
0316 
0317   //
0318   // Monochrome color
0319   //
0320   // Color arguments are constrained to 'false' (black pixel) and 'true'
0321   // (white pixel)
0322   class MagickPPExport ColorMono: public Color
0323   {
0324   public:
0325 
0326     // Default constructor
0327     ColorMono(void);
0328 
0329     // Construct ColorMono (false=black, true=white)
0330     ColorMono(const bool mono_);
0331 
0332     // Copy constructor
0333     ColorMono(const Color &color_);
0334 
0335     // Destructor
0336     ~ColorMono();
0337 
0338     // Assignment operator from base class
0339     ColorMono& operator=(const Color& color_);
0340 
0341     // Mono color
0342     void mono(const bool mono_);
0343     bool mono(void) const;
0344 
0345   protected:
0346 
0347     // Constructor to construct with PixelInfo*
0348     ColorMono(PixelInfo* rep_,PixelType pixelType_);
0349   };
0350 
0351   class MagickPPExport ColorRGB: public Color
0352   {
0353   public:
0354 
0355     // Default constructor
0356     ColorRGB(void);
0357 
0358     // Copy constructor
0359     ColorRGB(const Color &color_);
0360 
0361     // Construct ColorRGB using the specified RGB values
0362     ColorRGB(const double red_,const double green_,const double blue_);
0363 
0364     // Construct ColorRGB using the specified RGBA values
0365     ColorRGB(const double red_,const double green_,const double blue_,
0366       const double alpha_);
0367 
0368     // Destructor
0369     ~ColorRGB(void);
0370 
0371     // Assignment operator from base class
0372     ColorRGB& operator=(const Color& color_);
0373 
0374     // Alpha level (range 0 to 1.0)
0375     void alpha(const double alpha_);
0376     double alpha(void) const;
0377 
0378     // Blue color (range 0.0 to 1.0)
0379     void blue(const double blue_);
0380     double blue(void) const;
0381 
0382     // Green color (range 0 to 1.0)
0383     void green(const double green_);
0384     double green(void) const;
0385 
0386     // Red color (range 0 to 1.0)
0387     void red(const double red_);
0388     double red(void) const;
0389 
0390   protected:
0391 
0392     // Constructor to construct with PixelInfo*
0393     ColorRGB(PixelInfo *rep_,PixelType pixelType_);
0394   };
0395 
0396   //
0397   // YUV Colorspace color
0398   //
0399   // Argument ranges:
0400   //        Y:  0.0 through 1.0
0401   //        U: -0.5 through 0.5
0402   //        V: -0.5 through 0.5
0403   class MagickPPExport ColorYUV: public Color
0404   {
0405   public:
0406 
0407     // Default constructor
0408     ColorYUV(void);
0409 
0410     // Copy constructor
0411     ColorYUV(const Color &color_);
0412 
0413     // Construct ColorYUV using the specified YUV values
0414     ColorYUV(const double y_,const double u_,const double v_);
0415 
0416     // Destructor
0417     ~ColorYUV(void);
0418 
0419     // Assignment operator from base class
0420     ColorYUV& operator=(const Color& color_);
0421 
0422     // Color U (0.0 through 1.0)
0423     void u(const double u_);
0424     double u(void) const;
0425 
0426     // Color V (-0.5 through 0.5)
0427     void v(const double v_);
0428     double v(void) const;
0429 
0430     // Color Y (-0.5 through 0.5)
0431     void y(const double y_);
0432     double y(void) const;
0433 
0434   protected:
0435 
0436     // Constructor to construct with PixelInfo*
0437     ColorYUV(PixelInfo *rep_,PixelType pixelType_);
0438 
0439   private:
0440 
0441     void convert(const double y_,const double u_,const double v_);
0442 
0443   };
0444 } // namespace Magick
0445 
0446 #endif // Magick_Color_header