Rgba.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file Rgba.h 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 32-bit and HDR (128- or 256-bit floating point) Rgba structs 00009 <!-------------------------------------------------------------------->**/ 00010 00011 #ifndef MILTON_RGBA_H_ 00012 #define MILTON_RGBA_H_ 00013 00014 #include <common/math/Vector.h> 00015 00016 struct Rgba32; 00017 struct RgbaHDR; 00018 00019 /** 00020 * @brief 00021 * Standard 32-bit RGBA pixel with red, green, blue, and alpha channels, 00022 * all with integer values in the range [0, 255] 00023 */ 00024 struct Rgba32 { 00025 union { 00026 struct { unsigned char b, g, r, a; }; 00027 00028 unsigned char data[4]; 00029 }; 00030 00031 inline explicit Rgba32(unsigned char r_ = 0, unsigned char g_ = 0, 00032 unsigned char b_ = 0, unsigned char a_ = 255); 00033 00034 static Rgba32 fromVector(const Vector3 &v) { 00035 Rgba32 rgba; 00036 00037 rgba.b = CAP(255 * v[2], 0, 255); 00038 rgba.g = CAP(255 * v[1], 0, 255); 00039 rgba.r = CAP(255 * v[0], 0, 255); 00040 00041 return rgba; 00042 } 00043 00044 /// @returns this Rgba as a Vector3 (implicit conversion) for 00045 /// convenience purposes 00046 inline operator Vector3() const; 00047 00048 /// @returns this Rgba32 as a RgbaHDR 00049 inline operator RgbaHDR() const; 00050 00051 /// @returns the luminance of this Rgba 00052 inline real_t luminance() const; 00053 }; 00054 00055 /** 00056 * @brief 00057 * Standard 128- or 256-bit RGBA pixel with floating-point red, green, 00058 * blue, and alpha channels 00059 */ 00060 struct RgbaHDR { 00061 union { 00062 struct { real_t r, g, b, a; }; 00063 00064 real_t data[4]; 00065 }; 00066 00067 inline explicit RgbaHDR(real_t r_ = 0, real_t g_ = 0, 00068 real_t b_ = 0, real_t a_ = 1); 00069 00070 static RgbaHDR fromVector(const Vector3 &v) { 00071 return RgbaHDR(v[0], v[1], v[2]); 00072 } 00073 00074 /// @returns this RgbaHDR as a Vector3 (implicit conversion) for 00075 /// convenience purposes 00076 inline operator Vector3() const; 00077 00078 /// @returns this RgbaHDR as a 32-bit Rgba32 00079 inline operator Rgba32() const; 00080 00081 /// @returns the luminance of this Rgba 00082 inline real_t luminance() const; 00083 00084 /// @returns { r * s, g * s, b * s, a } 00085 inline RgbaHDR operator*(real_t scalar) const; 00086 00087 /// sets this rgba to { r * s, g * s, b * s, a } 00088 inline RgbaHDR &operator*=(real_t scalar); 00089 }; 00090 00091 // include inline definitions 00092 #include <common/image/Rgba.inl> 00093 00094 #endif // MILTON_RGBA_H_ 00095
Generated on 28 Feb 2009 for Milton by
1.5.6