1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* pvalue.c - program to print pixel values. |
6 |
|
* |
7 |
|
* 4/23/86 |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include <stdio.h> |
10 |
> |
#include <time.h> |
11 |
|
|
12 |
+ |
#include "standard.h" |
13 |
+ |
#include "platform.h" |
14 |
|
#include "color.h" |
15 |
+ |
#include "resolu.h" |
16 |
|
|
17 |
< |
#define min(a,b) ((a)<(b)?(a):(b)) |
17 |
> |
#define min(a,b) ((a)<(b)?(a):(b)) |
18 |
|
|
19 |
< |
int xres = 0; /* resolution of input */ |
20 |
< |
int yres = 0; |
19 |
> |
/* what to put out (also RED, GRN, BLU) */ |
20 |
> |
#define ALL 3 |
21 |
> |
#define BRIGHT 4 |
22 |
|
|
23 |
< |
int uniq = 0; /* unique values? */ |
23 |
> |
RESOLU picres; /* resolution of picture */ |
24 |
|
|
25 |
< |
int original = 0; /* original values? */ |
25 |
> |
int uniq = 0; /* print only unique values? */ |
26 |
|
|
27 |
+ |
int doexposure = 0; /* exposure change? (>100 to print) */ |
28 |
+ |
|
29 |
|
int dataonly = 0; /* data only format? */ |
30 |
|
|
31 |
< |
int brightonly = 0; /* only brightness values? */ |
31 |
> |
int putprim = ALL; /* what to put out */ |
32 |
|
|
33 |
|
int reverse = 0; /* reverse conversion? */ |
34 |
|
|
35 |
|
int format = 'a'; /* input/output format */ |
36 |
+ |
char *fmtid = "ascii"; /* format identifier for header */ |
37 |
|
|
38 |
< |
int header = 1; /* do header */ |
38 |
> |
int header = 1; /* do header? */ |
39 |
|
|
40 |
+ |
long skipbytes = 0; /* skip bytes in input? */ |
41 |
+ |
|
42 |
+ |
int swapbytes = 0; /* swap bytes in 16-bit words? */ |
43 |
+ |
|
44 |
+ |
int interleave = 1; /* file is interleaved? */ |
45 |
+ |
|
46 |
+ |
int resolution = 1; /* put/get resolution string? */ |
47 |
+ |
|
48 |
+ |
int original = 0; /* convert to original values? */ |
49 |
+ |
|
50 |
+ |
int wrongformat = 0; /* wrong input format? */ |
51 |
+ |
|
52 |
+ |
double gamcor = 1.0; /* gamma correction */ |
53 |
+ |
|
54 |
+ |
int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ |
55 |
+ |
int rord[4]; /* reverse ordering */ |
56 |
+ |
|
57 |
|
COLOR exposure = WHTCOLOR; |
58 |
|
|
59 |
|
char *progname; |
60 |
|
|
61 |
|
FILE *fin; |
62 |
+ |
FILE *fin2 = NULL, *fin3 = NULL; /* for other color channels */ |
63 |
|
|
64 |
|
int (*getval)(), (*putval)(); |
65 |
|
|
66 |
+ |
double |
67 |
+ |
rgb_bright(clr) |
68 |
+ |
COLOR clr; |
69 |
+ |
{ |
70 |
+ |
return(bright(clr)); |
71 |
+ |
} |
72 |
|
|
73 |
+ |
double |
74 |
+ |
xyz_bright(clr) |
75 |
+ |
COLOR clr; |
76 |
+ |
{ |
77 |
+ |
return(clr[CIEY]); |
78 |
+ |
} |
79 |
+ |
|
80 |
+ |
double (*mybright)() = &rgb_bright; |
81 |
+ |
|
82 |
+ |
|
83 |
|
main(argc, argv) |
84 |
|
int argc; |
85 |
|
char **argv; |
86 |
|
{ |
49 |
– |
extern double atof(); |
87 |
|
extern int checkhead(); |
88 |
+ |
extern long atol(); |
89 |
+ |
double d, expval = 1.0; |
90 |
|
int i; |
91 |
|
|
92 |
|
progname = argv[0]; |
93 |
|
|
94 |
|
for (i = 1; i < argc; i++) |
95 |
< |
if (argv[i][0] == '-') |
95 |
> |
if (argv[i][0] == '-' || argv[i][0] == '+') |
96 |
|
switch (argv[i][1]) { |
97 |
< |
case 'h': /* no header */ |
98 |
< |
header = 0; |
97 |
> |
case 'h': /* header */ |
98 |
> |
header = argv[i][0] == '+'; |
99 |
|
break; |
100 |
+ |
case 'H': /* resolution string */ |
101 |
+ |
resolution = argv[i][0] == '+'; |
102 |
+ |
break; |
103 |
+ |
case 's': /* skip bytes in header */ |
104 |
+ |
skipbytes = atol(argv[++i]); |
105 |
+ |
break; |
106 |
|
case 'u': /* unique values */ |
107 |
< |
uniq = 1; |
107 |
> |
uniq = argv[i][0] == '-'; |
108 |
|
break; |
109 |
|
case 'o': /* original values */ |
110 |
< |
original = 1; |
110 |
> |
original = argv[i][0] == '-'; |
111 |
|
break; |
112 |
+ |
case 'g': /* gamma correction */ |
113 |
+ |
gamcor = atof(argv[i+1]); |
114 |
+ |
if (argv[i][0] == '+') |
115 |
+ |
gamcor = 1.0/gamcor; |
116 |
+ |
i++; |
117 |
+ |
break; |
118 |
+ |
case 'e': /* exposure correction */ |
119 |
+ |
d = atof(argv[i+1]); |
120 |
+ |
if (argv[i+1][0] == '-' || argv[i+1][0] == '+') |
121 |
+ |
d = pow(2.0, d); |
122 |
+ |
if (argv[i][0] == '-') |
123 |
+ |
expval *= d; |
124 |
+ |
scalecolor(exposure, d); |
125 |
+ |
doexposure++; |
126 |
+ |
i++; |
127 |
+ |
break; |
128 |
+ |
case 'R': /* reverse byte sequence */ |
129 |
+ |
if (argv[i][0] == '-') { |
130 |
+ |
ord[0]=BLU; ord[1]=GRN; ord[2]=RED; |
131 |
+ |
} else { |
132 |
+ |
ord[0]=RED; ord[1]=GRN; ord[2]=BLU; |
133 |
+ |
} |
134 |
+ |
break; |
135 |
|
case 'r': /* reverse conversion */ |
136 |
< |
reverse = 1; |
136 |
> |
reverse = argv[i][0] == '-'; |
137 |
|
break; |
138 |
+ |
case 'n': /* non-interleaved RGB */ |
139 |
+ |
interleave = argv[i][0] == '+'; |
140 |
+ |
break; |
141 |
|
case 'b': /* brightness values */ |
142 |
< |
brightonly = 1; |
142 |
> |
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
143 |
|
break; |
144 |
+ |
case 'p': /* put primary */ |
145 |
+ |
switch (argv[i][2]) { |
146 |
+ |
case 'r': case 'R': putprim = RED; break; |
147 |
+ |
case 'g': case 'G': putprim = GRN; break; |
148 |
+ |
case 'b': case 'B': putprim = BLU; break; |
149 |
+ |
default: goto unkopt; |
150 |
+ |
} |
151 |
+ |
break; |
152 |
|
case 'd': /* data only (no indices) */ |
153 |
< |
dataonly = 1; |
153 |
> |
dataonly = argv[i][0] == '-'; |
154 |
|
switch (argv[i][2]) { |
155 |
|
case '\0': |
156 |
|
case 'a': /* ascii */ |
157 |
|
format = 'a'; |
158 |
+ |
fmtid = "ascii"; |
159 |
|
break; |
160 |
|
case 'i': /* integer */ |
161 |
+ |
format = 'i'; |
162 |
+ |
fmtid = "ascii"; |
163 |
+ |
break; |
164 |
|
case 'b': /* byte */ |
165 |
+ |
dataonly = 1; |
166 |
+ |
format = 'b'; |
167 |
+ |
fmtid = "byte"; |
168 |
+ |
break; |
169 |
+ |
case 'W': /* 16-bit swapped */ |
170 |
+ |
swapbytes = 1; |
171 |
+ |
case 'w': /* 16-bit */ |
172 |
+ |
dataonly = 1; |
173 |
+ |
format = 'w'; |
174 |
+ |
fmtid = "16-bit"; |
175 |
+ |
break; |
176 |
|
case 'f': /* float */ |
177 |
+ |
dataonly = 1; |
178 |
+ |
format = 'f'; |
179 |
+ |
fmtid = "float"; |
180 |
+ |
break; |
181 |
|
case 'd': /* double */ |
182 |
< |
format = argv[i][2]; |
182 |
> |
dataonly = 1; |
183 |
> |
format = 'd'; |
184 |
> |
fmtid = "double"; |
185 |
|
break; |
186 |
|
default: |
187 |
|
goto unkopt; |
188 |
|
} |
189 |
|
break; |
190 |
|
case 'x': /* x resolution */ |
191 |
< |
xres = atoi(argv[++i]); |
191 |
> |
case 'X': /* x resolution */ |
192 |
> |
resolution = 0; |
193 |
> |
if (argv[i][0] == '-') |
194 |
> |
picres.rt |= XDECR; |
195 |
> |
picres.xr = atoi(argv[++i]); |
196 |
|
break; |
197 |
|
case 'y': /* y resolution */ |
198 |
< |
yres = atoi(argv[++i]); |
198 |
> |
case 'Y': /* y resolution */ |
199 |
> |
resolution = 0; |
200 |
> |
if (argv[i][0] == '-') |
201 |
> |
picres.rt |= YDECR; |
202 |
> |
if (picres.xr == 0) |
203 |
> |
picres.rt |= YMAJOR; |
204 |
> |
picres.yr = atoi(argv[++i]); |
205 |
|
break; |
206 |
|
default: |
207 |
|
unkopt: |
212 |
|
} |
213 |
|
else |
214 |
|
break; |
215 |
< |
|
215 |
> |
/* recognize special formats */ |
216 |
> |
if (dataonly && format == 'b') |
217 |
> |
if (putprim == ALL) |
218 |
> |
fmtid = "24-bit_rgb"; |
219 |
> |
else |
220 |
> |
fmtid = "8-bit_grey"; |
221 |
> |
if (dataonly && format == 'w') |
222 |
> |
if (putprim == ALL) |
223 |
> |
fmtid = "48-bit_rgb"; |
224 |
> |
else |
225 |
> |
fmtid = "16-bit_grey"; |
226 |
> |
/* assign reverse ordering */ |
227 |
> |
rord[ord[0]] = 0; |
228 |
> |
rord[ord[1]] = 1; |
229 |
> |
rord[ord[2]] = 2; |
230 |
> |
/* get input */ |
231 |
|
if (i == argc) { |
232 |
|
fin = stdin; |
233 |
< |
} else if (i == argc-1) { |
233 |
> |
} else if (i < argc) { |
234 |
|
if ((fin = fopen(argv[i], "r")) == NULL) { |
235 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
236 |
|
progname, argv[i]); |
237 |
|
quit(1); |
238 |
|
} |
239 |
< |
} else { |
239 |
> |
if (reverse && putprim != BRIGHT && i == argc-3) { |
240 |
> |
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
241 |
> |
fprintf(stderr, "%s: can't open file \"%s\"\n", |
242 |
> |
progname, argv[i+1]); |
243 |
> |
quit(1); |
244 |
> |
} |
245 |
> |
if ((fin3 = fopen(argv[i+2], "r")) == NULL) { |
246 |
> |
fprintf(stderr, "%s: can't open file \"%s\"\n", |
247 |
> |
progname, argv[i+2]); |
248 |
> |
quit(1); |
249 |
> |
} |
250 |
> |
interleave = -1; |
251 |
> |
} else if (i != argc-1) |
252 |
> |
fin = NULL; |
253 |
> |
if (reverse && putprim != BRIGHT && !interleave) { |
254 |
> |
fin2 = fopen(argv[i], "r"); |
255 |
> |
fin3 = fopen(argv[i], "r"); |
256 |
> |
} |
257 |
> |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
258 |
> |
(fseek(fin2, skipbytes, 0) || |
259 |
> |
fseek(fin3, skipbytes, 0))))) { |
260 |
> |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
261 |
> |
progname, skipbytes); |
262 |
> |
quit(1); |
263 |
> |
} |
264 |
> |
} |
265 |
> |
if (fin == NULL) { |
266 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
267 |
|
quit(1); |
268 |
|
} |
269 |
|
|
119 |
– |
set_io(); |
120 |
– |
|
270 |
|
if (reverse) { |
271 |
< |
if (header) /* get header */ |
272 |
< |
copyheader(fin, stdout); |
273 |
< |
/* add to header */ |
274 |
< |
printargs(i, argv, stdout); |
275 |
< |
printf("\n"); |
276 |
< |
if (yres <= 0 || xres <= 0) { |
277 |
< |
fprintf(stderr, "%s: missing x and y resolution\n", |
278 |
< |
progname); |
271 |
> |
#ifdef _WIN32 |
272 |
> |
SET_FILE_BINARY(stdout); |
273 |
> |
if (format != 'a' && format != 'i') |
274 |
> |
SET_FILE_BINARY(fin); |
275 |
> |
#endif |
276 |
> |
/* get header */ |
277 |
> |
if (header) { |
278 |
> |
if (checkheader(fin, fmtid, stdout) < 0) { |
279 |
> |
fprintf(stderr, "%s: wrong input format\n", |
280 |
> |
progname); |
281 |
> |
quit(1); |
282 |
> |
} |
283 |
> |
if (fin2 != NULL) { |
284 |
> |
getheader(fin2, NULL, NULL); |
285 |
> |
getheader(fin3, NULL, NULL); |
286 |
> |
} |
287 |
> |
} else |
288 |
> |
newheader("RADIANCE", stdout); |
289 |
> |
/* get resolution */ |
290 |
> |
if ((resolution && !fgetsresolu(&picres, fin)) || |
291 |
> |
picres.xr <= 0 || picres.yr <= 0) { |
292 |
> |
fprintf(stderr, "%s: missing resolution\n", progname); |
293 |
|
quit(1); |
294 |
|
} |
295 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
296 |
< |
valtopix(); |
297 |
< |
} else { |
298 |
< |
/* get header */ |
299 |
< |
getheader(fin, checkhead); |
300 |
< |
|
301 |
< |
if (xres <= 0 || yres <= 0) /* get picture size */ |
302 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
303 |
< |
fprintf(stderr, |
304 |
< |
"%s: missing x and y resolution\n", |
295 |
> |
if (resolution && fin2 != NULL) { |
296 |
> |
RESOLU pres2; |
297 |
> |
if (!fgetsresolu(&pres2, fin2) || |
298 |
> |
pres2.rt != picres.rt || |
299 |
> |
pres2.xr != picres.xr || |
300 |
> |
pres2.yr != picres.yr || |
301 |
> |
!fgetsresolu(&pres2, fin3) || |
302 |
> |
pres2.rt != picres.rt || |
303 |
> |
pres2.xr != picres.xr || |
304 |
> |
pres2.yr != picres.yr) { |
305 |
> |
fprintf(stderr, "%s: resolution mismatch\n", |
306 |
|
progname); |
307 |
|
quit(1); |
308 |
|
} |
309 |
+ |
} |
310 |
+ |
/* add to header */ |
311 |
+ |
printargs(i, argv, stdout); |
312 |
+ |
if (expval < .99 || expval > 1.01) |
313 |
+ |
fputexpos(expval, stdout); |
314 |
+ |
fputformat(COLRFMT, stdout); |
315 |
+ |
putchar('\n'); |
316 |
+ |
fputsresolu(&picres, stdout); /* always put resolution */ |
317 |
+ |
valtopix(); |
318 |
+ |
} else { |
319 |
+ |
#ifdef _WIN32 |
320 |
+ |
SET_FILE_BINARY(fin); |
321 |
+ |
if (format != 'a' && format != 'i') |
322 |
+ |
SET_FILE_BINARY(stdout); |
323 |
+ |
#endif |
324 |
+ |
/* get header */ |
325 |
+ |
getheader(fin, checkhead, NULL); |
326 |
+ |
if (wrongformat) { |
327 |
+ |
fprintf(stderr, |
328 |
+ |
"%s: input not a Radiance RGBE picture\n", |
329 |
+ |
progname); |
330 |
+ |
quit(1); |
331 |
+ |
} |
332 |
+ |
if (!fgetsresolu(&picres, fin)) { |
333 |
+ |
fprintf(stderr, "%s: missing resolution\n", progname); |
334 |
+ |
quit(1); |
335 |
+ |
} |
336 |
|
if (header) { |
337 |
|
printargs(i, argv, stdout); |
338 |
< |
printf("\n"); |
338 |
> |
if (expval < .99 || expval > 1.01) |
339 |
> |
fputexpos(expval, stdout); |
340 |
> |
fputformat(fmtid, stdout); |
341 |
> |
putchar('\n'); |
342 |
|
} |
343 |
+ |
if (resolution) /* put resolution */ |
344 |
+ |
fputsresolu(&picres, stdout); |
345 |
|
pixtoval(); |
346 |
|
} |
347 |
|
|
349 |
|
} |
350 |
|
|
351 |
|
|
352 |
+ |
int |
353 |
|
checkhead(line) /* deal with line from header */ |
354 |
|
char *line; |
355 |
|
{ |
356 |
+ |
char fmt[32]; |
357 |
|
double d; |
358 |
|
COLOR ctmp; |
359 |
|
|
360 |
< |
if (header) |
361 |
< |
fputs(line, stdout); |
362 |
< |
if (isexpos(line)) { |
360 |
> |
if (formatval(fmt, line)) { |
361 |
> |
if (!strcmp(fmt, CIEFMT)) { |
362 |
> |
mybright = &xyz_bright; |
363 |
> |
if (original) { |
364 |
> |
scalecolor(exposure, 1./WHTEFFICACY); |
365 |
> |
doexposure++; |
366 |
> |
} |
367 |
> |
} else if (!strcmp(fmt, COLRFMT)) |
368 |
> |
mybright = &rgb_bright; |
369 |
> |
else |
370 |
> |
wrongformat++; |
371 |
> |
} else if (original && isexpos(line)) { |
372 |
|
d = 1.0/exposval(line); |
373 |
|
scalecolor(exposure, d); |
374 |
< |
} else if (iscolcor(line)) { |
374 |
> |
doexposure++; |
375 |
> |
} else if (original && iscolcor(line)) { |
376 |
|
colcorval(ctmp, line); |
377 |
< |
colval(exposure,RED) /= colval(ctmp,RED); |
378 |
< |
colval(exposure,GRN) /= colval(ctmp,GRN); |
379 |
< |
colval(exposure,BLU) /= colval(ctmp,BLU); |
380 |
< |
} |
377 |
> |
setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), |
378 |
> |
colval(exposure,GRN)/colval(ctmp,GRN), |
379 |
> |
colval(exposure,BLU)/colval(ctmp,BLU)); |
380 |
> |
doexposure++; |
381 |
> |
} else if (header) |
382 |
> |
fputs(line, stdout); |
383 |
> |
return(0); |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
|
pixtoval() /* convert picture to values */ |
388 |
|
{ |
389 |
< |
COLOR *scanln; |
389 |
> |
register COLOR *scanln; |
390 |
> |
int dogamma; |
391 |
|
COLOR lastc; |
392 |
+ |
RREAL hv[2]; |
393 |
+ |
int startprim, endprim; |
394 |
+ |
long startpos; |
395 |
|
int y; |
396 |
|
register int x; |
397 |
|
|
398 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
398 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
399 |
|
if (scanln == NULL) { |
400 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
401 |
|
quit(1); |
402 |
|
} |
403 |
< |
setcolor(lastc, 0.0, 0.0, 0.0); |
404 |
< |
for (y = yres-1; y >= 0; y--) { |
405 |
< |
if (freadscan(scanln, xres, fin) < 0) { |
406 |
< |
fprintf(stderr, "%s: read error\n", progname); |
403 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
404 |
> |
if (putprim == ALL && !interleave) { |
405 |
> |
startprim = RED; endprim = BLU; |
406 |
> |
startpos = ftell(fin); |
407 |
> |
} else { |
408 |
> |
startprim = putprim; endprim = putprim; |
409 |
> |
} |
410 |
> |
for (putprim = startprim; putprim <= endprim; putprim++) { |
411 |
> |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
412 |
> |
fprintf(stderr, "%s: seek error on input file\n", |
413 |
> |
progname); |
414 |
|
quit(1); |
415 |
|
} |
416 |
< |
for (x = 0; x < xres; x++) { |
417 |
< |
if (uniq) |
418 |
< |
if ( scanln[x][RED] == lastc[RED] && |
419 |
< |
scanln[x][GRN] == lastc[GRN] && |
420 |
< |
scanln[x][BLU] == lastc[BLU] ) |
199 |
< |
continue; |
200 |
< |
else |
201 |
< |
copycolor(lastc, scanln[x]); |
202 |
< |
if (original) |
203 |
< |
multcolor(scanln[x], exposure); |
204 |
< |
if (!dataonly) |
205 |
< |
printf("%7d %7d ", x, y); |
206 |
< |
if ((*putval)(scanln[x], stdout) < 0) { |
207 |
< |
fprintf(stderr, "%s: write error\n", progname); |
416 |
> |
set_io(); |
417 |
> |
setcolor(lastc, 0.0, 0.0, 0.0); |
418 |
> |
for (y = 0; y < numscans(&picres); y++) { |
419 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
420 |
> |
fprintf(stderr, "%s: read error\n", progname); |
421 |
|
quit(1); |
422 |
|
} |
423 |
+ |
for (x = 0; x < scanlen(&picres); x++) { |
424 |
+ |
if (uniq) |
425 |
+ |
if ( colval(scanln[x],RED) == |
426 |
+ |
colval(lastc,RED) && |
427 |
+ |
colval(scanln[x],GRN) == |
428 |
+ |
colval(lastc,GRN) && |
429 |
+ |
colval(scanln[x],BLU) == |
430 |
+ |
colval(lastc,BLU) ) |
431 |
+ |
continue; |
432 |
+ |
else |
433 |
+ |
copycolor(lastc, scanln[x]); |
434 |
+ |
if (doexposure) |
435 |
+ |
multcolor(scanln[x], exposure); |
436 |
+ |
if (dogamma) |
437 |
+ |
setcolor(scanln[x], |
438 |
+ |
pow(colval(scanln[x],RED), 1.0/gamcor), |
439 |
+ |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
440 |
+ |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
441 |
+ |
if (!dataonly) { |
442 |
+ |
pix2loc(hv, &picres, x, y); |
443 |
+ |
printf("%7d %7d ", |
444 |
+ |
(int)(hv[0]*picres.xr), |
445 |
+ |
(int)(hv[1]*picres.yr)); |
446 |
+ |
} |
447 |
+ |
if ((*putval)(scanln[x]) < 0) { |
448 |
+ |
fprintf(stderr, "%s: write error\n", |
449 |
+ |
progname); |
450 |
+ |
quit(1); |
451 |
+ |
} |
452 |
+ |
} |
453 |
|
} |
454 |
|
} |
455 |
< |
free((char *)scanln); |
455 |
> |
free((void *)scanln); |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
|
valtopix() /* convert values to a pixel file */ |
460 |
|
{ |
461 |
< |
COLOR *scanln; |
461 |
> |
int dogamma; |
462 |
> |
register COLOR *scanln; |
463 |
|
int y; |
464 |
|
register int x; |
465 |
|
|
466 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
466 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
467 |
|
if (scanln == NULL) { |
468 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
469 |
|
quit(1); |
470 |
|
} |
471 |
< |
for (y = yres-1; y >= 0; y--) { |
472 |
< |
for (x = 0; x < xres; x++) { |
473 |
< |
if (!dataonly) |
471 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
472 |
> |
set_io(); |
473 |
> |
for (y = 0; y < numscans(&picres); y++) { |
474 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
475 |
> |
if (!dataonly) { |
476 |
|
fscanf(fin, "%*d %*d"); |
477 |
< |
if ((*getval)(scanln[x], fin) < 0) { |
477 |
> |
if (fin2 != NULL) { |
478 |
> |
fscanf(fin2, "%*d %*d"); |
479 |
> |
fscanf(fin3, "%*d %*d"); |
480 |
> |
} |
481 |
> |
} |
482 |
> |
if ((*getval)(scanln[x]) < 0) { |
483 |
|
fprintf(stderr, "%s: read error\n", progname); |
484 |
|
quit(1); |
485 |
|
} |
486 |
+ |
if (dogamma) |
487 |
+ |
setcolor(scanln[x], |
488 |
+ |
pow(colval(scanln[x],RED), gamcor), |
489 |
+ |
pow(colval(scanln[x],GRN), gamcor), |
490 |
+ |
pow(colval(scanln[x],BLU), gamcor)); |
491 |
+ |
if (doexposure) |
492 |
+ |
multcolor(scanln[x], exposure); |
493 |
|
} |
494 |
< |
if (fwritescan(scanln, xres, stdout) < 0 |
237 |
< |
|| fflush(stdout) < 0) { |
494 |
> |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
495 |
|
fprintf(stderr, "%s: write error\n", progname); |
496 |
|
quit(1); |
497 |
|
} |
498 |
|
} |
499 |
< |
free((char *)scanln); |
499 |
> |
free((void *)scanln); |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
+ |
void |
504 |
|
quit(code) |
505 |
|
int code; |
506 |
|
{ |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
< |
getcascii(col, fp) /* get an ascii color value from fp */ |
511 |
> |
swap16(wp, n) /* swap n 16-bit words */ |
512 |
> |
register uint16 *wp; |
513 |
> |
int n; |
514 |
> |
{ |
515 |
> |
while (n-- > 0) { |
516 |
> |
*wp = *wp << 8 | ((*wp >> 8) & 0xff); |
517 |
> |
wp++; |
518 |
> |
} |
519 |
> |
} |
520 |
> |
|
521 |
> |
getcascii(col) /* get an ascii color value from stream(s) */ |
522 |
|
COLOR col; |
255 |
– |
FILE *fp; |
523 |
|
{ |
524 |
< |
double vd[3]; |
524 |
> |
double vd[3]; |
525 |
|
|
526 |
< |
if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
527 |
< |
return(-1); |
528 |
< |
setcolor(col, vd[0], vd[1], vd[2]); |
526 |
> |
if (fin2 == NULL) { |
527 |
> |
if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
528 |
> |
return(-1); |
529 |
> |
} else { |
530 |
> |
if (fscanf(fin, "%lf", &vd[0]) != 1 || |
531 |
> |
fscanf(fin2, "%lf", &vd[1]) != 1 || |
532 |
> |
fscanf(fin3, "%lf", &vd[2]) != 1) |
533 |
> |
return(-1); |
534 |
> |
} |
535 |
> |
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
536 |
|
return(0); |
537 |
|
} |
538 |
|
|
539 |
|
|
540 |
< |
getcdouble(col, fp) /* get a double color value from fp */ |
540 |
> |
getcdouble(col) /* get a double color value from stream(s) */ |
541 |
|
COLOR col; |
268 |
– |
FILE *fp; |
542 |
|
{ |
543 |
< |
double vd[3]; |
543 |
> |
double vd[3]; |
544 |
|
|
545 |
< |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
546 |
< |
return(-1); |
547 |
< |
setcolor(col, vd[0], vd[1], vd[2]); |
545 |
> |
if (fin2 == NULL) { |
546 |
> |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
547 |
> |
return(-1); |
548 |
> |
} else { |
549 |
> |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
550 |
> |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
551 |
> |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
552 |
> |
return(-1); |
553 |
> |
} |
554 |
> |
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
555 |
|
return(0); |
556 |
|
} |
557 |
|
|
558 |
|
|
559 |
< |
getcfloat(col, fp) /* get a float color value from fp */ |
559 |
> |
getcfloat(col) /* get a float color value from stream(s) */ |
560 |
|
COLOR col; |
281 |
– |
FILE *fp; |
561 |
|
{ |
562 |
|
float vf[3]; |
563 |
|
|
564 |
< |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
565 |
< |
return(-1); |
566 |
< |
setcolor(col, vf[0], vf[1], vf[2]); |
564 |
> |
if (fin2 == NULL) { |
565 |
> |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
566 |
> |
return(-1); |
567 |
> |
} else { |
568 |
> |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
569 |
> |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
570 |
> |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
571 |
> |
return(-1); |
572 |
> |
} |
573 |
> |
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
574 |
|
return(0); |
575 |
|
} |
576 |
|
|
577 |
|
|
578 |
< |
getcint(col, fp) /* get an int color value from fp */ |
578 |
> |
getcint(col) /* get an int color value from stream(s) */ |
579 |
|
COLOR col; |
294 |
– |
FILE *fp; |
580 |
|
{ |
581 |
|
int vi[3]; |
582 |
|
|
583 |
< |
if (fscanf(fp, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
584 |
< |
return(-1); |
585 |
< |
setcolor(col,(vi[0]+.5)/256.,(vi[1]+.5)/256.,(vi[2]+.5)/256.); |
583 |
> |
if (fin2 == NULL) { |
584 |
> |
if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
585 |
> |
return(-1); |
586 |
> |
} else { |
587 |
> |
if (fscanf(fin, "%d", &vi[0]) != 1 || |
588 |
> |
fscanf(fin2, "%d", &vi[1]) != 1 || |
589 |
> |
fscanf(fin3, "%d", &vi[2]) != 1) |
590 |
> |
return(-1); |
591 |
> |
} |
592 |
> |
setcolor(col, (vi[rord[RED]]+.5)/256., |
593 |
> |
(vi[rord[GRN]]+.5)/256., (vi[rord[BLU]]+.5)/256.); |
594 |
|
return(0); |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
< |
getcbyte(col, fp) /* get a byte color value from fp */ |
598 |
> |
getcbyte(col) /* get a byte color value from stream(s) */ |
599 |
|
COLOR col; |
307 |
– |
FILE *fp; |
600 |
|
{ |
601 |
|
BYTE vb[3]; |
602 |
|
|
603 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, fp) != 3) |
604 |
< |
return(-1); |
605 |
< |
setcolor(col,(vb[0]+.5)/256.,(vb[1]+.5)/256.,(vb[2]+.5)/256.); |
603 |
> |
if (fin2 == NULL) { |
604 |
> |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
605 |
> |
return(-1); |
606 |
> |
} else { |
607 |
> |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
608 |
> |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
609 |
> |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
610 |
> |
return(-1); |
611 |
> |
} |
612 |
> |
setcolor(col, (vb[rord[RED]]+.5)/256., |
613 |
> |
(vb[rord[GRN]]+.5)/256., (vb[rord[BLU]]+.5)/256.); |
614 |
|
return(0); |
615 |
|
} |
616 |
|
|
617 |
|
|
618 |
< |
getbascii(col, fp) /* get an ascii brightness value from fp */ |
618 |
> |
getcword(col) /* get a 16-bit color value from stream(s) */ |
619 |
|
COLOR col; |
320 |
– |
FILE *fp; |
620 |
|
{ |
621 |
< |
double vd; |
621 |
> |
uint16 vw[3]; |
622 |
|
|
623 |
< |
if (fscanf(fp, "%lf", &vd) != 1) |
623 |
> |
if (fin2 == NULL) { |
624 |
> |
if (fread((char *)vw, sizeof(uint16), 3, fin) != 3) |
625 |
> |
return(-1); |
626 |
> |
} else { |
627 |
> |
if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 || |
628 |
> |
fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 || |
629 |
> |
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
630 |
> |
return(-1); |
631 |
> |
} |
632 |
> |
if (swapbytes) |
633 |
> |
swap16(vw, 3); |
634 |
> |
setcolor(col, (vw[rord[RED]]+.5)/65536., |
635 |
> |
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
636 |
> |
return(0); |
637 |
> |
} |
638 |
> |
|
639 |
> |
|
640 |
> |
getbascii(col) /* get an ascii brightness value from fin */ |
641 |
> |
COLOR col; |
642 |
> |
{ |
643 |
> |
double vd; |
644 |
> |
|
645 |
> |
if (fscanf(fin, "%lf", &vd) != 1) |
646 |
|
return(-1); |
647 |
|
setcolor(col, vd, vd, vd); |
648 |
|
return(0); |
649 |
|
} |
650 |
|
|
651 |
|
|
652 |
< |
getbdouble(col, fp) /* get a double brightness value from fp */ |
652 |
> |
getbdouble(col) /* get a double brightness value from fin */ |
653 |
|
COLOR col; |
333 |
– |
FILE *fp; |
654 |
|
{ |
655 |
< |
double vd; |
655 |
> |
double vd; |
656 |
|
|
657 |
< |
if (fread((char *)&vd, sizeof(double), 1, fp) != 1) |
657 |
> |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
658 |
|
return(-1); |
659 |
|
setcolor(col, vd, vd, vd); |
660 |
|
return(0); |
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
< |
getbfloat(col, fp) /* get a float brightness value from fp */ |
664 |
> |
getbfloat(col) /* get a float brightness value from fin */ |
665 |
|
COLOR col; |
346 |
– |
FILE *fp; |
666 |
|
{ |
667 |
|
float vf; |
668 |
|
|
669 |
< |
if (fread((char *)&vf, sizeof(float), 1, fp) != 1) |
669 |
> |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
670 |
|
return(-1); |
671 |
|
setcolor(col, vf, vf, vf); |
672 |
|
return(0); |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
< |
getbint(col, fp) /* get an int brightness value from fp */ |
676 |
> |
getbint(col) /* get an int brightness value from fin */ |
677 |
|
COLOR col; |
359 |
– |
FILE *fp; |
678 |
|
{ |
679 |
|
int vi; |
680 |
< |
double d; |
680 |
> |
double d; |
681 |
|
|
682 |
< |
if (fscanf(fp, "%d", &vi) != 1) |
682 |
> |
if (fscanf(fin, "%d", &vi) != 1) |
683 |
|
return(-1); |
684 |
|
d = (vi+.5)/256.; |
685 |
|
setcolor(col, d, d, d); |
687 |
|
} |
688 |
|
|
689 |
|
|
690 |
< |
getbbyte(col, fp) /* get a byte brightness value from fp */ |
690 |
> |
getbbyte(col) /* get a byte brightness value from fin */ |
691 |
|
COLOR col; |
374 |
– |
FILE *fp; |
692 |
|
{ |
693 |
|
BYTE vb; |
694 |
< |
double d; |
694 |
> |
double d; |
695 |
|
|
696 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) |
696 |
> |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
697 |
|
return(-1); |
698 |
|
d = (vb+.5)/256.; |
699 |
|
setcolor(col, d, d, d); |
701 |
|
} |
702 |
|
|
703 |
|
|
704 |
< |
putcascii(col, fp) /* put an ascii color to fp */ |
704 |
> |
getbword(col) /* get a 16-bit brightness value from fin */ |
705 |
|
COLOR col; |
389 |
– |
FILE *fp; |
706 |
|
{ |
707 |
< |
fprintf(fp, "%15.3e %15.3e %15.3e\n", |
708 |
< |
colval(col,RED), |
393 |
< |
colval(col,GRN), |
394 |
< |
colval(col,BLU)); |
707 |
> |
uint16 vw; |
708 |
> |
double d; |
709 |
|
|
710 |
< |
return(ferror(fp) ? -1 : 0); |
710 |
> |
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
711 |
> |
return(-1); |
712 |
> |
if (swapbytes) |
713 |
> |
swap16(&vw, 1); |
714 |
> |
d = (vw+.5)/65536.; |
715 |
> |
setcolor(col, d, d, d); |
716 |
> |
return(0); |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
< |
putcfloat(col, fp) /* put a float color to fp */ |
720 |
> |
putcascii(col) /* put an ascii color to stdout */ |
721 |
|
COLOR col; |
402 |
– |
FILE *fp; |
722 |
|
{ |
723 |
+ |
fprintf(stdout, "%15.3e %15.3e %15.3e\n", |
724 |
+ |
colval(col,ord[0]), |
725 |
+ |
colval(col,ord[1]), |
726 |
+ |
colval(col,ord[2])); |
727 |
+ |
|
728 |
+ |
return(ferror(stdout) ? -1 : 0); |
729 |
+ |
} |
730 |
+ |
|
731 |
+ |
|
732 |
+ |
putcfloat(col) /* put a float color to stdout */ |
733 |
+ |
COLOR col; |
734 |
+ |
{ |
735 |
|
float vf[3]; |
736 |
|
|
737 |
< |
vf[0] = colval(col,RED); |
738 |
< |
vf[1] = colval(col,GRN); |
739 |
< |
vf[2] = colval(col,BLU); |
740 |
< |
fwrite((char *)vf, sizeof(float), 3, fp); |
737 |
> |
vf[0] = colval(col,ord[0]); |
738 |
> |
vf[1] = colval(col,ord[1]); |
739 |
> |
vf[2] = colval(col,ord[2]); |
740 |
> |
fwrite((char *)vf, sizeof(float), 3, stdout); |
741 |
|
|
742 |
< |
return(ferror(fp) ? -1 : 0); |
742 |
> |
return(ferror(stdout) ? -1 : 0); |
743 |
|
} |
744 |
|
|
745 |
|
|
746 |
< |
putcdouble(col, fp) /* put a double color to fp */ |
746 |
> |
putcdouble(col) /* put a double color to stdout */ |
747 |
|
COLOR col; |
417 |
– |
FILE *fp; |
748 |
|
{ |
749 |
< |
double vd[3]; |
749 |
> |
double vd[3]; |
750 |
|
|
751 |
< |
vd[0] = colval(col,RED); |
752 |
< |
vd[1] = colval(col,GRN); |
753 |
< |
vd[2] = colval(col,BLU); |
754 |
< |
fwrite((char *)vd, sizeof(double), 3, fp); |
751 |
> |
vd[0] = colval(col,ord[0]); |
752 |
> |
vd[1] = colval(col,ord[1]); |
753 |
> |
vd[2] = colval(col,ord[2]); |
754 |
> |
fwrite((char *)vd, sizeof(double), 3, stdout); |
755 |
|
|
756 |
< |
return(ferror(fp) ? -1 : 0); |
756 |
> |
return(ferror(stdout) ? -1 : 0); |
757 |
|
} |
758 |
|
|
759 |
|
|
760 |
< |
putcint(col, fp) /* put an int color to fp */ |
760 |
> |
putcint(col) /* put an int color to stdout */ |
761 |
|
COLOR col; |
432 |
– |
FILE *fp; |
762 |
|
{ |
763 |
< |
fprintf(fp, "%d %d %d\n", |
764 |
< |
(int)(colval(col,RED)*256.), |
765 |
< |
(int)(colval(col,GRN)*256.), |
766 |
< |
(int)(colval(col,BLU)*256.)); |
763 |
> |
fprintf(stdout, "%d %d %d\n", |
764 |
> |
(int)(colval(col,ord[0])*256.), |
765 |
> |
(int)(colval(col,ord[1])*256.), |
766 |
> |
(int)(colval(col,ord[2])*256.)); |
767 |
|
|
768 |
< |
return(ferror(fp) ? -1 : 0); |
768 |
> |
return(ferror(stdout) ? -1 : 0); |
769 |
|
} |
770 |
|
|
771 |
|
|
772 |
< |
putcbyte(col, fp) /* put a byte color to fp */ |
772 |
> |
putcbyte(col) /* put a byte color to stdout */ |
773 |
|
COLOR col; |
445 |
– |
FILE *fp; |
774 |
|
{ |
775 |
< |
register int i; |
775 |
> |
long i; |
776 |
|
BYTE vb[3]; |
777 |
|
|
778 |
< |
i = colval(col,RED)*256.; |
778 |
> |
i = colval(col,ord[0])*256.; |
779 |
|
vb[0] = min(i,255); |
780 |
< |
i = colval(col,GRN)*256.; |
780 |
> |
i = colval(col,ord[1])*256.; |
781 |
|
vb[1] = min(i,255); |
782 |
< |
i = colval(col,BLU)*256.; |
782 |
> |
i = colval(col,ord[2])*256.; |
783 |
|
vb[2] = min(i,255); |
784 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, fp); |
784 |
> |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
785 |
|
|
786 |
< |
return(ferror(fp) ? -1 : 0); |
786 |
> |
return(ferror(stdout) ? -1 : 0); |
787 |
|
} |
788 |
|
|
789 |
|
|
790 |
< |
putbascii(col, fp) /* put an ascii brightness to fp */ |
790 |
> |
putcword(col) /* put a 16-bit color to stdout */ |
791 |
|
COLOR col; |
464 |
– |
FILE *fp; |
792 |
|
{ |
793 |
< |
fprintf(fp, "%15.3e\n", bright(col)); |
793 |
> |
long i; |
794 |
> |
uint16 vw[3]; |
795 |
|
|
796 |
< |
return(ferror(fp) ? -1 : 0); |
796 |
> |
i = colval(col,ord[0])*65536.; |
797 |
> |
vw[0] = min(i,65535); |
798 |
> |
i = colval(col,ord[1])*65536.; |
799 |
> |
vw[1] = min(i,65535); |
800 |
> |
i = colval(col,ord[2])*65536.; |
801 |
> |
vw[2] = min(i,65535); |
802 |
> |
if (swapbytes) |
803 |
> |
swap16(vw, 3); |
804 |
> |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
805 |
> |
|
806 |
> |
return(ferror(stdout) ? -1 : 0); |
807 |
|
} |
808 |
|
|
809 |
|
|
810 |
< |
putbfloat(col, fp) /* put a float brightness to fp */ |
810 |
> |
putbascii(col) /* put an ascii brightness to stdout */ |
811 |
|
COLOR col; |
474 |
– |
FILE *fp; |
812 |
|
{ |
813 |
+ |
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
814 |
+ |
|
815 |
+ |
return(ferror(stdout) ? -1 : 0); |
816 |
+ |
} |
817 |
+ |
|
818 |
+ |
|
819 |
+ |
putbfloat(col) /* put a float brightness to stdout */ |
820 |
+ |
COLOR col; |
821 |
+ |
{ |
822 |
|
float vf; |
823 |
|
|
824 |
< |
vf = bright(col); |
825 |
< |
fwrite((char *)&vf, sizeof(float), 1, fp); |
824 |
> |
vf = (*mybright)(col); |
825 |
> |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
826 |
|
|
827 |
< |
return(ferror(fp) ? -1 : 0); |
827 |
> |
return(ferror(stdout) ? -1 : 0); |
828 |
|
} |
829 |
|
|
830 |
|
|
831 |
< |
putbdouble(col, fp) /* put a double brightness to fp */ |
831 |
> |
putbdouble(col) /* put a double brightness to stdout */ |
832 |
|
COLOR col; |
487 |
– |
FILE *fp; |
833 |
|
{ |
834 |
< |
double vd; |
834 |
> |
double vd; |
835 |
|
|
836 |
< |
vd = bright(col); |
837 |
< |
fwrite((char *)&vd, sizeof(double), 1, fp); |
836 |
> |
vd = (*mybright)(col); |
837 |
> |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
838 |
|
|
839 |
< |
return(ferror(fp) ? -1 : 0); |
839 |
> |
return(ferror(stdout) ? -1 : 0); |
840 |
|
} |
841 |
|
|
842 |
|
|
843 |
< |
putbint(col, fp) /* put an int brightness to fp */ |
843 |
> |
putbint(col) /* put an int brightness to stdout */ |
844 |
|
COLOR col; |
500 |
– |
FILE *fp; |
845 |
|
{ |
846 |
< |
fprintf(fp, "%d\n", (int)(bright(col)*256.)); |
846 |
> |
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
847 |
|
|
848 |
< |
return(ferror(fp) ? -1 : 0); |
848 |
> |
return(ferror(stdout) ? -1 : 0); |
849 |
|
} |
850 |
|
|
851 |
|
|
852 |
< |
putbbyte(col, fp) /* put a byte brightness to fp */ |
852 |
> |
putbbyte(col) /* put a byte brightness to stdout */ |
853 |
|
COLOR col; |
510 |
– |
FILE *fp; |
854 |
|
{ |
855 |
|
register int i; |
856 |
|
BYTE vb; |
857 |
|
|
858 |
< |
i = bright(col)*256.; |
858 |
> |
i = (*mybright)(col)*256.; |
859 |
|
vb = min(i,255); |
860 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
860 |
> |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
861 |
|
|
862 |
< |
return(ferror(fp) ? -1 : 0); |
862 |
> |
return(ferror(stdout) ? -1 : 0); |
863 |
|
} |
864 |
|
|
865 |
|
|
866 |
+ |
putbword(col) /* put a 16-bit brightness to stdout */ |
867 |
+ |
COLOR col; |
868 |
+ |
{ |
869 |
+ |
long i; |
870 |
+ |
uint16 vw; |
871 |
+ |
|
872 |
+ |
i = (*mybright)(col)*65536.; |
873 |
+ |
vw = min(i,65535); |
874 |
+ |
if (swapbytes) |
875 |
+ |
swap16(&vw, 1); |
876 |
+ |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
877 |
+ |
|
878 |
+ |
return(ferror(stdout) ? -1 : 0); |
879 |
+ |
} |
880 |
+ |
|
881 |
+ |
|
882 |
+ |
putpascii(col) /* put an ascii primary to stdout */ |
883 |
+ |
COLOR col; |
884 |
+ |
{ |
885 |
+ |
fprintf(stdout, "%15.3e\n", colval(col,putprim)); |
886 |
+ |
|
887 |
+ |
return(ferror(stdout) ? -1 : 0); |
888 |
+ |
} |
889 |
+ |
|
890 |
+ |
|
891 |
+ |
putpfloat(col) /* put a float primary to stdout */ |
892 |
+ |
COLOR col; |
893 |
+ |
{ |
894 |
+ |
float vf; |
895 |
+ |
|
896 |
+ |
vf = colval(col,putprim); |
897 |
+ |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
898 |
+ |
|
899 |
+ |
return(ferror(stdout) ? -1 : 0); |
900 |
+ |
} |
901 |
+ |
|
902 |
+ |
|
903 |
+ |
putpdouble(col) /* put a double primary to stdout */ |
904 |
+ |
COLOR col; |
905 |
+ |
{ |
906 |
+ |
double vd; |
907 |
+ |
|
908 |
+ |
vd = colval(col,putprim); |
909 |
+ |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
910 |
+ |
|
911 |
+ |
return(ferror(stdout) ? -1 : 0); |
912 |
+ |
} |
913 |
+ |
|
914 |
+ |
|
915 |
+ |
putpint(col) /* put an int primary to stdout */ |
916 |
+ |
COLOR col; |
917 |
+ |
{ |
918 |
+ |
fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); |
919 |
+ |
|
920 |
+ |
return(ferror(stdout) ? -1 : 0); |
921 |
+ |
} |
922 |
+ |
|
923 |
+ |
|
924 |
+ |
putpbyte(col) /* put a byte primary to stdout */ |
925 |
+ |
COLOR col; |
926 |
+ |
{ |
927 |
+ |
long i; |
928 |
+ |
BYTE vb; |
929 |
+ |
|
930 |
+ |
i = colval(col,putprim)*256.; |
931 |
+ |
vb = min(i,255); |
932 |
+ |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
933 |
+ |
|
934 |
+ |
return(ferror(stdout) ? -1 : 0); |
935 |
+ |
} |
936 |
+ |
|
937 |
+ |
|
938 |
+ |
putpword(col) /* put a 16-bit primary to stdout */ |
939 |
+ |
COLOR col; |
940 |
+ |
{ |
941 |
+ |
long i; |
942 |
+ |
uint16 vw; |
943 |
+ |
|
944 |
+ |
i = colval(col,putprim)*65536.; |
945 |
+ |
vw = min(i,65535); |
946 |
+ |
if (swapbytes) |
947 |
+ |
swap16(&vw, 1); |
948 |
+ |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
949 |
+ |
|
950 |
+ |
return(ferror(stdout) ? -1 : 0); |
951 |
+ |
} |
952 |
+ |
|
953 |
+ |
|
954 |
|
set_io() /* set put and get functions */ |
955 |
|
{ |
956 |
|
switch (format) { |
957 |
|
case 'a': /* ascii */ |
958 |
< |
if (brightonly) { |
958 |
> |
if (putprim == BRIGHT) { |
959 |
|
getval = getbascii; |
960 |
|
putval = putbascii; |
961 |
+ |
} else if (putprim != ALL) { |
962 |
+ |
getval = getbascii; |
963 |
+ |
putval = putpascii; |
964 |
|
} else { |
965 |
|
getval = getcascii; |
966 |
|
putval = putcascii; |
967 |
+ |
if (reverse && !interleave) { |
968 |
+ |
fprintf(stderr, |
969 |
+ |
"%s: ASCII input files must be interleaved\n", |
970 |
+ |
progname); |
971 |
+ |
quit(1); |
972 |
+ |
} |
973 |
|
} |
974 |
|
return; |
975 |
|
case 'f': /* binary float */ |
976 |
< |
if (brightonly) { |
976 |
> |
if (putprim == BRIGHT) { |
977 |
|
getval = getbfloat; |
978 |
|
putval = putbfloat; |
979 |
+ |
} else if (putprim != ALL) { |
980 |
+ |
getval = getbfloat; |
981 |
+ |
putval = putpfloat; |
982 |
|
} else { |
983 |
|
getval = getcfloat; |
984 |
|
putval = putcfloat; |
985 |
+ |
if (reverse && !interleave) { |
986 |
+ |
if (fin2 == NULL) |
987 |
+ |
goto namerr; |
988 |
+ |
if (fseek(fin2, |
989 |
+ |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
990 |
+ |
goto seekerr; |
991 |
+ |
if (fseek(fin3, |
992 |
+ |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
993 |
+ |
goto seekerr; |
994 |
+ |
} |
995 |
|
} |
996 |
|
return; |
997 |
|
case 'd': /* binary double */ |
998 |
< |
if (brightonly) { |
998 |
> |
if (putprim == BRIGHT) { |
999 |
|
getval = getbdouble; |
1000 |
|
putval = putbdouble; |
1001 |
+ |
} else if (putprim != ALL) { |
1002 |
+ |
getval = getbdouble; |
1003 |
+ |
putval = putpdouble; |
1004 |
|
} else { |
1005 |
|
getval = getcdouble; |
1006 |
|
putval = putcdouble; |
1007 |
+ |
if (reverse && !interleave) { |
1008 |
+ |
if (fin2 == NULL) |
1009 |
+ |
goto namerr; |
1010 |
+ |
if (fseek(fin2, |
1011 |
+ |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1012 |
+ |
goto seekerr; |
1013 |
+ |
if (fseek(fin3, |
1014 |
+ |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1015 |
+ |
goto seekerr; |
1016 |
+ |
} |
1017 |
|
} |
1018 |
|
return; |
1019 |
|
case 'i': /* integer */ |
1020 |
< |
if (brightonly) { |
1020 |
> |
if (putprim == BRIGHT) { |
1021 |
|
getval = getbint; |
1022 |
|
putval = putbint; |
1023 |
+ |
} else if (putprim != ALL) { |
1024 |
+ |
getval = getbint; |
1025 |
+ |
putval = putpint; |
1026 |
|
} else { |
1027 |
|
getval = getcint; |
1028 |
|
putval = putcint; |
1029 |
+ |
if (reverse && !interleave) { |
1030 |
+ |
fprintf(stderr, |
1031 |
+ |
"%s: integer input files must be interleaved\n", |
1032 |
+ |
progname); |
1033 |
+ |
quit(1); |
1034 |
+ |
} |
1035 |
|
} |
1036 |
|
return; |
1037 |
|
case 'b': /* byte */ |
1038 |
< |
if (brightonly) { |
1038 |
> |
if (putprim == BRIGHT) { |
1039 |
|
getval = getbbyte; |
1040 |
|
putval = putbbyte; |
1041 |
+ |
} else if (putprim != ALL) { |
1042 |
+ |
getval = getbbyte; |
1043 |
+ |
putval = putpbyte; |
1044 |
|
} else { |
1045 |
|
getval = getcbyte; |
1046 |
|
putval = putcbyte; |
1047 |
+ |
if (reverse && !interleave) { |
1048 |
+ |
if (fin2 == NULL) |
1049 |
+ |
goto namerr; |
1050 |
+ |
if (fseek(fin2, |
1051 |
+ |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
1052 |
+ |
goto seekerr; |
1053 |
+ |
if (fseek(fin3, |
1054 |
+ |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
1055 |
+ |
goto seekerr; |
1056 |
+ |
} |
1057 |
|
} |
1058 |
|
return; |
1059 |
+ |
case 'w': /* 16-bit */ |
1060 |
+ |
if (putprim == BRIGHT) { |
1061 |
+ |
getval = getbword; |
1062 |
+ |
putval = putbword; |
1063 |
+ |
} else if (putprim != ALL) { |
1064 |
+ |
getval = getbword; |
1065 |
+ |
putval = putpword; |
1066 |
+ |
} else { |
1067 |
+ |
getval = getcword; |
1068 |
+ |
putval = putcword; |
1069 |
+ |
if (reverse && !interleave) { |
1070 |
+ |
if (fin2 == NULL) |
1071 |
+ |
goto namerr; |
1072 |
+ |
if (fseek(fin2, |
1073 |
+ |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
1074 |
+ |
goto seekerr; |
1075 |
+ |
if (fseek(fin3, |
1076 |
+ |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
1077 |
+ |
goto seekerr; |
1078 |
+ |
} |
1079 |
+ |
} |
1080 |
+ |
return; |
1081 |
|
} |
1082 |
+ |
badopt: |
1083 |
+ |
fprintf(stderr, "%s: botched file type\n", progname); |
1084 |
+ |
quit(1); |
1085 |
+ |
namerr: |
1086 |
+ |
fprintf(stderr, "%s: non-interleaved file(s) must be named\n", |
1087 |
+ |
progname); |
1088 |
+ |
quit(1); |
1089 |
+ |
seekerr: |
1090 |
+ |
fprintf(stderr, "%s: cannot seek on interleaved input file\n", |
1091 |
+ |
progname); |
1092 |
+ |
quit(1); |
1093 |
|
} |