]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/ddslib.h
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / libs / ddslib.h
1 /* -----------------------------------------------------------------------------\r
2 \r
3 DDS Library \r
4 \r
5 Based on code from Nvidia's DDS example:\r
6 http://www.nvidia.com/object/dxtc_decompression_code.html\r
7 \r
8 Copyright (c) 2003 Randy Reddig\r
9 All rights reserved.\r
10 \r
11 Redistribution and use in source and binary forms, with or without modification,\r
12 are permitted provided that the following conditions are met:\r
13 \r
14 Redistributions of source code must retain the above copyright notice, this list\r
15 of conditions and the following disclaimer.\r
16 \r
17 Redistributions in binary form must reproduce the above copyright notice, this\r
18 list of conditions and the following disclaimer in the documentation and/or\r
19 other materials provided with the distribution.\r
20 \r
21 Neither the names of the copyright holders nor the names of its contributors may\r
22 be used to endorse or promote products derived from this software without\r
23 specific prior written permission. \r
24 \r
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
26 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\r
29 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r
32 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
35 \r
36 ----------------------------------------------------------------------------- */\r
37 \r
38 \r
39 \r
40 /* marker */\r
41 #ifndef DDSLIB_H\r
42 #define DDSLIB_H\r
43 \r
44 \r
45 \r
46 /* dependencies */\r
47 #include <stdio.h>\r
48 #include <memory.h>\r
49 \r
50 \r
51 \r
52 /* c++ marker */\r
53 #ifdef __cplusplus\r
54 extern "C"\r
55 {\r
56 #endif\r
57 \r
58 \r
59 \r
60 /* dds definition */\r
61 typedef enum\r
62 {\r
63         DDS_PF_ARGB8888,\r
64         DDS_PF_DXT1,\r
65         DDS_PF_DXT2,\r
66         DDS_PF_DXT3,\r
67         DDS_PF_DXT4,\r
68         DDS_PF_DXT5,\r
69         DDS_PF_UNKNOWN\r
70 }\r
71 ddsPF_t;\r
72 \r
73 \r
74 /* 16bpp stuff */\r
75 #define DDS_LOW_5               0x001F;\r
76 #define DDS_MID_6               0x07E0;\r
77 #define DDS_HIGH_5              0xF800;\r
78 #define DDS_MID_555             0x03E0;\r
79 #define DDS_HI_555              0x7C00;\r
80 \r
81 \r
82 /* structures */\r
83 typedef struct ddsColorKey_s\r
84 {\r
85         unsigned int            colorSpaceLowValue;\r
86         unsigned int            colorSpaceHighValue;\r
87\r
88 ddsColorKey_t;\r
89 \r
90 \r
91 typedef struct ddsCaps_s\r
92 {\r
93         unsigned int            caps1;\r
94         unsigned int            caps2;\r
95         unsigned int            caps3;\r
96         unsigned int            caps4;\r
97\r
98 ddsCaps_t;\r
99 \r
100 \r
101 typedef struct ddsMultiSampleCaps_s\r
102 {\r
103         unsigned short          flipMSTypes;\r
104         unsigned short          bltMSTypes;\r
105 }\r
106 ddsMultiSampleCaps_t;\r
107 \r
108 \r
109 typedef struct ddsPixelFormat_s\r
110 {\r
111         unsigned int            size;\r
112         unsigned int            flags;\r
113         unsigned int            fourCC;\r
114         union\r
115         {\r
116                 unsigned int    rgbBitCount;\r
117                 unsigned int    yuvBitCount;\r
118                 unsigned int    zBufferBitDepth;\r
119                 unsigned int    alphaBitDepth;\r
120                 unsigned int    luminanceBitCount;\r
121                 unsigned int    bumpBitCount;\r
122                 unsigned int    privateFormatBitCount;\r
123         };\r
124         union\r
125         {\r
126                 unsigned int    rBitMask;\r
127                 unsigned int    yBitMask;\r
128                 unsigned int    stencilBitDepth;\r
129                 unsigned int    luminanceBitMask;\r
130                 unsigned int    bumpDuBitMask;\r
131                 unsigned int    operations;\r
132         };\r
133         union\r
134         {\r
135                 unsigned int    gBitMask;\r
136                 unsigned int    uBitMask;\r
137                 unsigned int    zBitMask;\r
138                 unsigned int    bumpDvBitMask;\r
139                 ddsMultiSampleCaps_t    multiSampleCaps;\r
140         };\r
141         union\r
142         {\r
143                 unsigned int    bBitMask;\r
144                 unsigned int    vBitMask;\r
145                 unsigned int    stencilBitMask;\r
146                 unsigned int    bumpLuminanceBitMask;\r
147         };\r
148         union\r
149         {\r
150                 unsigned int    rgbAlphaBitMask;\r
151                 unsigned int    yuvAlphaBitMask;\r
152                 unsigned int    luminanceAlphaBitMask;\r
153                 unsigned int    rgbZBitMask;\r
154                 unsigned int    yuvZBitMask;\r
155         };\r
156 }\r
157 ddsPixelFormat_t;\r
158 \r
159 \r
160 typedef struct ddsBuffer_s\r
161 {\r
162         /* magic: 'dds ' */\r
163         char                            magic[ 4 ];\r
164         \r
165         /* directdraw surface */\r
166         unsigned int            size;\r
167         unsigned int            flags;\r
168         unsigned int            height;\r
169         unsigned int            width; \r
170         union\r
171         {\r
172                 int                             pitch;\r
173                 unsigned int    linearSize;\r
174         };\r
175         unsigned int            backBufferCount;\r
176         union\r
177         {\r
178                 unsigned int    mipMapCount;\r
179                 unsigned int    refreshRate;\r
180                 unsigned int    srcVBHandle;\r
181         };\r
182         unsigned int            alphaBitDepth;\r
183         unsigned int            reserved;\r
184         void                            *surface;\r
185         union\r
186         {\r
187                 ddsColorKey_t   ckDestOverlay;   \r
188                 unsigned int    emptyFaceColor;\r
189         };\r
190         ddsColorKey_t           ckDestBlt;\r
191         ddsColorKey_t           ckSrcOverlay;    \r
192         ddsColorKey_t           ckSrcBlt;     \r
193         union\r
194         {\r
195                 ddsPixelFormat_t        pixelFormat;\r
196                 unsigned int    fvf;\r
197         };\r
198         ddsCaps_t                       ddsCaps;\r
199         unsigned int            textureStage;\r
200         \r
201         /* data (Varying size) */\r
202         unsigned char           data[ 4 ];\r
203 }\r
204 ddsBuffer_t;\r
205 \r
206 \r
207 typedef struct ddsColorBlock_s\r
208 {\r
209         unsigned short          colors[ 2 ];\r
210         unsigned char           row[ 4 ];\r
211 }\r
212 ddsColorBlock_t;\r
213 \r
214 \r
215 typedef struct ddsAlphaBlockExplicit_s\r
216 {\r
217         unsigned short          row[ 4 ];\r
218 }\r
219 ddsAlphaBlockExplicit_t;\r
220 \r
221 \r
222 typedef struct ddsAlphaBlock3BitLinear_s\r
223 {\r
224         unsigned char           alpha0;\r
225         unsigned char           alpha1;\r
226         unsigned char           stuff[ 6 ];\r
227 }\r
228 ddsAlphaBlock3BitLinear_t;\r
229 \r
230 \r
231 typedef struct ddsColor_s\r
232 {\r
233         unsigned char           r, g, b, a;\r
234 }\r
235 ddsColor_t;\r
236 \r
237 \r
238 \r
239 /* public functions */\r
240 int                                             DDSGetInfo( ddsBuffer_t *dds, int *width, int *height, ddsPF_t *pf );\r
241 int                                             DDSDecompress( ddsBuffer_t *dds, unsigned char *pixels );\r
242 \r
243 \r
244 \r
245 /* end marker */\r
246 #ifdef __cplusplus\r
247 }\r
248 #endif\r
249 \r
250 #endif\r