1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
16 |
|
|
17 |
|
#include "resolu.h" |
18 |
|
|
19 |
< |
#define min(a,b) ((a)<(b)?(a):(b)) |
19 |
> |
#define min(a,b) ((a)<(b)?(a):(b)) |
20 |
|
|
21 |
< |
RESOLU picres; /* resolution of picture */ |
21 |
> |
/* what to put out (also RED, GRN, BLU) */ |
22 |
> |
#define ALL 3 |
23 |
> |
#define BRIGHT 4 |
24 |
|
|
25 |
+ |
#define brightonly (putprim==BRIGHT) |
26 |
+ |
|
27 |
+ |
RESOLU picres; /* resolution of picture */ |
28 |
+ |
|
29 |
|
int uniq = 0; /* print only unique values? */ |
30 |
|
|
31 |
< |
int original = 0; /* convert back to original values? */ |
31 |
> |
int doexposure = 0; /* exposure change? (>100 to print) */ |
32 |
|
|
33 |
|
int dataonly = 0; /* data only format? */ |
34 |
|
|
35 |
< |
int brightonly = 0; /* only brightness values? */ |
35 |
> |
int putprim = ALL; /* what to put out */ |
36 |
|
|
37 |
|
int reverse = 0; /* reverse conversion? */ |
38 |
|
|
39 |
|
int format = 'a'; /* input/output format */ |
40 |
|
char *fmtid = "ascii"; /* format identifier for header */ |
41 |
|
|
42 |
< |
int header = 1; /* do header */ |
42 |
> |
int header = 1; /* do header? */ |
43 |
|
|
44 |
+ |
long skipbytes = 0; /* skip bytes in input? */ |
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 */ |
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 |
|
|
69 |
|
char **argv; |
70 |
|
{ |
71 |
|
extern int checkhead(); |
72 |
+ |
extern long atol(); |
73 |
+ |
double d, expval = 1.0; |
74 |
|
int i; |
75 |
|
|
76 |
|
progname = argv[0]; |
81 |
|
case 'h': /* header */ |
82 |
|
header = argv[i][0] == '+'; |
83 |
|
break; |
84 |
+ |
case 'H': /* resolution string */ |
85 |
+ |
resolution = argv[i][0] == '+'; |
86 |
+ |
break; |
87 |
+ |
case 's': /* skip bytes in header */ |
88 |
+ |
skipbytes = atol(argv[++i]); |
89 |
+ |
break; |
90 |
|
case 'u': /* unique values */ |
91 |
|
uniq = argv[i][0] == '-'; |
92 |
|
break; |
94 |
|
original = argv[i][0] == '-'; |
95 |
|
break; |
96 |
|
case 'g': /* gamma correction */ |
97 |
< |
gamcor = atof(argv[++i]); |
97 |
> |
gamcor = atof(argv[i+1]); |
98 |
|
if (argv[i][0] == '+') |
99 |
|
gamcor = 1.0/gamcor; |
100 |
+ |
i++; |
101 |
|
break; |
102 |
+ |
case 'e': /* exposure correction */ |
103 |
+ |
d = atof(argv[i+1]); |
104 |
+ |
if (argv[i+1][0] == '-' || argv[i+1][0] == '+') |
105 |
+ |
d = pow(2.0, d); |
106 |
+ |
if (argv[i][0] == '-') |
107 |
+ |
expval *= d; |
108 |
+ |
scalecolor(exposure, d); |
109 |
+ |
doexposure++; |
110 |
+ |
i++; |
111 |
+ |
break; |
112 |
+ |
case 'R': /* reverse byte sequence */ |
113 |
+ |
if (argv[i][0] == '-') { |
114 |
+ |
ord[0]=BLU; ord[1]=GRN; ord[2]=RED; |
115 |
+ |
} else { |
116 |
+ |
ord[0]=RED; ord[1]=GRN; ord[2]=BLU; |
117 |
+ |
} |
118 |
+ |
break; |
119 |
|
case 'r': /* reverse conversion */ |
120 |
|
reverse = argv[i][0] == '-'; |
121 |
|
break; |
122 |
|
case 'b': /* brightness values */ |
123 |
< |
brightonly = argv[i][0] == '-'; |
123 |
> |
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
124 |
|
break; |
125 |
+ |
case 'p': /* put primary */ |
126 |
+ |
switch (argv[i][2]) { |
127 |
+ |
case 'r': case 'R': putprim = RED; break; |
128 |
+ |
case 'g': case 'G': putprim = GRN; break; |
129 |
+ |
case 'b': case 'B': putprim = BLU; break; |
130 |
+ |
default: goto unkopt; |
131 |
+ |
} |
132 |
+ |
break; |
133 |
|
case 'd': /* data only (no indices) */ |
134 |
|
dataonly = argv[i][0] == '-'; |
135 |
|
switch (argv[i][2]) { |
162 |
|
} |
163 |
|
break; |
164 |
|
case 'x': /* x resolution */ |
165 |
+ |
case 'X': /* x resolution */ |
166 |
+ |
resolution = 0; |
167 |
|
if (argv[i][0] == '-') |
168 |
|
picres.or |= XDECR; |
169 |
|
picres.xr = atoi(argv[++i]); |
170 |
|
break; |
171 |
|
case 'y': /* y resolution */ |
172 |
+ |
case 'Y': /* y resolution */ |
173 |
+ |
resolution = 0; |
174 |
|
if (argv[i][0] == '-') |
175 |
|
picres.or |= YDECR; |
176 |
|
if (picres.xr == 0) |
192 |
|
fmtid = "8-bit_grey"; |
193 |
|
else |
194 |
|
fmtid = "24-bit_rgb"; |
195 |
< |
|
195 |
> |
/* assign reverse ordering */ |
196 |
> |
rord[ord[0]] = 0; |
197 |
> |
rord[ord[1]] = 1; |
198 |
> |
rord[ord[2]] = 2; |
199 |
> |
/* get input */ |
200 |
|
if (i == argc) { |
201 |
|
fin = stdin; |
202 |
< |
} else if (i == argc-1) { |
202 |
> |
} else if (i < argc) { |
203 |
|
if ((fin = fopen(argv[i], "r")) == NULL) { |
204 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
205 |
|
progname, argv[i]); |
206 |
|
quit(1); |
207 |
|
} |
208 |
< |
} else { |
208 |
> |
if (skipbytes && fseek(fin, skipbytes, 0)) |
209 |
> |
goto seekerr; |
210 |
> |
if (reverse && !brightonly && i == argc-3) { |
211 |
> |
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
212 |
> |
fprintf(stderr, "%s: can't open file \"%s\"\n", |
213 |
> |
progname, argv[i+1]); |
214 |
> |
quit(1); |
215 |
> |
} |
216 |
> |
if ((fin3 = fopen(argv[i+2], "r")) == NULL) { |
217 |
> |
fprintf(stderr, "%s: can't open file \"%s\"\n", |
218 |
> |
progname, argv[i+2]); |
219 |
> |
quit(1); |
220 |
> |
} |
221 |
> |
if (skipbytes && (fseek(fin2, skipbytes, 0) || |
222 |
> |
fseek(fin3, skipbytes, 0))) |
223 |
> |
goto seekerr; |
224 |
> |
} else if (i != argc-1) |
225 |
> |
fin = NULL; |
226 |
> |
} |
227 |
> |
if (fin == NULL) { |
228 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
229 |
|
quit(1); |
230 |
|
} |
232 |
|
set_io(); |
233 |
|
|
234 |
|
if (reverse) { |
235 |
+ |
#ifdef MSDOS |
236 |
+ |
setmode(fileno(stdout), O_BINARY); |
237 |
+ |
if (format != 'a' && format != 'i') |
238 |
+ |
setmode(fileno(fin), O_BINARY); |
239 |
+ |
#endif |
240 |
|
/* get header */ |
241 |
< |
if (header && checkheader(fin, fmtid, stdout) < 0) { |
242 |
< |
fprintf(stderr, "%s: wrong input format\n", progname); |
241 |
> |
if (header) { |
242 |
> |
if (checkheader(fin, fmtid, stdout) < 0) { |
243 |
> |
fprintf(stderr, "%s: wrong input format\n", |
244 |
> |
progname); |
245 |
> |
quit(1); |
246 |
> |
} |
247 |
> |
if (fin2 != NULL) { |
248 |
> |
getheader(fin2, NULL, NULL); |
249 |
> |
getheader(fin3, NULL, NULL); |
250 |
> |
} |
251 |
> |
} else |
252 |
> |
newheader("RADIANCE", stdout); |
253 |
> |
/* get resolution */ |
254 |
> |
if ((resolution && !fgetsresolu(&picres, fin)) || |
255 |
> |
picres.xr <= 0 || picres.yr <= 0) { |
256 |
> |
fprintf(stderr, "%s: missing resolution\n", progname); |
257 |
|
quit(1); |
258 |
|
} |
259 |
< |
if (picres.xr <= 0 || picres.yr <= 0) /* get resolution */ |
260 |
< |
if (!fgetsresolu(&picres, fin)) { |
261 |
< |
fprintf(stderr, "%s: missing resolution\n", |
259 |
> |
if (resolution && fin2 != NULL) { |
260 |
> |
RESOLU pres2; |
261 |
> |
if (!fgetsresolu(&pres2, fin2) || |
262 |
> |
pres2.or != picres.or || |
263 |
> |
pres2.xr != picres.xr || |
264 |
> |
pres2.yr != picres.yr || |
265 |
> |
!fgetsresolu(&pres2, fin3) || |
266 |
> |
pres2.or != picres.or || |
267 |
> |
pres2.xr != picres.xr || |
268 |
> |
pres2.yr != picres.yr) { |
269 |
> |
fprintf(stderr, "%s: resolution mismatch\n", |
270 |
|
progname); |
271 |
|
quit(1); |
272 |
|
} |
273 |
+ |
} |
274 |
|
/* add to header */ |
275 |
|
printargs(i, argv, stdout); |
276 |
+ |
if (expval < .99 || expval > 1.01) |
277 |
+ |
fputexpos(expval, stdout); |
278 |
|
fputformat(COLRFMT, stdout); |
279 |
|
putchar('\n'); |
280 |
< |
fputsresolu(&picres, stdout); |
280 |
> |
fputsresolu(&picres, stdout); /* always put resolution */ |
281 |
|
valtopix(); |
282 |
|
} else { |
283 |
+ |
#ifdef MSDOS |
284 |
+ |
setmode(fileno(fin), O_BINARY); |
285 |
+ |
if (format != 'a' && format != 'i') |
286 |
+ |
setmode(fileno(stdout), O_BINARY); |
287 |
+ |
#endif |
288 |
|
/* get header */ |
289 |
|
getheader(fin, checkhead, NULL); |
290 |
|
if (wrongformat) { |
292 |
|
progname); |
293 |
|
quit(1); |
294 |
|
} |
295 |
< |
|
296 |
< |
if (picres.xr <= 0 || picres.yr <= 0) /* get picture size */ |
297 |
< |
if (!fgetsresolu(&picres, fin)) { |
298 |
< |
fprintf(stderr, "%s: missing resolution\n", |
187 |
< |
progname); |
188 |
< |
quit(1); |
189 |
< |
} |
295 |
> |
if (!fgetsresolu(&picres, fin)) { |
296 |
> |
fprintf(stderr, "%s: missing resolution\n", progname); |
297 |
> |
quit(1); |
298 |
> |
} |
299 |
|
if (header) { |
300 |
|
printargs(i, argv, stdout); |
301 |
+ |
if (expval < .99 || expval > 1.01) |
302 |
+ |
fputexpos(expval, stdout); |
303 |
|
fputformat(fmtid, stdout); |
304 |
|
putchar('\n'); |
305 |
|
} |
306 |
+ |
if (resolution) /* put resolution */ |
307 |
+ |
fputsresolu(&picres, stdout); |
308 |
|
pixtoval(); |
309 |
|
} |
310 |
|
|
311 |
|
quit(0); |
312 |
+ |
seekerr: |
313 |
+ |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
314 |
+ |
progname, skipbytes); |
315 |
+ |
quit(1); |
316 |
|
} |
317 |
|
|
318 |
|
|
323 |
|
double d; |
324 |
|
COLOR ctmp; |
325 |
|
|
326 |
< |
if (isformat(line)) { |
210 |
< |
formatval(fmt, line); |
326 |
> |
if (formatval(fmt, line)) |
327 |
|
wrongformat = strcmp(fmt, COLRFMT); |
328 |
< |
} else if (original && isexpos(line)) { |
328 |
> |
else if (original && isexpos(line)) { |
329 |
|
d = 1.0/exposval(line); |
330 |
|
scalecolor(exposure, d); |
331 |
+ |
doexposure++; |
332 |
|
} else if (original && iscolcor(line)) { |
333 |
|
colcorval(ctmp, line); |
334 |
|
setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), |
335 |
|
colval(exposure,GRN)/colval(ctmp,GRN), |
336 |
|
colval(exposure,BLU)/colval(ctmp,BLU)); |
337 |
+ |
doexposure++; |
338 |
|
} else if (header) |
339 |
|
fputs(line, stdout); |
340 |
|
} |
342 |
|
|
343 |
|
pixtoval() /* convert picture to values */ |
344 |
|
{ |
345 |
< |
register COLOR *scanln; |
345 |
> |
register COLOR *scanln; |
346 |
|
int dogamma; |
347 |
|
COLOR lastc; |
348 |
|
FLOAT hv[2]; |
372 |
|
continue; |
373 |
|
else |
374 |
|
copycolor(lastc, scanln[x]); |
375 |
< |
if (original) |
375 |
> |
if (doexposure) |
376 |
|
multcolor(scanln[x], exposure); |
377 |
|
if (dogamma) |
378 |
|
setcolor(scanln[x], |
397 |
|
valtopix() /* convert values to a pixel file */ |
398 |
|
{ |
399 |
|
int dogamma; |
400 |
< |
register COLOR *scanln; |
400 |
> |
register COLOR *scanln; |
401 |
|
int y; |
402 |
|
register int x; |
403 |
|
|
409 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
410 |
|
for (y = 0; y < numscans(&picres); y++) { |
411 |
|
for (x = 0; x < scanlen(&picres); x++) { |
412 |
< |
if (!dataonly) |
412 |
> |
if (!dataonly) { |
413 |
|
fscanf(fin, "%*d %*d"); |
414 |
< |
if ((*getval)(scanln[x], fin) < 0) { |
414 |
> |
if (fin2 != NULL) { |
415 |
> |
fscanf(fin2, "%*d %*d"); |
416 |
> |
fscanf(fin3, "%*d %*d"); |
417 |
> |
} |
418 |
> |
} |
419 |
> |
if ((*getval)(scanln[x], fin, fin2, fin3) < 0) { |
420 |
|
fprintf(stderr, "%s: read error\n", progname); |
421 |
|
quit(1); |
422 |
|
} |
425 |
|
pow(colval(scanln[x],RED), gamcor), |
426 |
|
pow(colval(scanln[x],GRN), gamcor), |
427 |
|
pow(colval(scanln[x],BLU), gamcor)); |
428 |
+ |
if (doexposure) |
429 |
+ |
multcolor(scanln[x], exposure); |
430 |
|
} |
431 |
|
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
432 |
|
fprintf(stderr, "%s: write error\n", progname); |
444 |
|
} |
445 |
|
|
446 |
|
|
447 |
< |
getcascii(col, fp) /* get an ascii color value from fp */ |
447 |
> |
getcascii(col, f1, f2, f3) /* get an ascii color value from stream(s) */ |
448 |
|
COLOR col; |
449 |
< |
FILE *fp; |
449 |
> |
FILE *f1, *f2, *f3; |
450 |
|
{ |
451 |
< |
double vd[3]; |
451 |
> |
double vd[3]; |
452 |
|
|
453 |
< |
if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
454 |
< |
return(-1); |
455 |
< |
setcolor(col, vd[0], vd[1], vd[2]); |
453 |
> |
if (f2 == NULL) { |
454 |
> |
if (fscanf(f1, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
455 |
> |
return(-1); |
456 |
> |
} else { |
457 |
> |
if (fscanf(f1, "%lf", &vd[0]) != 1 || |
458 |
> |
fscanf(f2, "%lf", &vd[1]) != 1 || |
459 |
> |
fscanf(f3, "%lf", &vd[2]) != 1) |
460 |
> |
return(-1); |
461 |
> |
} |
462 |
> |
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
463 |
|
return(0); |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
< |
getcdouble(col, fp) /* get a double color value from fp */ |
467 |
> |
getcdouble(col, f1, f2, f3) /* get a double color value from stream(s) */ |
468 |
|
COLOR col; |
469 |
< |
FILE *fp; |
469 |
> |
FILE *f1, *f2, *f3; |
470 |
|
{ |
471 |
< |
double vd[3]; |
471 |
> |
double vd[3]; |
472 |
|
|
473 |
< |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
474 |
< |
return(-1); |
475 |
< |
setcolor(col, vd[0], vd[1], vd[2]); |
473 |
> |
if (f2 == NULL) { |
474 |
> |
if (fread((char *)vd, sizeof(double), 3, f1) != 3) |
475 |
> |
return(-1); |
476 |
> |
} else { |
477 |
> |
if (fread((char *)vd, sizeof(double), 1, f1) != 1 || |
478 |
> |
fread((char *)(vd+1), sizeof(double), 1, f2) != 1 || |
479 |
> |
fread((char *)(vd+2), sizeof(double), 1, f3) != 1) |
480 |
> |
return(-1); |
481 |
> |
} |
482 |
> |
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
483 |
|
return(0); |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
< |
getcfloat(col, fp) /* get a float color value from fp */ |
487 |
> |
getcfloat(col, f1, f2, f3) /* get a float color value from stream(s) */ |
488 |
|
COLOR col; |
489 |
< |
FILE *fp; |
489 |
> |
FILE *f1, *f2, *f3; |
490 |
|
{ |
491 |
|
float vf[3]; |
492 |
|
|
493 |
< |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
494 |
< |
return(-1); |
495 |
< |
setcolor(col, vf[0], vf[1], vf[2]); |
493 |
> |
if (f2 == NULL) { |
494 |
> |
if (fread((char *)vf, sizeof(float), 3, f1) != 3) |
495 |
> |
return(-1); |
496 |
> |
} else { |
497 |
> |
if (fread((char *)vf, sizeof(float), 1, f1) != 1 || |
498 |
> |
fread((char *)(vf+1), sizeof(float), 1, f2) != 1 || |
499 |
> |
fread((char *)(vf+2), sizeof(float), 1, f3) != 1) |
500 |
> |
return(-1); |
501 |
> |
} |
502 |
> |
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
503 |
|
return(0); |
504 |
|
} |
505 |
|
|
506 |
|
|
507 |
< |
getcint(col, fp) /* get an int color value from fp */ |
507 |
> |
getcint(col, f1, f2, f3) /* get an int color value from stream(s) */ |
508 |
|
COLOR col; |
509 |
< |
FILE *fp; |
509 |
> |
FILE *f1, *f2, *f3; |
510 |
|
{ |
511 |
|
int vi[3]; |
512 |
|
|
513 |
< |
if (fscanf(fp, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
514 |
< |
return(-1); |
515 |
< |
setcolor(col,(vi[0]+.5)/256.,(vi[1]+.5)/256.,(vi[2]+.5)/256.); |
513 |
> |
if (f2 == NULL) { |
514 |
> |
if (fscanf(f1, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
515 |
> |
return(-1); |
516 |
> |
} else { |
517 |
> |
if (fscanf(f1, "%d", &vi[0]) != 1 || |
518 |
> |
fscanf(f2, "%d", &vi[1]) != 1 || |
519 |
> |
fscanf(f3, "%d", &vi[2]) != 1) |
520 |
> |
return(-1); |
521 |
> |
} |
522 |
> |
setcolor(col, (vi[rord[RED]]+.5)/256., |
523 |
> |
(vi[rord[GRN]]+.5)/256., (vi[rord[BLU]]+.5)/256.); |
524 |
|
return(0); |
525 |
|
} |
526 |
|
|
527 |
|
|
528 |
< |
getcbyte(col, fp) /* get a byte color value from fp */ |
528 |
> |
getcbyte(col, f1, f2, f3) /* get a byte color value from stream(s) */ |
529 |
|
COLOR col; |
530 |
< |
FILE *fp; |
530 |
> |
FILE *f1, *f2, *f3; |
531 |
|
{ |
532 |
|
BYTE vb[3]; |
533 |
|
|
534 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, fp) != 3) |
535 |
< |
return(-1); |
536 |
< |
setcolor(col,(vb[0]+.5)/256.,(vb[1]+.5)/256.,(vb[2]+.5)/256.); |
534 |
> |
if (f2 == NULL) { |
535 |
> |
if (fread((char *)vb, sizeof(BYTE), 3, f1) != 3) |
536 |
> |
return(-1); |
537 |
> |
} else { |
538 |
> |
if (fread((char *)vb, sizeof(BYTE), 1, f1) != 1 || |
539 |
> |
fread((char *)(vb+1), sizeof(BYTE), 1, f2) != 1 || |
540 |
> |
fread((char *)(vb+2), sizeof(BYTE), 1, f3) != 1) |
541 |
> |
return(-1); |
542 |
> |
} |
543 |
> |
setcolor(col, (vb[rord[RED]]+.5)/256., |
544 |
> |
(vb[rord[GRN]]+.5)/256., (vb[rord[BLU]]+.5)/256.); |
545 |
|
return(0); |
546 |
|
} |
547 |
|
|
550 |
|
COLOR col; |
551 |
|
FILE *fp; |
552 |
|
{ |
553 |
< |
double vd; |
553 |
> |
double vd; |
554 |
|
|
555 |
|
if (fscanf(fp, "%lf", &vd) != 1) |
556 |
|
return(-1); |
563 |
|
COLOR col; |
564 |
|
FILE *fp; |
565 |
|
{ |
566 |
< |
double vd; |
566 |
> |
double vd; |
567 |
|
|
568 |
|
if (fread((char *)&vd, sizeof(double), 1, fp) != 1) |
569 |
|
return(-1); |
590 |
|
FILE *fp; |
591 |
|
{ |
592 |
|
int vi; |
593 |
< |
double d; |
593 |
> |
double d; |
594 |
|
|
595 |
|
if (fscanf(fp, "%d", &vi) != 1) |
596 |
|
return(-1); |
605 |
|
FILE *fp; |
606 |
|
{ |
607 |
|
BYTE vb; |
608 |
< |
double d; |
608 |
> |
double d; |
609 |
|
|
610 |
|
if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) |
611 |
|
return(-1); |
620 |
|
FILE *fp; |
621 |
|
{ |
622 |
|
fprintf(fp, "%15.3e %15.3e %15.3e\n", |
623 |
< |
colval(col,RED), |
624 |
< |
colval(col,GRN), |
625 |
< |
colval(col,BLU)); |
623 |
> |
colval(col,ord[0]), |
624 |
> |
colval(col,ord[1]), |
625 |
> |
colval(col,ord[2])); |
626 |
|
|
627 |
|
return(ferror(fp) ? -1 : 0); |
628 |
|
} |
634 |
|
{ |
635 |
|
float vf[3]; |
636 |
|
|
637 |
< |
vf[0] = colval(col,RED); |
638 |
< |
vf[1] = colval(col,GRN); |
639 |
< |
vf[2] = colval(col,BLU); |
637 |
> |
vf[0] = colval(col,ord[0]); |
638 |
> |
vf[1] = colval(col,ord[1]); |
639 |
> |
vf[2] = colval(col,ord[2]); |
640 |
|
fwrite((char *)vf, sizeof(float), 3, fp); |
641 |
|
|
642 |
|
return(ferror(fp) ? -1 : 0); |
647 |
|
COLOR col; |
648 |
|
FILE *fp; |
649 |
|
{ |
650 |
< |
double vd[3]; |
650 |
> |
double vd[3]; |
651 |
|
|
652 |
< |
vd[0] = colval(col,RED); |
653 |
< |
vd[1] = colval(col,GRN); |
654 |
< |
vd[2] = colval(col,BLU); |
652 |
> |
vd[0] = colval(col,ord[0]); |
653 |
> |
vd[1] = colval(col,ord[1]); |
654 |
> |
vd[2] = colval(col,ord[2]); |
655 |
|
fwrite((char *)vd, sizeof(double), 3, fp); |
656 |
|
|
657 |
|
return(ferror(fp) ? -1 : 0); |
663 |
|
FILE *fp; |
664 |
|
{ |
665 |
|
fprintf(fp, "%d %d %d\n", |
666 |
< |
(int)(colval(col,RED)*256.), |
667 |
< |
(int)(colval(col,GRN)*256.), |
668 |
< |
(int)(colval(col,BLU)*256.)); |
666 |
> |
(int)(colval(col,ord[0])*256.), |
667 |
> |
(int)(colval(col,ord[1])*256.), |
668 |
> |
(int)(colval(col,ord[2])*256.)); |
669 |
|
|
670 |
|
return(ferror(fp) ? -1 : 0); |
671 |
|
} |
678 |
|
register int i; |
679 |
|
BYTE vb[3]; |
680 |
|
|
681 |
< |
i = colval(col,RED)*256.; |
681 |
> |
i = colval(col,ord[0])*256.; |
682 |
|
vb[0] = min(i,255); |
683 |
< |
i = colval(col,GRN)*256.; |
683 |
> |
i = colval(col,ord[1])*256.; |
684 |
|
vb[1] = min(i,255); |
685 |
< |
i = colval(col,BLU)*256.; |
685 |
> |
i = colval(col,ord[2])*256.; |
686 |
|
vb[2] = min(i,255); |
687 |
|
fwrite((char *)vb, sizeof(BYTE), 3, fp); |
688 |
|
|
717 |
|
COLOR col; |
718 |
|
FILE *fp; |
719 |
|
{ |
720 |
< |
double vd; |
720 |
> |
double vd; |
721 |
|
|
722 |
|
vd = bright(col); |
723 |
|
fwrite((char *)&vd, sizeof(double), 1, fp); |
751 |
|
} |
752 |
|
|
753 |
|
|
754 |
+ |
putpascii(col, fp) /* put an ascii primary to fp */ |
755 |
+ |
COLOR col; |
756 |
+ |
FILE *fp; |
757 |
+ |
{ |
758 |
+ |
fprintf(fp, "%15.3e\n", colval(col,putprim)); |
759 |
+ |
|
760 |
+ |
return(ferror(fp) ? -1 : 0); |
761 |
+ |
} |
762 |
+ |
|
763 |
+ |
|
764 |
+ |
putpfloat(col, fp) /* put a float primary to fp */ |
765 |
+ |
COLOR col; |
766 |
+ |
FILE *fp; |
767 |
+ |
{ |
768 |
+ |
float vf; |
769 |
+ |
|
770 |
+ |
vf = colval(col,putprim); |
771 |
+ |
fwrite((char *)&vf, sizeof(float), 1, fp); |
772 |
+ |
|
773 |
+ |
return(ferror(fp) ? -1 : 0); |
774 |
+ |
} |
775 |
+ |
|
776 |
+ |
|
777 |
+ |
putpdouble(col, fp) /* put a double primary to fp */ |
778 |
+ |
COLOR col; |
779 |
+ |
FILE *fp; |
780 |
+ |
{ |
781 |
+ |
double vd; |
782 |
+ |
|
783 |
+ |
vd = colval(col,putprim); |
784 |
+ |
fwrite((char *)&vd, sizeof(double), 1, fp); |
785 |
+ |
|
786 |
+ |
return(ferror(fp) ? -1 : 0); |
787 |
+ |
} |
788 |
+ |
|
789 |
+ |
|
790 |
+ |
putpint(col, fp) /* put an int primary to fp */ |
791 |
+ |
COLOR col; |
792 |
+ |
FILE *fp; |
793 |
+ |
{ |
794 |
+ |
fprintf(fp, "%d\n", (int)(colval(col,putprim)*256.)); |
795 |
+ |
|
796 |
+ |
return(ferror(fp) ? -1 : 0); |
797 |
+ |
} |
798 |
+ |
|
799 |
+ |
|
800 |
+ |
putpbyte(col, fp) /* put a byte primary to fp */ |
801 |
+ |
COLOR col; |
802 |
+ |
FILE *fp; |
803 |
+ |
{ |
804 |
+ |
register int i; |
805 |
+ |
BYTE vb; |
806 |
+ |
|
807 |
+ |
i = colval(col,putprim)*256.; |
808 |
+ |
vb = min(i,255); |
809 |
+ |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
810 |
+ |
|
811 |
+ |
return(ferror(fp) ? -1 : 0); |
812 |
+ |
} |
813 |
+ |
|
814 |
+ |
|
815 |
|
set_io() /* set put and get functions */ |
816 |
|
{ |
817 |
|
switch (format) { |
818 |
|
case 'a': /* ascii */ |
819 |
< |
if (brightonly) { |
819 |
> |
if (putprim == BRIGHT) { |
820 |
|
getval = getbascii; |
821 |
|
putval = putbascii; |
822 |
+ |
} else if (putprim != ALL) { |
823 |
+ |
getval = getbascii; |
824 |
+ |
putval = putpascii; |
825 |
|
} else { |
826 |
|
getval = getcascii; |
827 |
|
putval = putcascii; |
828 |
|
} |
829 |
|
return; |
830 |
|
case 'f': /* binary float */ |
831 |
< |
if (brightonly) { |
831 |
> |
if (putprim == BRIGHT) { |
832 |
|
getval = getbfloat; |
833 |
|
putval = putbfloat; |
834 |
+ |
} else if (putprim != ALL) { |
835 |
+ |
getval = getbfloat; |
836 |
+ |
putval = putpfloat; |
837 |
|
} else { |
838 |
|
getval = getcfloat; |
839 |
|
putval = putcfloat; |
840 |
|
} |
841 |
|
return; |
842 |
|
case 'd': /* binary double */ |
843 |
< |
if (brightonly) { |
843 |
> |
if (putprim == BRIGHT) { |
844 |
|
getval = getbdouble; |
845 |
|
putval = putbdouble; |
846 |
+ |
} else if (putprim != ALL) { |
847 |
+ |
getval = getbdouble; |
848 |
+ |
putval = putpdouble; |
849 |
|
} else { |
850 |
|
getval = getcdouble; |
851 |
|
putval = putcdouble; |
852 |
|
} |
853 |
|
return; |
854 |
|
case 'i': /* integer */ |
855 |
< |
if (brightonly) { |
855 |
> |
if (putprim == BRIGHT) { |
856 |
|
getval = getbint; |
857 |
|
putval = putbint; |
858 |
+ |
} else if (putprim != ALL) { |
859 |
+ |
getval = getbint; |
860 |
+ |
putval = putpint; |
861 |
|
} else { |
862 |
|
getval = getcint; |
863 |
|
putval = putcint; |
864 |
|
} |
865 |
|
return; |
866 |
|
case 'b': /* byte */ |
867 |
< |
if (brightonly) { |
867 |
> |
if (putprim == BRIGHT) { |
868 |
|
getval = getbbyte; |
869 |
|
putval = putbbyte; |
870 |
+ |
} else if (putprim != ALL) { |
871 |
+ |
getval = getbbyte; |
872 |
+ |
putval = putpbyte; |
873 |
|
} else { |
874 |
|
getval = getcbyte; |
875 |
|
putval = putcbyte; |