-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmainas.c
More file actions
executable file
·152 lines (130 loc) · 3.93 KB
/
mainas.c
File metadata and controls
executable file
·152 lines (130 loc) · 3.93 KB
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
/***********************************************
*
* file mainas.c
*
* Functions: This file contains
* main
*
* Purpose:
* This file contains the main calling
* routine in an image addition and subtraction
* program.
*
* External Calls:
* imageio.c - create_image_file
* read_image_array
* write_image_array
* get_image_size
* get_bitsperpixel
* allocate_image_array
* free_image_array
* does_not_exist
* are_not_same_size
* baddsub.c - add_image_array
* subtract_image_array
*
* Modifications:
* 1 April 1992 - created
* 10 August 1998 - modified to work on entire
* images at one time.
* 18 September 1998 - modified to work with
* all I O routines in imageio.c.
*
*************************************************/
#include "cips.h"
int does_not_exist();
int are_not_same_size();
int get_image_size();
int get_bitsperpixel();
int create_image_file();
int read_image_array();
int add_image_array();
int subtract_image_array();
int write_image_array();
int free_image_array();
int main(argc, argv)
int argc;
char *argv[];
{
char name1[80], name2[80], name3[80];
long bits_per_pixel, length, width;
short **image1, **image2;
short max;
/******************************************
*
* Interpret the command line parameters.
*
*******************************************/
if(argc != 5){
printf(
"\n"
"\n usage: mainas in1-file in2-file "
"out_file add-subtract"
"\n"
"\n recall add-subtract a=add s=subtract\n");
exit(0);
}
strcpy(name1, argv[1]);
strcpy(name2, argv[2]);
strcpy(name3, argv[3]);
if(does_not_exist(name1)){
printf("\nERROR input file %s does not exist",
name1);
exit(0);
}
if(does_not_exist(name2)){
printf("\nERROR input file %s does not exist",
name2);
exit(0);
}
/******************************************
*
* Ensure the two input images have the
* same sizes.
*
*******************************************/
if(are_not_same_size(name1, name2)){
printf(
"\nERROR Image files %s and %s are not same size",
name1, name2);
exit(0);
}
/******************************************
*
* Allocate the two image arrays
*
*******************************************/
get_image_size(name1, &length, &width);
get_bitsperpixel(name1, &bits_per_pixel);
image1 = allocate_image_array(length, width);
image2 = allocate_image_array(length, width);
/******************************************
*
* Create the output file and read the
* two input images.
*
*******************************************/
create_image_file(name1, name3);
read_image_array(name1, image1);
read_image_array(name2, image2);
/********************************************
*
* Add or subtract the input images and
* write the result to the output image.
*
********************************************/
if(argv[4][0] == 'a' || argv[4][0] == 'A'){
if(bits_per_pixel == 4)
max = 16;
else
max = 255;
add_image_array(image1, image2,
length, width, max);
} /* ends if add */
if(argv[4][0] == 's' || argv[4][0] == 'S')
subtract_image_array(image1, image2,
length, width);
write_image_array(name3, image2);
free_image_array(image1, length);
free_image_array(image2, length);
} /* ends main */