1 /* -----------------------------------------------------------------------------
5 Based on code from Nvidia's DDS example:
6 http://www.nvidia.com/object/dxtc_decompression_code.html
8 Copyright (c) 2003 Randy Reddig
11 Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
14 Redistributions of source code must retain the above copyright notice, this list
15 of conditions and the following disclaimer.
17 Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 Neither the names of the copyright holders nor the names of its contributors may
22 be used to endorse or promote products derived from this software without
23 specific prior written permission.
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
29 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ----------------------------------------------------------------------------- */
75 #define DDS_LOW_5 0x001F;
76 #define DDS_MID_6 0x07E0;
77 #define DDS_HIGH_5 0xF800;
78 #define DDS_MID_555 0x03E0;
79 #define DDS_HI_555 0x7C00;
83 typedef struct ddsColorKey_s
85 unsigned int colorSpaceLowValue;
86 unsigned int colorSpaceHighValue;
91 typedef struct ddsCaps_s
101 typedef struct ddsMultiSampleCaps_s
103 unsigned short flipMSTypes;
104 unsigned short bltMSTypes;
106 ddsMultiSampleCaps_t;
109 typedef struct ddsPixelFormat_s
116 unsigned int rgbBitCount;
117 unsigned int yuvBitCount;
118 unsigned int zBufferBitDepth;
119 unsigned int alphaBitDepth;
120 unsigned int luminanceBitCount;
121 unsigned int bumpBitCount;
122 unsigned int privateFormatBitCount;
126 unsigned int rBitMask;
127 unsigned int yBitMask;
128 unsigned int stencilBitDepth;
129 unsigned int luminanceBitMask;
130 unsigned int bumpDuBitMask;
131 unsigned int operations;
135 unsigned int gBitMask;
136 unsigned int uBitMask;
137 unsigned int zBitMask;
138 unsigned int bumpDvBitMask;
139 ddsMultiSampleCaps_t multiSampleCaps;
143 unsigned int bBitMask;
144 unsigned int vBitMask;
145 unsigned int stencilBitMask;
146 unsigned int bumpLuminanceBitMask;
150 unsigned int rgbAlphaBitMask;
151 unsigned int yuvAlphaBitMask;
152 unsigned int luminanceAlphaBitMask;
153 unsigned int rgbZBitMask;
154 unsigned int yuvZBitMask;
160 typedef struct ddsBuffer_s
165 /* directdraw surface */
173 unsigned int linearSize;
175 unsigned int backBufferCount;
178 unsigned int mipMapCount;
179 unsigned int refreshRate;
180 unsigned int srcVBHandle;
182 unsigned int alphaBitDepth;
183 unsigned int reserved;
187 ddsColorKey_t ckDestOverlay;
188 unsigned int emptyFaceColor;
190 ddsColorKey_t ckDestBlt;
191 ddsColorKey_t ckSrcOverlay;
192 ddsColorKey_t ckSrcBlt;
195 ddsPixelFormat_t pixelFormat;
199 unsigned int textureStage;
201 /* data (Varying size) */
202 unsigned char data[ 4 ];
207 typedef struct ddsColorBlock_s
209 unsigned short colors[ 2 ];
210 unsigned char row[ 4 ];
215 typedef struct ddsAlphaBlockExplicit_s
217 unsigned short row[ 4 ];
219 ddsAlphaBlockExplicit_t;
222 typedef struct ddsAlphaBlock3BitLinear_s
224 unsigned char alpha0;
225 unsigned char alpha1;
226 unsigned char stuff[ 6 ];
228 ddsAlphaBlock3BitLinear_t;
231 typedef struct ddsColor_s
233 unsigned char r, g, b, a;
239 /* public functions */
240 int DDSGetInfo( ddsBuffer_t *dds, int *width, int *height, ddsPF_t *pf );
241 int DDSDecompress( ddsBuffer_t *dds, unsigned char *pixels );