|
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_DIRECTDRAWSURFACE_H 00056 #define _DDS_DIRECTDRAWSURFACE_H 00057 00058 #include <Common.h> 00059 #include <Stream.h> 00060 #include <ColorBlock.h> 00061 #include <Image.h> 00062 00063 struct DDSPixelFormat 00064 { 00065 uint size; 00066 uint flags; 00067 uint fourcc; 00068 uint bitcount; 00069 uint rmask; 00070 uint gmask; 00071 uint bmask; 00072 uint amask; 00073 }; 00074 00075 struct DDSCaps 00076 { 00077 uint caps1; 00078 uint caps2; 00079 uint caps3; 00080 uint caps4; 00081 }; 00082 00084 struct DDSHeader10 00085 { 00086 uint dxgiFormat; 00087 uint resourceDimension; 00088 uint miscFlag; 00089 uint arraySize; 00090 uint reserved; 00091 }; 00092 00094 struct DDSHeader 00095 { 00096 uint fourcc; 00097 uint size; 00098 uint flags; 00099 uint height; 00100 uint width; 00101 uint pitch; 00102 uint depth; 00103 uint mipmapcount; 00104 uint reserved[11]; 00105 DDSPixelFormat pf; 00106 DDSCaps caps; 00107 uint notused; 00108 DDSHeader10 header10; 00109 00110 00111 // Helper methods. 00112 DDSHeader(); 00113 00114 void setWidth(uint w); 00115 void setHeight(uint h); 00116 void setDepth(uint d); 00117 void setMipmapCount(uint count); 00118 void setTexture2D(); 00119 void setTexture3D(); 00120 void setTextureCube(); 00121 void setLinearSize(uint size); 00122 void setPitch(uint pitch); 00123 void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3); 00124 void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); 00125 void setDX10Format(uint format); 00126 void setNormalFlag(bool b); 00127 00128 bool hasDX10Header() const; 00129 }; 00130 00132 class DirectDrawSurface 00133 { 00134 public: 00135 DirectDrawSurface(unsigned char *mem, uint size); 00136 ~DirectDrawSurface(); 00137 00138 bool isValid() const; 00139 bool isSupported() const; 00140 00141 uint mipmapCount() const; 00142 uint width() const; 00143 uint height() const; 00144 uint depth() const; 00145 bool isTexture1D() const; 00146 bool isTexture2D() const; 00147 bool isTexture3D() const; 00148 bool isTextureCube() const; 00149 00150 void setNormalFlag(bool b); 00151 00152 bool hasAlpha() const; /* false for DXT1, true for all other DXTs */ 00153 00154 void mipmap(Image * img, uint f, uint m); 00155 // void mipmap(FloatImage * img, uint f, uint m); 00156 00157 void printInfo() const; 00158 00159 private: 00160 00161 uint blockSize() const; 00162 uint faceSize() const; 00163 uint mipmapSize(uint m) const; 00164 00165 uint offset(uint f, uint m); 00166 00167 void readLinearImage(Image * img); 00168 void readBlockImage(Image * img); 00169 void readBlock(ColorBlock * rgba); 00170 00171 00172 private: 00173 Stream stream; // memory where DDS file resides 00174 DDSHeader header; 00175 }; 00176 00177 void mem_read(Stream & mem, DDSPixelFormat & pf); 00178 void mem_read(Stream & mem, DDSCaps & caps); 00179 void mem_read(Stream & mem, DDSHeader & header); 00180 void mem_read(Stream & mem, DDSHeader10 & header); 00181 00182 #endif // _DDS_DIRECTDRAWSURFACE_H
1.7.3