diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CImageLoaderDDS.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CImageLoaderDDS.h | 592 |
1 files changed, 296 insertions, 296 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CImageLoaderDDS.h b/libraries/irrlicht-1.8/source/Irrlicht/CImageLoaderDDS.h index f8c3516..64237c6 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CImageLoaderDDS.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/CImageLoaderDDS.h | |||
@@ -1,296 +1,296 @@ | |||
1 | // Copyright (C) 2002-2012 Thomas Alten | 1 | // Copyright (C) 2002-2012 Thomas Alten |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #ifndef __C_IMAGE_LOADER_DDS_H_INCLUDED__ | 5 | #ifndef __C_IMAGE_LOADER_DDS_H_INCLUDED__ |
6 | #define __C_IMAGE_LOADER_DDS_H_INCLUDED__ | 6 | #define __C_IMAGE_LOADER_DDS_H_INCLUDED__ |
7 | 7 | ||
8 | #include "IrrCompileConfig.h" | 8 | #include "IrrCompileConfig.h" |
9 | 9 | ||
10 | #if defined(_IRR_COMPILE_WITH_DDS_LOADER_) | 10 | #if defined(_IRR_COMPILE_WITH_DDS_LOADER_) |
11 | 11 | ||
12 | #include "IImageLoader.h" | 12 | #include "IImageLoader.h" |
13 | 13 | ||
14 | namespace irr | 14 | namespace irr |
15 | { | 15 | { |
16 | namespace video | 16 | namespace video |
17 | { | 17 | { |
18 | 18 | ||
19 | /* dependencies */ | 19 | /* dependencies */ |
20 | /* dds definition */ | 20 | /* dds definition */ |
21 | enum eDDSPixelFormat | 21 | enum eDDSPixelFormat |
22 | { | 22 | { |
23 | DDS_PF_ARGB8888, | 23 | DDS_PF_ARGB8888, |
24 | DDS_PF_DXT1, | 24 | DDS_PF_DXT1, |
25 | DDS_PF_DXT2, | 25 | DDS_PF_DXT2, |
26 | DDS_PF_DXT3, | 26 | DDS_PF_DXT3, |
27 | DDS_PF_DXT4, | 27 | DDS_PF_DXT4, |
28 | DDS_PF_DXT5, | 28 | DDS_PF_DXT5, |
29 | DDS_PF_UNKNOWN | 29 | DDS_PF_UNKNOWN |
30 | }; | 30 | }; |
31 | 31 | ||
32 | /* 16bpp stuff */ | 32 | /* 16bpp stuff */ |
33 | #define DDS_LOW_5 0x001F; | 33 | #define DDS_LOW_5 0x001F; |
34 | #define DDS_MID_6 0x07E0; | 34 | #define DDS_MID_6 0x07E0; |
35 | #define DDS_HIGH_5 0xF800; | 35 | #define DDS_HIGH_5 0xF800; |
36 | #define DDS_MID_555 0x03E0; | 36 | #define DDS_MID_555 0x03E0; |
37 | #define DDS_HI_555 0x7C00; | 37 | #define DDS_HI_555 0x7C00; |
38 | 38 | ||
39 | 39 | ||
40 | // byte-align structures | 40 | // byte-align structures |
41 | #include "irrpack.h" | 41 | #include "irrpack.h" |
42 | 42 | ||
43 | /* structures */ | 43 | /* structures */ |
44 | struct ddsColorKey | 44 | struct ddsColorKey |
45 | { | 45 | { |
46 | u32 colorSpaceLowValue; | 46 | u32 colorSpaceLowValue; |
47 | u32 colorSpaceHighValue; | 47 | u32 colorSpaceHighValue; |
48 | } PACK_STRUCT; | 48 | } PACK_STRUCT; |
49 | 49 | ||
50 | struct ddsCaps | 50 | struct ddsCaps |
51 | { | 51 | { |
52 | u32 caps1; | 52 | u32 caps1; |
53 | u32 caps2; | 53 | u32 caps2; |
54 | u32 caps3; | 54 | u32 caps3; |
55 | u32 caps4; | 55 | u32 caps4; |
56 | } PACK_STRUCT; | 56 | } PACK_STRUCT; |
57 | 57 | ||
58 | struct ddsMultiSampleCaps | 58 | struct ddsMultiSampleCaps |
59 | { | 59 | { |
60 | u16 flipMSTypes; | 60 | u16 flipMSTypes; |
61 | u16 bltMSTypes; | 61 | u16 bltMSTypes; |
62 | } PACK_STRUCT; | 62 | } PACK_STRUCT; |
63 | 63 | ||
64 | 64 | ||
65 | struct ddsPixelFormat | 65 | struct ddsPixelFormat |
66 | { | 66 | { |
67 | u32 size; | 67 | u32 size; |
68 | u32 flags; | 68 | u32 flags; |
69 | u32 fourCC; | 69 | u32 fourCC; |
70 | union | 70 | union |
71 | { | 71 | { |
72 | u32 rgbBitCount; | 72 | u32 rgbBitCount; |
73 | u32 yuvBitCount; | 73 | u32 yuvBitCount; |
74 | u32 zBufferBitDepth; | 74 | u32 zBufferBitDepth; |
75 | u32 alphaBitDepth; | 75 | u32 alphaBitDepth; |
76 | u32 luminanceBitCount; | 76 | u32 luminanceBitCount; |
77 | u32 bumpBitCount; | 77 | u32 bumpBitCount; |
78 | u32 privateFormatBitCount; | 78 | u32 privateFormatBitCount; |
79 | }; | 79 | }; |
80 | union | 80 | union |
81 | { | 81 | { |
82 | u32 rBitMask; | 82 | u32 rBitMask; |
83 | u32 yBitMask; | 83 | u32 yBitMask; |
84 | u32 stencilBitDepth; | 84 | u32 stencilBitDepth; |
85 | u32 luminanceBitMask; | 85 | u32 luminanceBitMask; |
86 | u32 bumpDuBitMask; | 86 | u32 bumpDuBitMask; |
87 | u32 operations; | 87 | u32 operations; |
88 | }; | 88 | }; |
89 | union | 89 | union |
90 | { | 90 | { |
91 | u32 gBitMask; | 91 | u32 gBitMask; |
92 | u32 uBitMask; | 92 | u32 uBitMask; |
93 | u32 zBitMask; | 93 | u32 zBitMask; |
94 | u32 bumpDvBitMask; | 94 | u32 bumpDvBitMask; |
95 | ddsMultiSampleCaps multiSampleCaps; | 95 | ddsMultiSampleCaps multiSampleCaps; |
96 | }; | 96 | }; |
97 | union | 97 | union |
98 | { | 98 | { |
99 | u32 bBitMask; | 99 | u32 bBitMask; |
100 | u32 vBitMask; | 100 | u32 vBitMask; |
101 | u32 stencilBitMask; | 101 | u32 stencilBitMask; |
102 | u32 bumpLuminanceBitMask; | 102 | u32 bumpLuminanceBitMask; |
103 | }; | 103 | }; |
104 | union | 104 | union |
105 | { | 105 | { |
106 | u32 rgbAlphaBitMask; | 106 | u32 rgbAlphaBitMask; |
107 | u32 yuvAlphaBitMask; | 107 | u32 yuvAlphaBitMask; |
108 | u32 luminanceAlphaBitMask; | 108 | u32 luminanceAlphaBitMask; |
109 | u32 rgbZBitMask; | 109 | u32 rgbZBitMask; |
110 | u32 yuvZBitMask; | 110 | u32 yuvZBitMask; |
111 | }; | 111 | }; |
112 | } PACK_STRUCT; | 112 | } PACK_STRUCT; |
113 | 113 | ||
114 | 114 | ||
115 | struct ddsBuffer | 115 | struct ddsBuffer |
116 | { | 116 | { |
117 | /* magic: 'dds ' */ | 117 | /* magic: 'dds ' */ |
118 | c8 magic[ 4 ]; | 118 | c8 magic[ 4 ]; |
119 | 119 | ||
120 | /* directdraw surface */ | 120 | /* directdraw surface */ |
121 | u32 size; | 121 | u32 size; |
122 | u32 flags; | 122 | u32 flags; |
123 | u32 height; | 123 | u32 height; |
124 | u32 width; | 124 | u32 width; |
125 | union | 125 | union |
126 | { | 126 | { |
127 | s32 pitch; | 127 | s32 pitch; |
128 | u32 linearSize; | 128 | u32 linearSize; |
129 | }; | 129 | }; |
130 | u32 backBufferCount; | 130 | u32 backBufferCount; |
131 | union | 131 | union |
132 | { | 132 | { |
133 | u32 mipMapCount; | 133 | u32 mipMapCount; |
134 | u32 refreshRate; | 134 | u32 refreshRate; |
135 | u32 srcVBHandle; | 135 | u32 srcVBHandle; |
136 | }; | 136 | }; |
137 | u32 alphaBitDepth; | 137 | u32 alphaBitDepth; |
138 | u32 reserved; | 138 | u32 reserved; |
139 | void *surface; | 139 | void *surface; |
140 | union | 140 | union |
141 | { | 141 | { |
142 | ddsColorKey ckDestOverlay; | 142 | ddsColorKey ckDestOverlay; |
143 | u32 emptyFaceColor; | 143 | u32 emptyFaceColor; |
144 | }; | 144 | }; |
145 | ddsColorKey ckDestBlt; | 145 | ddsColorKey ckDestBlt; |
146 | ddsColorKey ckSrcOverlay; | 146 | ddsColorKey ckSrcOverlay; |
147 | ddsColorKey ckSrcBlt; | 147 | ddsColorKey ckSrcBlt; |
148 | union | 148 | union |
149 | { | 149 | { |
150 | ddsPixelFormat pixelFormat; | 150 | ddsPixelFormat pixelFormat; |
151 | u32 fvf; | 151 | u32 fvf; |
152 | }; | 152 | }; |
153 | ddsCaps caps; | 153 | ddsCaps caps; |
154 | u32 textureStage; | 154 | u32 textureStage; |
155 | 155 | ||
156 | /* data (Varying size) */ | 156 | /* data (Varying size) */ |
157 | u8 data[ 4 ]; | 157 | u8 data[ 4 ]; |
158 | } PACK_STRUCT; | 158 | } PACK_STRUCT; |
159 | 159 | ||
160 | 160 | ||
161 | struct ddsColorBlock | 161 | struct ddsColorBlock |
162 | { | 162 | { |
163 | u16 colors[ 2 ]; | 163 | u16 colors[ 2 ]; |
164 | u8 row[ 4 ]; | 164 | u8 row[ 4 ]; |
165 | } PACK_STRUCT; | 165 | } PACK_STRUCT; |
166 | 166 | ||
167 | 167 | ||
168 | struct ddsAlphaBlockExplicit | 168 | struct ddsAlphaBlockExplicit |
169 | { | 169 | { |
170 | u16 row[ 4 ]; | 170 | u16 row[ 4 ]; |
171 | } PACK_STRUCT; | 171 | } PACK_STRUCT; |
172 | 172 | ||
173 | 173 | ||
174 | struct ddsAlphaBlock3BitLinear | 174 | struct ddsAlphaBlock3BitLinear |
175 | { | 175 | { |
176 | u8 alpha0; | 176 | u8 alpha0; |
177 | u8 alpha1; | 177 | u8 alpha1; |
178 | u8 stuff[ 6 ]; | 178 | u8 stuff[ 6 ]; |
179 | } PACK_STRUCT; | 179 | } PACK_STRUCT; |
180 | 180 | ||
181 | 181 | ||
182 | struct ddsColor | 182 | struct ddsColor |
183 | { | 183 | { |
184 | u8 r, g, b, a; | 184 | u8 r, g, b, a; |
185 | } PACK_STRUCT; | 185 | } PACK_STRUCT; |
186 | 186 | ||
187 | // Default alignment | 187 | // Default alignment |
188 | #include "irrunpack.h" | 188 | #include "irrunpack.h" |
189 | 189 | ||
190 | 190 | ||
191 | /* endian tomfoolery */ | 191 | /* endian tomfoolery */ |
192 | typedef union | 192 | typedef union |
193 | { | 193 | { |
194 | f32 f; | 194 | f32 f; |
195 | c8 c[ 4 ]; | 195 | c8 c[ 4 ]; |
196 | } | 196 | } |
197 | floatSwapUnion; | 197 | floatSwapUnion; |
198 | 198 | ||
199 | 199 | ||
200 | #ifndef __BIG_ENDIAN__ | 200 | #ifndef __BIG_ENDIAN__ |
201 | #ifdef _SGI_SOURCE | 201 | #ifdef _SGI_SOURCE |
202 | #define __BIG_ENDIAN__ | 202 | #define __BIG_ENDIAN__ |
203 | #endif | 203 | #endif |
204 | #endif | 204 | #endif |
205 | 205 | ||
206 | 206 | ||
207 | #ifdef __BIG_ENDIAN__ | 207 | #ifdef __BIG_ENDIAN__ |
208 | 208 | ||
209 | s32 DDSBigLong( s32 src ) { return src; } | 209 | s32 DDSBigLong( s32 src ) { return src; } |
210 | s16 DDSBigShort( s16 src ) { return src; } | 210 | s16 DDSBigShort( s16 src ) { return src; } |
211 | f32 DDSBigFloat( f32 src ) { return src; } | 211 | f32 DDSBigFloat( f32 src ) { return src; } |
212 | 212 | ||
213 | s32 DDSLittleLong( s32 src ) | 213 | s32 DDSLittleLong( s32 src ) |
214 | { | 214 | { |
215 | return ((src & 0xFF000000) >> 24) | | 215 | return ((src & 0xFF000000) >> 24) | |
216 | ((src & 0x00FF0000) >> 8) | | 216 | ((src & 0x00FF0000) >> 8) | |
217 | ((src & 0x0000FF00) << 8) | | 217 | ((src & 0x0000FF00) << 8) | |
218 | ((src & 0x000000FF) << 24); | 218 | ((src & 0x000000FF) << 24); |
219 | } | 219 | } |
220 | 220 | ||
221 | s16 DDSLittleShort( s16 src ) | 221 | s16 DDSLittleShort( s16 src ) |
222 | { | 222 | { |
223 | return ((src & 0xFF00) >> 8) | | 223 | return ((src & 0xFF00) >> 8) | |
224 | ((src & 0x00FF) << 8); | 224 | ((src & 0x00FF) << 8); |
225 | } | 225 | } |
226 | 226 | ||
227 | f32 DDSLittleFloat( f32 src ) | 227 | f32 DDSLittleFloat( f32 src ) |
228 | { | 228 | { |
229 | floatSwapUnion in,out; | 229 | floatSwapUnion in,out; |
230 | in.f = src; | 230 | in.f = src; |
231 | out.c[ 0 ] = in.c[ 3 ]; | 231 | out.c[ 0 ] = in.c[ 3 ]; |
232 | out.c[ 1 ] = in.c[ 2 ]; | 232 | out.c[ 1 ] = in.c[ 2 ]; |
233 | out.c[ 2 ] = in.c[ 1 ]; | 233 | out.c[ 2 ] = in.c[ 1 ]; |
234 | out.c[ 3 ] = in.c[ 0 ]; | 234 | out.c[ 3 ] = in.c[ 0 ]; |
235 | return out.f; | 235 | return out.f; |
236 | } | 236 | } |
237 | 237 | ||
238 | #else /*__BIG_ENDIAN__*/ | 238 | #else /*__BIG_ENDIAN__*/ |
239 | 239 | ||
240 | s32 DDSLittleLong( s32 src ) { return src; } | 240 | s32 DDSLittleLong( s32 src ) { return src; } |
241 | s16 DDSLittleShort( s16 src ) { return src; } | 241 | s16 DDSLittleShort( s16 src ) { return src; } |
242 | f32 DDSLittleFloat( f32 src ) { return src; } | 242 | f32 DDSLittleFloat( f32 src ) { return src; } |
243 | 243 | ||
244 | s32 DDSBigLong( s32 src ) | 244 | s32 DDSBigLong( s32 src ) |
245 | { | 245 | { |
246 | return ((src & 0xFF000000) >> 24) | | 246 | return ((src & 0xFF000000) >> 24) | |
247 | ((src & 0x00FF0000) >> 8) | | 247 | ((src & 0x00FF0000) >> 8) | |
248 | ((src & 0x0000FF00) << 8) | | 248 | ((src & 0x0000FF00) << 8) | |
249 | ((src & 0x000000FF) << 24); | 249 | ((src & 0x000000FF) << 24); |
250 | } | 250 | } |
251 | 251 | ||
252 | s16 DDSBigShort( s16 src ) | 252 | s16 DDSBigShort( s16 src ) |
253 | { | 253 | { |
254 | return ((src & 0xFF00) >> 8) | | 254 | return ((src & 0xFF00) >> 8) | |
255 | ((src & 0x00FF) << 8); | 255 | ((src & 0x00FF) << 8); |
256 | } | 256 | } |
257 | 257 | ||
258 | f32 DDSBigFloat( f32 src ) | 258 | f32 DDSBigFloat( f32 src ) |
259 | { | 259 | { |
260 | floatSwapUnion in,out; | 260 | floatSwapUnion in,out; |
261 | in.f = src; | 261 | in.f = src; |
262 | out.c[ 0 ] = in.c[ 3 ]; | 262 | out.c[ 0 ] = in.c[ 3 ]; |
263 | out.c[ 1 ] = in.c[ 2 ]; | 263 | out.c[ 1 ] = in.c[ 2 ]; |
264 | out.c[ 2 ] = in.c[ 1 ]; | 264 | out.c[ 2 ] = in.c[ 1 ]; |
265 | out.c[ 3 ] = in.c[ 0 ]; | 265 | out.c[ 3 ] = in.c[ 0 ]; |
266 | return out.f; | 266 | return out.f; |
267 | } | 267 | } |
268 | 268 | ||
269 | #endif /*__BIG_ENDIAN__*/ | 269 | #endif /*__BIG_ENDIAN__*/ |
270 | 270 | ||
271 | 271 | ||
272 | /*! | 272 | /*! |
273 | Surface Loader for DDS images | 273 | Surface Loader for DDS images |
274 | */ | 274 | */ |
275 | class CImageLoaderDDS : public IImageLoader | 275 | class CImageLoaderDDS : public IImageLoader |
276 | { | 276 | { |
277 | public: | 277 | public: |
278 | 278 | ||
279 | //! returns true if the file maybe is able to be loaded by this class | 279 | //! returns true if the file maybe is able to be loaded by this class |
280 | //! based on the file extension (e.g. ".tga") | 280 | //! based on the file extension (e.g. ".tga") |
281 | virtual bool isALoadableFileExtension(const io::path& filename) const; | 281 | virtual bool isALoadableFileExtension(const io::path& filename) const; |
282 | 282 | ||
283 | //! returns true if the file maybe is able to be loaded by this class | 283 | //! returns true if the file maybe is able to be loaded by this class |
284 | virtual bool isALoadableFileFormat(io::IReadFile* file) const; | 284 | virtual bool isALoadableFileFormat(io::IReadFile* file) const; |
285 | 285 | ||
286 | //! creates a surface from the file | 286 | //! creates a surface from the file |
287 | virtual IImage* loadImage(io::IReadFile* file) const; | 287 | virtual IImage* loadImage(io::IReadFile* file) const; |
288 | }; | 288 | }; |
289 | 289 | ||
290 | 290 | ||
291 | } // end namespace video | 291 | } // end namespace video |
292 | } // end namespace irr | 292 | } // end namespace irr |
293 | 293 | ||
294 | #endif // compiled with DDS loader | 294 | #endif // compiled with DDS loader |
295 | #endif | 295 | #endif |
296 | 296 | ||