// // Computergraphik II // Prof. Dr. Juergen Doellner // Wintersemester 2001/2002 // // Rahmenprogramm fuer Aufgabenzettel 3 // // Autoren: Florian Kirsch (kirsch@hpi.uni-potsdam.de) // Marc Nienhaus (nienhaus@hpi.uni-potsdam.de) // Juergen Doellner (doellner@hpi.uni-potsdam.de) // #ifndef CG_COLOR_H #define CG_COLOR_H #include class Color { public: Color(double grey=0); Color(double red, double green, double blue, double alpha = 1.0); /* A color is specified by the red, green, and blue coefficients and the alpha (e.g., transmission) coefficient. All coefficients are clamped to the double interval [0.0, 1.0]. */ bool operator==(const Color&) const; bool operator!=(const Color&) const; Color operator+(const Color& col) const; Color operator-(const Color& col) const; Color operator*(double coef) const; /* These operators transform the red, green, and blue components. They do *not* apply to the alpha value. The result of each operation is clamped to [0.0, 1.0]. */ double operator[](int i) const; double& operator[](int i); /* The four components are indexed by R=[0], G=[1], B=[2], and A=[3]. The index is checked for out of range errors. */ static Color hsv(double hue, double saturation, double value, double alpha=1.0); double hue() const; double saturation() const; double value() const; /* Provide the conversion between the RGB and HSV color models. `hsv' can specify achromatic (gray-scale) colors by setting `s' to 0.0 and `v' to the gray coefficient between [0,1]. The `hue' factor must be specified in degrees in the range [-360,360]. If hue is smaller 0, 360 degrees are added before the conversion is invoked. Both saturation and value must be in the range [0,1]. */ static Color InterpolateRGB(const Color& from, const Color& to, double dPercentage); static Color InterpolateHSV(const Color& from, const Color& to, double dPercentage, bool bClockwise = true); friend ostream& operator<<(ostream&, const Color&); friend istream& operator>>(istream&, Color&); private: double rgba_[4]; }; #endif // CG_COLOR_H