1 |
– |
/* Copyright (c) 1992 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 |
|
* |
11 |
|
|
12 |
|
#include "color.h" |
13 |
|
|
14 |
+ |
#include <time.h> |
15 |
+ |
|
16 |
|
#include "resolu.h" |
17 |
|
|
18 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
42 |
|
|
43 |
|
long skipbytes = 0; /* skip bytes in input? */ |
44 |
|
|
45 |
+ |
int interleave = 1; /* file is interleaved? */ |
46 |
+ |
|
47 |
|
int resolution = 1; /* put/get resolution string? */ |
48 |
|
|
49 |
|
int original = 0; /* convert to original values? */ |
64 |
|
|
65 |
|
int (*getval)(), (*putval)(); |
66 |
|
|
67 |
+ |
double |
68 |
+ |
rgb_bright(clr) |
69 |
+ |
COLOR clr; |
70 |
+ |
{ |
71 |
+ |
return(bright(clr)); |
72 |
+ |
} |
73 |
|
|
74 |
+ |
double |
75 |
+ |
xyz_bright(clr) |
76 |
+ |
COLOR clr; |
77 |
+ |
{ |
78 |
+ |
return(clr[CIEY]); |
79 |
+ |
} |
80 |
+ |
|
81 |
+ |
double (*mybright)() = &rgb_bright; |
82 |
+ |
|
83 |
+ |
|
84 |
|
main(argc, argv) |
85 |
|
int argc; |
86 |
|
char **argv; |
136 |
|
case 'r': /* reverse conversion */ |
137 |
|
reverse = argv[i][0] == '-'; |
138 |
|
break; |
139 |
+ |
case 'n': /* non-interleaved RGB */ |
140 |
+ |
interleave = argv[i][0] == '+'; |
141 |
+ |
break; |
142 |
|
case 'b': /* brightness values */ |
143 |
|
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
144 |
|
break; |
185 |
|
case 'X': /* x resolution */ |
186 |
|
resolution = 0; |
187 |
|
if (argv[i][0] == '-') |
188 |
< |
picres.or |= XDECR; |
188 |
> |
picres.rt |= XDECR; |
189 |
|
picres.xr = atoi(argv[++i]); |
190 |
|
break; |
191 |
|
case 'y': /* y resolution */ |
192 |
|
case 'Y': /* y resolution */ |
193 |
|
resolution = 0; |
194 |
|
if (argv[i][0] == '-') |
195 |
< |
picres.or |= YDECR; |
195 |
> |
picres.rt |= YDECR; |
196 |
|
if (picres.xr == 0) |
197 |
< |
picres.or |= YMAJOR; |
197 |
> |
picres.rt |= YMAJOR; |
198 |
|
picres.yr = atoi(argv[++i]); |
199 |
|
break; |
200 |
|
default: |
225 |
|
progname, argv[i]); |
226 |
|
quit(1); |
227 |
|
} |
208 |
– |
if (skipbytes && fseek(fin, skipbytes, 0)) |
209 |
– |
goto seekerr; |
228 |
|
if (reverse && !brightonly && i == argc-3) { |
229 |
|
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
230 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
236 |
|
progname, argv[i+2]); |
237 |
|
quit(1); |
238 |
|
} |
239 |
< |
if (skipbytes && (fseek(fin2, skipbytes, 0) || |
222 |
< |
fseek(fin3, skipbytes, 0))) |
223 |
< |
goto seekerr; |
239 |
> |
interleave = -1; |
240 |
|
} else if (i != argc-1) |
241 |
|
fin = NULL; |
242 |
+ |
if (reverse && !brightonly && !interleave) { |
243 |
+ |
fin2 = fopen(argv[i], "r"); |
244 |
+ |
fin3 = fopen(argv[i], "r"); |
245 |
+ |
} |
246 |
+ |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
247 |
+ |
(fseek(fin2, skipbytes, 0) || |
248 |
+ |
fseek(fin3, skipbytes, 0))))) { |
249 |
+ |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
250 |
+ |
progname, skipbytes); |
251 |
+ |
quit(1); |
252 |
+ |
} |
253 |
|
} |
254 |
|
if (fin == NULL) { |
255 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
256 |
|
quit(1); |
257 |
|
} |
258 |
|
|
232 |
– |
set_io(); |
233 |
– |
|
259 |
|
if (reverse) { |
260 |
|
#ifdef MSDOS |
261 |
|
setmode(fileno(stdout), O_BINARY); |
284 |
|
if (resolution && fin2 != NULL) { |
285 |
|
RESOLU pres2; |
286 |
|
if (!fgetsresolu(&pres2, fin2) || |
287 |
< |
pres2.or != picres.or || |
287 |
> |
pres2.rt != picres.rt || |
288 |
|
pres2.xr != picres.xr || |
289 |
|
pres2.yr != picres.yr || |
290 |
|
!fgetsresolu(&pres2, fin3) || |
291 |
< |
pres2.or != picres.or || |
291 |
> |
pres2.rt != picres.rt || |
292 |
|
pres2.xr != picres.xr || |
293 |
|
pres2.yr != picres.yr) { |
294 |
|
fprintf(stderr, "%s: resolution mismatch\n", |
313 |
|
/* get header */ |
314 |
|
getheader(fin, checkhead, NULL); |
315 |
|
if (wrongformat) { |
316 |
< |
fprintf(stderr, "%s: input not a Radiance picture\n", |
316 |
> |
fprintf(stderr, |
317 |
> |
"%s: input not a Radiance RGBE picture\n", |
318 |
|
progname); |
319 |
|
quit(1); |
320 |
|
} |
335 |
|
} |
336 |
|
|
337 |
|
quit(0); |
312 |
– |
seekerr: |
313 |
– |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
314 |
– |
progname, skipbytes); |
315 |
– |
quit(1); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
+ |
int |
342 |
|
checkhead(line) /* deal with line from header */ |
343 |
|
char *line; |
344 |
|
{ |
346 |
|
double d; |
347 |
|
COLOR ctmp; |
348 |
|
|
349 |
< |
if (formatval(fmt, line)) |
350 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
351 |
< |
else if (original && isexpos(line)) { |
349 |
> |
if (formatval(fmt, line)) { |
350 |
> |
if (!strcmp(fmt, CIEFMT)) { |
351 |
> |
mybright = &xyz_bright; |
352 |
> |
if (original) { |
353 |
> |
scalecolor(exposure, 1./WHTEFFICACY); |
354 |
> |
doexposure++; |
355 |
> |
} |
356 |
> |
} else if (!strcmp(fmt, COLRFMT)) |
357 |
> |
mybright = &rgb_bright; |
358 |
> |
else |
359 |
> |
wrongformat++; |
360 |
> |
} else if (original && isexpos(line)) { |
361 |
|
d = 1.0/exposval(line); |
362 |
|
scalecolor(exposure, d); |
363 |
|
doexposure++; |
369 |
|
doexposure++; |
370 |
|
} else if (header) |
371 |
|
fputs(line, stdout); |
372 |
+ |
return(0); |
373 |
|
} |
374 |
|
|
375 |
|
|
379 |
|
int dogamma; |
380 |
|
COLOR lastc; |
381 |
|
FLOAT hv[2]; |
382 |
+ |
int startprim, endprim; |
383 |
+ |
long startpos; |
384 |
|
int y; |
385 |
|
register int x; |
386 |
|
|
390 |
|
quit(1); |
391 |
|
} |
392 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
393 |
< |
setcolor(lastc, 0.0, 0.0, 0.0); |
394 |
< |
for (y = 0; y < numscans(&picres); y++) { |
395 |
< |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
396 |
< |
fprintf(stderr, "%s: read error\n", progname); |
393 |
> |
if (putprim == ALL && !interleave) { |
394 |
> |
startprim = RED; endprim = BLU; |
395 |
> |
startpos = ftell(fin); |
396 |
> |
} else { |
397 |
> |
startprim = putprim; endprim = putprim; |
398 |
> |
} |
399 |
> |
for (putprim = startprim; putprim <= endprim; putprim++) { |
400 |
> |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
401 |
> |
fprintf(stderr, "%s: seek error on input file\n", |
402 |
> |
progname); |
403 |
|
quit(1); |
404 |
|
} |
405 |
< |
for (x = 0; x < scanlen(&picres); x++) { |
406 |
< |
if (uniq) |
407 |
< |
if ( colval(scanln[x],RED) == |
408 |
< |
colval(lastc,RED) && |
409 |
< |
colval(scanln[x],GRN) == |
369 |
< |
colval(lastc,GRN) && |
370 |
< |
colval(scanln[x],BLU) == |
371 |
< |
colval(lastc,BLU) ) |
372 |
< |
continue; |
373 |
< |
else |
374 |
< |
copycolor(lastc, scanln[x]); |
375 |
< |
if (doexposure) |
376 |
< |
multcolor(scanln[x], exposure); |
377 |
< |
if (dogamma) |
378 |
< |
setcolor(scanln[x], |
379 |
< |
pow(colval(scanln[x],RED), 1.0/gamcor), |
380 |
< |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
381 |
< |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
382 |
< |
if (!dataonly) { |
383 |
< |
pix2loc(hv, &picres, x, y); |
384 |
< |
printf("%7d %7d ", (int)(hv[0]*picres.xr), |
385 |
< |
(int)(hv[1]*picres.yr)); |
386 |
< |
} |
387 |
< |
if ((*putval)(scanln[x], stdout) < 0) { |
388 |
< |
fprintf(stderr, "%s: write error\n", progname); |
405 |
> |
set_io(); |
406 |
> |
setcolor(lastc, 0.0, 0.0, 0.0); |
407 |
> |
for (y = 0; y < numscans(&picres); y++) { |
408 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
409 |
> |
fprintf(stderr, "%s: read error\n", progname); |
410 |
|
quit(1); |
411 |
|
} |
412 |
+ |
for (x = 0; x < scanlen(&picres); x++) { |
413 |
+ |
if (uniq) |
414 |
+ |
if ( colval(scanln[x],RED) == |
415 |
+ |
colval(lastc,RED) && |
416 |
+ |
colval(scanln[x],GRN) == |
417 |
+ |
colval(lastc,GRN) && |
418 |
+ |
colval(scanln[x],BLU) == |
419 |
+ |
colval(lastc,BLU) ) |
420 |
+ |
continue; |
421 |
+ |
else |
422 |
+ |
copycolor(lastc, scanln[x]); |
423 |
+ |
if (doexposure) |
424 |
+ |
multcolor(scanln[x], exposure); |
425 |
+ |
if (dogamma) |
426 |
+ |
setcolor(scanln[x], |
427 |
+ |
pow(colval(scanln[x],RED), 1.0/gamcor), |
428 |
+ |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
429 |
+ |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
430 |
+ |
if (!dataonly) { |
431 |
+ |
pix2loc(hv, &picres, x, y); |
432 |
+ |
printf("%7d %7d ", |
433 |
+ |
(int)(hv[0]*picres.xr), |
434 |
+ |
(int)(hv[1]*picres.yr)); |
435 |
+ |
} |
436 |
+ |
if ((*putval)(scanln[x]) < 0) { |
437 |
+ |
fprintf(stderr, "%s: write error\n", |
438 |
+ |
progname); |
439 |
+ |
quit(1); |
440 |
+ |
} |
441 |
+ |
} |
442 |
|
} |
443 |
|
} |
444 |
< |
free((char *)scanln); |
444 |
> |
free((void *)scanln); |
445 |
|
} |
446 |
|
|
447 |
|
|
458 |
|
quit(1); |
459 |
|
} |
460 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
461 |
+ |
set_io(); |
462 |
|
for (y = 0; y < numscans(&picres); y++) { |
463 |
|
for (x = 0; x < scanlen(&picres); x++) { |
464 |
|
if (!dataonly) { |
468 |
|
fscanf(fin3, "%*d %*d"); |
469 |
|
} |
470 |
|
} |
471 |
< |
if ((*getval)(scanln[x], fin, fin2, fin3) < 0) { |
471 |
> |
if ((*getval)(scanln[x]) < 0) { |
472 |
|
fprintf(stderr, "%s: read error\n", progname); |
473 |
|
quit(1); |
474 |
|
} |
485 |
|
quit(1); |
486 |
|
} |
487 |
|
} |
488 |
< |
free((char *)scanln); |
488 |
> |
free((void *)scanln); |
489 |
|
} |
490 |
|
|
491 |
|
|
492 |
+ |
void |
493 |
|
quit(code) |
494 |
|
int code; |
495 |
|
{ |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
< |
getcascii(col, f1, f2, f3) /* get an ascii color value from stream(s) */ |
500 |
> |
getcascii(col) /* get an ascii color value from stream(s) */ |
501 |
|
COLOR col; |
449 |
– |
FILE *f1, *f2, *f3; |
502 |
|
{ |
503 |
|
double vd[3]; |
504 |
|
|
505 |
< |
if (f2 == NULL) { |
506 |
< |
if (fscanf(f1, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
505 |
> |
if (fin2 == NULL) { |
506 |
> |
if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
507 |
|
return(-1); |
508 |
|
} else { |
509 |
< |
if (fscanf(f1, "%lf", &vd[0]) != 1 || |
510 |
< |
fscanf(f2, "%lf", &vd[1]) != 1 || |
511 |
< |
fscanf(f3, "%lf", &vd[2]) != 1) |
509 |
> |
if (fscanf(fin, "%lf", &vd[0]) != 1 || |
510 |
> |
fscanf(fin2, "%lf", &vd[1]) != 1 || |
511 |
> |
fscanf(fin3, "%lf", &vd[2]) != 1) |
512 |
|
return(-1); |
513 |
|
} |
514 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
< |
getcdouble(col, f1, f2, f3) /* get a double color value from stream(s) */ |
519 |
> |
getcdouble(col) /* get a double color value from stream(s) */ |
520 |
|
COLOR col; |
469 |
– |
FILE *f1, *f2, *f3; |
521 |
|
{ |
522 |
|
double vd[3]; |
523 |
|
|
524 |
< |
if (f2 == NULL) { |
525 |
< |
if (fread((char *)vd, sizeof(double), 3, f1) != 3) |
524 |
> |
if (fin2 == NULL) { |
525 |
> |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
526 |
|
return(-1); |
527 |
|
} else { |
528 |
< |
if (fread((char *)vd, sizeof(double), 1, f1) != 1 || |
529 |
< |
fread((char *)(vd+1), sizeof(double), 1, f2) != 1 || |
530 |
< |
fread((char *)(vd+2), sizeof(double), 1, f3) != 1) |
528 |
> |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
529 |
> |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
530 |
> |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
531 |
|
return(-1); |
532 |
|
} |
533 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
< |
getcfloat(col, f1, f2, f3) /* get a float color value from stream(s) */ |
538 |
> |
getcfloat(col) /* get a float color value from stream(s) */ |
539 |
|
COLOR col; |
489 |
– |
FILE *f1, *f2, *f3; |
540 |
|
{ |
541 |
|
float vf[3]; |
542 |
|
|
543 |
< |
if (f2 == NULL) { |
544 |
< |
if (fread((char *)vf, sizeof(float), 3, f1) != 3) |
543 |
> |
if (fin2 == NULL) { |
544 |
> |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
545 |
|
return(-1); |
546 |
|
} else { |
547 |
< |
if (fread((char *)vf, sizeof(float), 1, f1) != 1 || |
548 |
< |
fread((char *)(vf+1), sizeof(float), 1, f2) != 1 || |
549 |
< |
fread((char *)(vf+2), sizeof(float), 1, f3) != 1) |
547 |
> |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
548 |
> |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
549 |
> |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
550 |
|
return(-1); |
551 |
|
} |
552 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
554 |
|
} |
555 |
|
|
556 |
|
|
557 |
< |
getcint(col, f1, f2, f3) /* get an int color value from stream(s) */ |
557 |
> |
getcint(col) /* get an int color value from stream(s) */ |
558 |
|
COLOR col; |
509 |
– |
FILE *f1, *f2, *f3; |
559 |
|
{ |
560 |
|
int vi[3]; |
561 |
|
|
562 |
< |
if (f2 == NULL) { |
563 |
< |
if (fscanf(f1, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
562 |
> |
if (fin2 == NULL) { |
563 |
> |
if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
564 |
|
return(-1); |
565 |
|
} else { |
566 |
< |
if (fscanf(f1, "%d", &vi[0]) != 1 || |
567 |
< |
fscanf(f2, "%d", &vi[1]) != 1 || |
568 |
< |
fscanf(f3, "%d", &vi[2]) != 1) |
566 |
> |
if (fscanf(fin, "%d", &vi[0]) != 1 || |
567 |
> |
fscanf(fin2, "%d", &vi[1]) != 1 || |
568 |
> |
fscanf(fin3, "%d", &vi[2]) != 1) |
569 |
|
return(-1); |
570 |
|
} |
571 |
|
setcolor(col, (vi[rord[RED]]+.5)/256., |
574 |
|
} |
575 |
|
|
576 |
|
|
577 |
< |
getcbyte(col, f1, f2, f3) /* get a byte color value from stream(s) */ |
577 |
> |
getcbyte(col) /* get a byte color value from stream(s) */ |
578 |
|
COLOR col; |
530 |
– |
FILE *f1, *f2, *f3; |
579 |
|
{ |
580 |
|
BYTE vb[3]; |
581 |
|
|
582 |
< |
if (f2 == NULL) { |
583 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, f1) != 3) |
582 |
> |
if (fin2 == NULL) { |
583 |
> |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
584 |
|
return(-1); |
585 |
|
} else { |
586 |
< |
if (fread((char *)vb, sizeof(BYTE), 1, f1) != 1 || |
587 |
< |
fread((char *)(vb+1), sizeof(BYTE), 1, f2) != 1 || |
588 |
< |
fread((char *)(vb+2), sizeof(BYTE), 1, f3) != 1) |
586 |
> |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
587 |
> |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
588 |
> |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
589 |
|
return(-1); |
590 |
|
} |
591 |
|
setcolor(col, (vb[rord[RED]]+.5)/256., |
594 |
|
} |
595 |
|
|
596 |
|
|
597 |
< |
getbascii(col, fp) /* get an ascii brightness value from fp */ |
597 |
> |
getbascii(col) /* get an ascii brightness value from fin */ |
598 |
|
COLOR col; |
551 |
– |
FILE *fp; |
599 |
|
{ |
600 |
|
double vd; |
601 |
|
|
602 |
< |
if (fscanf(fp, "%lf", &vd) != 1) |
602 |
> |
if (fscanf(fin, "%lf", &vd) != 1) |
603 |
|
return(-1); |
604 |
|
setcolor(col, vd, vd, vd); |
605 |
|
return(0); |
606 |
|
} |
607 |
|
|
608 |
|
|
609 |
< |
getbdouble(col, fp) /* get a double brightness value from fp */ |
609 |
> |
getbdouble(col) /* get a double brightness value from fin */ |
610 |
|
COLOR col; |
564 |
– |
FILE *fp; |
611 |
|
{ |
612 |
|
double vd; |
613 |
|
|
614 |
< |
if (fread((char *)&vd, sizeof(double), 1, fp) != 1) |
614 |
> |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
615 |
|
return(-1); |
616 |
|
setcolor(col, vd, vd, vd); |
617 |
|
return(0); |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
< |
getbfloat(col, fp) /* get a float brightness value from fp */ |
621 |
> |
getbfloat(col) /* get a float brightness value from fin */ |
622 |
|
COLOR col; |
577 |
– |
FILE *fp; |
623 |
|
{ |
624 |
|
float vf; |
625 |
|
|
626 |
< |
if (fread((char *)&vf, sizeof(float), 1, fp) != 1) |
626 |
> |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
627 |
|
return(-1); |
628 |
|
setcolor(col, vf, vf, vf); |
629 |
|
return(0); |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
< |
getbint(col, fp) /* get an int brightness value from fp */ |
633 |
> |
getbint(col) /* get an int brightness value from fin */ |
634 |
|
COLOR col; |
590 |
– |
FILE *fp; |
635 |
|
{ |
636 |
|
int vi; |
637 |
|
double d; |
638 |
|
|
639 |
< |
if (fscanf(fp, "%d", &vi) != 1) |
639 |
> |
if (fscanf(fin, "%d", &vi) != 1) |
640 |
|
return(-1); |
641 |
|
d = (vi+.5)/256.; |
642 |
|
setcolor(col, d, d, d); |
644 |
|
} |
645 |
|
|
646 |
|
|
647 |
< |
getbbyte(col, fp) /* get a byte brightness value from fp */ |
647 |
> |
getbbyte(col) /* get a byte brightness value from fin */ |
648 |
|
COLOR col; |
605 |
– |
FILE *fp; |
649 |
|
{ |
650 |
|
BYTE vb; |
651 |
|
double d; |
652 |
|
|
653 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) |
653 |
> |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
654 |
|
return(-1); |
655 |
|
d = (vb+.5)/256.; |
656 |
|
setcolor(col, d, d, d); |
658 |
|
} |
659 |
|
|
660 |
|
|
661 |
< |
putcascii(col, fp) /* put an ascii color to fp */ |
661 |
> |
putcascii(col) /* put an ascii color to stdout */ |
662 |
|
COLOR col; |
620 |
– |
FILE *fp; |
663 |
|
{ |
664 |
< |
fprintf(fp, "%15.3e %15.3e %15.3e\n", |
664 |
> |
fprintf(stdout, "%15.3e %15.3e %15.3e\n", |
665 |
|
colval(col,ord[0]), |
666 |
|
colval(col,ord[1]), |
667 |
|
colval(col,ord[2])); |
668 |
|
|
669 |
< |
return(ferror(fp) ? -1 : 0); |
669 |
> |
return(ferror(stdout) ? -1 : 0); |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
< |
putcfloat(col, fp) /* put a float color to fp */ |
673 |
> |
putcfloat(col) /* put a float color to stdout */ |
674 |
|
COLOR col; |
633 |
– |
FILE *fp; |
675 |
|
{ |
676 |
|
float vf[3]; |
677 |
|
|
678 |
|
vf[0] = colval(col,ord[0]); |
679 |
|
vf[1] = colval(col,ord[1]); |
680 |
|
vf[2] = colval(col,ord[2]); |
681 |
< |
fwrite((char *)vf, sizeof(float), 3, fp); |
681 |
> |
fwrite((char *)vf, sizeof(float), 3, stdout); |
682 |
|
|
683 |
< |
return(ferror(fp) ? -1 : 0); |
683 |
> |
return(ferror(stdout) ? -1 : 0); |
684 |
|
} |
685 |
|
|
686 |
|
|
687 |
< |
putcdouble(col, fp) /* put a double color to fp */ |
687 |
> |
putcdouble(col) /* put a double color to stdout */ |
688 |
|
COLOR col; |
648 |
– |
FILE *fp; |
689 |
|
{ |
690 |
|
double vd[3]; |
691 |
|
|
692 |
|
vd[0] = colval(col,ord[0]); |
693 |
|
vd[1] = colval(col,ord[1]); |
694 |
|
vd[2] = colval(col,ord[2]); |
695 |
< |
fwrite((char *)vd, sizeof(double), 3, fp); |
695 |
> |
fwrite((char *)vd, sizeof(double), 3, stdout); |
696 |
|
|
697 |
< |
return(ferror(fp) ? -1 : 0); |
697 |
> |
return(ferror(stdout) ? -1 : 0); |
698 |
|
} |
699 |
|
|
700 |
|
|
701 |
< |
putcint(col, fp) /* put an int color to fp */ |
701 |
> |
putcint(col) /* put an int color to stdout */ |
702 |
|
COLOR col; |
663 |
– |
FILE *fp; |
703 |
|
{ |
704 |
< |
fprintf(fp, "%d %d %d\n", |
704 |
> |
fprintf(stdout, "%d %d %d\n", |
705 |
|
(int)(colval(col,ord[0])*256.), |
706 |
|
(int)(colval(col,ord[1])*256.), |
707 |
|
(int)(colval(col,ord[2])*256.)); |
708 |
|
|
709 |
< |
return(ferror(fp) ? -1 : 0); |
709 |
> |
return(ferror(stdout) ? -1 : 0); |
710 |
|
} |
711 |
|
|
712 |
|
|
713 |
< |
putcbyte(col, fp) /* put a byte color to fp */ |
713 |
> |
putcbyte(col) /* put a byte color to stdout */ |
714 |
|
COLOR col; |
676 |
– |
FILE *fp; |
715 |
|
{ |
716 |
|
register int i; |
717 |
|
BYTE vb[3]; |
722 |
|
vb[1] = min(i,255); |
723 |
|
i = colval(col,ord[2])*256.; |
724 |
|
vb[2] = min(i,255); |
725 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, fp); |
725 |
> |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
726 |
|
|
727 |
< |
return(ferror(fp) ? -1 : 0); |
727 |
> |
return(ferror(stdout) ? -1 : 0); |
728 |
|
} |
729 |
|
|
730 |
|
|
731 |
< |
putbascii(col, fp) /* put an ascii brightness to fp */ |
731 |
> |
putbascii(col) /* put an ascii brightness to stdout */ |
732 |
|
COLOR col; |
695 |
– |
FILE *fp; |
733 |
|
{ |
734 |
< |
fprintf(fp, "%15.3e\n", bright(col)); |
734 |
> |
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
735 |
|
|
736 |
< |
return(ferror(fp) ? -1 : 0); |
736 |
> |
return(ferror(stdout) ? -1 : 0); |
737 |
|
} |
738 |
|
|
739 |
|
|
740 |
< |
putbfloat(col, fp) /* put a float brightness to fp */ |
740 |
> |
putbfloat(col) /* put a float brightness to stdout */ |
741 |
|
COLOR col; |
705 |
– |
FILE *fp; |
742 |
|
{ |
743 |
|
float vf; |
744 |
|
|
745 |
< |
vf = bright(col); |
746 |
< |
fwrite((char *)&vf, sizeof(float), 1, fp); |
745 |
> |
vf = (*mybright)(col); |
746 |
> |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
747 |
|
|
748 |
< |
return(ferror(fp) ? -1 : 0); |
748 |
> |
return(ferror(stdout) ? -1 : 0); |
749 |
|
} |
750 |
|
|
751 |
|
|
752 |
< |
putbdouble(col, fp) /* put a double brightness to fp */ |
752 |
> |
putbdouble(col) /* put a double brightness to stdout */ |
753 |
|
COLOR col; |
718 |
– |
FILE *fp; |
754 |
|
{ |
755 |
|
double vd; |
756 |
|
|
757 |
< |
vd = bright(col); |
758 |
< |
fwrite((char *)&vd, sizeof(double), 1, fp); |
757 |
> |
vd = (*mybright)(col); |
758 |
> |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
759 |
|
|
760 |
< |
return(ferror(fp) ? -1 : 0); |
760 |
> |
return(ferror(stdout) ? -1 : 0); |
761 |
|
} |
762 |
|
|
763 |
|
|
764 |
< |
putbint(col, fp) /* put an int brightness to fp */ |
764 |
> |
putbint(col) /* put an int brightness to stdout */ |
765 |
|
COLOR col; |
731 |
– |
FILE *fp; |
766 |
|
{ |
767 |
< |
fprintf(fp, "%d\n", (int)(bright(col)*256.)); |
767 |
> |
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
768 |
|
|
769 |
< |
return(ferror(fp) ? -1 : 0); |
769 |
> |
return(ferror(stdout) ? -1 : 0); |
770 |
|
} |
771 |
|
|
772 |
|
|
773 |
< |
putbbyte(col, fp) /* put a byte brightness to fp */ |
773 |
> |
putbbyte(col) /* put a byte brightness to stdout */ |
774 |
|
COLOR col; |
741 |
– |
FILE *fp; |
775 |
|
{ |
776 |
|
register int i; |
777 |
|
BYTE vb; |
778 |
|
|
779 |
< |
i = bright(col)*256.; |
779 |
> |
i = (*mybright)(col)*256.; |
780 |
|
vb = min(i,255); |
781 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
781 |
> |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
782 |
|
|
783 |
< |
return(ferror(fp) ? -1 : 0); |
783 |
> |
return(ferror(stdout) ? -1 : 0); |
784 |
|
} |
785 |
|
|
786 |
|
|
787 |
< |
putpascii(col, fp) /* put an ascii primary to fp */ |
787 |
> |
putpascii(col) /* put an ascii primary to stdout */ |
788 |
|
COLOR col; |
756 |
– |
FILE *fp; |
789 |
|
{ |
790 |
< |
fprintf(fp, "%15.3e\n", colval(col,putprim)); |
790 |
> |
fprintf(stdout, "%15.3e\n", colval(col,putprim)); |
791 |
|
|
792 |
< |
return(ferror(fp) ? -1 : 0); |
792 |
> |
return(ferror(stdout) ? -1 : 0); |
793 |
|
} |
794 |
|
|
795 |
|
|
796 |
< |
putpfloat(col, fp) /* put a float primary to fp */ |
796 |
> |
putpfloat(col) /* put a float primary to stdout */ |
797 |
|
COLOR col; |
766 |
– |
FILE *fp; |
798 |
|
{ |
799 |
|
float vf; |
800 |
|
|
801 |
|
vf = colval(col,putprim); |
802 |
< |
fwrite((char *)&vf, sizeof(float), 1, fp); |
802 |
> |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
803 |
|
|
804 |
< |
return(ferror(fp) ? -1 : 0); |
804 |
> |
return(ferror(stdout) ? -1 : 0); |
805 |
|
} |
806 |
|
|
807 |
|
|
808 |
< |
putpdouble(col, fp) /* put a double primary to fp */ |
808 |
> |
putpdouble(col) /* put a double primary to stdout */ |
809 |
|
COLOR col; |
779 |
– |
FILE *fp; |
810 |
|
{ |
811 |
|
double vd; |
812 |
|
|
813 |
|
vd = colval(col,putprim); |
814 |
< |
fwrite((char *)&vd, sizeof(double), 1, fp); |
814 |
> |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
815 |
|
|
816 |
< |
return(ferror(fp) ? -1 : 0); |
816 |
> |
return(ferror(stdout) ? -1 : 0); |
817 |
|
} |
818 |
|
|
819 |
|
|
820 |
< |
putpint(col, fp) /* put an int primary to fp */ |
820 |
> |
putpint(col) /* put an int primary to stdout */ |
821 |
|
COLOR col; |
792 |
– |
FILE *fp; |
822 |
|
{ |
823 |
< |
fprintf(fp, "%d\n", (int)(colval(col,putprim)*256.)); |
823 |
> |
fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); |
824 |
|
|
825 |
< |
return(ferror(fp) ? -1 : 0); |
825 |
> |
return(ferror(stdout) ? -1 : 0); |
826 |
|
} |
827 |
|
|
828 |
|
|
829 |
< |
putpbyte(col, fp) /* put a byte primary to fp */ |
829 |
> |
putpbyte(col) /* put a byte primary to stdout */ |
830 |
|
COLOR col; |
802 |
– |
FILE *fp; |
831 |
|
{ |
832 |
|
register int i; |
833 |
|
BYTE vb; |
834 |
|
|
835 |
|
i = colval(col,putprim)*256.; |
836 |
|
vb = min(i,255); |
837 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
837 |
> |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
838 |
|
|
839 |
< |
return(ferror(fp) ? -1 : 0); |
839 |
> |
return(ferror(stdout) ? -1 : 0); |
840 |
|
} |
841 |
|
|
842 |
|
|
853 |
|
} else { |
854 |
|
getval = getcascii; |
855 |
|
putval = putcascii; |
856 |
+ |
if (reverse && !interleave) { |
857 |
+ |
fprintf(stderr, |
858 |
+ |
"%s: ASCII input files must be interleaved\n", |
859 |
+ |
progname); |
860 |
+ |
quit(1); |
861 |
+ |
} |
862 |
|
} |
863 |
|
return; |
864 |
|
case 'f': /* binary float */ |
871 |
|
} else { |
872 |
|
getval = getcfloat; |
873 |
|
putval = putcfloat; |
874 |
+ |
if (reverse && !interleave) { |
875 |
+ |
if (fin2 == NULL) |
876 |
+ |
goto namerr; |
877 |
+ |
if (fseek(fin2, |
878 |
+ |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
879 |
+ |
goto seekerr; |
880 |
+ |
if (fseek(fin3, |
881 |
+ |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
882 |
+ |
goto seekerr; |
883 |
+ |
} |
884 |
|
} |
885 |
|
return; |
886 |
|
case 'd': /* binary double */ |
893 |
|
} else { |
894 |
|
getval = getcdouble; |
895 |
|
putval = putcdouble; |
896 |
+ |
if (reverse && !interleave) { |
897 |
+ |
if (fin2 == NULL) |
898 |
+ |
goto namerr; |
899 |
+ |
if (fseek(fin2, |
900 |
+ |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
901 |
+ |
goto seekerr; |
902 |
+ |
if (fseek(fin3, |
903 |
+ |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
904 |
+ |
goto seekerr; |
905 |
+ |
} |
906 |
|
} |
907 |
|
return; |
908 |
|
case 'i': /* integer */ |
915 |
|
} else { |
916 |
|
getval = getcint; |
917 |
|
putval = putcint; |
918 |
+ |
if (reverse && !interleave) { |
919 |
+ |
fprintf(stderr, |
920 |
+ |
"%s: integer input files must be interleaved\n", |
921 |
+ |
progname); |
922 |
+ |
quit(1); |
923 |
+ |
} |
924 |
|
} |
925 |
|
return; |
926 |
|
case 'b': /* byte */ |
933 |
|
} else { |
934 |
|
getval = getcbyte; |
935 |
|
putval = putcbyte; |
936 |
+ |
if (reverse && !interleave) { |
937 |
+ |
if (fin2 == NULL) |
938 |
+ |
goto namerr; |
939 |
+ |
if (fseek(fin2, |
940 |
+ |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
941 |
+ |
goto seekerr; |
942 |
+ |
if (fseek(fin3, |
943 |
+ |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
944 |
+ |
goto seekerr; |
945 |
+ |
} |
946 |
|
} |
947 |
|
return; |
948 |
|
} |
949 |
+ |
badopt: |
950 |
+ |
fprintf(stderr, "%s: botched file type\n", progname); |
951 |
+ |
quit(1); |
952 |
+ |
namerr: |
953 |
+ |
fprintf(stderr, "%s: non-interleaved file(s) must be named\n", |
954 |
+ |
progname); |
955 |
+ |
quit(1); |
956 |
+ |
seekerr: |
957 |
+ |
fprintf(stderr, "%s: cannot seek on interleaved input file\n", |
958 |
+ |
progname); |
959 |
+ |
quit(1); |
960 |
|
} |