-
Notifications
You must be signed in to change notification settings - Fork 3
/
paint_canvas.c
201 lines (169 loc) · 4.63 KB
/
paint_canvas.c
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "header.h"
void paint_canvas(
int *reference_rgb_image_arr,
int width,
int height,
int *initial_canvas_rgb_image_arr,
int initial_canvas_rgb_image_width,
int initial_canvas_rgb_image_height,
int *initial_canvas_bumpity_image_arr,
int initial_canvas_bumpity_image_width,
int initial_canvas_bumpity_image_height,
int *brush_radius_arr,
int brush_radius_nbr,
double *opacity_strength_arr,
double *bumpity_strength_arr,
double *error_threshold_arr,
double *grid_size_factor_arr,
int *texture_ind_arr,
texture_struct *texture_arr,
int texture_nbr,
int **pcanvas_rgb_image_arr,
int **pcanvas_bumpity_image_arr
)
{
int *canvas_rgb_image_arr;
int brush_radius_ind;
int brush_radius;
int debug_flag= 0;
int err_flag;
int *canvas_bumpity_image_arr;
double error_threshold;
double opacity_strength;
double bumpity_strength;
char scale_method[256];
char scale_gaussian[256];
double grid_size_factor;
int texture_ind;
/*
Allocate memory for canvas_rgb_image_arr
*/
canvas_rgb_image_arr= (int *)calloc(width*height,3*sizeof(int));
/*
Initialize the canvas rgb image with the input initial canvas rgb image
*/
strcpy(scale_method,"cubic");
strcpy(scale_gaussian,"no");
scale_rgb_image(
initial_canvas_rgb_image_arr,
initial_canvas_rgb_image_width,
initial_canvas_rgb_image_height,
canvas_rgb_image_arr,
width,
height,
scale_method,
scale_gaussian
);
if ( debug_flag == 1 ) {
/*
Print the canvas rgb image
*/
err_flag= write_rgb_image(
(char *)"canvas_rgb_image.png",
canvas_rgb_image_arr,
width,
height
);
if ( err_flag == 1 ) {
error_handler((char *)"paint_canvas");
}
}
/*
Allocate memory for canvas_bumpity_image_arr
*/
canvas_bumpity_image_arr= (int *)calloc(width*height,sizeof(int));
/*
Initialize the canvas bumpity image with the input initial canvas bumpity image
*/
strcpy(scale_method,"cubic");
strcpy(scale_gaussian,"no");
scale_image(
initial_canvas_bumpity_image_arr,
initial_canvas_bumpity_image_width,
initial_canvas_bumpity_image_height,
canvas_bumpity_image_arr,
width,
height,
scale_method,
scale_gaussian
);
if ( debug_flag == 1 ) {
/*
Print the canvas bumpity image
*/
err_flag= write_image(
(char *)"canvas_bumpity_image.png",
canvas_bumpity_image_arr,
width,
height
);
if ( err_flag == 1 ) {
error_handler((char *)"paint_canvas");
}
}
/*
Paint the canvas layer by layer
*/
for ( brush_radius_ind= 0 ;
brush_radius_ind< brush_radius_nbr ;
brush_radius_ind++ ) {
brush_radius= brush_radius_arr[brush_radius_ind];
opacity_strength= opacity_strength_arr[brush_radius_ind];
bumpity_strength= bumpity_strength_arr[brush_radius_ind];
error_threshold= error_threshold_arr[brush_radius_ind];
grid_size_factor= grid_size_factor_arr[brush_radius_ind];
texture_ind= texture_ind_arr[brush_radius_ind];
fprintf(stdout,"Painting canvas layer using brush_radius_ind = %2d brush_radius = %3d opacity_strength = %.2f bumpity_strength = %.2f error_threshold = %6.2f grid_size_factor = %.2f texture_ind = %2d...\n",
brush_radius_ind,brush_radius,opacity_strength,bumpity_strength,error_threshold,grid_size_factor,texture_ind);
/*
Paint the canvas layer
*/
paint_canvas_layer(
reference_rgb_image_arr,
width,
height,
brush_radius,
opacity_strength,
bumpity_strength,
texture_arr,
texture_nbr,
error_threshold,
grid_size_factor,
texture_ind,
canvas_rgb_image_arr,
canvas_bumpity_image_arr
);
if ( debug_flag == 1 ) {
/*
Print the canvas image
*/
err_flag= write_rgb_image(
(char *)"canvas_rgb_image.png",
canvas_rgb_image_arr,
width,
height
);
if ( err_flag == 1 ) {
error_handler((char *)"paint_canvas");
}
}
if ( debug_flag == 1 ) {
/*
Print the canvas bumpity image
*/
err_flag= write_image(
(char *)"canvas_bumpity_image.png",
canvas_bumpity_image_arr,
width,
height
);
if ( err_flag == 1 ) {
error_handler((char *)"paint_canvas");
}
}
fprintf(stdout,"Painting canvas layer using brush_radius_ind = %2d brush_radius = %3d opacity_strength = %.2f bumpity_strength = %.2f error_threshold = %6.2f grid_size_factor = %.2f texture_ind = %2d... done.\n",
brush_radius_ind,brush_radius,opacity_strength,bumpity_strength,error_threshold,grid_size_factor,texture_ind);
}
(*pcanvas_rgb_image_arr)= canvas_rgb_image_arr;
(*pcanvas_bumpity_image_arr)= canvas_bumpity_image_arr;
}