Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributors: Amorilia (amorilia@users.sourceforge.net) 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 /* 00029 * This file is based on a similar file from the NVIDIA texture tools 00030 * (http://nvidia-texture-tools.googlecode.com/) 00031 * 00032 * Original license from NVIDIA follows. 00033 */ 00034 00035 // Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com> 00036 // 00037 // Permission is hereby granted, free of charge, to any person 00038 // obtaining a copy of this software and associated documentation 00039 // files (the "Software"), to deal in the Software without 00040 // restriction, including without limitation the rights to use, 00041 // copy, modify, merge, publish, distribute, sublicense, and/or sell 00042 // copies of the Software, and to permit persons to whom the 00043 // Software is furnished to do so, subject to the following 00044 // conditions: 00045 // 00046 // The above copyright notice and this permission notice shall be 00047 // included in all copies or substantial portions of the Software. 00048 // 00049 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00050 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00051 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00052 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00053 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00054 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00055 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00056 // OTHER DEALINGS IN THE SOFTWARE. 00057 00058 #ifndef _DDS_DIRECTDRAWSURFACE_H 00059 #define _DDS_DIRECTDRAWSURFACE_H 00060 00061 #include <Common.h> 00062 #include <Stream.h> 00063 #include <ColorBlock.h> 00064 #include <Image.h> 00065 00066 struct DDSPixelFormat 00067 { 00068 uint size; 00069 uint flags; 00070 uint fourcc; 00071 uint bitcount; 00072 uint rmask; 00073 uint gmask; 00074 uint bmask; 00075 uint amask; 00076 }; 00077 00078 struct DDSCaps 00079 { 00080 uint caps1; 00081 uint caps2; 00082 uint caps3; 00083 uint caps4; 00084 }; 00085 00087 struct DDSHeader10 00088 { 00089 uint dxgiFormat; 00090 uint resourceDimension; 00091 uint miscFlag; 00092 uint arraySize; 00093 uint reserved; 00094 }; 00095 00097 struct DDSHeader 00098 { 00099 uint fourcc; 00100 uint size; 00101 uint flags; 00102 uint height; 00103 uint width; 00104 uint pitch; 00105 uint depth; 00106 uint mipmapcount; 00107 uint reserved[11]; 00108 DDSPixelFormat pf; 00109 DDSCaps caps; 00110 uint notused; 00111 DDSHeader10 header10; 00112 00113 00114 // Helper methods. 00115 DDSHeader(); 00116 00117 void setWidth(uint w); 00118 void setHeight(uint h); 00119 void setDepth(uint d); 00120 void setMipmapCount(uint count); 00121 void setTexture2D(); 00122 void setTexture3D(); 00123 void setTextureCube(); 00124 void setLinearSize(uint size); 00125 void setPitch(uint pitch); 00126 void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3); 00127 void setFormatCode(uint code); 00128 void setSwizzleCode(uint8 c0, uint8 c1, uint8 c2, uint8 c3); 00129 void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); 00130 void setDX10Format(uint format); 00131 void setNormalFlag(bool b); 00132 void setSrgbFlag(bool b); 00133 void setHasAlphaFlag(bool b); 00134 void setUserVersion(int version); 00135 00136 /*void swapBytes();*/ 00137 00138 bool hasDX10Header() const; 00139 uint signature() const; 00140 uint toolVersion() const; 00141 uint userVersion() const; 00142 bool isNormalMap() const; 00143 bool isSrgb() const; 00144 bool hasAlpha() const; 00145 uint d3d9Format() const; 00146 }; 00147 00149 class DirectDrawSurface 00150 { 00151 public: 00152 DirectDrawSurface(unsigned char *mem, uint size); 00153 ~DirectDrawSurface(); 00154 00155 bool isValid() const; 00156 bool isSupported() const; 00157 00158 bool hasAlpha() const; 00159 00160 uint mipmapCount() const; 00161 uint width() const; 00162 uint height() const; 00163 uint depth() const; 00164 bool isTexture1D() const; 00165 bool isTexture2D() const; 00166 bool isTexture3D() const; 00167 bool isTextureCube() const; 00168 00169 void setNormalFlag(bool b); 00170 void setHasAlphaFlag(bool b); 00171 void setUserVersion(int version); 00172 00173 void mipmap(Image * img, uint f, uint m); 00174 // void mipmap(FloatImage * img, uint f, uint m); 00175 00176 void printInfo() const; 00177 00178 private: 00179 00180 uint blockSize() const; 00181 uint faceSize() const; 00182 uint mipmapSize(uint m) const; 00183 00184 uint offset(uint f, uint m); 00185 00186 void readLinearImage(Image * img); 00187 void readBlockImage(Image * img); 00188 void readBlock(ColorBlock * rgba); 00189 00190 00191 private: 00192 Stream stream; // memory where DDS file resides 00193 DDSHeader header; 00194 }; 00195 00196 void mem_read(Stream & mem, DDSPixelFormat & pf); 00197 void mem_read(Stream & mem, DDSCaps & caps); 00198 void mem_read(Stream & mem, DDSHeader & header); 00199 void mem_read(Stream & mem, DDSHeader10 & header); 00200 00201 #endif // _DDS_DIRECTDRAWSURFACE_H