forked from tanasaro10/CIPr
/
mainover.c
162 lines (140 loc) · 4.51 KB
/
mainover.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
/*********************************************
*
* file mainover.c
*
* Functions: This file contains
* main
*
* Purpose:
* This file contains the main calling
* routine that calls the overlay functions.
*
* External Calls:
* imageio.c - create_image_file
* read_image_array
* write_image_array
* get_image_size
* allocate_image_array
* free_image_array
* overlay.c - non_zero_overlay
* zero_overlay
* greater_overlay
* less_overlay
* average_overlay
*
* Modifications:
* 6 March 1993 - created
* 22 August 1998 - modified to work on
* entire images at once.
* 19 September 1998 - modified to work with
* all I O routines in imageio.c.
*
Modified date: 27/07/2015
Author: Pardau Stefan
Scoala de Cara - Thales -2015
*
********************************************/
#include "mainover.h"
int main(int32_t argc, char_t *argv[])
{
errFlag = eReturnOK;
char_t name1[80], name2[80], name3[80], type[80];
int32_t count, i, j;
uint32_t length, width;
/*********************************************
*
* Interpret the command line parameters.
*
**********************************************/
if(argc < 5)
{
printf(
"\n\nNot enough parameters:"
"\n"
"\n usage: mainover in-file1 in-file2 out-file "
"type"
"\n"
"\n recall type: nonzero zero greater less"
" average"
"\n the input images must be the same size"
"\n"
"\n");
errFlag = eNotSuffArg;
}
if(errFlag == eReturnOK)
{
strcpy(name1, argv[ARGV_ARGUMENT1]);
strcpy(name2, argv[ARGV_ARGUMENT2]);
strcpy(name3, argv[ARGV_ARGUMENT3]);
strcpy(type, argv[ARGV_ARGUMENT4]);
if(does_not_exist(name1))
{
printf("\nERROR input file %s does not exist", name1);
errFlag = eNotInputFile1;
}
if(errFlag == eReturnOK)
{
if(does_not_exist(name2))
{
printf("\nERROR input file %s does not exist", name2);
errFlag = eNotInputFile2;
}
/*********************************************
*
* Read the input image headers.
* Ensure the input image are the same size.
* Allocate the image arrays and read
* the image data.
*
**********************************************/
if(errFlag == eReturnOK)
{
if(are_not_same_size(name1, name2))
{
printf("\n Images %s and %s are not the same size", name1, name2);
errFlag = eNotSameSize;
} /* ends if sizes not the same */
if(errFlag == eReturnOK)
{
get_image_size(name1, &length, &width);
the_image = allocate_image_array(length, width);
out_image = allocate_image_array(length, width);
create_image_file(name1, name3);
read_image_array(name1, the_image);
read_image_array(name2, out_image);
/*********************************************
*
* Apply the desired overlay function.
*
**********************************************/
/* non-zero */
if(strncmp("non", type, 3) == 0)
{
non_zero_overlay(the_image, out_image, length, width);
} /* ends non_zero operation */
/* zero */
if(strcmp("zero", type) == 0)
{
zero_overlay(the_image, out_image, length, width);
} /* ends zero operation */
/* greater */
if(strncmp("gre", type, 3) == 0)
{
greater_overlay(the_image, out_image, length, width);
} /* ends greater operation */
/* less */
if(strncmp("les", type, 3) == 0)
{
less_overlay(the_image, out_image, length, width);
} /* ends less operation */
/* average */
if(strncmp("ave", type, 3) == 0)
{
average_overlay(the_image, out_image, length, width);
} /* ends average operation */
write_image_array(name3, out_image);
free_image_array(out_image, length);
free_image_array(the_image, length);
}}}}
return errFlag;
} /* ends main */