| 7 |
|
* 4/23/86 |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
+ |
#include "platform.h" |
| 11 |
|
#include "standard.h" |
| 11 |
– |
|
| 12 |
|
#include "color.h" |
| 13 |
– |
|
| 14 |
– |
#include <time.h> |
| 15 |
– |
|
| 13 |
|
#include "resolu.h" |
| 14 |
+ |
#include "view.h" |
| 15 |
|
|
| 18 |
– |
typedef unsigned short uint16; /* sizeof (uint16) must == 2 */ |
| 19 |
– |
|
| 16 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
| 17 |
|
|
| 18 |
|
/* what to put out (also RED, GRN, BLU) */ |
| 19 |
|
#define ALL 3 |
| 20 |
|
#define BRIGHT 4 |
| 21 |
|
|
| 26 |
– |
#define brightonly (putprim==BRIGHT) |
| 27 |
– |
|
| 22 |
|
RESOLU picres; /* resolution of picture */ |
| 29 |
– |
|
| 23 |
|
int uniq = 0; /* print only unique values? */ |
| 31 |
– |
|
| 24 |
|
int doexposure = 0; /* exposure change? (>100 to print) */ |
| 33 |
– |
|
| 25 |
|
int dataonly = 0; /* data only format? */ |
| 35 |
– |
|
| 26 |
|
int putprim = ALL; /* what to put out */ |
| 37 |
– |
|
| 27 |
|
int reverse = 0; /* reverse conversion? */ |
| 39 |
– |
|
| 28 |
|
int format = 'a'; /* input/output format */ |
| 29 |
|
char *fmtid = "ascii"; /* format identifier for header */ |
| 42 |
– |
|
| 30 |
|
int header = 1; /* do header? */ |
| 44 |
– |
|
| 31 |
|
long skipbytes = 0; /* skip bytes in input? */ |
| 32 |
< |
|
| 47 |
< |
int swapbytes = 0; /* swap bytes in 16-bit words? */ |
| 48 |
< |
|
| 32 |
> |
int swapbytes = 0; /* swap bytes? */ |
| 33 |
|
int interleave = 1; /* file is interleaved? */ |
| 50 |
– |
|
| 34 |
|
int resolution = 1; /* put/get resolution string? */ |
| 52 |
– |
|
| 35 |
|
int original = 0; /* convert to original values? */ |
| 54 |
– |
|
| 36 |
|
int wrongformat = 0; /* wrong input format? */ |
| 56 |
– |
|
| 37 |
|
double gamcor = 1.0; /* gamma correction */ |
| 38 |
|
|
| 39 |
|
int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ |
| 46 |
|
FILE *fin; |
| 47 |
|
FILE *fin2 = NULL, *fin3 = NULL; /* for other color channels */ |
| 48 |
|
|
| 69 |
– |
int (*getval)(), (*putval)(); |
| 49 |
|
|
| 50 |
< |
double |
| 51 |
< |
rgb_bright(clr) |
| 52 |
< |
COLOR clr; |
| 50 |
> |
typedef int getfunc_t(COLOR col); |
| 51 |
> |
typedef int putfunc_t(COLOR col); |
| 52 |
> |
typedef double brightfunc_t(COLOR col); |
| 53 |
> |
|
| 54 |
> |
getfunc_t *getval; |
| 55 |
> |
putfunc_t *putval; |
| 56 |
> |
brightfunc_t *mybright; |
| 57 |
> |
|
| 58 |
> |
static gethfunc checkhead; |
| 59 |
> |
static brightfunc_t rgb_bright, xyz_bright; |
| 60 |
> |
static getfunc_t getbascii, getbint, getbdouble, getbfloat, getbbyte, getbword; |
| 61 |
> |
static getfunc_t getcascii, getcint, getcdouble, getcfloat, getcbyte, getcword; |
| 62 |
> |
static putfunc_t putbascii, putbint, putbdouble, putbfloat, putbbyte, putbword; |
| 63 |
> |
static putfunc_t putcascii, putcint, putcdouble, putcfloat, putcbyte, putcword; |
| 64 |
> |
static putfunc_t putpascii, putpint, putpdouble, putpfloat, putpbyte, putpword; |
| 65 |
> |
|
| 66 |
> |
static void set_io(void); |
| 67 |
> |
static void pixtoval(void); |
| 68 |
> |
static void valtopix(void); |
| 69 |
> |
static void swap16(uint16 *wp, int n); |
| 70 |
> |
static void swap32(uint32 *wp, int n); |
| 71 |
> |
static void swap64(char *wp, int n); |
| 72 |
> |
|
| 73 |
> |
|
| 74 |
> |
static double |
| 75 |
> |
rgb_bright( |
| 76 |
> |
COLOR clr |
| 77 |
> |
) |
| 78 |
|
{ |
| 79 |
|
return(bright(clr)); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
< |
double |
| 83 |
< |
xyz_bright(clr) |
| 84 |
< |
COLOR clr; |
| 82 |
> |
static double |
| 83 |
> |
xyz_bright( |
| 84 |
> |
COLOR clr |
| 85 |
> |
) |
| 86 |
|
{ |
| 87 |
|
return(clr[CIEY]); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
< |
double (*mybright)() = &rgb_bright; |
| 91 |
< |
|
| 92 |
< |
|
| 93 |
< |
main(argc, argv) |
| 94 |
< |
int argc; |
| 90 |
< |
char **argv; |
| 90 |
> |
int |
| 91 |
> |
main( |
| 92 |
> |
int argc, |
| 93 |
> |
char **argv |
| 94 |
> |
) |
| 95 |
|
{ |
| 92 |
– |
extern int checkhead(); |
| 93 |
– |
extern long atol(); |
| 96 |
|
double d, expval = 1.0; |
| 97 |
|
int i; |
| 98 |
|
|
| 99 |
|
progname = argv[0]; |
| 100 |
+ |
mybright = &rgb_bright; /* default */ |
| 101 |
|
|
| 102 |
|
for (i = 1; i < argc; i++) |
| 103 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
| 181 |
|
format = 'w'; |
| 182 |
|
fmtid = "16-bit"; |
| 183 |
|
break; |
| 184 |
+ |
case 'F': /* swapped floats */ |
| 185 |
+ |
swapbytes = 1; |
| 186 |
|
case 'f': /* float */ |
| 187 |
|
dataonly = 1; |
| 188 |
|
format = 'f'; |
| 189 |
|
fmtid = "float"; |
| 190 |
|
break; |
| 191 |
+ |
case 'D': /* swapped doubles */ |
| 192 |
+ |
swapbytes = 1; |
| 193 |
|
case 'd': /* double */ |
| 194 |
|
dataonly = 1; |
| 195 |
|
format = 'd'; |
| 225 |
|
else |
| 226 |
|
break; |
| 227 |
|
/* recognize special formats */ |
| 228 |
< |
if (dataonly && format == 'b') |
| 229 |
< |
if (brightonly) |
| 223 |
< |
fmtid = "8-bit_grey"; |
| 224 |
< |
else |
| 228 |
> |
if (dataonly && format == 'b') { |
| 229 |
> |
if (putprim == ALL) |
| 230 |
|
fmtid = "24-bit_rgb"; |
| 226 |
– |
if (dataonly && format == 'w') |
| 227 |
– |
if (brightonly) |
| 228 |
– |
fmtid = "16-bit_grey"; |
| 231 |
|
else |
| 232 |
+ |
fmtid = "8-bit_grey"; |
| 233 |
+ |
} |
| 234 |
+ |
if (dataonly && format == 'w') { |
| 235 |
+ |
if (putprim == ALL) |
| 236 |
|
fmtid = "48-bit_rgb"; |
| 237 |
+ |
else |
| 238 |
+ |
fmtid = "16-bit_grey"; |
| 239 |
+ |
} |
| 240 |
|
/* assign reverse ordering */ |
| 241 |
|
rord[ord[0]] = 0; |
| 242 |
|
rord[ord[1]] = 1; |
| 250 |
|
progname, argv[i]); |
| 251 |
|
quit(1); |
| 252 |
|
} |
| 253 |
< |
if (reverse && !brightonly && i == argc-3) { |
| 253 |
> |
if (reverse && putprim != BRIGHT && i == argc-3) { |
| 254 |
|
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
| 255 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
| 256 |
|
progname, argv[i+1]); |
| 264 |
|
interleave = -1; |
| 265 |
|
} else if (i != argc-1) |
| 266 |
|
fin = NULL; |
| 267 |
< |
if (reverse && !brightonly && !interleave) { |
| 267 |
> |
if (reverse && putprim != BRIGHT && !interleave) { |
| 268 |
|
fin2 = fopen(argv[i], "r"); |
| 269 |
|
fin3 = fopen(argv[i], "r"); |
| 270 |
|
} |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
if (reverse) { |
| 285 |
< |
#ifdef MSDOS |
| 286 |
< |
setmode(fileno(stdout), O_BINARY); |
| 285 |
> |
#ifdef _WIN32 |
| 286 |
> |
SET_FILE_BINARY(stdout); |
| 287 |
|
if (format != 'a' && format != 'i') |
| 288 |
< |
setmode(fileno(fin), O_BINARY); |
| 288 |
> |
SET_FILE_BINARY(fin); |
| 289 |
|
#endif |
| 290 |
|
/* get header */ |
| 291 |
|
if (header) { |
| 330 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
| 331 |
|
valtopix(); |
| 332 |
|
} else { |
| 333 |
< |
#ifdef MSDOS |
| 334 |
< |
setmode(fileno(fin), O_BINARY); |
| 333 |
> |
#ifdef _WIN32 |
| 334 |
> |
SET_FILE_BINARY(fin); |
| 335 |
|
if (format != 'a' && format != 'i') |
| 336 |
< |
setmode(fileno(stdout), O_BINARY); |
| 336 |
> |
SET_FILE_BINARY(stdout); |
| 337 |
|
#endif |
| 338 |
|
/* get header */ |
| 339 |
|
getheader(fin, checkhead, NULL); |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
quit(0); |
| 363 |
+ |
return 0; /* pro forma return */ |
| 364 |
|
} |
| 365 |
|
|
| 366 |
|
|
| 367 |
< |
int |
| 368 |
< |
checkhead(line) /* deal with line from header */ |
| 369 |
< |
char *line; |
| 367 |
> |
static int |
| 368 |
> |
checkhead( /* deal with line from header */ |
| 369 |
> |
char *line, |
| 370 |
> |
void *p |
| 371 |
> |
) |
| 372 |
|
{ |
| 373 |
|
char fmt[32]; |
| 374 |
|
double d; |
| 375 |
|
COLOR ctmp; |
| 376 |
|
|
| 377 |
|
if (formatval(fmt, line)) { |
| 378 |
< |
if (!strcmp(fmt, CIEFMT)) { |
| 378 |
> |
if (!strcmp(fmt, CIEFMT)) |
| 379 |
|
mybright = &xyz_bright; |
| 380 |
< |
if (original) { |
| 369 |
< |
scalecolor(exposure, 1./WHTEFFICACY); |
| 370 |
< |
doexposure++; |
| 371 |
< |
} |
| 372 |
< |
} else if (!strcmp(fmt, COLRFMT)) |
| 380 |
> |
else if (!strcmp(fmt, COLRFMT)) |
| 381 |
|
mybright = &rgb_bright; |
| 382 |
|
else |
| 383 |
|
wrongformat++; |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 400 |
< |
pixtoval() /* convert picture to values */ |
| 400 |
> |
static void |
| 401 |
> |
pixtoval(void) /* convert picture to values */ |
| 402 |
|
{ |
| 403 |
|
register COLOR *scanln; |
| 404 |
|
int dogamma; |
| 405 |
|
COLOR lastc; |
| 406 |
< |
FLOAT hv[2]; |
| 406 |
> |
RREAL hv[2]; |
| 407 |
|
int startprim, endprim; |
| 408 |
|
long startpos; |
| 409 |
|
int y; |
| 435 |
|
quit(1); |
| 436 |
|
} |
| 437 |
|
for (x = 0; x < scanlen(&picres); x++) { |
| 438 |
< |
if (uniq) |
| 438 |
> |
if (uniq) { |
| 439 |
|
if ( colval(scanln[x],RED) == |
| 440 |
|
colval(lastc,RED) && |
| 441 |
|
colval(scanln[x],GRN) == |
| 445 |
|
continue; |
| 446 |
|
else |
| 447 |
|
copycolor(lastc, scanln[x]); |
| 448 |
+ |
} |
| 449 |
|
if (doexposure) |
| 450 |
|
multcolor(scanln[x], exposure); |
| 451 |
|
if (dogamma) |
| 471 |
|
} |
| 472 |
|
|
| 473 |
|
|
| 474 |
< |
valtopix() /* convert values to a pixel file */ |
| 474 |
> |
static void |
| 475 |
> |
valtopix(void) /* convert values to a pixel file */ |
| 476 |
|
{ |
| 477 |
|
int dogamma; |
| 478 |
|
register COLOR *scanln; |
| 524 |
|
} |
| 525 |
|
|
| 526 |
|
|
| 527 |
< |
swap16(wp, n) /* swap n 16-bit words */ |
| 528 |
< |
register uint16 *wp; |
| 529 |
< |
int n; |
| 527 |
> |
static void |
| 528 |
> |
swap16( /* swap n 16-bit words */ |
| 529 |
> |
register uint16 *wp, |
| 530 |
> |
int n |
| 531 |
> |
) |
| 532 |
|
{ |
| 533 |
|
while (n-- > 0) { |
| 534 |
|
*wp = *wp << 8 | ((*wp >> 8) & 0xff); |
| 536 |
|
} |
| 537 |
|
} |
| 538 |
|
|
| 539 |
< |
getcascii(col) /* get an ascii color value from stream(s) */ |
| 540 |
< |
COLOR col; |
| 539 |
> |
|
| 540 |
> |
static void |
| 541 |
> |
swap32( /* swap n 32-bit words */ |
| 542 |
> |
register uint32 *wp, |
| 543 |
> |
int n |
| 544 |
> |
) |
| 545 |
|
{ |
| 546 |
+ |
while (n-- > 0) { |
| 547 |
+ |
*wp = *wp << 24 | ((*wp >> 24) & 0xff) | |
| 548 |
+ |
(*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8; |
| 549 |
+ |
wp++; |
| 550 |
+ |
} |
| 551 |
+ |
} |
| 552 |
+ |
|
| 553 |
+ |
|
| 554 |
+ |
static void |
| 555 |
+ |
swap64( /* swap n 64-bit words */ |
| 556 |
+ |
register char *wp, |
| 557 |
+ |
int n |
| 558 |
+ |
) |
| 559 |
+ |
{ |
| 560 |
+ |
register int t; |
| 561 |
+ |
|
| 562 |
+ |
while (n-- > 0) { |
| 563 |
+ |
t = wp[0]; wp[0] = wp[7]; wp[7] = t; |
| 564 |
+ |
t = wp[1]; wp[1] = wp[6]; wp[6] = t; |
| 565 |
+ |
t = wp[2]; wp[2] = wp[5]; wp[5] = t; |
| 566 |
+ |
t = wp[3]; wp[3] = wp[4]; wp[4] = t; |
| 567 |
+ |
wp += 8; |
| 568 |
+ |
} |
| 569 |
+ |
} |
| 570 |
+ |
|
| 571 |
+ |
|
| 572 |
+ |
static int |
| 573 |
+ |
getcascii( /* get an ascii color value from stream(s) */ |
| 574 |
+ |
COLOR col |
| 575 |
+ |
) |
| 576 |
+ |
{ |
| 577 |
|
double vd[3]; |
| 578 |
|
|
| 579 |
|
if (fin2 == NULL) { |
| 590 |
|
} |
| 591 |
|
|
| 592 |
|
|
| 593 |
< |
getcdouble(col) /* get a double color value from stream(s) */ |
| 594 |
< |
COLOR col; |
| 593 |
> |
static int |
| 594 |
> |
getcdouble( /* get a double color value from stream(s) */ |
| 595 |
> |
COLOR col |
| 596 |
> |
) |
| 597 |
|
{ |
| 598 |
|
double vd[3]; |
| 599 |
|
|
| 606 |
|
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
| 607 |
|
return(-1); |
| 608 |
|
} |
| 609 |
+ |
if (swapbytes) |
| 610 |
+ |
swap64((char *)vd, 3); |
| 611 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
| 612 |
|
return(0); |
| 613 |
|
} |
| 614 |
|
|
| 615 |
|
|
| 616 |
< |
getcfloat(col) /* get a float color value from stream(s) */ |
| 617 |
< |
COLOR col; |
| 616 |
> |
static int |
| 617 |
> |
getcfloat( /* get a float color value from stream(s) */ |
| 618 |
> |
COLOR col |
| 619 |
> |
) |
| 620 |
|
{ |
| 621 |
|
float vf[3]; |
| 622 |
|
|
| 629 |
|
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
| 630 |
|
return(-1); |
| 631 |
|
} |
| 632 |
+ |
if (swapbytes) |
| 633 |
+ |
swap32((uint32 *)vf, 3); |
| 634 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
| 635 |
|
return(0); |
| 636 |
|
} |
| 637 |
|
|
| 638 |
|
|
| 639 |
< |
getcint(col) /* get an int color value from stream(s) */ |
| 640 |
< |
COLOR col; |
| 639 |
> |
static int |
| 640 |
> |
getcint( /* get an int color value from stream(s) */ |
| 641 |
> |
COLOR col |
| 642 |
> |
) |
| 643 |
|
{ |
| 644 |
|
int vi[3]; |
| 645 |
|
|
| 658 |
|
} |
| 659 |
|
|
| 660 |
|
|
| 661 |
< |
getcbyte(col) /* get a byte color value from stream(s) */ |
| 662 |
< |
COLOR col; |
| 661 |
> |
static int |
| 662 |
> |
getcbyte( /* get a byte color value from stream(s) */ |
| 663 |
> |
COLOR col |
| 664 |
> |
) |
| 665 |
|
{ |
| 666 |
|
BYTE vb[3]; |
| 667 |
|
|
| 680 |
|
} |
| 681 |
|
|
| 682 |
|
|
| 683 |
< |
getcword(col) /* get a 16-bit color value from stream(s) */ |
| 684 |
< |
COLOR col; |
| 683 |
> |
static int |
| 684 |
> |
getcword( /* get a 16-bit color value from stream(s) */ |
| 685 |
> |
COLOR col |
| 686 |
> |
) |
| 687 |
|
{ |
| 688 |
|
uint16 vw[3]; |
| 689 |
|
|
| 704 |
|
} |
| 705 |
|
|
| 706 |
|
|
| 707 |
< |
getbascii(col) /* get an ascii brightness value from fin */ |
| 708 |
< |
COLOR col; |
| 707 |
> |
static int |
| 708 |
> |
getbascii( /* get an ascii brightness value from fin */ |
| 709 |
> |
COLOR col |
| 710 |
> |
) |
| 711 |
|
{ |
| 712 |
|
double vd; |
| 713 |
|
|
| 718 |
|
} |
| 719 |
|
|
| 720 |
|
|
| 721 |
< |
getbdouble(col) /* get a double brightness value from fin */ |
| 722 |
< |
COLOR col; |
| 721 |
> |
static int |
| 722 |
> |
getbdouble( /* get a double brightness value from fin */ |
| 723 |
> |
COLOR col |
| 724 |
> |
) |
| 725 |
|
{ |
| 726 |
|
double vd; |
| 727 |
|
|
| 728 |
|
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
| 729 |
|
return(-1); |
| 730 |
+ |
if (swapbytes) |
| 731 |
+ |
swap64((char *)&vd, 1); |
| 732 |
|
setcolor(col, vd, vd, vd); |
| 733 |
|
return(0); |
| 734 |
|
} |
| 735 |
|
|
| 736 |
|
|
| 737 |
< |
getbfloat(col) /* get a float brightness value from fin */ |
| 738 |
< |
COLOR col; |
| 737 |
> |
static int |
| 738 |
> |
getbfloat( /* get a float brightness value from fin */ |
| 739 |
> |
COLOR col |
| 740 |
> |
) |
| 741 |
|
{ |
| 742 |
|
float vf; |
| 743 |
|
|
| 744 |
|
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
| 745 |
|
return(-1); |
| 746 |
+ |
if (swapbytes) |
| 747 |
+ |
swap32((uint32 *)&vf, 1); |
| 748 |
|
setcolor(col, vf, vf, vf); |
| 749 |
|
return(0); |
| 750 |
|
} |
| 751 |
|
|
| 752 |
|
|
| 753 |
< |
getbint(col) /* get an int brightness value from fin */ |
| 754 |
< |
COLOR col; |
| 753 |
> |
static int |
| 754 |
> |
getbint( /* get an int brightness value from fin */ |
| 755 |
> |
COLOR col |
| 756 |
> |
) |
| 757 |
|
{ |
| 758 |
|
int vi; |
| 759 |
|
double d; |
| 766 |
|
} |
| 767 |
|
|
| 768 |
|
|
| 769 |
< |
getbbyte(col) /* get a byte brightness value from fin */ |
| 770 |
< |
COLOR col; |
| 769 |
> |
static int |
| 770 |
> |
getbbyte( /* get a byte brightness value from fin */ |
| 771 |
> |
COLOR col |
| 772 |
> |
) |
| 773 |
|
{ |
| 774 |
|
BYTE vb; |
| 775 |
|
double d; |
| 782 |
|
} |
| 783 |
|
|
| 784 |
|
|
| 785 |
< |
getbword(col) /* get a 16-bit brightness value from fin */ |
| 786 |
< |
COLOR col; |
| 785 |
> |
static int |
| 786 |
> |
getbword( /* get a 16-bit brightness value from fin */ |
| 787 |
> |
COLOR col |
| 788 |
> |
) |
| 789 |
|
{ |
| 790 |
|
uint16 vw; |
| 791 |
|
double d; |
| 800 |
|
} |
| 801 |
|
|
| 802 |
|
|
| 803 |
< |
putcascii(col) /* put an ascii color to stdout */ |
| 804 |
< |
COLOR col; |
| 803 |
> |
static int |
| 804 |
> |
putcascii( /* put an ascii color to stdout */ |
| 805 |
> |
COLOR col |
| 806 |
> |
) |
| 807 |
|
{ |
| 808 |
|
fprintf(stdout, "%15.3e %15.3e %15.3e\n", |
| 809 |
|
colval(col,ord[0]), |
| 814 |
|
} |
| 815 |
|
|
| 816 |
|
|
| 817 |
< |
putcfloat(col) /* put a float color to stdout */ |
| 818 |
< |
COLOR col; |
| 817 |
> |
static int |
| 818 |
> |
putcfloat( /* put a float color to stdout */ |
| 819 |
> |
COLOR col |
| 820 |
> |
) |
| 821 |
|
{ |
| 822 |
|
float vf[3]; |
| 823 |
|
|
| 824 |
|
vf[0] = colval(col,ord[0]); |
| 825 |
|
vf[1] = colval(col,ord[1]); |
| 826 |
|
vf[2] = colval(col,ord[2]); |
| 827 |
+ |
if (swapbytes) |
| 828 |
+ |
swap32((uint32 *)vf, 3); |
| 829 |
|
fwrite((char *)vf, sizeof(float), 3, stdout); |
| 830 |
|
|
| 831 |
|
return(ferror(stdout) ? -1 : 0); |
| 832 |
|
} |
| 833 |
|
|
| 834 |
|
|
| 835 |
< |
putcdouble(col) /* put a double color to stdout */ |
| 836 |
< |
COLOR col; |
| 835 |
> |
static int |
| 836 |
> |
putcdouble( /* put a double color to stdout */ |
| 837 |
> |
COLOR col |
| 838 |
> |
) |
| 839 |
|
{ |
| 840 |
|
double vd[3]; |
| 841 |
|
|
| 842 |
|
vd[0] = colval(col,ord[0]); |
| 843 |
|
vd[1] = colval(col,ord[1]); |
| 844 |
|
vd[2] = colval(col,ord[2]); |
| 845 |
+ |
if (swapbytes) |
| 846 |
+ |
swap64((char *)vd, 3); |
| 847 |
|
fwrite((char *)vd, sizeof(double), 3, stdout); |
| 848 |
|
|
| 849 |
|
return(ferror(stdout) ? -1 : 0); |
| 850 |
|
} |
| 851 |
|
|
| 852 |
|
|
| 853 |
< |
putcint(col) /* put an int color to stdout */ |
| 854 |
< |
COLOR col; |
| 853 |
> |
static int |
| 854 |
> |
putcint( /* put an int color to stdout */ |
| 855 |
> |
COLOR col |
| 856 |
> |
) |
| 857 |
|
{ |
| 858 |
|
fprintf(stdout, "%d %d %d\n", |
| 859 |
|
(int)(colval(col,ord[0])*256.), |
| 864 |
|
} |
| 865 |
|
|
| 866 |
|
|
| 867 |
< |
putcbyte(col) /* put a byte color to stdout */ |
| 868 |
< |
COLOR col; |
| 867 |
> |
static int |
| 868 |
> |
putcbyte( /* put a byte color to stdout */ |
| 869 |
> |
COLOR col |
| 870 |
> |
) |
| 871 |
|
{ |
| 872 |
|
long i; |
| 873 |
|
BYTE vb[3]; |
| 884 |
|
} |
| 885 |
|
|
| 886 |
|
|
| 887 |
< |
putcword(col) /* put a 16-bit color to stdout */ |
| 888 |
< |
COLOR col; |
| 887 |
> |
static int |
| 888 |
> |
putcword( /* put a 16-bit color to stdout */ |
| 889 |
> |
COLOR col |
| 890 |
> |
) |
| 891 |
|
{ |
| 892 |
|
long i; |
| 893 |
|
uint16 vw[3]; |
| 906 |
|
} |
| 907 |
|
|
| 908 |
|
|
| 909 |
< |
putbascii(col) /* put an ascii brightness to stdout */ |
| 910 |
< |
COLOR col; |
| 909 |
> |
static int |
| 910 |
> |
putbascii( /* put an ascii brightness to stdout */ |
| 911 |
> |
COLOR col |
| 912 |
> |
) |
| 913 |
|
{ |
| 914 |
|
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
| 915 |
|
|
| 917 |
|
} |
| 918 |
|
|
| 919 |
|
|
| 920 |
< |
putbfloat(col) /* put a float brightness to stdout */ |
| 921 |
< |
COLOR col; |
| 920 |
> |
static int |
| 921 |
> |
putbfloat( /* put a float brightness to stdout */ |
| 922 |
> |
COLOR col |
| 923 |
> |
) |
| 924 |
|
{ |
| 925 |
|
float vf; |
| 926 |
|
|
| 927 |
|
vf = (*mybright)(col); |
| 928 |
+ |
if (swapbytes) |
| 929 |
+ |
swap32((uint32 *)&vf, 1); |
| 930 |
|
fwrite((char *)&vf, sizeof(float), 1, stdout); |
| 931 |
|
|
| 932 |
|
return(ferror(stdout) ? -1 : 0); |
| 933 |
|
} |
| 934 |
|
|
| 935 |
|
|
| 936 |
< |
putbdouble(col) /* put a double brightness to stdout */ |
| 937 |
< |
COLOR col; |
| 936 |
> |
static int |
| 937 |
> |
putbdouble( /* put a double brightness to stdout */ |
| 938 |
> |
COLOR col |
| 939 |
> |
) |
| 940 |
|
{ |
| 941 |
|
double vd; |
| 942 |
|
|
| 943 |
|
vd = (*mybright)(col); |
| 944 |
+ |
if (swapbytes) |
| 945 |
+ |
swap64((char *)&vd, 1); |
| 946 |
|
fwrite((char *)&vd, sizeof(double), 1, stdout); |
| 947 |
|
|
| 948 |
|
return(ferror(stdout) ? -1 : 0); |
| 949 |
|
} |
| 950 |
|
|
| 951 |
|
|
| 952 |
< |
putbint(col) /* put an int brightness to stdout */ |
| 953 |
< |
COLOR col; |
| 952 |
> |
static int |
| 953 |
> |
putbint( /* put an int brightness to stdout */ |
| 954 |
> |
COLOR col |
| 955 |
> |
) |
| 956 |
|
{ |
| 957 |
|
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
| 958 |
|
|
| 960 |
|
} |
| 961 |
|
|
| 962 |
|
|
| 963 |
< |
putbbyte(col) /* put a byte brightness to stdout */ |
| 964 |
< |
COLOR col; |
| 963 |
> |
static int |
| 964 |
> |
putbbyte( /* put a byte brightness to stdout */ |
| 965 |
> |
COLOR col |
| 966 |
> |
) |
| 967 |
|
{ |
| 968 |
|
register int i; |
| 969 |
|
BYTE vb; |
| 976 |
|
} |
| 977 |
|
|
| 978 |
|
|
| 979 |
< |
putbword(col) /* put a 16-bit brightness to stdout */ |
| 980 |
< |
COLOR col; |
| 979 |
> |
static int |
| 980 |
> |
putbword( /* put a 16-bit brightness to stdout */ |
| 981 |
> |
COLOR col |
| 982 |
> |
) |
| 983 |
|
{ |
| 984 |
|
long i; |
| 985 |
|
uint16 vw; |
| 994 |
|
} |
| 995 |
|
|
| 996 |
|
|
| 997 |
< |
putpascii(col) /* put an ascii primary to stdout */ |
| 998 |
< |
COLOR col; |
| 997 |
> |
static int |
| 998 |
> |
putpascii( /* put an ascii primary to stdout */ |
| 999 |
> |
COLOR col |
| 1000 |
> |
) |
| 1001 |
|
{ |
| 1002 |
|
fprintf(stdout, "%15.3e\n", colval(col,putprim)); |
| 1003 |
|
|
| 1005 |
|
} |
| 1006 |
|
|
| 1007 |
|
|
| 1008 |
< |
putpfloat(col) /* put a float primary to stdout */ |
| 1009 |
< |
COLOR col; |
| 1008 |
> |
static int |
| 1009 |
> |
putpfloat( /* put a float primary to stdout */ |
| 1010 |
> |
COLOR col |
| 1011 |
> |
) |
| 1012 |
|
{ |
| 1013 |
|
float vf; |
| 1014 |
|
|
| 1015 |
|
vf = colval(col,putprim); |
| 1016 |
+ |
if (swapbytes) |
| 1017 |
+ |
swap32((uint32 *)&vf, 1); |
| 1018 |
|
fwrite((char *)&vf, sizeof(float), 1, stdout); |
| 1019 |
|
|
| 1020 |
|
return(ferror(stdout) ? -1 : 0); |
| 1021 |
|
} |
| 1022 |
|
|
| 1023 |
|
|
| 1024 |
< |
putpdouble(col) /* put a double primary to stdout */ |
| 1025 |
< |
COLOR col; |
| 1024 |
> |
static int |
| 1025 |
> |
putpdouble( /* put a double primary to stdout */ |
| 1026 |
> |
COLOR col |
| 1027 |
> |
) |
| 1028 |
|
{ |
| 1029 |
|
double vd; |
| 1030 |
|
|
| 1031 |
|
vd = colval(col,putprim); |
| 1032 |
+ |
if (swapbytes) |
| 1033 |
+ |
swap64((char *)&vd, 1); |
| 1034 |
|
fwrite((char *)&vd, sizeof(double), 1, stdout); |
| 1035 |
|
|
| 1036 |
|
return(ferror(stdout) ? -1 : 0); |
| 1037 |
|
} |
| 1038 |
|
|
| 1039 |
|
|
| 1040 |
< |
putpint(col) /* put an int primary to stdout */ |
| 1041 |
< |
COLOR col; |
| 1040 |
> |
static int |
| 1041 |
> |
putpint( /* put an int primary to stdout */ |
| 1042 |
> |
COLOR col |
| 1043 |
> |
) |
| 1044 |
|
{ |
| 1045 |
|
fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); |
| 1046 |
|
|
| 1048 |
|
} |
| 1049 |
|
|
| 1050 |
|
|
| 1051 |
< |
putpbyte(col) /* put a byte primary to stdout */ |
| 1052 |
< |
COLOR col; |
| 1051 |
> |
static int |
| 1052 |
> |
putpbyte( /* put a byte primary to stdout */ |
| 1053 |
> |
COLOR col |
| 1054 |
> |
) |
| 1055 |
|
{ |
| 1056 |
|
long i; |
| 1057 |
|
BYTE vb; |
| 1064 |
|
} |
| 1065 |
|
|
| 1066 |
|
|
| 1067 |
< |
putpword(col) /* put a 16-bit primary to stdout */ |
| 1068 |
< |
COLOR col; |
| 1067 |
> |
static int |
| 1068 |
> |
putpword( /* put a 16-bit primary to stdout */ |
| 1069 |
> |
COLOR col |
| 1070 |
> |
) |
| 1071 |
|
{ |
| 1072 |
|
long i; |
| 1073 |
|
uint16 vw; |
| 1082 |
|
} |
| 1083 |
|
|
| 1084 |
|
|
| 1085 |
< |
set_io() /* set put and get functions */ |
| 1085 |
> |
static void |
| 1086 |
> |
set_io(void) /* set put and get functions */ |
| 1087 |
|
{ |
| 1088 |
|
switch (format) { |
| 1089 |
|
case 'a': /* ascii */ |
| 1211 |
|
} |
| 1212 |
|
return; |
| 1213 |
|
} |
| 1214 |
< |
badopt: |
| 1214 |
> |
/* badopt: */ /* label not used */ |
| 1215 |
|
fprintf(stderr, "%s: botched file type\n", progname); |
| 1216 |
|
quit(1); |
| 1217 |
|
namerr: |