|
Blender V2.27
|
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 // Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com> 00033 // 00034 // Permission is hereby granted, free of charge, to any person 00035 // obtaining a copy of this software and associated documentation 00036 // files (the "Software"), to deal in the Software without 00037 // restriction, including without limitation the rights to use, 00038 // copy, modify, merge, publish, distribute, sublicense, and/or sell 00039 // copies of the Software, and to permit persons to whom the 00040 // Software is furnished to do so, subject to the following 00041 // conditions: 00042 // 00043 // The above copyright notice and this permission notice shall be 00044 // included in all copies or substantial portions of the Software. 00045 // 00046 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00047 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00048 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00049 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00050 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00051 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00052 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00053 // OTHER DEALINGS IN THE SOFTWARE. 00054 00055 #ifndef _DDS_BLOCKDXT_H 00056 #define _DDS_BLOCKDXT_H 00057 00058 #include <Common.h> 00059 #include <Color.h> 00060 #include <ColorBlock.h> 00061 #include <Stream.h> 00062 00064 struct BlockDXT1 00065 { 00066 Color16 col0; 00067 Color16 col1; 00068 union { 00069 uint8 row[4]; 00070 uint indices; 00071 }; 00072 00073 bool isFourColorMode() const; 00074 00075 uint evaluatePalette(Color32 color_array[4]) const; 00076 uint evaluatePaletteFast(Color32 color_array[4]) const; 00077 void evaluatePalette3(Color32 color_array[4]) const; 00078 void evaluatePalette4(Color32 color_array[4]) const; 00079 00080 void decodeBlock(ColorBlock * block) const; 00081 00082 void setIndices(int * idx); 00083 00084 void flip4(); 00085 void flip2(); 00086 }; 00087 00089 inline bool BlockDXT1::isFourColorMode() const 00090 { 00091 return col0.u > col1.u; 00092 } 00093 00094 00096 struct AlphaBlockDXT3 00097 { 00098 union { 00099 struct { 00100 uint alpha0 : 4; 00101 uint alpha1 : 4; 00102 uint alpha2 : 4; 00103 uint alpha3 : 4; 00104 uint alpha4 : 4; 00105 uint alpha5 : 4; 00106 uint alpha6 : 4; 00107 uint alpha7 : 4; 00108 uint alpha8 : 4; 00109 uint alpha9 : 4; 00110 uint alphaA : 4; 00111 uint alphaB : 4; 00112 uint alphaC : 4; 00113 uint alphaD : 4; 00114 uint alphaE : 4; 00115 uint alphaF : 4; 00116 }; 00117 uint16 row[4]; 00118 }; 00119 00120 void decodeBlock(ColorBlock * block) const; 00121 00122 void flip4(); 00123 void flip2(); 00124 }; 00125 00126 00128 struct BlockDXT3 00129 { 00130 AlphaBlockDXT3 alpha; 00131 BlockDXT1 color; 00132 00133 void decodeBlock(ColorBlock * block) const; 00134 00135 void flip4(); 00136 void flip2(); 00137 }; 00138 00139 00141 struct AlphaBlockDXT5 00142 { 00143 // uint64 unions do not compile on all platforms 00144 /* 00145 union { 00146 struct { 00147 uint64 alpha0 : 8; // 8 00148 uint64 alpha1 : 8; // 16 00149 uint64 bits0 : 3; // 3 - 19 00150 uint64 bits1 : 3; // 6 - 22 00151 uint64 bits2 : 3; // 9 - 25 00152 uint64 bits3 : 3; // 12 - 28 00153 uint64 bits4 : 3; // 15 - 31 00154 uint64 bits5 : 3; // 18 - 34 00155 uint64 bits6 : 3; // 21 - 37 00156 uint64 bits7 : 3; // 24 - 40 00157 uint64 bits8 : 3; // 27 - 43 00158 uint64 bits9 : 3; // 30 - 46 00159 uint64 bitsA : 3; // 33 - 49 00160 uint64 bitsB : 3; // 36 - 52 00161 uint64 bitsC : 3; // 39 - 55 00162 uint64 bitsD : 3; // 42 - 58 00163 uint64 bitsE : 3; // 45 - 61 00164 uint64 bitsF : 3; // 48 - 64 00165 }; 00166 uint64 u; 00167 }; 00168 */ 00169 uint64 u; 00170 uint8 alpha0() const { return u & 0xffLL; }; 00171 uint8 alpha1() const { return (u >> 8) & 0xffLL; }; 00172 uint8 bits0() const { return (u >> 16) & 0x7LL; }; 00173 uint8 bits1() const { return (u >> 19) & 0x7LL; }; 00174 uint8 bits2() const { return (u >> 22) & 0x7LL; }; 00175 uint8 bits3() const { return (u >> 25) & 0x7LL; }; 00176 uint8 bits4() const { return (u >> 28) & 0x7LL; }; 00177 uint8 bits5() const { return (u >> 31) & 0x7LL; }; 00178 uint8 bits6() const { return (u >> 34) & 0x7LL; }; 00179 uint8 bits7() const { return (u >> 37) & 0x7LL; }; 00180 uint8 bits8() const { return (u >> 40) & 0x7LL; }; 00181 uint8 bits9() const { return (u >> 43) & 0x7LL; }; 00182 uint8 bitsA() const { return (u >> 46) & 0x7LL; }; 00183 uint8 bitsB() const { return (u >> 49) & 0x7LL; }; 00184 uint8 bitsC() const { return (u >> 52) & 0x7LL; }; 00185 uint8 bitsD() const { return (u >> 55) & 0x7LL; }; 00186 uint8 bitsE() const { return (u >> 58) & 0x7LL; }; 00187 uint8 bitsF() const { return (u >> 61) & 0x7LL; }; 00188 00189 void evaluatePalette(uint8 alpha[8]) const; 00190 void evaluatePalette8(uint8 alpha[8]) const; 00191 void evaluatePalette6(uint8 alpha[8]) const; 00192 void indices(uint8 index_array[16]) const; 00193 00194 uint index(uint index) const; 00195 void setIndex(uint index, uint value); 00196 00197 void decodeBlock(ColorBlock * block) const; 00198 00199 void flip4(); 00200 void flip2(); 00201 }; 00202 00203 00205 struct BlockDXT5 00206 { 00207 AlphaBlockDXT5 alpha; 00208 BlockDXT1 color; 00209 00210 void decodeBlock(ColorBlock * block) const; 00211 00212 void flip4(); 00213 void flip2(); 00214 }; 00215 00217 struct BlockATI1 00218 { 00219 AlphaBlockDXT5 alpha; 00220 00221 void decodeBlock(ColorBlock * block) const; 00222 00223 void flip4(); 00224 void flip2(); 00225 }; 00226 00228 struct BlockATI2 00229 { 00230 AlphaBlockDXT5 x; 00231 AlphaBlockDXT5 y; 00232 00233 void decodeBlock(ColorBlock * block) const; 00234 00235 void flip4(); 00236 void flip2(); 00237 }; 00238 00240 struct BlockCTX1 00241 { 00242 uint8 col0[2]; 00243 uint8 col1[2]; 00244 union { 00245 uint8 row[4]; 00246 uint indices; 00247 }; 00248 00249 void evaluatePalette(Color32 color_array[4]) const; 00250 void setIndices(int * idx); 00251 00252 void decodeBlock(ColorBlock * block) const; 00253 00254 void flip4(); 00255 void flip2(); 00256 }; 00257 00258 void mem_read(Stream & mem, BlockDXT1 & block); 00259 void mem_read(Stream & mem, AlphaBlockDXT3 & block); 00260 void mem_read(Stream & mem, BlockDXT3 & block); 00261 void mem_read(Stream & mem, AlphaBlockDXT5 & block); 00262 void mem_read(Stream & mem, BlockDXT5 & block); 00263 void mem_read(Stream & mem, BlockATI1 & block); 00264 void mem_read(Stream & mem, BlockATI2 & block); 00265 void mem_read(Stream & mem, BlockCTX1 & block); 00266 00267 #endif // _DDS_BLOCKDXT_H
1.7.3