~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CImageLoaderDDS.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

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