Blender  V2.59
ColorBlock.h
Go to the documentation of this file.
00001 /*
00002  * $Id: ColorBlock.h 36546 2011-05-08 09:05:52Z 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_COLORBLOCK_H
00040 #define _DDS_COLORBLOCK_H
00041 
00042 #include <Color.h>
00043 #include <Image.h>
00044 
00046 struct ColorBlock
00047 {
00048         ColorBlock();
00049         ColorBlock(const uint * linearImage);
00050         ColorBlock(const ColorBlock & block);
00051         ColorBlock(const Image * img, uint x, uint y);
00052         
00053         void init(const Image * img, uint x, uint y);
00054     void init(uint w, uint h, const uint * data, uint x, uint y);
00055     void init(uint w, uint h, const float * data, uint x, uint y);
00056         
00057         void swizzle(uint x, uint y, uint z, uint w); // 0=r, 1=g, 2=b, 3=a, 4=0xFF, 5=0
00058         
00059     bool isSingleColor(Color32 mask = Color32(0xFF, 0xFF, 0xFF, 0x00)) const;
00060         bool hasAlpha() const;
00061         
00062         
00063         // Accessors
00064         const Color32 * colors() const;
00065 
00066         Color32 color(uint i) const;
00067         Color32 & color(uint i);
00068         
00069         Color32 color(uint x, uint y) const;
00070         Color32 & color(uint x, uint y);
00071         
00072 private:
00073         
00074         Color32 m_color[4*4];
00075         
00076 };
00077 
00078 
00080 inline const Color32 * ColorBlock::colors() const
00081 {
00082         return m_color;
00083 }
00084 
00086 inline Color32 ColorBlock::color(uint i) const
00087 {
00088         return m_color[i];
00089 }
00090 
00092 inline Color32 & ColorBlock::color(uint i)
00093 {
00094         return m_color[i];
00095 }
00096 
00098 inline Color32 ColorBlock::color(uint x, uint y) const
00099 {
00100         return m_color[y * 4 + x];
00101 }
00102 
00104 inline Color32 & ColorBlock::color(uint x, uint y)
00105 {
00106         return m_color[y * 4 + x];
00107 }
00108 
00109 #endif // _DDS_COLORBLOCK_H