Subversion Repositories gelsvn

Rev

Rev 369 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 369 Rev 594
-
 
1
/**
-
 
2
 * @file image_DXT.h
-
 
3
 * @brief simple DXT compression / decompression code
-
 
4
 */
1
/*
5
/*
2
	Jonathan Dummer
6
	Jonathan Dummer
3
	2007-07-31-10.32
7
	2007-07-31-10.32
4

8

5
	simple DXT compression / decompression code
9
	simple DXT compression / decompression code
6

10

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