Blender V2.27

Color.h

00001 
00025 /*
00026  * This file is based on a similar file from the NVIDIA texture tools
00027  * (http://nvidia-texture-tools.googlecode.com/)
00028  *
00029  * Original license from NVIDIA follows.
00030  */
00031 
00032 // This code is in the public domain -- castanyo@yahoo.es
00033 
00034 #ifndef _DDS_COLOR_H
00035 #define _DDS_COLOR_H
00036 
00038 class Color32
00039 {
00040 public:
00041         Color32() { }
00042         Color32(const Color32 & c) : u(c.u) { }
00043         Color32(unsigned char R, unsigned char G, unsigned char B) { setRGBA(R, G, B, 0xFF); }
00044         Color32(unsigned char R, unsigned char G, unsigned char B, unsigned char A) { setRGBA( R, G, B, A); }
00045         //Color32(unsigned char c[4]) { setRGBA(c[0], c[1], c[2], c[3]); }
00046         //Color32(float R, float G, float B) { setRGBA(uint(R*255), uint(G*255), uint(B*255), 0xFF); }
00047         //Color32(float R, float G, float B, float A) { setRGBA(uint(R*255), uint(G*255), uint(B*255), uint(A*255)); }
00048         Color32(unsigned int U) : u(U) { }
00049 
00050         void setRGBA(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
00051         {
00052                 r = R;
00053                 g = G;
00054                 b = B;
00055                 a = A;
00056         }
00057 
00058         void setBGRA(unsigned char B, unsigned char G, unsigned char R, unsigned char A = 0xFF)
00059         {
00060                 r = R;
00061                 g = G;
00062                 b = B;
00063                 a = A;
00064         }
00065 
00066         operator unsigned int () const {
00067                 return u;
00068         }
00069         
00070         union {
00071                 struct {
00072                         unsigned char b, g, r, a;
00073                 };
00074                 unsigned int u;
00075         };
00076 };
00077 
00079 class Color16
00080 {
00081 public:
00082         Color16() { }
00083         Color16(const Color16 & c) : u(c.u) { }
00084         explicit Color16(unsigned short U) : u(U) { }
00085         
00086         union {
00087                 struct {
00088                         unsigned short b : 5;
00089                         unsigned short g : 6;
00090                         unsigned short r : 5;
00091                 };
00092                 unsigned short u;
00093         };
00094 };
00095 
00096 #endif // _DDS_COLOR_H