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