-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathxemboss.c
executable file
·312 lines (238 loc) · 6.65 KB
/
xemboss.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*********************************************
*
* file xemboss.c
*
* Functions: This file contains
* main
* emboss_convolution
* copy_array
*
* Purpose:
* This program performs embossing on
* images using a collection of
* convolution masks.
*
* External Calls:
* imageio.c - create_image_file
* read_image_array
* write_image_array
* get_image_size
* allocate_image_array
* free_image_array
*
* Modifications:
* 11 May 1999 - created
*
***********************************************/
#include "cips.h"
int does_not_exist();
int create_image_file();
int get_image_size();
int read_image_array();
int free_image_array();
int write_image_array();
int emboss_convolution();
int get_bitsperpixel();
int copy_array();
/* list the convolution masks */
short emboss_0_mask[3][3] = {
{-1, 0, 1},
{-1, 1, 1},
{-1, 0, 1} };
short emboss_1_mask[3][3] = {
{ 0, 1, 1},
{-1, 1, 1},
{-1, -1, 0} };
short emboss_2_mask[3][3] = {
{ 1, 1, 0},
{ 1, 1, -1},
{ 0, -1, -1} };
short emboss_3_mask[3][3] = {
{ 1, 0, -1},
{ 1, 1, -1},
{ 1, 0, -1} };
short emboss_4_mask[3][3] = {
{ 0, -1, -1},
{ 1, 1, -1},
{ 1, 1, 0} };
short emboss_5_mask[3][3] = {
{-1, -1, -1},
{ 0, 1, 0},
{ 1, 1, 1} };
short emboss_6_mask[3][3] = {
{-1, -1, 0},
{-1, 1, 1},
{ 0, 1, 1} };
short emboss_7_mask[3][3] = {
{-1, 1, 1},
{-1, 1, 1},
{-1, 1, 1} };
short emboss_8_mask[3][3] = {
{ 1, 1, 1},
{-1, 1, 1},
{-1, -1, 1} };
short emboss_9_mask[3][3] = {
{ 1, 1, 1},
{ 1, 1, -1},
{ 1, -1, -1} };
short emboss_10_mask[3][3] = {
{ 1, 1, -1},
{ 1, 1, -1},
{ 1, 1, -1} };
short emboss_11_mask[3][3] = {
{ 1, -1, -1},
{ 1, 1, -1},
{ 1, 1, 1} };
short emboss_12_mask[3][3] = {
{-1, -1, -1},
{ 1, 1, 1},
{ 1, 1, 1} };
short emboss_13_mask[3][3] = {
{-1, -1, 1},
{-1, 1, 1},
{ 1, 1, 1} };
short **the_image;
short **out_image;
int main(argc, argv)
int argc;
char *argv[];
{
char in_name[80], out_name[80];
int i, j, size, type;
long bitsperpixel, length, width;
/* Get the command line parameters */
if(argc != 4){
printf("\n"
"\n usage: xemboss in-file out-file"
" type (0 thru 13)"
"\n ");
exit(0);
}
strcpy(in_name, argv[1]);
strcpy(out_name, argv[2]);
type = atoi(argv[3]);
/* Read the input file */
if(does_not_exist(in_name)){
printf("\nERROR input file %s does not exist",
in_name);
exit(0);
} /* ends if does_not_exist */
create_image_file(in_name, out_name);
get_image_size(in_name, &length, &width);
get_bitsperpixel(in_name, &bitsperpixel);
the_image = allocate_image_array(length, width);
out_image = allocate_image_array(length, width);
read_image_array(in_name, the_image);
emboss_convolution(the_image, out_image,
type,
length, width,
bitsperpixel);
write_image_array(out_name, out_image);
free_image_array(the_image, length);
free_image_array(out_image, length);
} /* ends main */
/**********************************************
*
* emoboss_convolution(...
*
* This function performs convolution
* between the input image and a 3x3 mask.
* The result is placed in the out_image.
*
***********************************************/
int emboss_convolution(image, out_image,
type,
rows, cols,
bitsperpixel)
short **image,
**out_image;
int type;
long rows, cols, bitsperpixel;
{
int a, b, i, is_present, j, sum;
short mask[3][3],
max,
min;
min = 0;
max = 255;
if(bitsperpixel == 4)
max = 16;
/* clear output image array */
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
out_image[i][j] = image[i][j];
copy_array(type, mask);
for(i=1; i<rows-1; i++){
for(j=1; j<cols-1; j++){
sum = 0;
for(a=-1; a<2; a++){
for(b=-1; b<2; b++){
sum = sum + image[i+a][j+b] *
mask[a+1][b+1];
}
}
if(sum > max) sum = max;
if(sum < 0) sum = 0;
out_image[i][j] = sum;
if( type >= 7 &&
type <= 13)
out_image[i][j] = out_image[i][j]/3;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends emboss_convolution */
int copy_array(type, mask)
int type;
short mask[3][3];
{
int i, j;
for(i=0; i<3; i++){
for(j=0; j<3; j++){
switch(type){
case 0:
mask[i][j] = emboss_0_mask[i][j];
break;
case 1:
mask[i][j] = emboss_1_mask[i][j];
break;
case 2:
mask[i][j] = emboss_2_mask[i][j];
break;
case 3:
mask[i][j] = emboss_3_mask[i][j];
break;
case 4:
mask[i][j] = emboss_4_mask[i][j];
break;
case 5:
mask[i][j] = emboss_5_mask[i][j];
break;
case 6:
mask[i][j] = emboss_6_mask[i][j];
break;
case 7:
mask[i][j] = emboss_7_mask[i][j];
break;
case 8:
mask[i][j] = emboss_8_mask[i][j];
break;
case 9:
mask[i][j] = emboss_9_mask[i][j];
break;
case 10:
mask[i][j] = emboss_10_mask[i][j];
break;
case 11:
mask[i][j] = emboss_11_mask[i][j];
break;
case 12:
mask[i][j] = emboss_12_mask[i][j];
break;
case 13:
mask[i][j] = emboss_13_mask[i][j];
break;
} /* ends switch */
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends copy_array */