Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
594 jab 1
/**
2
 * @file image_DXT.h
3
 * @brief simple DXT compression / decompression code
4
 */
369 jab 5
/*
6
	Jonathan Dummer
7
	2007-07-31-10.32
8
 
9
	simple DXT compression / decompression code
10
 
11
	public domain
12
*/
13
 
14
#ifndef HEADER_IMAGE_DXT
15
#define HEADER_IMAGE_DXT
16
 
17
/**
18
	Converts an image from an array of unsigned chars (RGB or RGBA) to
19
	DXT1 or DXT5, then saves the converted image to disk.
20
	\return 0 if failed, otherwise returns 1
21
**/
22
int
23
save_image_as_DDS
24
(
25
    const char *filename,
26
    int width, int height, int channels,
27
    const unsigned char *const data
28
);
29
 
30
/**
31
	take an image and convert it to DXT1 (no alpha)
32
**/
33
unsigned char*
34
convert_image_to_DXT1
35
(
36
    const unsigned char *const uncompressed,
37
    int width, int height, int channels,
38
    int *out_size
39
);
40
 
41
/**
42
	take an image and convert it to DXT5 (with alpha)
43
**/
44
unsigned char*
45
convert_image_to_DXT5
46
(
47
    const unsigned char *const uncompressed,
48
    int width, int height, int channels,
49
    int *out_size
50
);
51
 
52
/**	A bunch of DirectDraw Surface structures and flags **/
53
typedef struct
54
{
55
    unsigned int    dwMagic;
56
    unsigned int    dwSize;
57
    unsigned int    dwFlags;
58
    unsigned int    dwHeight;
59
    unsigned int    dwWidth;
60
    unsigned int    dwPitchOrLinearSize;
61
    unsigned int    dwDepth;
62
    unsigned int    dwMipMapCount;
63
    unsigned int    dwReserved1[ 11 ];
64
 
65
    /*  DDPIXELFORMAT	*/
66
    struct
67
    {
68
        unsigned int    dwSize;
69
        unsigned int    dwFlags;
70
        unsigned int    dwFourCC;
71
        unsigned int    dwRGBBitCount;
72
        unsigned int    dwRBitMask;
73
        unsigned int    dwGBitMask;
74
        unsigned int    dwBBitMask;
75
        unsigned int    dwAlphaBitMask;
76
    }
77
    sPixelFormat;
78
 
79
    /*  DDCAPS2	*/
80
    struct
81
    {
82
        unsigned int    dwCaps1;
83
        unsigned int    dwCaps2;
84
        unsigned int    dwDDSX;
85
        unsigned int    dwReserved;
86
    }
87
    sCaps;
88
    unsigned int    dwReserved2;
89
}
90
DDS_header ;
91
 
92
/*	the following constants were copied directly off the MSDN website	*/
93
 
94
/*	The dwFlags member of the original DDSURFACEDESC2 structure
95
	can be set to one or more of the following values.	*/
96
#define DDSD_CAPS	0x00000001
97
#define DDSD_HEIGHT	0x00000002
98
#define DDSD_WIDTH	0x00000004
99
#define DDSD_PITCH	0x00000008
100
#define DDSD_PIXELFORMAT	0x00001000
101
#define DDSD_MIPMAPCOUNT	0x00020000
102
#define DDSD_LINEARSIZE	0x00080000
103
#define DDSD_DEPTH	0x00800000
104
 
105
/*	DirectDraw Pixel Format	*/
106
#define DDPF_ALPHAPIXELS	0x00000001
107
#define DDPF_FOURCC	0x00000004
108
#define DDPF_RGB	0x00000040
109
 
110
/*	The dwCaps1 member of the DDSCAPS2 structure can be
111
	set to one or more of the following values.	*/
112
#define DDSCAPS_COMPLEX	0x00000008
113
#define DDSCAPS_TEXTURE	0x00001000
114
#define DDSCAPS_MIPMAP	0x00400000
115
 
116
/*	The dwCaps2 member of the DDSCAPS2 structure can be
117
	set to one or more of the following values.		*/
118
#define DDSCAPS2_CUBEMAP	0x00000200
119
#define DDSCAPS2_CUBEMAP_POSITIVEX	0x00000400
120
#define DDSCAPS2_CUBEMAP_NEGATIVEX	0x00000800
121
#define DDSCAPS2_CUBEMAP_POSITIVEY	0x00001000
122
#define DDSCAPS2_CUBEMAP_NEGATIVEY	0x00002000
123
#define DDSCAPS2_CUBEMAP_POSITIVEZ	0x00004000
124
#define DDSCAPS2_CUBEMAP_NEGATIVEZ	0x00008000
125
#define DDSCAPS2_VOLUME	0x00200000
126
 
127
#endif /* HEADER_IMAGE_DXT	*/