|
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 #include <DirectDrawSurface.h> 00056 #include <BlockDXT.h> 00057 #include <PixelFormat.h> 00058 00059 #include <stdio.h> // printf 00060 #include <math.h> // sqrt 00061 #include <sys/types.h> 00062 00063 /*** declarations ***/ 00064 00065 #if !defined(MAKEFOURCC) 00066 # define MAKEFOURCC(ch0, ch1, ch2, ch3) \ 00067 ((uint)((unsigned char)(ch0)) | \ 00068 ((uint)((unsigned char)(ch1)) << 8) | \ 00069 ((uint)((unsigned char)(ch2)) << 16) | \ 00070 ((uint)((unsigned char)(ch3)) << 24 )) 00071 #endif 00072 00073 static const uint FOURCC_DDS = MAKEFOURCC('D', 'D', 'S', ' '); 00074 static const uint FOURCC_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'); 00075 static const uint FOURCC_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'); 00076 static const uint FOURCC_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'); 00077 static const uint FOURCC_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'); 00078 static const uint FOURCC_DXT5 = MAKEFOURCC('D', 'X', 'T', '5'); 00079 static const uint FOURCC_RXGB = MAKEFOURCC('R', 'X', 'G', 'B'); 00080 static const uint FOURCC_ATI1 = MAKEFOURCC('A', 'T', 'I', '1'); 00081 static const uint FOURCC_ATI2 = MAKEFOURCC('A', 'T', 'I', '2'); 00082 00083 static const uint FOURCC_A2XY = MAKEFOURCC('A', '2', 'X', 'Y'); 00084 00085 static const uint FOURCC_DX10 = MAKEFOURCC('D', 'X', '1', '0'); 00086 00087 // 32 bit RGB formats. 00088 static const uint D3DFMT_R8G8B8 = 20; 00089 static const uint D3DFMT_A8R8G8B8 = 21; 00090 static const uint D3DFMT_X8R8G8B8 = 22; 00091 static const uint D3DFMT_R5G6B5 = 23; 00092 static const uint D3DFMT_X1R5G5B5 = 24; 00093 static const uint D3DFMT_A1R5G5B5 = 25; 00094 static const uint D3DFMT_A4R4G4B4 = 26; 00095 static const uint D3DFMT_R3G3B2 = 27; 00096 static const uint D3DFMT_A8 = 28; 00097 static const uint D3DFMT_A8R3G3B2 = 29; 00098 static const uint D3DFMT_X4R4G4B4 = 30; 00099 static const uint D3DFMT_A2B10G10R10 = 31; 00100 static const uint D3DFMT_A8B8G8R8 = 32; 00101 static const uint D3DFMT_X8B8G8R8 = 33; 00102 static const uint D3DFMT_G16R16 = 34; 00103 static const uint D3DFMT_A2R10G10B10 = 35; 00104 00105 static const uint D3DFMT_A16B16G16R16 = 36; 00106 00107 // Palette formats. 00108 static const uint D3DFMT_A8P8 = 40; 00109 static const uint D3DFMT_P8 = 41; 00110 00111 // Luminance formats. 00112 static const uint D3DFMT_L8 = 50; 00113 static const uint D3DFMT_A8L8 = 51; 00114 static const uint D3DFMT_A4L4 = 52; 00115 static const uint D3DFMT_L16 = 81; 00116 00117 // Floating point formats 00118 static const uint D3DFMT_R16F = 111; 00119 static const uint D3DFMT_G16R16F = 112; 00120 static const uint D3DFMT_A16B16G16R16F = 113; 00121 static const uint D3DFMT_R32F = 114; 00122 static const uint D3DFMT_G32R32F = 115; 00123 static const uint D3DFMT_A32B32G32R32F = 116; 00124 00125 static const uint DDSD_CAPS = 0x00000001U; 00126 static const uint DDSD_PIXELFORMAT = 0x00001000U; 00127 static const uint DDSD_WIDTH = 0x00000004U; 00128 static const uint DDSD_HEIGHT = 0x00000002U; 00129 static const uint DDSD_PITCH = 0x00000008U; 00130 static const uint DDSD_MIPMAPCOUNT = 0x00020000U; 00131 static const uint DDSD_LINEARSIZE = 0x00080000U; 00132 static const uint DDSD_DEPTH = 0x00800000U; 00133 00134 static const uint DDSCAPS_COMPLEX = 0x00000008U; 00135 static const uint DDSCAPS_TEXTURE = 0x00001000U; 00136 static const uint DDSCAPS_MIPMAP = 0x00400000U; 00137 static const uint DDSCAPS2_VOLUME = 0x00200000U; 00138 static const uint DDSCAPS2_CUBEMAP = 0x00000200U; 00139 00140 static const uint DDSCAPS2_CUBEMAP_POSITIVEX = 0x00000400U; 00141 static const uint DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800U; 00142 static const uint DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000U; 00143 static const uint DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000U; 00144 static const uint DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000U; 00145 static const uint DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000U; 00146 static const uint DDSCAPS2_CUBEMAP_ALL_FACES = 0x0000FC00U; 00147 00148 static const uint DDPF_ALPHAPIXELS = 0x00000001U; 00149 static const uint DDPF_ALPHA = 0x00000002U; 00150 static const uint DDPF_FOURCC = 0x00000004U; 00151 static const uint DDPF_RGB = 0x00000040U; 00152 static const uint DDPF_PALETTEINDEXED1 = 0x00000800U; 00153 static const uint DDPF_PALETTEINDEXED2 = 0x00001000U; 00154 static const uint DDPF_PALETTEINDEXED4 = 0x00000008U; 00155 static const uint DDPF_PALETTEINDEXED8 = 0x00000020U; 00156 static const uint DDPF_LUMINANCE = 0x00020000U; 00157 static const uint DDPF_ALPHAPREMULT = 0x00008000U; 00158 static const uint DDPF_NORMAL = 0x80000000U; // @@ Custom nv flag. 00159 00160 // DX10 formats. 00161 enum DXGI_FORMAT 00162 { 00163 DXGI_FORMAT_UNKNOWN = 0, 00164 00165 DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, 00166 DXGI_FORMAT_R32G32B32A32_FLOAT = 2, 00167 DXGI_FORMAT_R32G32B32A32_UINT = 3, 00168 DXGI_FORMAT_R32G32B32A32_SINT = 4, 00169 00170 DXGI_FORMAT_R32G32B32_TYPELESS = 5, 00171 DXGI_FORMAT_R32G32B32_FLOAT = 6, 00172 DXGI_FORMAT_R32G32B32_UINT = 7, 00173 DXGI_FORMAT_R32G32B32_SINT = 8, 00174 00175 DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, 00176 DXGI_FORMAT_R16G16B16A16_FLOAT = 10, 00177 DXGI_FORMAT_R16G16B16A16_UNORM = 11, 00178 DXGI_FORMAT_R16G16B16A16_UINT = 12, 00179 DXGI_FORMAT_R16G16B16A16_SNORM = 13, 00180 DXGI_FORMAT_R16G16B16A16_SINT = 14, 00181 00182 DXGI_FORMAT_R32G32_TYPELESS = 15, 00183 DXGI_FORMAT_R32G32_FLOAT = 16, 00184 DXGI_FORMAT_R32G32_UINT = 17, 00185 DXGI_FORMAT_R32G32_SINT = 18, 00186 00187 DXGI_FORMAT_R32G8X24_TYPELESS = 19, 00188 DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, 00189 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, 00190 DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, 00191 00192 DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, 00193 DXGI_FORMAT_R10G10B10A2_UNORM = 24, 00194 DXGI_FORMAT_R10G10B10A2_UINT = 25, 00195 00196 DXGI_FORMAT_R11G11B10_FLOAT = 26, 00197 00198 DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, 00199 DXGI_FORMAT_R8G8B8A8_UNORM = 28, 00200 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, 00201 DXGI_FORMAT_R8G8B8A8_UINT = 30, 00202 DXGI_FORMAT_R8G8B8A8_SNORM = 31, 00203 DXGI_FORMAT_R8G8B8A8_SINT = 32, 00204 00205 DXGI_FORMAT_R16G16_TYPELESS = 33, 00206 DXGI_FORMAT_R16G16_FLOAT = 34, 00207 DXGI_FORMAT_R16G16_UNORM = 35, 00208 DXGI_FORMAT_R16G16_UINT = 36, 00209 DXGI_FORMAT_R16G16_SNORM = 37, 00210 DXGI_FORMAT_R16G16_SINT = 38, 00211 00212 DXGI_FORMAT_R32_TYPELESS = 39, 00213 DXGI_FORMAT_D32_FLOAT = 40, 00214 DXGI_FORMAT_R32_FLOAT = 41, 00215 DXGI_FORMAT_R32_UINT = 42, 00216 DXGI_FORMAT_R32_SINT = 43, 00217 00218 DXGI_FORMAT_R24G8_TYPELESS = 44, 00219 DXGI_FORMAT_D24_UNORM_S8_UINT = 45, 00220 DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, 00221 DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, 00222 00223 DXGI_FORMAT_R8G8_TYPELESS = 48, 00224 DXGI_FORMAT_R8G8_UNORM = 49, 00225 DXGI_FORMAT_R8G8_UINT = 50, 00226 DXGI_FORMAT_R8G8_SNORM = 51, 00227 DXGI_FORMAT_R8G8_SINT = 52, 00228 00229 DXGI_FORMAT_R16_TYPELESS = 53, 00230 DXGI_FORMAT_R16_FLOAT = 54, 00231 DXGI_FORMAT_D16_UNORM = 55, 00232 DXGI_FORMAT_R16_UNORM = 56, 00233 DXGI_FORMAT_R16_UINT = 57, 00234 DXGI_FORMAT_R16_SNORM = 58, 00235 DXGI_FORMAT_R16_SINT = 59, 00236 00237 DXGI_FORMAT_R8_TYPELESS = 60, 00238 DXGI_FORMAT_R8_UNORM = 61, 00239 DXGI_FORMAT_R8_UINT = 62, 00240 DXGI_FORMAT_R8_SNORM = 63, 00241 DXGI_FORMAT_R8_SINT = 64, 00242 DXGI_FORMAT_A8_UNORM = 65, 00243 00244 DXGI_FORMAT_R1_UNORM = 66, 00245 00246 DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, 00247 00248 DXGI_FORMAT_R8G8_B8G8_UNORM = 68, 00249 DXGI_FORMAT_G8R8_G8B8_UNORM = 69, 00250 00251 DXGI_FORMAT_BC1_TYPELESS = 70, 00252 DXGI_FORMAT_BC1_UNORM = 71, 00253 DXGI_FORMAT_BC1_UNORM_SRGB = 72, 00254 00255 DXGI_FORMAT_BC2_TYPELESS = 73, 00256 DXGI_FORMAT_BC2_UNORM = 74, 00257 DXGI_FORMAT_BC2_UNORM_SRGB = 75, 00258 00259 DXGI_FORMAT_BC3_TYPELESS = 76, 00260 DXGI_FORMAT_BC3_UNORM = 77, 00261 DXGI_FORMAT_BC3_UNORM_SRGB = 78, 00262 00263 DXGI_FORMAT_BC4_TYPELESS = 79, 00264 DXGI_FORMAT_BC4_UNORM = 80, 00265 DXGI_FORMAT_BC4_SNORM = 81, 00266 00267 DXGI_FORMAT_BC5_TYPELESS = 82, 00268 DXGI_FORMAT_BC5_UNORM = 83, 00269 DXGI_FORMAT_BC5_SNORM = 84, 00270 00271 DXGI_FORMAT_B5G6R5_UNORM = 85, 00272 DXGI_FORMAT_B5G5R5A1_UNORM = 86, 00273 DXGI_FORMAT_B8G8R8A8_UNORM = 87, 00274 DXGI_FORMAT_B8G8R8X8_UNORM = 88, 00275 }; 00276 00277 enum D3D10_RESOURCE_DIMENSION 00278 { 00279 D3D10_RESOURCE_DIMENSION_UNKNOWN = 0, 00280 D3D10_RESOURCE_DIMENSION_BUFFER = 1, 00281 D3D10_RESOURCE_DIMENSION_TEXTURE1D = 2, 00282 D3D10_RESOURCE_DIMENSION_TEXTURE2D = 3, 00283 D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4, 00284 }; 00285 00286 00287 const char * getDxgiFormatString(DXGI_FORMAT dxgiFormat) 00288 { 00289 #define CASE(format) case DXGI_FORMAT_##format: return #format 00290 switch(dxgiFormat) 00291 { 00292 CASE(UNKNOWN); 00293 00294 CASE(R32G32B32A32_TYPELESS); 00295 CASE(R32G32B32A32_FLOAT); 00296 CASE(R32G32B32A32_UINT); 00297 CASE(R32G32B32A32_SINT); 00298 00299 CASE(R32G32B32_TYPELESS); 00300 CASE(R32G32B32_FLOAT); 00301 CASE(R32G32B32_UINT); 00302 CASE(R32G32B32_SINT); 00303 00304 CASE(R16G16B16A16_TYPELESS); 00305 CASE(R16G16B16A16_FLOAT); 00306 CASE(R16G16B16A16_UNORM); 00307 CASE(R16G16B16A16_UINT); 00308 CASE(R16G16B16A16_SNORM); 00309 CASE(R16G16B16A16_SINT); 00310 00311 CASE(R32G32_TYPELESS); 00312 CASE(R32G32_FLOAT); 00313 CASE(R32G32_UINT); 00314 CASE(R32G32_SINT); 00315 00316 CASE(R32G8X24_TYPELESS); 00317 CASE(D32_FLOAT_S8X24_UINT); 00318 CASE(R32_FLOAT_X8X24_TYPELESS); 00319 CASE(X32_TYPELESS_G8X24_UINT); 00320 00321 CASE(R10G10B10A2_TYPELESS); 00322 CASE(R10G10B10A2_UNORM); 00323 CASE(R10G10B10A2_UINT); 00324 00325 CASE(R11G11B10_FLOAT); 00326 00327 CASE(R8G8B8A8_TYPELESS); 00328 CASE(R8G8B8A8_UNORM); 00329 CASE(R8G8B8A8_UNORM_SRGB); 00330 CASE(R8G8B8A8_UINT); 00331 CASE(R8G8B8A8_SNORM); 00332 CASE(R8G8B8A8_SINT); 00333 00334 CASE(R16G16_TYPELESS); 00335 CASE(R16G16_FLOAT); 00336 CASE(R16G16_UNORM); 00337 CASE(R16G16_UINT); 00338 CASE(R16G16_SNORM); 00339 CASE(R16G16_SINT); 00340 00341 CASE(R32_TYPELESS); 00342 CASE(D32_FLOAT); 00343 CASE(R32_FLOAT); 00344 CASE(R32_UINT); 00345 CASE(R32_SINT); 00346 00347 CASE(R24G8_TYPELESS); 00348 CASE(D24_UNORM_S8_UINT); 00349 CASE(R24_UNORM_X8_TYPELESS); 00350 CASE(X24_TYPELESS_G8_UINT); 00351 00352 CASE(R8G8_TYPELESS); 00353 CASE(R8G8_UNORM); 00354 CASE(R8G8_UINT); 00355 CASE(R8G8_SNORM); 00356 CASE(R8G8_SINT); 00357 00358 CASE(R16_TYPELESS); 00359 CASE(R16_FLOAT); 00360 CASE(D16_UNORM); 00361 CASE(R16_UNORM); 00362 CASE(R16_UINT); 00363 CASE(R16_SNORM); 00364 CASE(R16_SINT); 00365 00366 CASE(R8_TYPELESS); 00367 CASE(R8_UNORM); 00368 CASE(R8_UINT); 00369 CASE(R8_SNORM); 00370 CASE(R8_SINT); 00371 CASE(A8_UNORM); 00372 00373 CASE(R1_UNORM); 00374 00375 CASE(R9G9B9E5_SHAREDEXP); 00376 00377 CASE(R8G8_B8G8_UNORM); 00378 CASE(G8R8_G8B8_UNORM); 00379 00380 CASE(BC1_TYPELESS); 00381 CASE(BC1_UNORM); 00382 CASE(BC1_UNORM_SRGB); 00383 00384 CASE(BC2_TYPELESS); 00385 CASE(BC2_UNORM); 00386 CASE(BC2_UNORM_SRGB); 00387 00388 CASE(BC3_TYPELESS); 00389 CASE(BC3_UNORM); 00390 CASE(BC3_UNORM_SRGB); 00391 00392 CASE(BC4_TYPELESS); 00393 CASE(BC4_UNORM); 00394 CASE(BC4_SNORM); 00395 00396 CASE(BC5_TYPELESS); 00397 CASE(BC5_UNORM); 00398 CASE(BC5_SNORM); 00399 00400 CASE(B5G6R5_UNORM); 00401 CASE(B5G5R5A1_UNORM); 00402 CASE(B8G8R8A8_UNORM); 00403 CASE(B8G8R8X8_UNORM); 00404 00405 default: 00406 return "UNKNOWN"; 00407 } 00408 #undef CASE 00409 } 00410 00411 const char * getD3d10ResourceDimensionString(D3D10_RESOURCE_DIMENSION resourceDimension) 00412 { 00413 switch(resourceDimension) 00414 { 00415 default: 00416 case D3D10_RESOURCE_DIMENSION_UNKNOWN: return "UNKNOWN"; 00417 case D3D10_RESOURCE_DIMENSION_BUFFER: return "BUFFER"; 00418 case D3D10_RESOURCE_DIMENSION_TEXTURE1D: return "TEXTURE1D"; 00419 case D3D10_RESOURCE_DIMENSION_TEXTURE2D: return "TEXTURE2D"; 00420 case D3D10_RESOURCE_DIMENSION_TEXTURE3D: return "TEXTURE3D"; 00421 } 00422 } 00423 00424 /*** implementation ***/ 00425 00426 void mem_read(Stream & mem, DDSPixelFormat & pf) 00427 { 00428 mem_read(mem, pf.size); 00429 mem_read(mem, pf.flags); 00430 mem_read(mem, pf.fourcc); 00431 mem_read(mem, pf.bitcount); 00432 mem_read(mem, pf.rmask); 00433 mem_read(mem, pf.gmask); 00434 mem_read(mem, pf.bmask); 00435 mem_read(mem, pf.amask); 00436 } 00437 00438 void mem_read(Stream & mem, DDSCaps & caps) 00439 { 00440 mem_read(mem, caps.caps1); 00441 mem_read(mem, caps.caps2); 00442 mem_read(mem, caps.caps3); 00443 mem_read(mem, caps.caps4); 00444 } 00445 00446 void mem_read(Stream & mem, DDSHeader10 & header) 00447 { 00448 mem_read(mem, header.dxgiFormat); 00449 mem_read(mem, header.resourceDimension); 00450 mem_read(mem, header.miscFlag); 00451 mem_read(mem, header.arraySize); 00452 mem_read(mem, header.reserved); 00453 } 00454 00455 void mem_read(Stream & mem, DDSHeader & header) 00456 { 00457 mem_read(mem, header.fourcc); 00458 mem_read(mem, header.size); 00459 mem_read(mem, header.flags); 00460 mem_read(mem, header.height); 00461 mem_read(mem, header.width); 00462 mem_read(mem, header.pitch); 00463 mem_read(mem, header.depth); 00464 mem_read(mem, header.mipmapcount); 00465 for (uint i = 0; i < 11; i++) mem_read(mem, header.reserved[i]); 00466 mem_read(mem, header.pf); 00467 mem_read(mem, header.caps); 00468 mem_read(mem, header.notused); 00469 00470 if (header.hasDX10Header()) 00471 { 00472 mem_read(mem, header.header10); 00473 } 00474 } 00475 00476 00477 00478 DDSHeader::DDSHeader() 00479 { 00480 this->fourcc = FOURCC_DDS; 00481 this->size = 124; 00482 this->flags = (DDSD_CAPS|DDSD_PIXELFORMAT); 00483 this->height = 0; 00484 this->width = 0; 00485 this->pitch = 0; 00486 this->depth = 0; 00487 this->mipmapcount = 0; 00488 for (uint i = 0; i < 11; i++) this->reserved[i] = 0; 00489 00490 // Store version information on the reserved header attributes. 00491 this->reserved[9] = MAKEFOURCC('N', 'V', 'T', 'T'); 00492 this->reserved[10] = (0 << 16) | (9 << 8) | (5); // major.minor.revision 00493 00494 this->pf.size = 32; 00495 this->pf.flags = 0; 00496 this->pf.fourcc = 0; 00497 this->pf.bitcount = 0; 00498 this->pf.rmask = 0; 00499 this->pf.gmask = 0; 00500 this->pf.bmask = 0; 00501 this->pf.amask = 0; 00502 this->caps.caps1 = DDSCAPS_TEXTURE; 00503 this->caps.caps2 = 0; 00504 this->caps.caps3 = 0; 00505 this->caps.caps4 = 0; 00506 this->notused = 0; 00507 00508 this->header10.dxgiFormat = DXGI_FORMAT_UNKNOWN; 00509 this->header10.resourceDimension = D3D10_RESOURCE_DIMENSION_UNKNOWN; 00510 this->header10.miscFlag = 0; 00511 this->header10.arraySize = 0; 00512 this->header10.reserved = 0; 00513 } 00514 00515 void DDSHeader::setWidth(uint w) 00516 { 00517 this->flags |= DDSD_WIDTH; 00518 this->width = w; 00519 } 00520 00521 void DDSHeader::setHeight(uint h) 00522 { 00523 this->flags |= DDSD_HEIGHT; 00524 this->height = h; 00525 } 00526 00527 void DDSHeader::setDepth(uint d) 00528 { 00529 this->flags |= DDSD_DEPTH; 00530 this->height = d; 00531 } 00532 00533 void DDSHeader::setMipmapCount(uint count) 00534 { 00535 if (count == 0 || count == 1) 00536 { 00537 this->flags &= ~DDSD_MIPMAPCOUNT; 00538 this->mipmapcount = 0; 00539 00540 if (this->caps.caps2 == 0) { 00541 this->caps.caps1 = DDSCAPS_TEXTURE; 00542 } 00543 else { 00544 this->caps.caps1 = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX; 00545 } 00546 } 00547 else 00548 { 00549 this->flags |= DDSD_MIPMAPCOUNT; 00550 this->mipmapcount = count; 00551 00552 this->caps.caps1 |= DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; 00553 } 00554 } 00555 00556 void DDSHeader::setTexture2D() 00557 { 00558 this->header10.resourceDimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D; 00559 } 00560 00561 void DDSHeader::setTexture3D() 00562 { 00563 this->caps.caps2 = DDSCAPS2_VOLUME; 00564 00565 this->header10.resourceDimension = D3D10_RESOURCE_DIMENSION_TEXTURE3D; 00566 } 00567 00568 void DDSHeader::setTextureCube() 00569 { 00570 this->caps.caps1 |= DDSCAPS_COMPLEX; 00571 this->caps.caps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALL_FACES; 00572 00573 this->header10.resourceDimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D; 00574 this->header10.arraySize = 6; 00575 } 00576 00577 void DDSHeader::setLinearSize(uint size) 00578 { 00579 this->flags &= ~DDSD_PITCH; 00580 this->flags |= DDSD_LINEARSIZE; 00581 this->pitch = size; 00582 } 00583 00584 void DDSHeader::setPitch(uint pitch) 00585 { 00586 this->flags &= ~DDSD_LINEARSIZE; 00587 this->flags |= DDSD_PITCH; 00588 this->pitch = pitch; 00589 } 00590 00591 void DDSHeader::setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3) 00592 { 00593 // set fourcc pixel format. 00594 this->pf.flags = DDPF_FOURCC; 00595 this->pf.fourcc = MAKEFOURCC(c0, c1, c2, c3); 00596 00597 if (this->pf.fourcc == FOURCC_ATI2) 00598 { 00599 this->pf.bitcount = FOURCC_A2XY; 00600 } 00601 else 00602 { 00603 this->pf.bitcount = 0; 00604 } 00605 00606 this->pf.rmask = 0; 00607 this->pf.gmask = 0; 00608 this->pf.bmask = 0; 00609 this->pf.amask = 0; 00610 } 00611 00612 void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask) 00613 { 00614 // Make sure the masks are correct. 00615 if ((rmask & gmask) || \ 00616 (rmask & bmask) || \ 00617 (rmask & amask) || \ 00618 (gmask & bmask) || \ 00619 (gmask & amask) || \ 00620 (bmask & amask)) { 00621 printf("DDS: bad RGBA masks, pixel format not set\n"); 00622 return; 00623 } 00624 00625 this->pf.flags = DDPF_RGB; 00626 00627 if (amask != 0) { 00628 this->pf.flags |= DDPF_ALPHAPIXELS; 00629 } 00630 00631 if (bitcount == 0) 00632 { 00633 // Compute bit count from the masks. 00634 uint total = rmask | gmask | bmask | amask; 00635 while(total != 0) { 00636 bitcount++; 00637 total >>= 1; 00638 } 00639 } 00640 00641 if (!(bitcount > 0 && bitcount <= 32)) { 00642 printf("DDS: bad bit count, pixel format not set\n"); 00643 return; 00644 } 00645 00646 // Align to 8. 00647 if (bitcount <= 8) bitcount = 8; 00648 else if (bitcount <= 16) bitcount = 16; 00649 else if (bitcount <= 24) bitcount = 24; 00650 else bitcount = 32; 00651 00652 this->pf.fourcc = 0; //findD3D9Format(bitcount, rmask, gmask, bmask, amask); 00653 this->pf.bitcount = bitcount; 00654 this->pf.rmask = rmask; 00655 this->pf.gmask = gmask; 00656 this->pf.bmask = bmask; 00657 this->pf.amask = amask; 00658 } 00659 00660 void DDSHeader::setDX10Format(uint format) 00661 { 00662 //this->pf.flags = 0; 00663 this->pf.fourcc = FOURCC_DX10; 00664 this->header10.dxgiFormat = format; 00665 } 00666 00667 void DDSHeader::setNormalFlag(bool b) 00668 { 00669 if (b) this->pf.flags |= DDPF_NORMAL; 00670 else this->pf.flags &= ~DDPF_NORMAL; 00671 } 00672 00673 bool DDSHeader::hasDX10Header() const 00674 { 00675 return this->pf.fourcc == FOURCC_DX10; // @@ This is according to AMD 00676 //return this->pf.flags == 0; // @@ This is according to MS 00677 } 00678 00679 DirectDrawSurface::DirectDrawSurface(unsigned char *mem, uint size) : stream(mem, size), header() 00680 { 00681 mem_read(stream, header); 00682 00683 // some ATI2 compressed normal maps do not have their 00684 // normal flag set, so force it here (the original nvtt don't do 00685 // this, but the decompressor has a -forcenormal flag) 00686 if (header.pf.fourcc == FOURCC_ATI2) header.setNormalFlag(true); 00687 } 00688 00689 DirectDrawSurface::~DirectDrawSurface() 00690 { 00691 } 00692 00693 bool DirectDrawSurface::isValid() const 00694 { 00695 if (header.fourcc != FOURCC_DDS || header.size != 124) 00696 { 00697 return false; 00698 } 00699 00700 const uint required = (DDSD_WIDTH|DDSD_HEIGHT/*|DDSD_CAPS|DDSD_PIXELFORMAT*/); 00701 if( (header.flags & required) != required ) { 00702 return false; 00703 } 00704 00705 if (header.pf.size != 32) { 00706 return false; 00707 } 00708 00709 /* in some files DDSCAPS_TEXTURE is missing: silently ignore */ 00710 /* 00711 if( !(header.caps.caps1 & DDSCAPS_TEXTURE) ) { 00712 return false; 00713 } 00714 */ 00715 00716 return true; 00717 } 00718 00719 bool DirectDrawSurface::isSupported() const 00720 { 00721 if (header.hasDX10Header()) 00722 { 00723 } 00724 else 00725 { 00726 if (header.pf.flags & DDPF_FOURCC) 00727 { 00728 if (header.pf.fourcc != FOURCC_DXT1 && 00729 header.pf.fourcc != FOURCC_DXT2 && 00730 header.pf.fourcc != FOURCC_DXT3 && 00731 header.pf.fourcc != FOURCC_DXT4 && 00732 header.pf.fourcc != FOURCC_DXT5 && 00733 header.pf.fourcc != FOURCC_RXGB && 00734 header.pf.fourcc != FOURCC_ATI1 && 00735 header.pf.fourcc != FOURCC_ATI2) 00736 { 00737 // Unknown fourcc code. 00738 return false; 00739 } 00740 } 00741 else if (header.pf.flags & DDPF_RGB) 00742 { 00743 // All RGB formats are supported now. 00744 } 00745 else 00746 { 00747 return false; 00748 } 00749 00750 if (isTextureCube() && (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES) 00751 { 00752 // Cubemaps must contain all faces. 00753 return false; 00754 } 00755 00756 if (isTexture3D()) 00757 { 00758 // @@ 3D textures not supported yet. 00759 return false; 00760 } 00761 } 00762 00763 return true; 00764 } 00765 00766 00767 uint DirectDrawSurface::mipmapCount() const 00768 { 00769 if (header.flags & DDSD_MIPMAPCOUNT) return header.mipmapcount; 00770 else return 1; 00771 } 00772 00773 00774 uint DirectDrawSurface::width() const 00775 { 00776 if (header.flags & DDSD_WIDTH) return header.width; 00777 else return 1; 00778 } 00779 00780 uint DirectDrawSurface::height() const 00781 { 00782 if (header.flags & DDSD_HEIGHT) return header.height; 00783 else return 1; 00784 } 00785 00786 uint DirectDrawSurface::depth() const 00787 { 00788 if (header.flags & DDSD_DEPTH) return header.depth; 00789 else return 1; 00790 } 00791 00792 bool DirectDrawSurface::hasAlpha() const 00793 { 00794 if ((header.pf.flags & DDPF_RGB) && (header.pf.amask == 0)) 00795 { 00796 return false; 00797 } 00798 else if (header.pf.fourcc == FOURCC_DXT1) 00799 { 00800 return false; 00801 } 00802 else 00803 { 00804 return true; 00805 } 00806 } 00807 00808 bool DirectDrawSurface::isTexture1D() const 00809 { 00810 if (header.hasDX10Header()) 00811 { 00812 return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE1D; 00813 } 00814 return false; 00815 } 00816 00817 bool DirectDrawSurface::isTexture2D() const 00818 { 00819 if (header.hasDX10Header()) 00820 { 00821 return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE2D; 00822 } 00823 else 00824 { 00825 return !isTexture3D() && !isTextureCube(); 00826 } 00827 } 00828 00829 bool DirectDrawSurface::isTexture3D() const 00830 { 00831 if (header.hasDX10Header()) 00832 { 00833 return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D; 00834 } 00835 else 00836 { 00837 return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0; 00838 } 00839 } 00840 00841 bool DirectDrawSurface::isTextureCube() const 00842 { 00843 return (header.caps.caps2 & DDSCAPS2_CUBEMAP) != 0; 00844 } 00845 00846 void DirectDrawSurface::setNormalFlag(bool b) 00847 { 00848 header.setNormalFlag(b); 00849 } 00850 00851 void DirectDrawSurface::mipmap(Image * img, uint face, uint mipmap) 00852 { 00853 stream.seek(offset(face, mipmap)); 00854 00855 uint w = width(); 00856 uint h = height(); 00857 00858 // Compute width and height. 00859 for (uint m = 0; m < mipmap; m++) 00860 { 00861 w = max(1U, w / 2); 00862 h = max(1U, h / 2); 00863 } 00864 00865 img->allocate(w, h); 00866 00867 if (header.pf.flags & DDPF_RGB) 00868 { 00869 readLinearImage(img); 00870 } 00871 else if (header.pf.flags & DDPF_FOURCC) 00872 { 00873 readBlockImage(img); 00874 } 00875 } 00876 00877 void DirectDrawSurface::readLinearImage(Image * img) 00878 { 00879 00880 const uint w = img->width(); 00881 const uint h = img->height(); 00882 00883 uint rshift, rsize; 00884 PixelFormat::maskShiftAndSize(header.pf.rmask, &rshift, &rsize); 00885 00886 uint gshift, gsize; 00887 PixelFormat::maskShiftAndSize(header.pf.gmask, &gshift, &gsize); 00888 00889 uint bshift, bsize; 00890 PixelFormat::maskShiftAndSize(header.pf.bmask, &bshift, &bsize); 00891 00892 uint ashift, asize; 00893 PixelFormat::maskShiftAndSize(header.pf.amask, &ashift, &asize); 00894 00895 uint byteCount = (header.pf.bitcount + 7) / 8; 00896 00897 if (byteCount > 4) 00898 { 00899 /* just in case... we could have segfaults later on if byteCount > 4 */ 00900 printf("DDS: bitcount too large"); 00901 return; 00902 } 00903 00904 // set image format: RGB or ARGB 00905 // alpha channel exists if and only if the alpha mask is non-zero 00906 if (header.pf.amask == 0) 00907 { 00908 img->setFormat(Image::Format_RGB); 00909 } 00910 else 00911 { 00912 img->setFormat(Image::Format_ARGB); 00913 } 00914 00915 // Read linear RGB images. 00916 for (uint y = 0; y < h; y++) 00917 { 00918 for (uint x = 0; x < w; x++) 00919 { 00920 uint c = 0; 00921 mem_read(stream, (unsigned char *)(&c), byteCount); 00922 00923 Color32 pixel(0, 0, 0, 0xFF); 00924 pixel.r = PixelFormat::convert(c >> rshift, rsize, 8); 00925 pixel.g = PixelFormat::convert(c >> gshift, gsize, 8); 00926 pixel.b = PixelFormat::convert(c >> bshift, bsize, 8); 00927 pixel.a = PixelFormat::convert(c >> ashift, asize, 8); 00928 00929 img->pixel(x, y) = pixel; 00930 } 00931 } 00932 } 00933 00934 void DirectDrawSurface::readBlockImage(Image * img) 00935 { 00936 00937 // set image format: RGB or ARGB 00938 if (header.pf.fourcc == FOURCC_RXGB || 00939 header.pf.fourcc == FOURCC_ATI1 || 00940 header.pf.fourcc == FOURCC_ATI2 || 00941 header.pf.flags & DDPF_NORMAL) 00942 { 00943 img->setFormat(Image::Format_RGB); 00944 } 00945 else 00946 { 00947 img->setFormat(Image::Format_ARGB); 00948 } 00949 00950 const uint w = img->width(); 00951 const uint h = img->height(); 00952 00953 const uint bw = (w + 3) / 4; 00954 const uint bh = (h + 3) / 4; 00955 00956 for (uint by = 0; by < bh; by++) 00957 { 00958 for (uint bx = 0; bx < bw; bx++) 00959 { 00960 ColorBlock block; 00961 00962 // Read color block. 00963 readBlock(&block); 00964 00965 // Write color block. 00966 for (uint y = 0; y < min(4U, h-4*by); y++) 00967 { 00968 for (uint x = 0; x < min(4U, w-4*bx); x++) 00969 { 00970 img->pixel(4*bx+x, 4*by+y) = block.color(x, y); 00971 } 00972 } 00973 } 00974 } 00975 } 00976 00977 static Color32 buildNormal(uint8 x, uint8 y) 00978 { 00979 float nx = 2 * (x / 255.0f) - 1; 00980 float ny = 2 * (y / 255.0f) - 1; 00981 float nz = 0.0f; 00982 if (1 - nx*nx - ny*ny > 0) nz = sqrt(1 - nx*nx - ny*ny); 00983 uint8 z = clamp(int(255.0f * (nz + 1) / 2.0f), 0, 255); 00984 00985 return Color32(x, y, z); 00986 } 00987 00988 00989 void DirectDrawSurface::readBlock(ColorBlock * rgba) 00990 { 00991 if (header.pf.fourcc == FOURCC_DXT1) 00992 { 00993 BlockDXT1 block; 00994 mem_read(stream, block); 00995 block.decodeBlock(rgba); 00996 } 00997 else if (header.pf.fourcc == FOURCC_DXT2 || 00998 header.pf.fourcc == FOURCC_DXT3) 00999 { 01000 BlockDXT3 block; 01001 mem_read(stream, block); 01002 block.decodeBlock(rgba); 01003 } 01004 else if (header.pf.fourcc == FOURCC_DXT4 || 01005 header.pf.fourcc == FOURCC_DXT5 || 01006 header.pf.fourcc == FOURCC_RXGB) 01007 { 01008 BlockDXT5 block; 01009 mem_read(stream, block); 01010 block.decodeBlock(rgba); 01011 01012 if (header.pf.fourcc == FOURCC_RXGB) 01013 { 01014 // Swap R & A. 01015 for (int i = 0; i < 16; i++) 01016 { 01017 Color32 & c = rgba->color(i); 01018 uint tmp = c.r; 01019 c.r = c.a; 01020 c.a = tmp; 01021 } 01022 } 01023 } 01024 else if (header.pf.fourcc == FOURCC_ATI1) 01025 { 01026 BlockATI1 block; 01027 mem_read(stream, block); 01028 block.decodeBlock(rgba); 01029 } 01030 else if (header.pf.fourcc == FOURCC_ATI2) 01031 { 01032 BlockATI2 block; 01033 mem_read(stream, block); 01034 block.decodeBlock(rgba); 01035 } 01036 01037 // If normal flag set, convert to normal. 01038 if (header.pf.flags & DDPF_NORMAL) 01039 { 01040 if (header.pf.fourcc == FOURCC_ATI2) 01041 { 01042 for (int i = 0; i < 16; i++) 01043 { 01044 Color32 & c = rgba->color(i); 01045 c = buildNormal(c.r, c.g); 01046 } 01047 } 01048 else if (header.pf.fourcc == FOURCC_DXT5) 01049 { 01050 for (int i = 0; i < 16; i++) 01051 { 01052 Color32 & c = rgba->color(i); 01053 c = buildNormal(c.a, c.g); 01054 } 01055 } 01056 } 01057 } 01058 01059 01060 uint DirectDrawSurface::blockSize() const 01061 { 01062 switch(header.pf.fourcc) 01063 { 01064 case FOURCC_DXT1: 01065 case FOURCC_ATI1: 01066 return 8; 01067 case FOURCC_DXT2: 01068 case FOURCC_DXT3: 01069 case FOURCC_DXT4: 01070 case FOURCC_DXT5: 01071 case FOURCC_RXGB: 01072 case FOURCC_ATI2: 01073 return 16; 01074 }; 01075 01076 // Not a block image. 01077 return 0; 01078 } 01079 01080 uint DirectDrawSurface::mipmapSize(uint mipmap) const 01081 { 01082 uint w = width(); 01083 uint h = height(); 01084 uint d = depth(); 01085 01086 for (uint m = 0; m < mipmap; m++) 01087 { 01088 w = max(1U, w / 2); 01089 h = max(1U, h / 2); 01090 d = max(1U, d / 2); 01091 } 01092 01093 if (header.pf.flags & DDPF_FOURCC) 01094 { 01095 // @@ How are 3D textures aligned? 01096 w = (w + 3) / 4; 01097 h = (h + 3) / 4; 01098 return blockSize() * w * h; 01099 } 01100 else if (header.pf.flags & DDPF_RGB) 01101 { 01102 // Align pixels to bytes. 01103 uint byteCount = (header.pf.bitcount + 7) / 8; 01104 01105 // Align pitch to 4 bytes. 01106 uint pitch = 4 * ((w * byteCount + 3) / 4); 01107 01108 return pitch * h * d; 01109 } 01110 else { 01111 printf("DDS: mipmap format not supported\n"); 01112 return(0); 01113 }; 01114 } 01115 01116 uint DirectDrawSurface::faceSize() const 01117 { 01118 const uint count = mipmapCount(); 01119 uint size = 0; 01120 01121 for (uint m = 0; m < count; m++) 01122 { 01123 size += mipmapSize(m); 01124 } 01125 01126 return size; 01127 } 01128 01129 uint DirectDrawSurface::offset(const uint face, const uint mipmap) 01130 { 01131 uint size = 128; //sizeof(DDSHeader); 01132 01133 if (header.hasDX10Header()) 01134 { 01135 size += 20; // sizeof(DDSHeader10); 01136 } 01137 01138 if (face != 0) 01139 { 01140 size += face * faceSize(); 01141 } 01142 01143 for (uint m = 0; m < mipmap; m++) 01144 { 01145 size += mipmapSize(m); 01146 } 01147 01148 return size; 01149 } 01150 01151 01152 void DirectDrawSurface::printInfo() const 01153 { 01154 /* printf("FOURCC: %c%c%c%c\n", ((unsigned char *)&header.fourcc)[0], ((unsigned char *)&header.fourcc)[1], ((unsigned char *)&header.fourcc)[2], ((unsigned char *)&header.fourcc)[3]); */ 01155 printf("Flags: 0x%.8X\n", header.flags); 01156 if (header.flags & DDSD_CAPS) printf("\tDDSD_CAPS\n"); 01157 if (header.flags & DDSD_PIXELFORMAT) printf("\tDDSD_PIXELFORMAT\n"); 01158 if (header.flags & DDSD_WIDTH) printf("\tDDSD_WIDTH\n"); 01159 if (header.flags & DDSD_HEIGHT) printf("\tDDSD_HEIGHT\n"); 01160 if (header.flags & DDSD_DEPTH) printf("\tDDSD_DEPTH\n"); 01161 if (header.flags & DDSD_PITCH) printf("\tDDSD_PITCH\n"); 01162 if (header.flags & DDSD_LINEARSIZE) printf("\tDDSD_LINEARSIZE\n"); 01163 if (header.flags & DDSD_MIPMAPCOUNT) printf("\tDDSD_MIPMAPCOUNT\n"); 01164 01165 printf("Height: %d\n", header.height); 01166 printf("Width: %d\n", header.width); 01167 printf("Depth: %d\n", header.depth); 01168 if (header.flags & DDSD_PITCH) printf("Pitch: %d\n", header.pitch); 01169 else if (header.flags & DDSD_LINEARSIZE) printf("Linear size: %d\n", header.pitch); 01170 printf("Mipmap count: %d\n", header.mipmapcount); 01171 01172 printf("Pixel Format:\n"); 01173 /* printf("\tSize: %d\n", header.pf.size); */ 01174 printf("\tFlags: 0x%.8X\n", header.pf.flags); 01175 if (header.pf.flags & DDPF_RGB) printf("\t\tDDPF_RGB\n"); 01176 if (header.pf.flags & DDPF_FOURCC) printf("\t\tDDPF_FOURCC\n"); 01177 if (header.pf.flags & DDPF_ALPHAPIXELS) printf("\t\tDDPF_ALPHAPIXELS\n"); 01178 if (header.pf.flags & DDPF_ALPHA) printf("\t\tDDPF_ALPHA\n"); 01179 if (header.pf.flags & DDPF_PALETTEINDEXED1) printf("\t\tDDPF_PALETTEINDEXED1\n"); 01180 if (header.pf.flags & DDPF_PALETTEINDEXED2) printf("\t\tDDPF_PALETTEINDEXED2\n"); 01181 if (header.pf.flags & DDPF_PALETTEINDEXED4) printf("\t\tDDPF_PALETTEINDEXED4\n"); 01182 if (header.pf.flags & DDPF_PALETTEINDEXED8) printf("\t\tDDPF_PALETTEINDEXED8\n"); 01183 if (header.pf.flags & DDPF_ALPHAPREMULT) printf("\t\tDDPF_ALPHAPREMULT\n"); 01184 if (header.pf.flags & DDPF_NORMAL) printf("\t\tDDPF_NORMAL\n"); 01185 01186 printf("\tFourCC: '%c%c%c%c'\n", 01187 ((header.pf.fourcc >> 0) & 0xFF), 01188 ((header.pf.fourcc >> 8) & 0xFF), 01189 ((header.pf.fourcc >> 16) & 0xFF), 01190 ((header.pf.fourcc >> 24) & 0xFF)); 01191 if ((header.pf.fourcc & DDPF_FOURCC) && (header.pf.bitcount != 0)) 01192 { 01193 printf("\tSwizzle: '%c%c%c%c'\n", 01194 (header.pf.bitcount >> 0) & 0xFF, 01195 (header.pf.bitcount >> 8) & 0xFF, 01196 (header.pf.bitcount >> 16) & 0xFF, 01197 (header.pf.bitcount >> 24) & 0xFF); 01198 } 01199 else 01200 { 01201 printf("\tBit count: %d\n", header.pf.bitcount); 01202 } 01203 printf("\tRed mask: 0x%.8X\n", header.pf.rmask); 01204 printf("\tGreen mask: 0x%.8X\n", header.pf.gmask); 01205 printf("\tBlue mask: 0x%.8X\n", header.pf.bmask); 01206 printf("\tAlpha mask: 0x%.8X\n", header.pf.amask); 01207 01208 printf("Caps:\n"); 01209 printf("\tCaps 1: 0x%.8X\n", header.caps.caps1); 01210 if (header.caps.caps1 & DDSCAPS_COMPLEX) printf("\t\tDDSCAPS_COMPLEX\n"); 01211 if (header.caps.caps1 & DDSCAPS_TEXTURE) printf("\t\tDDSCAPS_TEXTURE\n"); 01212 if (header.caps.caps1 & DDSCAPS_MIPMAP) printf("\t\tDDSCAPS_MIPMAP\n"); 01213 01214 printf("\tCaps 2: 0x%.8X\n", header.caps.caps2); 01215 if (header.caps.caps2 & DDSCAPS2_VOLUME) printf("\t\tDDSCAPS2_VOLUME\n"); 01216 else if (header.caps.caps2 & DDSCAPS2_CUBEMAP) 01217 { 01218 printf("\t\tDDSCAPS2_CUBEMAP\n"); 01219 if ((header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) == DDSCAPS2_CUBEMAP_ALL_FACES) printf("\t\tDDSCAPS2_CUBEMAP_ALL_FACES\n"); 01220 else { 01221 if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEX\n"); 01222 if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEX\n"); 01223 if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEY\n"); 01224 if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEY\n"); 01225 if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEZ\n"); 01226 if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ) printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEZ\n"); 01227 } 01228 } 01229 01230 printf("\tCaps 3: 0x%.8X\n", header.caps.caps3); 01231 printf("\tCaps 4: 0x%.8X\n", header.caps.caps4); 01232 01233 if (header.hasDX10Header()) 01234 { 01235 printf("DX10 Header:\n"); 01236 printf("\tDXGI Format: %u (%s)\n", header.header10.dxgiFormat, getDxgiFormatString((DXGI_FORMAT)header.header10.dxgiFormat)); 01237 printf("\tResource dimension: %u (%s)\n", header.header10.resourceDimension, getD3d10ResourceDimensionString((D3D10_RESOURCE_DIMENSION)header.header10.resourceDimension)); 01238 printf("\tMisc flag: %u\n", header.header10.miscFlag); 01239 printf("\tArray size: %u\n", header.header10.arraySize); 01240 } 01241 01242 if (header.reserved[9] == MAKEFOURCC('N', 'V', 'T', 'T')) 01243 { 01244 int major = (header.reserved[10] >> 16) & 0xFF; 01245 int minor = (header.reserved[10] >> 8) & 0xFF; 01246 int revision= header.reserved[10] & 0xFF; 01247 01248 printf("Version:\n"); 01249 printf("\tNVIDIA Texture Tools %d.%d.%d\n", major, minor, revision); 01250 } 01251 } 01252
1.7.3