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 |
|
|
60 |
|
progname = argv[0]; |
61 |
|
|
62 |
|
for (i = 1; i < argc; i++) |
63 |
< |
if (argv[i][0] == '-') |
63 |
> |
if (argv[i][0] == '-' || argv[i][0] == '+') |
64 |
|
switch (argv[i][1]) { |
65 |
< |
case 'h': /* no header */ |
66 |
< |
header = 0; |
65 |
> |
case 'h': /* header */ |
66 |
> |
header = argv[i][0] == '+'; |
67 |
|
break; |
68 |
|
case 'u': /* unique values */ |
69 |
< |
uniq = 1; |
69 |
> |
uniq = argv[i][0] == '-'; |
70 |
|
break; |
71 |
|
case 'o': /* original values */ |
72 |
< |
original = 1; |
72 |
> |
original = argv[i][0] == '-'; |
73 |
|
break; |
74 |
|
case 'g': /* gamma correction */ |
75 |
< |
gamma = atof(argv[++i]); |
75 |
> |
gamcor = atof(argv[++i]); |
76 |
> |
if (argv[i][0] == '+') |
77 |
> |
gamcor = 1.0/gamcor; |
78 |
|
break; |
79 |
|
case 'r': /* reverse conversion */ |
80 |
< |
reverse = 1; |
80 |
> |
reverse = argv[i][0] == '-'; |
81 |
|
break; |
82 |
|
case 'b': /* brightness values */ |
83 |
< |
brightonly = 1; |
83 |
> |
brightonly = argv[i][0] == '-'; |
84 |
|
break; |
85 |
|
case 'd': /* data only (no indices) */ |
86 |
< |
dataonly = 1; |
86 |
> |
dataonly = argv[i][0] == '-'; |
87 |
|
switch (argv[i][2]) { |
88 |
|
case '\0': |
89 |
|
case 'a': /* ascii */ |
95 |
|
fmtid = "ascii"; |
96 |
|
break; |
97 |
|
case 'b': /* byte */ |
98 |
+ |
dataonly = 1; |
99 |
|
format = 'b'; |
100 |
|
fmtid = "byte"; |
101 |
|
break; |
102 |
|
case 'f': /* float */ |
103 |
+ |
dataonly = 1; |
104 |
|
format = 'f'; |
105 |
|
fmtid = "float"; |
106 |
|
break; |
107 |
|
case 'd': /* double */ |
108 |
+ |
dataonly = 1; |
109 |
|
format = 'd'; |
110 |
|
fmtid = "double"; |
111 |
|
break; |
114 |
|
} |
115 |
|
break; |
116 |
|
case 'x': /* x resolution */ |
117 |
< |
xres = atoi(argv[++i]); |
117 |
> |
if (argv[i][0] == '-') |
118 |
> |
picres.or |= XDECR; |
119 |
> |
picres.xr = atoi(argv[++i]); |
120 |
|
break; |
121 |
|
case 'y': /* y resolution */ |
122 |
< |
yres = atoi(argv[++i]); |
122 |
> |
if (argv[i][0] == '-') |
123 |
> |
picres.or |= YDECR; |
124 |
> |
if (picres.xr == 0) |
125 |
> |
picres.or |= YMAJOR; |
126 |
> |
picres.yr = atoi(argv[++i]); |
127 |
|
break; |
128 |
|
default: |
129 |
|
unkopt: |
157 |
|
set_io(); |
158 |
|
|
159 |
|
if (reverse) { |
148 |
– |
if (yres <= 0 || xres <= 0) { |
149 |
– |
fprintf(stderr, "%s: missing x and y resolution\n", |
150 |
– |
progname); |
151 |
– |
quit(1); |
152 |
– |
} |
160 |
|
/* get header */ |
161 |
|
if (header && checkheader(fin, fmtid, stdout) < 0) { |
162 |
|
fprintf(stderr, "%s: wrong input format\n", progname); |
163 |
|
quit(1); |
164 |
|
} |
165 |
+ |
if (picres.xr <= 0 || picres.yr <= 0) /* get resolution */ |
166 |
+ |
if (!fgetsresolu(&picres, fin)) { |
167 |
+ |
fprintf(stderr, "%s: missing resolution\n", |
168 |
+ |
progname); |
169 |
+ |
quit(1); |
170 |
+ |
} |
171 |
|
/* add to header */ |
172 |
|
printargs(i, argv, stdout); |
173 |
|
fputformat(COLRFMT, stdout); |
174 |
< |
printf("\n"); |
175 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
174 |
> |
putchar('\n'); |
175 |
> |
fputsresolu(&picres, stdout); |
176 |
|
valtopix(); |
177 |
|
} else { |
178 |
|
/* get header */ |
183 |
|
quit(1); |
184 |
|
} |
185 |
|
|
186 |
< |
if (xres <= 0 || yres <= 0) /* get picture size */ |
187 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
188 |
< |
fprintf(stderr, |
176 |
< |
"%s: missing x and y resolution\n", |
186 |
> |
if (picres.xr <= 0 || picres.yr <= 0) /* get picture size */ |
187 |
> |
if (!fgetsresolu(&picres, fin)) { |
188 |
> |
fprintf(stderr, "%s: missing resolution\n", |
189 |
|
progname); |
190 |
|
quit(1); |
191 |
|
} |
192 |
|
if (header) { |
193 |
|
printargs(i, argv, stdout); |
194 |
|
fputformat(fmtid, stdout); |
195 |
< |
printf("\n"); |
195 |
> |
putchar('\n'); |
196 |
|
} |
197 |
|
pixtoval(); |
198 |
|
} |
229 |
|
register COLOR *scanln; |
230 |
|
int dogamma; |
231 |
|
COLOR lastc; |
232 |
+ |
FLOAT hv[2]; |
233 |
|
int y; |
234 |
|
register int x; |
235 |
|
|
236 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
236 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
237 |
|
if (scanln == NULL) { |
238 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
239 |
|
quit(1); |
240 |
|
} |
241 |
< |
dogamma = gamma < .95 || gamma > 1.05; |
241 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
242 |
|
setcolor(lastc, 0.0, 0.0, 0.0); |
243 |
< |
for (y = yres-1; y >= 0; y--) { |
244 |
< |
if (freadscan(scanln, xres, fin) < 0) { |
243 |
> |
for (y = 0; y < numscans(&picres); y++) { |
244 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
245 |
|
fprintf(stderr, "%s: read error\n", progname); |
246 |
|
quit(1); |
247 |
|
} |
248 |
< |
for (x = 0; x < xres; x++) { |
248 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
249 |
|
if (uniq) |
250 |
|
if ( colval(scanln[x],RED) == |
251 |
|
colval(lastc,RED) && |
260 |
|
multcolor(scanln[x], exposure); |
261 |
|
if (dogamma) |
262 |
|
setcolor(scanln[x], |
263 |
< |
pow(colval(scanln[x],RED), 1.0/gamma), |
264 |
< |
pow(colval(scanln[x],GRN), 1.0/gamma), |
265 |
< |
pow(colval(scanln[x],BLU), 1.0/gamma)); |
266 |
< |
if (!dataonly) |
267 |
< |
printf("%7d %7d ", x, y); |
263 |
> |
pow(colval(scanln[x],RED), 1.0/gamcor), |
264 |
> |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
265 |
> |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
266 |
> |
if (!dataonly) { |
267 |
> |
pix2loc(hv, &picres, x, y); |
268 |
> |
printf("%7d %7d ", (int)(hv[0]*picres.xr), |
269 |
> |
(int)(hv[1]*picres.yr)); |
270 |
> |
} |
271 |
|
if ((*putval)(scanln[x], stdout) < 0) { |
272 |
|
fprintf(stderr, "%s: write error\n", progname); |
273 |
|
quit(1); |
285 |
|
int y; |
286 |
|
register int x; |
287 |
|
|
288 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
288 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
289 |
|
if (scanln == NULL) { |
290 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
291 |
|
quit(1); |
292 |
|
} |
293 |
< |
dogamma = gamma < .95 || gamma > 1.05; |
294 |
< |
for (y = yres-1; y >= 0; y--) { |
295 |
< |
for (x = 0; x < xres; x++) { |
293 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
294 |
> |
for (y = 0; y < numscans(&picres); y++) { |
295 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
296 |
|
if (!dataonly) |
297 |
|
fscanf(fin, "%*d %*d"); |
298 |
|
if ((*getval)(scanln[x], fin) < 0) { |
301 |
|
} |
302 |
|
if (dogamma) |
303 |
|
setcolor(scanln[x], |
304 |
< |
pow(colval(scanln[x],RED), gamma), |
305 |
< |
pow(colval(scanln[x],GRN), gamma), |
306 |
< |
pow(colval(scanln[x],BLU), gamma)); |
304 |
> |
pow(colval(scanln[x],RED), gamcor), |
305 |
> |
pow(colval(scanln[x],GRN), gamcor), |
306 |
> |
pow(colval(scanln[x],BLU), gamcor)); |
307 |
|
} |
308 |
< |
if (fwritescan(scanln, xres, stdout) < 0) { |
308 |
> |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
309 |
|
fprintf(stderr, "%s: write error\n", progname); |
310 |
|
quit(1); |
311 |
|
} |