summaryrefslogtreecommitdiff
path: root/graymap.h
blob: fd3a0ca5ee86451b9314889695b48d6d86e8141d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef _graymap_h_
#define _graymap_h_

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @file graymap.h
 *
 * This header files contains thedefinition of data types and functions to deal
 * with graymap images.
 */

/* ******************************** MACROS ************************************/
/**
 * This macro makes accessing graymap pixels easier.
 * 
 * If you use pointers to graymaps, you have to call this macro like this:
 * GM_PIX(*my_graymap, x,y) = foo;
 *
 * @param gm the graymap
 * @param x X coordinate
 * @param y Y coordinate
 * @return The pixel of the graymap which can be used like a variable.
 * @see set_pix_graymap()
 * @see get_pix_graymap()
 * @see color_t
 */
#define GM_PIX(gm,x,y) (gm).data[((y)*(gm).w)+(x)]

/* ****************************** DATA TYPES **********************************/
/**
 * This is a data type to hold RGBA color values.
 *
 * All values are stored as floating point numbers.
 */
typedef struct
{
	double r; /**< Red color component. */
	double g; /**< Green color component. */
	double b; /**< Blue color component. */
	double a; /**< Alpha value component. */
} color_t;

/**
 * The data structure for graymaps.
 */
typedef struct
{
	int w; /**< Width of the image */
	int h; /**< Height of the image. */
	double* data; /**< Image data. */
} graymap_t;

/* ******************************* FUNCTIONS **********************************/
/**
 * Creating a graymap.
 * 
 * @param w the width of the new image.
 * @param h the height of the new image.
 * @return a new graymap image.
 * @see destroy_graymap()
 */
extern graymap_t create_graymap(int w, int h);

/**
 * Destroying a graymap.
 * 
 * This will free the memory of the image data and set width/height to -1.
 *
 * @param gm Pointer to the graymap.
 * @see create_graymap()
 */
extern void destroy_graymap(graymap_t* gm);

/**
 * Clear the graymap to a grayscale value.
 *
 * This will override all pixels in the graymap to the specified greyscale
 * value.
 *
 * @param gm Pointer to the graymap.
 * @param grayval Grayscale value.
 */
extern void clear_graymap(graymap_t* gm, double grayval);

/**
 * Set a pixel in a graymap.
 *
 * @param gm Pointer to the graymap
 * @param x X coordinate
 * @param y Y coordinate
 * @param gray grayscale value of the pixel
 * @see get_pix_graymap()
 * @see GM_PIX()
 */
extern void set_pix_graymap(graymap_t* gm, int x, int y, double gray);

/**
 * Get a pixel from a graymap.
 *
 * @param gm Pointer to the graymap
 * @param x X coordinate
 * @param y Y coordinate
 * @return grayscale value of the pixel
 * @see set_pix_graymap()
 * @see GM_PIX()
 */
extern double get_pix_graymap(graymap_t* gm, int x, int y);

/**
 * Blitting (copying) image data from one graymap to another.
 *
 * @param src pointer to the source graymap
 * @param dst pointer to the destination graymap
 * @param src_x Blitting start X coordinate in the source graymap
 * @param src_y Blitting start Y coordinate in the source graymap
 * @param dst_x Blitting start X coordinate in the destination graymap
 * @param dst_y Blitting start Y coordinate in the destination graymap
 * @param w Width of the blitting rectangle.
 * @param h Height of the blitting rectangle.
 */
extern void blit_graymaps(graymap_t* src, graymap_t* dst, int src_x, int src_y,
 int dst_x, int dst_y, int w, int h);

/**
 * Calculate a color from a palette and a grayscale value.
 * 
 * A palette is represented by two arrays. One array contains colors, the other
 * one contains the corresponding grayscale values. This palette now represents
 * a color gradient. The color which fits to the grayscale value will be
 * returned.
 *
 * @param grayval The grayscale value.
 * @param pal_cols Array of colors.
 * @param pal_grays Array of grayscale values
 * @param pal_n length of the arrays.
 * @return The calculated color.
 */
extern color_t get_palette_color(double grayval, color_t* pal_cols,
 double* pal_grays, int pal_n);

/**
 * Create a color_t object.
 *
 * @param r The red color component.
 * @param g The green color component.
 * @param b The blue color component.
 * @param a The Alpha value.
 * @return the color_t object.
 * @see color_t
 */
extern color_t mkcol(double r, double g, double b, double a);

#ifdef __cplusplus
}
#endif

#endif