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