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