Blender V2.61 - r43446

Color.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributors: Amorilia (amorilia@users.sourceforge.net)
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 /*
00029  * This file is based on a similar file from the NVIDIA texture tools
00030  * (http://nvidia-texture-tools.googlecode.com/)
00031  *
00032  * Original license from NVIDIA follows.
00033  */
00034 
00035 // This code is in the public domain -- castanyo@yahoo.es
00036 
00037 #ifndef _DDS_COLOR_H
00038 #define _DDS_COLOR_H
00039 
00041 class Color32
00042 {
00043 public:
00044     Color32() { }
00045     Color32(const Color32 & c) : u(c.u) { }
00046     Color32(unsigned char R, unsigned char G, unsigned char B) { setRGBA(R, G, B, 0xFF); }
00047     Color32(unsigned char R, unsigned char G, unsigned char B, unsigned char A) { setRGBA( R, G, B, A); }
00048     //Color32(unsigned char c[4]) { setRGBA(c[0], c[1], c[2], c[3]); }
00049     //Color32(float R, float G, float B) { setRGBA(uint(R*255), uint(G*255), uint(B*255), 0xFF); }
00050     //Color32(float R, float G, float B, float A) { setRGBA(uint(R*255), uint(G*255), uint(B*255), uint(A*255)); }
00051     Color32(unsigned int U) : u(U) { }
00052 
00053     void setRGBA(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
00054     {
00055         r = R;
00056         g = G;
00057         b = B;
00058         a = A;
00059     }
00060 
00061     void setBGRA(unsigned char B, unsigned char G, unsigned char R, unsigned char A = 0xFF)
00062     {
00063         r = R;
00064         g = G;
00065         b = B;
00066         a = A;
00067     }
00068 
00069     operator unsigned int () const {
00070         return u;
00071     }
00072     
00073     union {
00074         struct {
00075             unsigned char b, g, r, a;
00076         };
00077         unsigned int u;
00078     };
00079 };
00080 
00082 class Color16
00083 {
00084 public:
00085     Color16() { }
00086     Color16(const Color16 & c) : u(c.u) { }
00087     explicit Color16(unsigned short U) : u(U) { }
00088     
00089     union {
00090         struct {
00091             unsigned short b : 5;
00092             unsigned short g : 6;
00093             unsigned short r : 5;
00094         };
00095         unsigned short u;
00096     };
00097 };
00098 
00099 #endif // _DDS_COLOR_H