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_helper.h
-
 
3
 * @brief Image helper functions
-
 
4
 */
1
/*
5
/*
2
    Jonathan Dummer
6
    Jonathan Dummer
3

7

4
    Image helper functions
8
    Image helper functions
5

9

6
    MIT license
10
    MIT license
7
*/
11
*/
8
 
12
 
9
#ifndef HEADER_IMAGE_HELPER
13
#ifndef HEADER_IMAGE_HELPER
10
#define HEADER_IMAGE_HELPER
14
#define HEADER_IMAGE_HELPER
11
 
15
 
12
#ifdef __cplusplus
16
#ifdef __cplusplus
13
extern "C" {
17
extern "C" {
14
#endif
18
#endif
15
 
19
 
16
/**
20
/**
17
	This function upscales an image.
21
	This function upscales an image.
18
	Not to be used to create MIPmaps,
22
	Not to be used to create MIPmaps,
19
	but to make it square,
23
	but to make it square,
20
	or to make it a power-of-two sized.
24
	or to make it a power-of-two sized.
21
**/
25
**/
22
int
26
int
23
	up_scale_image
27
	up_scale_image
24
	(
28
	(
25
		const unsigned char* const orig,
29
		const unsigned char* const orig,
26
		int width, int height, int channels,
30
		int width, int height, int channels,
27
		unsigned char* resampled,
31
		unsigned char* resampled,
28
		int resampled_width, int resampled_height
32
		int resampled_width, int resampled_height
29
	);
33
	);
30
 
34
 
31
/**
35
/**
32
	This function downscales an image.
36
	This function downscales an image.
33
	Used for creating MIPmaps,
37
	Used for creating MIPmaps,
34
	the incoming image should be a
38
	the incoming image should be a
35
	power-of-two sized.
39
	power-of-two sized.
36
**/
40
**/
37
int
41
int
38
	mipmap_image
42
	mipmap_image
39
	(
43
	(
40
		const unsigned char* const orig,
44
		const unsigned char* const orig,
41
		int width, int height, int channels,
45
		int width, int height, int channels,
42
		unsigned char* resampled,
46
		unsigned char* resampled,
43
		int block_size_x, int block_size_y
47
		int block_size_x, int block_size_y
44
	);
48
	);
45
 
49
 
46
/**
50
/**
47
	This function takes the RGB components of the image
51
	This function takes the RGB components of the image
48
	and scales each channel from [0,255] to [16,235].
52
	and scales each channel from [0,255] to [16,235].
49
	This makes the colors "Safe" for display on NTSC
53
	This makes the colors "Safe" for display on NTSC
50
	displays.  Note that this is _NOT_ a good idea for
54
	displays.  Note that this is _NOT_ a good idea for
51
	loading images like normal- or height-maps!
55
	loading images like normal- or height-maps!
52
**/
56
**/
53
int
57
int
54
	scale_image_RGB_to_NTSC_safe
58
	scale_image_RGB_to_NTSC_safe
55
	(
59
	(
56
		unsigned char* orig,
60
		unsigned char* orig,
57
		int width, int height, int channels
61
		int width, int height, int channels
58
	);
62
	);
59
 
63
 
60
/**
64
/**
61
	This function takes the RGB components of the image
65
	This function takes the RGB components of the image
62
	and converts them into YCoCg.  3 components will be
66
	and converts them into YCoCg.  3 components will be
63
	re-ordered to CoYCg (for optimum DXT1 compression),
67
	re-ordered to CoYCg (for optimum DXT1 compression),
64
	while 4 components will be ordered CoCgAY (for DXT5
68
	while 4 components will be ordered CoCgAY (for DXT5
65
	compression).
69
	compression).
66
**/
70
**/
67
int
71
int
68
	convert_RGB_to_YCoCg
72
	convert_RGB_to_YCoCg
69
	(
73
	(
70
		unsigned char* orig,
74
		unsigned char* orig,
71
		int width, int height, int channels
75
		int width, int height, int channels
72
	);
76
	);
73
 
77
 
74
/**
78
/**
75
	This function takes the YCoCg components of the image
79
	This function takes the YCoCg components of the image
76
	and converts them into RGB.  See above.
80
	and converts them into RGB.  See above.
77
**/
81
**/
78
int
82
int
79
	convert_YCoCg_to_RGB
83
	convert_YCoCg_to_RGB
80
	(
84
	(
81
		unsigned char* orig,
85
		unsigned char* orig,
82
		int width, int height, int channels
86
		int width, int height, int channels
83
	);
87
	);
84
 
88
 
85
/**
89
/**
86
	Converts an HDR image from an array
90
	Converts an HDR image from an array
87
	of unsigned chars (RGBE) to RGBdivA
91
	of unsigned chars (RGBE) to RGBdivA
88
	\return 0 if failed, otherwise returns 1
92
	\return 0 if failed, otherwise returns 1
89
**/
93
**/
90
int
94
int
91
	RGBE_to_RGBdivA
95
	RGBE_to_RGBdivA
92
	(
96
	(
93
		unsigned char *image,
97
		unsigned char *image,
94
		int width, int height,
98
		int width, int height,
95
		int rescale_to_max
99
		int rescale_to_max
96
	);
100
	);
97
 
101
 
98
/**
102
/**
99
	Converts an HDR image from an array
103
	Converts an HDR image from an array
100
	of unsigned chars (RGBE) to RGBdivA2
104
	of unsigned chars (RGBE) to RGBdivA2
101
	\return 0 if failed, otherwise returns 1
105
	\return 0 if failed, otherwise returns 1
102
**/
106
**/
103
int
107
int
104
	RGBE_to_RGBdivA2
108
	RGBE_to_RGBdivA2
105
	(
109
	(
106
		unsigned char *image,
110
		unsigned char *image,
107
		int width, int height,
111
		int width, int height,
108
		int rescale_to_max
112
		int rescale_to_max
109
	);
113
	);
110
 
114
 
111
#ifdef __cplusplus
115
#ifdef __cplusplus
112
}
116
}
113
#endif
117
#endif
114
 
118
 
115
#endif /* HEADER_IMAGE_HELPER	*/
119
#endif /* HEADER_IMAGE_HELPER	*/
116
 
120