-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdx.c
237 lines (194 loc) · 6.31 KB
/
dx.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
/*
* HISTORY:
* Quick and dirty hack -- linas November 1989
* Quick and dirty updates -- linas June 1991
* Refurbish, dust off, -- linas March 1996
*/
#include <stdio.h>
#include <math.h>
#include "opers.h"
/*-------------------------------------------------------------------*/
void edge (row_m1, row, row_p1, row_out, sizex, scale_factor)
float row_m1 []; /* row minus 1 */
float row []; /* row */
float row_p1 []; /* row plus 1 */
float row_out [];
unsigned int sizex;
float scale_factor;
{
long i;
float oops;
oops = 1.0 / scale_factor;
/* first pixel is special */
row_out[0] = 3.0*row[0] -row[1] -row_p1[0] -row_m1[0];
row_out[0] *= oops;
for (i=1; i<sizex-1; i++) {
row_out[i] = 4.0*row[i] -row[i+1] -row[i-1] -row_p1[i] -row_m1[i];
row_out[i] *= oops;
}
/* last pixel is special */
row_out[sizex-1] = 3.0*row[sizex-1] -row[sizex-2] -row_p1[sizex-1] -row_m1[sizex-1];
row_out[sizex-1] *= oops;
}
/*-------------------------------------------------------------------*/
void dredge (row_m1, row, row_p1, row_out, sizex, threshold)
float row_m1 []; /* row minus 1 */
float row []; /* row */
float row_p1 []; /* row plus 1 */
float row_out [];
unsigned int sizex;
float threshold;
{
long i;
/* first pixel is special */
if ((fabs (row[0]-row[1]) > threshold) ||
(fabs (row_p1[0]-row[0]) > threshold) ||
(fabs (row_m1[0]-row[0]) > threshold)) {
row_out [0] = 0.999;
} else {
row_out[0] = 0.0;
}
for (i=1; i<sizex-1; i++) {
if ((fabs (row[i]-row[i-1]) > threshold) ||
(fabs (row[i+1]-row[i]) > threshold) ||
(fabs (row_p1[i]-row[i]) > threshold) ||
(fabs (row_m1[i]-row[i]) > threshold)) {
row_out[i] = 0.999;
} else {
row_out[i] = 0.0;
}
}
/* last pixel is special */
if ((fabs (row[sizex-1]-row[sizex-2]) > threshold) ||
(fabs (row_p1[sizex-1]-row[sizex-1]) > threshold) ||
(fabs (row_m1[sizex-1]-row[sizex-1]) > threshold)) {
row_out[sizex-1] = 0.999;
} else {
row_out[sizex-1] = 0.0;
}
}
/*-------------------------------------------------------------------*/
void contour (row_m1, row, row_p1, row_out, sizex)
float row_m1 []; /* row minus 1 */
float row []; /* row */
float row_p1 []; /* row plus 1 */
float row_out [];
unsigned int sizex;
{
long i;
/* first pixel is special */
if ( (((int) row[0]) != ((int) row[1])) ||
(((int) row[0]) != ((int) row_p1[0])) ||
(((int) row[0]) != ((int) row_m1[0])) ) {
row_out[0] = 0.999;
} else {
row_out[0] = 0.0001;
}
for (i=1; i<sizex-1; i++) {
if ( (((int) row[i]) != ((int) row[i-1])) ||
(((int) row[i]) != ((int) row[i+1])) ||
(((int) row[i]) != ((int) row_p1[i])) ||
(((int) row[i]) != ((int) row_m1[i])) ) {
row_out[i] = 0.999;
} else {
row_out[i] = 0.0001;
}
}
/* last pixel is special */
if ( (((int) row[sizex-1]) != ((int) row[sizex-2])) ||
(((int) row[sizex-1]) != ((int) row_p1[sizex-1])) ||
(((int) row[sizex-1]) != ((int) row_m1[sizex-1])) ) {
row_out[sizex-1] = 0.999;
} else {
row_out[sizex-1] = 0.0001;
}
}
/*-------------------------------------------------------------------*/
#define SCALE 1.3
#define THRESH 0.9
#define PIX_WID 1600
#define PIX_HIG 1280
extern FILE *Fopen();
extern FILE *Fopenr();
void main (argc, argv)
int argc;
char *argv[];
{
static float data_in [PIX_WID*4]; /* my data array */
static float data_out [PIX_WID*4]; /* my data array */
float *ptr_a; /* pointer into data array */
float *ptr_b; /* pointer into data array */
float *ptr_c; /* pointer into data array */
float *tmp; /* pointer into data array */
unsigned int data_width, data_height;/* data array dimensions */
int i,j;
char str[80];
FILE *fp_in, *fp_out;
float scale_fact;
if ( argc < 3) {
printf ("usage: %s <input file> <output file> \n", argv[0]);
return;
}
/*-----------------------------------------------*/
/* open input file */
if ( (fp_in = Fopenr (argv[1], ".flo")) == NULL) {
printf (" Can't open input file \n");
return;
}
if ( NULL == fgets (str, 80, fp_in)) {
printf (" Can't read input file \n");
fclose (fp_in);
return;
}
sscanf (str, "%d %d", &data_width, &data_height);
printf (" input file has width %d height %d \n", data_width, data_height);
/*-----------------------------------------------*/
/* open output file */
if ( (fp_out = Fopen (argv[2], ".flo")) == NULL) {
printf (" Can't open output file \n");
return;
}
/* dump the size to output */
fprintf (fp_out, "%d %d\n", data_width, data_height);
/*-----------------------------------------------*/
ptr_a = data_in;
ptr_b = ptr_a + data_width;
ptr_c = ptr_b + data_width;
/* read in first two rows */
fread(ptr_a, sizeof(float), data_width, fp_in);
fread(ptr_b, sizeof(float), data_width, fp_in);
/* first row is special */
expand (ptr_a, data_width, 1, SCALE, 0.0);
expand (ptr_b, data_width, 1, SCALE, 0.0);
/*
dredge (ptr_a, ptr_b, ptr_b, data_out, data_width, THRESH);
*/
contour (ptr_a, ptr_b, ptr_b, data_out, data_width);
fwrite (data_out, sizeof(float), data_width, fp_out);
for (i=1; i<data_height-1; i++) {
printf (" working on row %d\n", i);
/* read floating point data */
fread(ptr_c, sizeof(float), data_width, fp_in);
expand (ptr_c, data_width, 1, SCALE, 0.0);
contour (ptr_a, ptr_b, ptr_c, data_out, data_width);
/*
dredge (ptr_a, ptr_b, ptr_c, data_out, data_width, THRESH);
*/
/* dump the floating point data */
fwrite (data_out, sizeof(float), data_width, fp_out);
/* do the Harlem shuffle */
tmp = ptr_a;
ptr_a = ptr_b;
ptr_b = ptr_c;
ptr_c = tmp;
}
/* last row is special */
/*
dredge (ptr_b, ptr_b, ptr_c, data_out, data_width, THRESH);
*/
contour (ptr_b, ptr_b, ptr_c, data_out, data_width);
fwrite (data_out, sizeof(float), data_width, fp_out);
fclose (fp_in);
fclose (fp_out);
}
/* --------------- END OF FILE ------------------------- */