Blender V2.27

ColorBlock.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_COLORBLOCK_H
00035 #define _DDS_COLORBLOCK_H
00036 
00037 #include <Color.h>
00038 #include <Image.h>
00039 
00041 struct ColorBlock
00042 {
00043         ColorBlock();
00044         ColorBlock(const uint * linearImage);
00045         ColorBlock(const ColorBlock & block);
00046         ColorBlock(const Image * img, uint x, uint y);
00047         
00048         void init(const Image * img, uint x, uint y);
00049         
00050         void swizzleDXT5n();
00051         void splatX();
00052         void splatY();
00053         
00054         bool isSingleColor() const;
00055         bool isSingleColorNoAlpha() const;
00056         uint countUniqueColors() const;
00057         Color32 averageColor() const;
00058         bool hasAlpha() const;
00059         
00060         void diameterRange(Color32 * start, Color32 * end) const;
00061         void luminanceRange(Color32 * start, Color32 * end) const;
00062         void boundsRange(Color32 * start, Color32 * end) const;
00063         void boundsRangeAlpha(Color32 * start, Color32 * end) const;
00064         
00065         void sortColorsByAbsoluteValue();
00066 
00067         float volume() const;
00068 
00069         // Accessors
00070         const Color32 * colors() const;
00071 
00072         Color32 color(uint i) const;
00073         Color32 & color(uint i);
00074         
00075         Color32 color(uint x, uint y) const;
00076         Color32 & color(uint x, uint y);
00077         
00078 private:
00079         
00080         Color32 m_color[4*4];
00081         
00082 };
00083 
00084 
00086 inline const Color32 * ColorBlock::colors() const
00087 {
00088         return m_color;
00089 }
00090 
00092 inline Color32 ColorBlock::color(uint i) const
00093 {
00094         return m_color[i];
00095 }
00096 
00098 inline Color32 & ColorBlock::color(uint i)
00099 {
00100         return m_color[i];
00101 }
00102 
00104 inline Color32 ColorBlock::color(uint x, uint y) const
00105 {
00106         return m_color[y * 4 + x];
00107 }
00108 
00110 inline Color32 & ColorBlock::color(uint x, uint y)
00111 {
00112         return m_color[y * 4 + x];
00113 }
00114 
00115 #endif // _DDS_COLORBLOCK_H