-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathboole.c
executable file
·271 lines (225 loc) · 6.84 KB
/
boole.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
/***********************************************
*
* file boole.c
*
* Functions: This file contains
* and_image
* or_image
* xor_image
* nand_image
* nor_image
* not_image
*
* Purpose:
* These functions implement the basic
* Boolean algebra functions AND, OR,
* XOR, NAND, NOR, and NOT.
*
* External Calls:
* none
*
* Modifications:
* 3 March 1993 - created
* 22 August 1998 - modified to work on
* entire images at once.
*
***********************************************/
#include "cips.h"
/************************************************
*
* and_image(...
*
* This function performs the Boolean AND
* operation. The output image = in1 AND in2.
* This works for 0 non-zero images. If both
* in1 and in2 are non-zero, the output = in1.
*
*************************************************/
int and_image(the_image, out_image,
rows, cols)
short **the_image,
**out_image;
long cols, rows;
{
int i, j;
for(i=0; i<rows; i++){
if( (i%10) == 0) printf(" %d", i);
for(j=0; j<cols; j++){
if( the_image[i][j] != 0 &&
out_image[i][j] != 0)
out_image[i][j] = the_image[i][j];
else
out_image[i][j] = 0;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends and_image */
/************************************************
*
* or_image(...
*
* This function performs the Boolean OR
* operation. The output image = in1 OR in2.
* This works for 0 non-zero images. If both
* in1 and in2 are non-zero, the output = in1.
* If in1 is non-zero, the output = in1.
* If in1 is zero and in2 is non-zero, the
* output = in2.
*
*************************************************/
int or_image(the_image, out_image,
rows, cols)
short **the_image,
**out_image;
long cols, rows;
{
int i, j;
for(i=0; i<rows; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<cols; j++){
if( the_image[i][j] != 0 ||
out_image[i][j] != 0){
if(the_image[i][j] != 0)
out_image[i][j] = the_image[i][j];
else
out_image[i][j] = out_image[i][j];
}
else
out_image[i][j] = 0;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends or_image */
/************************************************
*
* xor_image(...
*
* This function performs the Boolean XOR
* operation. The output image = in1 XOR in2.
* This works for 0 non-zero images. If
* in1 is non-zero and in2 is 0, output = in1. If
* in2 is non-zero and in1 is 0, output = in2.
* If both in1 and in2 are non-zero, output = 0.
* If both in1 and in2 are zero, output = 0.
*
*************************************************/
int xor_image(the_image, out_image,
rows, cols)
short **the_image,
**out_image;
long cols, rows;
{
int i, j;
short answer;
for(i=0; i<rows; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<cols; j++){
if( (the_image[i][j] != 0 &&
out_image[i][j] == 0))
answer = the_image[i][j];
if( (the_image[i][j] == 0 &&
out_image[i][j] != 0))
answer = out_image[i][j];
if( (the_image[i][j] == 0 &&
out_image[i][j] == 0))
answer = 0;
if( (the_image[i][j] != 0 &&
out_image[i][j] != 0))
answer = 0;
out_image[i][j] = answer;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends xor_image */
/***********************************************
*
* nand_image(...
*
* This function performs the Boolean NAND
* operation. The output image = in1 NAND in2.
* This works for 0 non-zero images. If both
* in1 and in2 are non-zero, the output = 0.
* Otherwise, the output = value.
*
************************************************/
int nand_image(the_image, out_image,
value, rows, cols)
short **the_image,
**out_image, value;
long cols, rows;
{
int i, j;
for(i=0; i<rows; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<cols; j++){
if( the_image[i][j] != 0 &&
out_image[i][j] != 0)
out_image[i][j] = 0;
else
out_image[i][j] = value;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends nand_image */
/***********************************************
*
* nor_image(...
*
* This function performs the Boolean NOR
* operation. The output image = in1 NOR in2.
* This works for 0 non-zero images. If niether
* in1 nor in2 are non-zero, the output = value.
* That is, if both in1 and in2 are zero, the
* output = value.
*
************************************************/
int nor_image(the_image, out_image,
value, rows, cols)
short **the_image,
**out_image, value;
long cols, rows;
{
int i, j;
for(i=0; i<rows; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<cols; j++){
if( the_image[i][j] == 0 &&
out_image[i][j] == 0)
out_image[i][j] = value;
else
out_image[i][j] = 0;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends nor_image */
/***********************************************
*
* not_image(...
*
* This function will complement the values
* of the input image and put them into the
* output image. It will complement using a
* 0-value scheme where value is one of the
* input parameters.
*
************************************************/
int not_image(the_image, out_image,
value, rows, cols)
short **the_image,
**out_image,
value;
long cols, rows;
{
int i, j;
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
out_image[i][j] = value;
for(i=0; i<rows; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<cols; j++){
if(the_image[i][j] == value)
out_image[i][j] = 0;
} /* ends loop over j */
} /* ends loop over i */
return(1);
} /* ends not_image */