10 |
|
* 4/23/86 |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include <stdio.h> |
13 |
> |
#include "standard.h" |
14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
+ |
#include "resolu.h" |
18 |
+ |
|
19 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
20 |
|
|
21 |
< |
int xres = 0; /* resolution of input */ |
20 |
< |
int yres = 0; |
21 |
> |
RESOLU picres; /* resolution of picture */ |
22 |
|
|
23 |
|
int uniq = 0; /* print only unique values? */ |
24 |
|
|
37 |
|
|
38 |
|
int wrongformat = 0; /* wrong input format? */ |
39 |
|
|
40 |
< |
double gamma = 1.0; /* gamma correction */ |
40 |
> |
double gamcor = 1.0; /* gamma correction */ |
41 |
|
|
42 |
|
COLOR exposure = WHTCOLOR; |
43 |
|
|
45 |
|
|
46 |
|
FILE *fin; |
47 |
|
|
47 |
– |
extern double atof(), pow(); |
48 |
– |
|
48 |
|
int (*getval)(), (*putval)(); |
49 |
|
|
50 |
|
|
58 |
|
progname = argv[0]; |
59 |
|
|
60 |
|
for (i = 1; i < argc; i++) |
61 |
< |
if (argv[i][0] == '-') |
61 |
> |
if (argv[i][0] == '-' || argv[i][0] == '+') |
62 |
|
switch (argv[i][1]) { |
63 |
< |
case 'h': /* no header */ |
64 |
< |
header = 0; |
63 |
> |
case 'h': /* header */ |
64 |
> |
header = argv[i][0] == '+'; |
65 |
|
break; |
66 |
|
case 'u': /* unique values */ |
67 |
< |
uniq = 1; |
67 |
> |
uniq = argv[i][0] == '-'; |
68 |
|
break; |
69 |
|
case 'o': /* original values */ |
70 |
< |
original = 1; |
70 |
> |
original = argv[i][0] == '-'; |
71 |
|
break; |
72 |
|
case 'g': /* gamma correction */ |
73 |
< |
gamma = atof(argv[++i]); |
73 |
> |
gamcor = atof(argv[++i]); |
74 |
> |
if (argv[i][0] == '+') |
75 |
> |
gamcor = 1.0/gamcor; |
76 |
|
break; |
77 |
|
case 'r': /* reverse conversion */ |
78 |
< |
reverse = 1; |
78 |
> |
reverse = argv[i][0] == '-'; |
79 |
|
break; |
80 |
|
case 'b': /* brightness values */ |
81 |
< |
brightonly = 1; |
81 |
> |
brightonly = argv[i][0] == '-'; |
82 |
|
break; |
83 |
|
case 'd': /* data only (no indices) */ |
84 |
< |
dataonly = 1; |
84 |
> |
dataonly = argv[i][0] == '-'; |
85 |
|
switch (argv[i][2]) { |
86 |
|
case '\0': |
87 |
|
case 'a': /* ascii */ |
93 |
|
fmtid = "ascii"; |
94 |
|
break; |
95 |
|
case 'b': /* byte */ |
96 |
+ |
dataonly = 1; |
97 |
|
format = 'b'; |
98 |
|
fmtid = "byte"; |
99 |
|
break; |
100 |
|
case 'f': /* float */ |
101 |
+ |
dataonly = 1; |
102 |
|
format = 'f'; |
103 |
|
fmtid = "float"; |
104 |
|
break; |
105 |
|
case 'd': /* double */ |
106 |
+ |
dataonly = 1; |
107 |
|
format = 'd'; |
108 |
|
fmtid = "double"; |
109 |
|
break; |
112 |
|
} |
113 |
|
break; |
114 |
|
case 'x': /* x resolution */ |
115 |
< |
xres = atoi(argv[++i]); |
115 |
> |
if (argv[i][0] == '-') |
116 |
> |
picres.or |= XDECR; |
117 |
> |
picres.xr = atoi(argv[++i]); |
118 |
|
break; |
119 |
|
case 'y': /* y resolution */ |
120 |
< |
yres = atoi(argv[++i]); |
120 |
> |
if (argv[i][0] == '-') |
121 |
> |
picres.or |= YDECR; |
122 |
> |
if (picres.xr == 0) |
123 |
> |
picres.or |= YMAJOR; |
124 |
> |
picres.yr = atoi(argv[++i]); |
125 |
|
break; |
126 |
|
default: |
127 |
|
unkopt: |
155 |
|
set_io(); |
156 |
|
|
157 |
|
if (reverse) { |
148 |
– |
if (yres <= 0 || xres <= 0) { |
149 |
– |
fprintf(stderr, "%s: missing x and y resolution\n", |
150 |
– |
progname); |
151 |
– |
quit(1); |
152 |
– |
} |
158 |
|
/* get header */ |
159 |
|
if (header && checkheader(fin, fmtid, stdout) < 0) { |
160 |
|
fprintf(stderr, "%s: wrong input format\n", progname); |
161 |
|
quit(1); |
162 |
|
} |
163 |
+ |
if (picres.xr <= 0 || picres.yr <= 0) /* get resolution */ |
164 |
+ |
if (!fgetsresolu(&picres, fin)) { |
165 |
+ |
fprintf(stderr, "%s: missing resolution\n", |
166 |
+ |
progname); |
167 |
+ |
quit(1); |
168 |
+ |
} |
169 |
|
/* add to header */ |
170 |
|
printargs(i, argv, stdout); |
171 |
|
fputformat(COLRFMT, stdout); |
172 |
< |
printf("\n"); |
173 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
172 |
> |
putchar('\n'); |
173 |
> |
fputsresolu(&picres, stdout); |
174 |
|
valtopix(); |
175 |
|
} else { |
176 |
|
/* get header */ |
181 |
|
quit(1); |
182 |
|
} |
183 |
|
|
184 |
< |
if (xres <= 0 || yres <= 0) /* get picture size */ |
185 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
186 |
< |
fprintf(stderr, |
176 |
< |
"%s: missing x and y resolution\n", |
184 |
> |
if (picres.xr <= 0 || picres.yr <= 0) /* get picture size */ |
185 |
> |
if (!fgetsresolu(&picres, fin)) { |
186 |
> |
fprintf(stderr, "%s: missing resolution\n", |
187 |
|
progname); |
188 |
|
quit(1); |
189 |
|
} |
190 |
|
if (header) { |
191 |
|
printargs(i, argv, stdout); |
192 |
|
fputformat(fmtid, stdout); |
193 |
< |
printf("\n"); |
193 |
> |
putchar('\n'); |
194 |
|
} |
195 |
|
pixtoval(); |
196 |
|
} |
227 |
|
register COLOR *scanln; |
228 |
|
int dogamma; |
229 |
|
COLOR lastc; |
230 |
+ |
FLOAT hv[2]; |
231 |
|
int y; |
232 |
|
register int x; |
233 |
|
|
234 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
234 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
235 |
|
if (scanln == NULL) { |
236 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
237 |
|
quit(1); |
238 |
|
} |
239 |
< |
dogamma = gamma < .95 || gamma > 1.05; |
239 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
240 |
|
setcolor(lastc, 0.0, 0.0, 0.0); |
241 |
< |
for (y = yres-1; y >= 0; y--) { |
242 |
< |
if (freadscan(scanln, xres, fin) < 0) { |
241 |
> |
for (y = 0; y < numscans(&picres); y++) { |
242 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
243 |
|
fprintf(stderr, "%s: read error\n", progname); |
244 |
|
quit(1); |
245 |
|
} |
246 |
< |
for (x = 0; x < xres; x++) { |
246 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
247 |
|
if (uniq) |
248 |
|
if ( colval(scanln[x],RED) == |
249 |
|
colval(lastc,RED) && |
258 |
|
multcolor(scanln[x], exposure); |
259 |
|
if (dogamma) |
260 |
|
setcolor(scanln[x], |
261 |
< |
pow(colval(scanln[x],RED), 1.0/gamma), |
262 |
< |
pow(colval(scanln[x],GRN), 1.0/gamma), |
263 |
< |
pow(colval(scanln[x],BLU), 1.0/gamma)); |
264 |
< |
if (!dataonly) |
265 |
< |
printf("%7d %7d ", x, y); |
261 |
> |
pow(colval(scanln[x],RED), 1.0/gamcor), |
262 |
> |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
263 |
> |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
264 |
> |
if (!dataonly) { |
265 |
> |
pix2loc(hv, &picres, x, y); |
266 |
> |
printf("%7d %7d ", (int)(hv[0]*picres.xr), |
267 |
> |
(int)(hv[1]*picres.yr)); |
268 |
> |
} |
269 |
|
if ((*putval)(scanln[x], stdout) < 0) { |
270 |
|
fprintf(stderr, "%s: write error\n", progname); |
271 |
|
quit(1); |
283 |
|
int y; |
284 |
|
register int x; |
285 |
|
|
286 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
286 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
287 |
|
if (scanln == NULL) { |
288 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
289 |
|
quit(1); |
290 |
|
} |
291 |
< |
dogamma = gamma < .95 || gamma > 1.05; |
292 |
< |
for (y = yres-1; y >= 0; y--) { |
293 |
< |
for (x = 0; x < xres; x++) { |
291 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
292 |
> |
for (y = 0; y < numscans(&picres); y++) { |
293 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
294 |
|
if (!dataonly) |
295 |
|
fscanf(fin, "%*d %*d"); |
296 |
|
if ((*getval)(scanln[x], fin) < 0) { |
299 |
|
} |
300 |
|
if (dogamma) |
301 |
|
setcolor(scanln[x], |
302 |
< |
pow(colval(scanln[x],RED), gamma), |
303 |
< |
pow(colval(scanln[x],GRN), gamma), |
304 |
< |
pow(colval(scanln[x],BLU), gamma)); |
302 |
> |
pow(colval(scanln[x],RED), gamcor), |
303 |
> |
pow(colval(scanln[x],GRN), gamcor), |
304 |
> |
pow(colval(scanln[x],BLU), gamcor)); |
305 |
|
} |
306 |
< |
if (fwritescan(scanln, xres, stdout) < 0) { |
306 |
> |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
307 |
|
fprintf(stderr, "%s: write error\n", progname); |
308 |
|
quit(1); |
309 |
|
} |