1 // Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com> 2 // 3 // Permission is hereby granted, free of charge, to any person 4 // obtaining a copy of this software and associated documentation 5 // files (the "Software"), to deal in the Software without 6 // restriction, including without limitation the rights to use, 7 // copy, modify, merge, publish, distribute, sublicense, and/or sell 8 // copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following 10 // conditions: 11 // 12 // The above copyright notice and this permission notice shall be 13 // included in all copies or substantial portions of the Software. 14 // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 // OTHER DEALINGS IN THE SOFTWARE. 23 24 #ifndef NV_IMAGE_DIRECTDRAWSURFACE_H 25 #define NV_IMAGE_DIRECTDRAWSURFACE_H 26 27 #include <nvimage/nvimage.h> 28 29 namespace nv 30 { 31 class Image; 32 class Stream; 33 struct ColorBlock; 34 35 struct NVIMAGE_CLASS DDSPixelFormat 36 { 37 uint size; 38 uint flags; 39 uint fourcc; 40 uint bitcount; 41 uint rmask; 42 uint gmask; 43 uint bmask; 44 uint amask; 45 }; 46 47 struct NVIMAGE_CLASS DDSCaps 48 { 49 uint caps1; 50 uint caps2; 51 uint caps3; 52 uint caps4; 53 }; 54 55 /// DDS file header for DX10. 56 struct NVIMAGE_CLASS DDSHeader10 57 { 58 uint dxgiFormat; 59 uint resourceDimension; 60 uint miscFlag; 61 uint arraySize; 62 uint reserved; 63 }; 64 65 /// DDS file header. 66 struct NVIMAGE_CLASS DDSHeader 67 { 68 uint fourcc; 69 uint size; 70 uint flags; 71 uint height; 72 uint width; 73 uint pitch; 74 uint depth; 75 uint mipmapcount; 76 uint reserved[11]; 77 DDSPixelFormat pf; 78 DDSCaps caps; 79 uint notused; 80 DDSHeader10 header10; 81 82 83 // Helper methods. 84 DDSHeader(); 85 86 void setWidth(uint w); 87 void setHeight(uint h); 88 void setDepth(uint d); 89 void setMipmapCount(uint count); 90 void setTexture2D(); 91 void setTexture3D(); 92 void setTextureCube(); 93 void setLinearSize(uint size); 94 void setPitch(uint pitch); 95 void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3); 96 void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); 97 void setDX10Format(uint format); 98 void setNormalFlag(bool b); 99 100 void swapBytes(); 101 102 bool hasDX10Header() const; 103 }; 104 105 NVIMAGE_API Stream & operator<< (Stream & s, DDSHeader & header); 106 107 108 /// DirectDraw Surface. (DDS) 109 class NVIMAGE_CLASS DirectDrawSurface 110 { 111 public: 112 DirectDrawSurface(const char * file); 113 ~DirectDrawSurface(); 114 115 bool isValid() const; 116 bool isSupported() const; 117 118 uint mipmapCount() const; 119 uint width() const; 120 uint height() const; 121 uint depth() const; 122 bool isTexture1D() const; 123 bool isTexture2D() const; 124 bool isTexture3D() const; 125 bool isTextureCube() const; 126 127 void setNormalFlag(bool b); 128 129 void mipmap(Image * img, uint f, uint m); 130 // void mipmap(FloatImage * img, uint f, uint m); 131 132 void printInfo() const; 133 134 private: 135 136 uint blockSize() const; 137 uint faceSize() const; 138 uint mipmapSize(uint m) const; 139 140 uint offset(uint f, uint m); 141 142 void readLinearImage(Image * img); 143 void readBlockImage(Image * img); 144 void readBlock(ColorBlock * rgba); 145 146 147 private: 148 Stream * const stream; 149 DDSHeader header; 150 DDSHeader10 header10; 151 }; 152 153 } // nv namespace 154 155 #endif // NV_IMAGE_DIRECTDRAWSURFACE_H 156