color.h

Go to the documentation of this file.
00001 #ifndef COLOR_H
00002 #define COLOR_H
00003 
00004 #include <Magick++.h>
00005 
00006 inline void operator*=(Magick::ColorRGB & color, double n) {
00007     color.red  (color.red()   * n);
00008     color.green(color.green() * n);
00009     color.blue (color.blue()  * n);
00010 }
00011 
00012 inline Magick::ColorRGB operator* (const Magick::ColorRGB & color, double n) {
00013     return Magick::ColorRGB(color.red() * n, color.green() * n, color.blue() * n);
00014 }
00015 
00016 inline void operator*=(Magick::ColorRGB & color, const Magick::ColorRGB & other) {
00017     color.red(color.red() * other.red());
00018     color.green(color.green() * other.green());
00019     color.blue(color.blue() * other.blue());
00020 }
00021 inline Magick::ColorRGB operator* (const Magick::ColorRGB & color, const Magick::ColorRGB & other) {
00022     return Magick::ColorRGB(
00023             color.red()   * other.red(),
00024             color.green() * other.green(),
00025             color.blue()  * other.blue()
00026             );
00027 }
00028 
00029 inline void operator+=(Magick::ColorRGB & color, const Magick::ColorRGB & other) {
00030     color.red  ( color.red()   + other.red()   );
00031     color.green( color.green() + other.green() );
00032     color.blue ( color.blue()  + other.blue()  );
00033 }
00034 
00035 inline Magick::ColorRGB operator+ (const Magick::ColorRGB & color, const Magick::ColorRGB & other) {
00036     return Magick::ColorRGB(
00037             color.red()   + other.red(),
00038             color.green() + other.green(),
00039             color.blue()  + other.blue()
00040             );
00041 }
00042 
00043 //{{{
00044 // Pre-ImageMagick++ color implementation
00045 #if 0
00046 #include "raytrace_defs.h"
00047 
00048 typedef unsigned char uchar;
00050 class Color {
00051     private:
00053         double m_red;
00055         double m_green;
00057         double m_blue;
00058 
00059         inline double get_largest_color_component() const {
00060             if(m_red >= m_green && m_red >= m_blue) {
00061                 return m_red;
00062             }
00063             else if(m_green >= m_red && m_green >= m_blue) {
00064                 return m_green;
00065             }
00066             else if(m_blue >= m_red && m_blue >= m_green) {
00067                 return m_blue;
00068             }
00069         }
00070     public:
00071 
00073         Color() : m_red(0.0), m_green(0.0), m_blue(0.0) {}
00074 
00076         Color(int rgb) : m_red(((unsigned char*)rgb)[0]/256.0), m_green(((unsigned char*)rgb)[1]/256.0), m_blue(((unsigned char*)rgb)[2]/256.0) {}
00077 
00079         Color(double _red, double _green, double _blue) : m_red(_red), m_green(_green), m_blue(_blue) {
00080             int a = 3;
00081         }
00082 
00084         Color(int _red, int _green, int _blue) : m_red(_red / 256.0), m_green(_green / 256.0), m_blue(_blue / 256.0) {
00085         }
00086 
00088         Color(const Color &other) : m_red(other.m_red), m_green(other.m_green), m_blue(other.m_blue) {
00089         }
00090 
00091         void operator=(const Color &other) {
00092             set_red ( other.m_red );
00093             set_green ( other.m_green );
00094             set_blue ( other.m_blue );
00095         }
00096 
00097 
00098         void operator*=(double n) {
00099             set_red(m_red * n);
00100             set_green(m_green * n);
00101             set_blue(m_blue * n);
00102         }
00103         Color operator* (double n) { return Color(m_red * n, m_green * n, m_blue * n); }
00104 
00105         Color operator-(const Color &other) { return Color( m_red - other.m_red, m_green - other.m_green, m_blue - other.m_blue); }
00106         bool operator==(const Color &other) {
00107             double FUDGE_FACTOR = 0.0001;
00108             return (m_red >= other.m_red - FUDGE_FACTOR && m_red <= other.m_red + FUDGE_FACTOR)
00109                 && (m_green >= other.m_green - FUDGE_FACTOR && m_green <= other.m_green + FUDGE_FACTOR)
00110                 && (m_blue >= other.m_blue - FUDGE_FACTOR && m_blue <= other.m_blue + FUDGE_FACTOR);
00111         } 
00112 
00115         void set_red (double new_red) { m_red = new_red; }
00118         void set_green (double new_green) { m_green = new_green; }
00121         void set_blue (double new_blue) { m_blue = new_blue; }
00122 
00125         inline uchar get_rgb_red () const {
00126             double max = get_largest_color_component();
00127             if(max > 1.0) {
00128                 return (uchar)((m_red/max) * 255); 
00129             }
00130             return (uchar)(m_red * 255);
00131         }
00132 
00135         inline uchar get_rgb_green() const {
00136             double max = get_largest_color_component();
00137             if(max > 1.0) {
00138                 return (uchar)((m_green/max) * 255); 
00139             }
00140             return (uchar)(m_green * 255);
00141         }
00142         
00145         inline uchar get_rgb_blue () const {
00146             double max = get_largest_color_component();
00147             if(max > 1.0) {
00148                 return (uchar)((m_blue/max) * 255); 
00149             }
00150             return (uchar)(m_blue * 255);
00151         }
00152 
00153 
00156         inline double get_red () const { return m_red; }
00157 
00160         inline double get_green() const { return m_green; }
00161         
00164         inline double get_blue () const { return m_blue; }
00165 
00166 };
00167 #endif
00168 //}}}
00169 
00170 #endif

Generated on Tue Oct 30 22:12:15 2007 for mbrt by  doxygen 1.5.2