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 |
+ |
RGBPRIMP outprims = stdprims; /* output primaries for reverse conversion */ |
40 |
+ |
RGBPRIMS myprims; |
41 |
+ |
|
42 |
|
int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ |
43 |
|
int rord[4]; /* reverse ordering */ |
44 |
|
|
49 |
|
FILE *fin; |
50 |
|
FILE *fin2 = NULL, *fin3 = NULL; /* for other color channels */ |
51 |
|
|
69 |
– |
int (*getval)(), (*putval)(); |
52 |
|
|
53 |
< |
double |
54 |
< |
rgb_bright(clr) |
55 |
< |
COLOR clr; |
53 |
> |
typedef int getfunc_t(COLOR col); |
54 |
> |
typedef int putfunc_t(COLOR col); |
55 |
> |
typedef double brightfunc_t(COLOR col); |
56 |
> |
|
57 |
> |
getfunc_t *getval; |
58 |
> |
putfunc_t *putval; |
59 |
> |
brightfunc_t *mybright; |
60 |
> |
|
61 |
> |
static gethfunc checkhead; |
62 |
> |
static brightfunc_t rgb_bright, xyz_bright; |
63 |
> |
static getfunc_t getbascii, getbint, getbdouble, getbfloat, getbbyte, getbword; |
64 |
> |
static getfunc_t getcascii, getcint, getcdouble, getcfloat, getcbyte, getcword; |
65 |
> |
static putfunc_t putbascii, putbint, putbdouble, putbfloat, putbbyte, putbword; |
66 |
> |
static putfunc_t putcascii, putcint, putcdouble, putcfloat, putcbyte, putcword; |
67 |
> |
static putfunc_t putpascii, putpint, putpdouble, putpfloat, putpbyte, putpword; |
68 |
> |
|
69 |
> |
static void set_io(void); |
70 |
> |
static void pixtoval(void); |
71 |
> |
static void valtopix(void); |
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] == '+') |
149 |
|
case 'b': /* brightness values */ |
150 |
|
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
151 |
|
break; |
152 |
< |
case 'p': /* put primary */ |
152 |
> |
case 'p': /* primary controls */ |
153 |
|
switch (argv[i][2]) { |
154 |
+ |
/* these two options affect -r conversion */ |
155 |
+ |
case '\0': |
156 |
+ |
myprims[RED][CIEX] = atof(argv[++i]); |
157 |
+ |
myprims[RED][CIEY] = atof(argv[++i]); |
158 |
+ |
myprims[GRN][CIEX] = atof(argv[++i]); |
159 |
+ |
myprims[GRN][CIEY] = atof(argv[++i]); |
160 |
+ |
myprims[BLU][CIEX] = atof(argv[++i]); |
161 |
+ |
myprims[BLU][CIEY] = atof(argv[++i]); |
162 |
+ |
myprims[WHT][CIEX] = atof(argv[++i]); |
163 |
+ |
myprims[WHT][CIEY] = atof(argv[++i]); |
164 |
+ |
outprims = myprims; |
165 |
+ |
break; |
166 |
+ |
case 'x': case 'X': outprims = NULL; break; |
167 |
+ |
/* the following options affect +r only */ |
168 |
|
case 'r': case 'R': putprim = RED; break; |
169 |
|
case 'g': case 'G': putprim = GRN; break; |
170 |
|
case 'b': case 'B': putprim = BLU; break; |
195 |
|
format = 'w'; |
196 |
|
fmtid = "16-bit"; |
197 |
|
break; |
198 |
+ |
case 'F': /* swapped floats */ |
199 |
+ |
swapbytes = 1; |
200 |
|
case 'f': /* float */ |
201 |
|
dataonly = 1; |
202 |
|
format = 'f'; |
203 |
|
fmtid = "float"; |
204 |
|
break; |
205 |
+ |
case 'D': /* swapped doubles */ |
206 |
+ |
swapbytes = 1; |
207 |
|
case 'd': /* double */ |
208 |
|
dataonly = 1; |
209 |
|
format = 'd'; |
239 |
|
else |
240 |
|
break; |
241 |
|
/* recognize special formats */ |
242 |
< |
if (dataonly && format == 'b') |
243 |
< |
if (brightonly) |
223 |
< |
fmtid = "8-bit_grey"; |
224 |
< |
else |
242 |
> |
if (dataonly && format == 'b') { |
243 |
> |
if (putprim == ALL) |
244 |
|
fmtid = "24-bit_rgb"; |
226 |
– |
if (dataonly && format == 'w') |
227 |
– |
if (brightonly) |
228 |
– |
fmtid = "16-bit_grey"; |
245 |
|
else |
246 |
+ |
fmtid = "8-bit_grey"; |
247 |
+ |
} |
248 |
+ |
if (dataonly && format == 'w') { |
249 |
+ |
if (putprim == ALL) |
250 |
|
fmtid = "48-bit_rgb"; |
251 |
+ |
else |
252 |
+ |
fmtid = "16-bit_grey"; |
253 |
+ |
} |
254 |
|
/* assign reverse ordering */ |
255 |
|
rord[ord[0]] = 0; |
256 |
|
rord[ord[1]] = 1; |
264 |
|
progname, argv[i]); |
265 |
|
quit(1); |
266 |
|
} |
267 |
< |
if (reverse && !brightonly && i == argc-3) { |
267 |
> |
if (reverse && putprim != BRIGHT && i == argc-3) { |
268 |
|
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
269 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
270 |
|
progname, argv[i+1]); |
278 |
|
interleave = -1; |
279 |
|
} else if (i != argc-1) |
280 |
|
fin = NULL; |
281 |
< |
if (reverse && !brightonly && !interleave) { |
281 |
> |
if (reverse && putprim != BRIGHT && !interleave) { |
282 |
|
fin2 = fopen(argv[i], "r"); |
283 |
|
fin3 = fopen(argv[i], "r"); |
284 |
|
} |
296 |
|
} |
297 |
|
|
298 |
|
if (reverse) { |
299 |
< |
#ifdef MSDOS |
300 |
< |
setmode(fileno(stdout), O_BINARY); |
299 |
> |
#if defined(_WIN32) || defined(_WIN64) |
300 |
> |
SET_FILE_BINARY(stdout); |
301 |
|
if (format != 'a' && format != 'i') |
302 |
< |
setmode(fileno(fin), O_BINARY); |
302 |
> |
SET_FILE_BINARY(fin); |
303 |
|
#endif |
304 |
|
/* get header */ |
305 |
|
if (header) { |
339 |
|
printargs(i, argv, stdout); |
340 |
|
if (expval < .99 || expval > 1.01) |
341 |
|
fputexpos(expval, stdout); |
342 |
< |
fputformat(COLRFMT, stdout); |
342 |
> |
if (outprims != NULL) { |
343 |
> |
if (outprims != stdprims) |
344 |
> |
fputprims(outprims, stdout); |
345 |
> |
fputformat(COLRFMT, stdout); |
346 |
> |
} else /* XYZ data */ |
347 |
> |
fputformat(CIEFMT, stdout); |
348 |
|
putchar('\n'); |
349 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
350 |
|
valtopix(); |
351 |
|
} else { |
352 |
< |
#ifdef MSDOS |
353 |
< |
setmode(fileno(fin), O_BINARY); |
352 |
> |
#if defined(_WIN32) || defined(_WIN64) |
353 |
> |
SET_FILE_BINARY(fin); |
354 |
|
if (format != 'a' && format != 'i') |
355 |
< |
setmode(fileno(stdout), O_BINARY); |
355 |
> |
SET_FILE_BINARY(stdout); |
356 |
|
#endif |
357 |
|
/* get header */ |
358 |
|
getheader(fin, checkhead, NULL); |
379 |
|
} |
380 |
|
|
381 |
|
quit(0); |
382 |
+ |
return 0; /* pro forma return */ |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
< |
int |
387 |
< |
checkhead(line) /* deal with line from header */ |
388 |
< |
char *line; |
386 |
> |
static int |
387 |
> |
checkhead( /* deal with line from header */ |
388 |
> |
char *line, |
389 |
> |
void *p |
390 |
> |
) |
391 |
|
{ |
392 |
< |
char fmt[32]; |
392 |
> |
char fmt[MAXFMTLEN]; |
393 |
|
double d; |
394 |
|
COLOR ctmp; |
395 |
|
|
396 |
|
if (formatval(fmt, line)) { |
397 |
< |
if (!strcmp(fmt, CIEFMT)) { |
397 |
> |
if (!strcmp(fmt, CIEFMT)) |
398 |
|
mybright = &xyz_bright; |
399 |
< |
if (original) { |
369 |
< |
scalecolor(exposure, 1./WHTEFFICACY); |
370 |
< |
doexposure++; |
371 |
< |
} |
372 |
< |
} else if (!strcmp(fmt, COLRFMT)) |
399 |
> |
else if (!strcmp(fmt, COLRFMT)) |
400 |
|
mybright = &rgb_bright; |
401 |
|
else |
402 |
|
wrongformat++; |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
< |
pixtoval() /* convert picture to values */ |
419 |
> |
static void |
420 |
> |
pixtoval(void) /* convert picture to values */ |
421 |
|
{ |
422 |
< |
register COLOR *scanln; |
422 |
> |
COLOR *scanln; |
423 |
|
int dogamma; |
424 |
|
COLOR lastc; |
425 |
< |
FLOAT hv[2]; |
425 |
> |
RREAL hv[2]; |
426 |
|
int startprim, endprim; |
427 |
|
long startpos; |
428 |
< |
int y; |
401 |
< |
register int x; |
428 |
> |
int x, y; |
429 |
|
|
430 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
431 |
|
if (scanln == NULL) { |
453 |
|
quit(1); |
454 |
|
} |
455 |
|
for (x = 0; x < scanlen(&picres); x++) { |
456 |
< |
if (uniq) |
456 |
> |
if (uniq) { |
457 |
|
if ( colval(scanln[x],RED) == |
458 |
|
colval(lastc,RED) && |
459 |
|
colval(scanln[x],GRN) == |
463 |
|
continue; |
464 |
|
else |
465 |
|
copycolor(lastc, scanln[x]); |
466 |
+ |
} |
467 |
|
if (doexposure) |
468 |
|
multcolor(scanln[x], exposure); |
469 |
|
if (dogamma) |
489 |
|
} |
490 |
|
|
491 |
|
|
492 |
< |
valtopix() /* convert values to a pixel file */ |
492 |
> |
static void |
493 |
> |
valtopix(void) /* convert values to a pixel file */ |
494 |
|
{ |
495 |
< |
int dogamma; |
496 |
< |
register COLOR *scanln; |
497 |
< |
int y; |
498 |
< |
register int x; |
495 |
> |
int dogamma; |
496 |
> |
COLOR *scanln; |
497 |
> |
COLR rgbe; |
498 |
> |
int x, y; |
499 |
|
|
500 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
501 |
|
if (scanln == NULL) { |
524 |
|
pow(colval(scanln[x],BLU), gamcor)); |
525 |
|
if (doexposure) |
526 |
|
multcolor(scanln[x], exposure); |
527 |
+ |
if (uniq) { /* uncompressed? */ |
528 |
+ |
setcolr(rgbe, scanln[x][RED], |
529 |
+ |
scanln[x][GRN], |
530 |
+ |
scanln[x][BLU]); |
531 |
+ |
if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1) |
532 |
+ |
goto writerr; |
533 |
+ |
} |
534 |
|
} |
535 |
< |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
536 |
< |
fprintf(stderr, "%s: write error\n", progname); |
537 |
< |
quit(1); |
502 |
< |
} |
535 |
> |
/* write scan if compressed */ |
536 |
> |
if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0) |
537 |
> |
goto writerr; |
538 |
|
} |
539 |
|
free((void *)scanln); |
540 |
+ |
return; |
541 |
+ |
writerr: |
542 |
+ |
fprintf(stderr, "%s: write error\n", progname); |
543 |
+ |
quit(1); |
544 |
|
} |
545 |
|
|
546 |
|
|
552 |
|
} |
553 |
|
|
554 |
|
|
555 |
< |
swap16(wp, n) /* swap n 16-bit words */ |
556 |
< |
register uint16 *wp; |
557 |
< |
int n; |
555 |
> |
static int |
556 |
> |
getcascii( /* get an ascii color value from stream(s) */ |
557 |
> |
COLOR col |
558 |
> |
) |
559 |
|
{ |
520 |
– |
while (n-- > 0) { |
521 |
– |
*wp = *wp << 8 | ((*wp >> 8) & 0xff); |
522 |
– |
wp++; |
523 |
– |
} |
524 |
– |
} |
525 |
– |
|
526 |
– |
getcascii(col) /* get an ascii color value from stream(s) */ |
527 |
– |
COLOR col; |
528 |
– |
{ |
560 |
|
double vd[3]; |
561 |
|
|
562 |
|
if (fin2 == NULL) { |
573 |
|
} |
574 |
|
|
575 |
|
|
576 |
< |
getcdouble(col) /* get a double color value from stream(s) */ |
577 |
< |
COLOR col; |
576 |
> |
static int |
577 |
> |
getcdouble( /* get a double color value from stream(s) */ |
578 |
> |
COLOR col |
579 |
> |
) |
580 |
|
{ |
581 |
|
double vd[3]; |
582 |
|
|
583 |
|
if (fin2 == NULL) { |
584 |
< |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
584 |
> |
if (getbinary(vd, sizeof(double), 3, fin) != 3) |
585 |
|
return(-1); |
586 |
|
} else { |
587 |
< |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
588 |
< |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
589 |
< |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
587 |
> |
if (getbinary(vd, sizeof(double), 1, fin) != 1 || |
588 |
> |
getbinary(vd+1, sizeof(double), 1, fin2) != 1 || |
589 |
> |
getbinary(vd+2, sizeof(double), 1, fin3) != 1) |
590 |
|
return(-1); |
591 |
|
} |
592 |
+ |
if (swapbytes) |
593 |
+ |
swap64((char *)vd, 3); |
594 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
595 |
|
return(0); |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
< |
getcfloat(col) /* get a float color value from stream(s) */ |
600 |
< |
COLOR col; |
599 |
> |
static int |
600 |
> |
getcfloat( /* get a float color value from stream(s) */ |
601 |
> |
COLOR col |
602 |
> |
) |
603 |
|
{ |
604 |
|
float vf[3]; |
605 |
|
|
606 |
|
if (fin2 == NULL) { |
607 |
< |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
607 |
> |
if (getbinary(vf, sizeof(float), 3, fin) != 3) |
608 |
|
return(-1); |
609 |
|
} else { |
610 |
< |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
611 |
< |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
612 |
< |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
610 |
> |
if (getbinary(vf, sizeof(float), 1, fin) != 1 || |
611 |
> |
getbinary(vf+1, sizeof(float), 1, fin2) != 1 || |
612 |
> |
getbinary(vf+2, sizeof(float), 1, fin3) != 1) |
613 |
|
return(-1); |
614 |
|
} |
615 |
+ |
if (swapbytes) |
616 |
+ |
swap32((char *)vf, 3); |
617 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
618 |
|
return(0); |
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
< |
getcint(col) /* get an int color value from stream(s) */ |
623 |
< |
COLOR col; |
622 |
> |
static int |
623 |
> |
getcint( /* get an int color value from stream(s) */ |
624 |
> |
COLOR col |
625 |
> |
) |
626 |
|
{ |
627 |
|
int vi[3]; |
628 |
|
|
641 |
|
} |
642 |
|
|
643 |
|
|
644 |
< |
getcbyte(col) /* get a byte color value from stream(s) */ |
645 |
< |
COLOR col; |
644 |
> |
static int |
645 |
> |
getcbyte( /* get a byte color value from stream(s) */ |
646 |
> |
COLOR col |
647 |
> |
) |
648 |
|
{ |
649 |
< |
BYTE vb[3]; |
649 |
> |
uby8 vb[3]; |
650 |
|
|
651 |
|
if (fin2 == NULL) { |
652 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
652 |
> |
if (getbinary(vb, sizeof(uby8), 3, fin) != 3) |
653 |
|
return(-1); |
654 |
|
} else { |
655 |
< |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
656 |
< |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
657 |
< |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
655 |
> |
if (getbinary(vb, sizeof(uby8), 1, fin) != 1 || |
656 |
> |
getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 || |
657 |
> |
getbinary(vb+2, sizeof(uby8), 1, fin3) != 1) |
658 |
|
return(-1); |
659 |
|
} |
660 |
|
setcolor(col, (vb[rord[RED]]+.5)/256., |
663 |
|
} |
664 |
|
|
665 |
|
|
666 |
< |
getcword(col) /* get a 16-bit color value from stream(s) */ |
667 |
< |
COLOR col; |
666 |
> |
static int |
667 |
> |
getcword( /* get a 16-bit color value from stream(s) */ |
668 |
> |
COLOR col |
669 |
> |
) |
670 |
|
{ |
671 |
|
uint16 vw[3]; |
672 |
|
|
673 |
|
if (fin2 == NULL) { |
674 |
< |
if (fread((char *)vw, sizeof(uint16), 3, fin) != 3) |
674 |
> |
if (getbinary(vw, sizeof(uint16), 3, fin) != 3) |
675 |
|
return(-1); |
676 |
|
} else { |
677 |
< |
if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 || |
678 |
< |
fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 || |
679 |
< |
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
677 |
> |
if (getbinary(vw, sizeof(uint16), 1, fin) != 1 || |
678 |
> |
getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 || |
679 |
> |
getbinary(vw+2, sizeof(uint16), 1, fin3) != 1) |
680 |
|
return(-1); |
681 |
|
} |
682 |
|
if (swapbytes) |
683 |
< |
swap16(vw, 3); |
683 |
> |
swap16((char *)vw, 3); |
684 |
|
setcolor(col, (vw[rord[RED]]+.5)/65536., |
685 |
|
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
686 |
|
return(0); |
687 |
|
} |
688 |
|
|
689 |
|
|
690 |
< |
getbascii(col) /* get an ascii brightness value from fin */ |
691 |
< |
COLOR col; |
690 |
> |
static int |
691 |
> |
getbascii( /* get an ascii brightness value from fin */ |
692 |
> |
COLOR col |
693 |
> |
) |
694 |
|
{ |
695 |
|
double vd; |
696 |
|
|
701 |
|
} |
702 |
|
|
703 |
|
|
704 |
< |
getbdouble(col) /* get a double brightness value from fin */ |
705 |
< |
COLOR col; |
704 |
> |
static int |
705 |
> |
getbdouble( /* get a double brightness value from fin */ |
706 |
> |
COLOR col |
707 |
> |
) |
708 |
|
{ |
709 |
|
double vd; |
710 |
|
|
711 |
< |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
711 |
> |
if (getbinary(&vd, sizeof(double), 1, fin) != 1) |
712 |
|
return(-1); |
713 |
+ |
if (swapbytes) |
714 |
+ |
swap64((char *)&vd, 1); |
715 |
|
setcolor(col, vd, vd, vd); |
716 |
|
return(0); |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
< |
getbfloat(col) /* get a float brightness value from fin */ |
721 |
< |
COLOR col; |
720 |
> |
static int |
721 |
> |
getbfloat( /* get a float brightness value from fin */ |
722 |
> |
COLOR col |
723 |
> |
) |
724 |
|
{ |
725 |
|
float vf; |
726 |
|
|
727 |
< |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
727 |
> |
if (getbinary(&vf, sizeof(float), 1, fin) != 1) |
728 |
|
return(-1); |
729 |
+ |
if (swapbytes) |
730 |
+ |
swap32((char *)&vf, 1); |
731 |
|
setcolor(col, vf, vf, vf); |
732 |
|
return(0); |
733 |
|
} |
734 |
|
|
735 |
|
|
736 |
< |
getbint(col) /* get an int brightness value from fin */ |
737 |
< |
COLOR col; |
736 |
> |
static int |
737 |
> |
getbint( /* get an int brightness value from fin */ |
738 |
> |
COLOR col |
739 |
> |
) |
740 |
|
{ |
741 |
|
int vi; |
742 |
|
double d; |
749 |
|
} |
750 |
|
|
751 |
|
|
752 |
< |
getbbyte(col) /* get a byte brightness value from fin */ |
753 |
< |
COLOR col; |
752 |
> |
static int |
753 |
> |
getbbyte( /* get a byte brightness value from fin */ |
754 |
> |
COLOR col |
755 |
> |
) |
756 |
|
{ |
757 |
< |
BYTE vb; |
757 |
> |
uby8 vb; |
758 |
|
double d; |
759 |
|
|
760 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
760 |
> |
if (getbinary(&vb, sizeof(uby8), 1, fin) != 1) |
761 |
|
return(-1); |
762 |
|
d = (vb+.5)/256.; |
763 |
|
setcolor(col, d, d, d); |
765 |
|
} |
766 |
|
|
767 |
|
|
768 |
< |
getbword(col) /* get a 16-bit brightness value from fin */ |
769 |
< |
COLOR col; |
768 |
> |
static int |
769 |
> |
getbword( /* get a 16-bit brightness value from fin */ |
770 |
> |
COLOR col |
771 |
> |
) |
772 |
|
{ |
773 |
|
uint16 vw; |
774 |
|
double d; |
775 |
|
|
776 |
< |
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
776 |
> |
if (getbinary(&vw, sizeof(uint16), 1, fin) != 1) |
777 |
|
return(-1); |
778 |
|
if (swapbytes) |
779 |
< |
swap16(&vw, 1); |
779 |
> |
swap16((char *)&vw, 1); |
780 |
|
d = (vw+.5)/65536.; |
781 |
|
setcolor(col, d, d, d); |
782 |
|
return(0); |
783 |
|
} |
784 |
|
|
785 |
|
|
786 |
< |
putcascii(col) /* put an ascii color to stdout */ |
787 |
< |
COLOR col; |
786 |
> |
static int |
787 |
> |
putcascii( /* put an ascii color to stdout */ |
788 |
> |
COLOR col |
789 |
> |
) |
790 |
|
{ |
791 |
|
fprintf(stdout, "%15.3e %15.3e %15.3e\n", |
792 |
|
colval(col,ord[0]), |
797 |
|
} |
798 |
|
|
799 |
|
|
800 |
< |
putcfloat(col) /* put a float color to stdout */ |
801 |
< |
COLOR col; |
800 |
> |
static int |
801 |
> |
putcfloat( /* put a float color to stdout */ |
802 |
> |
COLOR col |
803 |
> |
) |
804 |
|
{ |
805 |
|
float vf[3]; |
806 |
|
|
807 |
|
vf[0] = colval(col,ord[0]); |
808 |
|
vf[1] = colval(col,ord[1]); |
809 |
|
vf[2] = colval(col,ord[2]); |
810 |
< |
fwrite((char *)vf, sizeof(float), 3, stdout); |
810 |
> |
if (swapbytes) |
811 |
> |
swap32((char *)vf, 3); |
812 |
> |
putbinary(vf, sizeof(float), 3, stdout); |
813 |
|
|
814 |
|
return(ferror(stdout) ? -1 : 0); |
815 |
|
} |
816 |
|
|
817 |
|
|
818 |
< |
putcdouble(col) /* put a double color to stdout */ |
819 |
< |
COLOR col; |
818 |
> |
static int |
819 |
> |
putcdouble( /* put a double color to stdout */ |
820 |
> |
COLOR col |
821 |
> |
) |
822 |
|
{ |
823 |
|
double vd[3]; |
824 |
|
|
825 |
|
vd[0] = colval(col,ord[0]); |
826 |
|
vd[1] = colval(col,ord[1]); |
827 |
|
vd[2] = colval(col,ord[2]); |
828 |
< |
fwrite((char *)vd, sizeof(double), 3, stdout); |
828 |
> |
if (swapbytes) |
829 |
> |
swap64((char *)vd, 3); |
830 |
> |
putbinary(vd, sizeof(double), 3, stdout); |
831 |
|
|
832 |
|
return(ferror(stdout) ? -1 : 0); |
833 |
|
} |
834 |
|
|
835 |
|
|
836 |
< |
putcint(col) /* put an int color to stdout */ |
837 |
< |
COLOR col; |
836 |
> |
static int |
837 |
> |
putcint( /* put an int color to stdout */ |
838 |
> |
COLOR col |
839 |
> |
) |
840 |
|
{ |
841 |
|
fprintf(stdout, "%d %d %d\n", |
842 |
|
(int)(colval(col,ord[0])*256.), |
847 |
|
} |
848 |
|
|
849 |
|
|
850 |
< |
putcbyte(col) /* put a byte color to stdout */ |
851 |
< |
COLOR col; |
850 |
> |
static int |
851 |
> |
putcbyte( /* put a byte color to stdout */ |
852 |
> |
COLOR col |
853 |
> |
) |
854 |
|
{ |
855 |
|
long i; |
856 |
< |
BYTE vb[3]; |
856 |
> |
uby8 vb[3]; |
857 |
|
|
858 |
|
i = colval(col,ord[0])*256.; |
859 |
|
vb[0] = min(i,255); |
861 |
|
vb[1] = min(i,255); |
862 |
|
i = colval(col,ord[2])*256.; |
863 |
|
vb[2] = min(i,255); |
864 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
864 |
> |
putbinary(vb, sizeof(uby8), 3, stdout); |
865 |
|
|
866 |
|
return(ferror(stdout) ? -1 : 0); |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
< |
putcword(col) /* put a 16-bit color to stdout */ |
871 |
< |
COLOR col; |
870 |
> |
static int |
871 |
> |
putcword( /* put a 16-bit color to stdout */ |
872 |
> |
COLOR col |
873 |
> |
) |
874 |
|
{ |
875 |
|
long i; |
876 |
|
uint16 vw[3]; |
882 |
|
i = colval(col,ord[2])*65536.; |
883 |
|
vw[2] = min(i,65535); |
884 |
|
if (swapbytes) |
885 |
< |
swap16(vw, 3); |
886 |
< |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
885 |
> |
swap16((char *)vw, 3); |
886 |
> |
putbinary(vw, sizeof(uint16), 3, stdout); |
887 |
|
|
888 |
|
return(ferror(stdout) ? -1 : 0); |
889 |
|
} |
890 |
|
|
891 |
|
|
892 |
< |
putbascii(col) /* put an ascii brightness to stdout */ |
893 |
< |
COLOR col; |
892 |
> |
static int |
893 |
> |
putbascii( /* put an ascii brightness to stdout */ |
894 |
> |
COLOR col |
895 |
> |
) |
896 |
|
{ |
897 |
|
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
898 |
|
|
900 |
|
} |
901 |
|
|
902 |
|
|
903 |
< |
putbfloat(col) /* put a float brightness to stdout */ |
904 |
< |
COLOR col; |
903 |
> |
static int |
904 |
> |
putbfloat( /* put a float brightness to stdout */ |
905 |
> |
COLOR col |
906 |
> |
) |
907 |
|
{ |
908 |
|
float vf; |
909 |
|
|
910 |
|
vf = (*mybright)(col); |
911 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
911 |
> |
if (swapbytes) |
912 |
> |
swap32((char *)&vf, 1); |
913 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
914 |
|
|
915 |
|
return(ferror(stdout) ? -1 : 0); |
916 |
|
} |
917 |
|
|
918 |
|
|
919 |
< |
putbdouble(col) /* put a double brightness to stdout */ |
920 |
< |
COLOR col; |
919 |
> |
static int |
920 |
> |
putbdouble( /* put a double brightness to stdout */ |
921 |
> |
COLOR col |
922 |
> |
) |
923 |
|
{ |
924 |
|
double vd; |
925 |
|
|
926 |
|
vd = (*mybright)(col); |
927 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
927 |
> |
if (swapbytes) |
928 |
> |
swap64((char *)&vd, 1); |
929 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
930 |
|
|
931 |
|
return(ferror(stdout) ? -1 : 0); |
932 |
|
} |
933 |
|
|
934 |
|
|
935 |
< |
putbint(col) /* put an int brightness to stdout */ |
936 |
< |
COLOR col; |
935 |
> |
static int |
936 |
> |
putbint( /* put an int brightness to stdout */ |
937 |
> |
COLOR col |
938 |
> |
) |
939 |
|
{ |
940 |
|
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
941 |
|
|
943 |
|
} |
944 |
|
|
945 |
|
|
946 |
< |
putbbyte(col) /* put a byte brightness to stdout */ |
947 |
< |
COLOR col; |
946 |
> |
static int |
947 |
> |
putbbyte( /* put a byte brightness to stdout */ |
948 |
> |
COLOR col |
949 |
> |
) |
950 |
|
{ |
951 |
< |
register int i; |
952 |
< |
BYTE vb; |
951 |
> |
int i; |
952 |
> |
uby8 vb; |
953 |
|
|
954 |
|
i = (*mybright)(col)*256.; |
955 |
|
vb = min(i,255); |
956 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
956 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
957 |
|
|
958 |
|
return(ferror(stdout) ? -1 : 0); |
959 |
|
} |
960 |
|
|
961 |
|
|
962 |
< |
putbword(col) /* put a 16-bit brightness to stdout */ |
963 |
< |
COLOR col; |
962 |
> |
static int |
963 |
> |
putbword( /* put a 16-bit brightness to stdout */ |
964 |
> |
COLOR col |
965 |
> |
) |
966 |
|
{ |
967 |
|
long i; |
968 |
|
uint16 vw; |
970 |
|
i = (*mybright)(col)*65536.; |
971 |
|
vw = min(i,65535); |
972 |
|
if (swapbytes) |
973 |
< |
swap16(&vw, 1); |
974 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
973 |
> |
swap16((char *)&vw, 1); |
974 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
975 |
|
|
976 |
|
return(ferror(stdout) ? -1 : 0); |
977 |
|
} |
978 |
|
|
979 |
|
|
980 |
< |
putpascii(col) /* put an ascii primary to stdout */ |
981 |
< |
COLOR col; |
980 |
> |
static int |
981 |
> |
putpascii( /* put an ascii primary to stdout */ |
982 |
> |
COLOR col |
983 |
> |
) |
984 |
|
{ |
985 |
|
fprintf(stdout, "%15.3e\n", colval(col,putprim)); |
986 |
|
|
988 |
|
} |
989 |
|
|
990 |
|
|
991 |
< |
putpfloat(col) /* put a float primary to stdout */ |
992 |
< |
COLOR col; |
991 |
> |
static int |
992 |
> |
putpfloat( /* put a float primary to stdout */ |
993 |
> |
COLOR col |
994 |
> |
) |
995 |
|
{ |
996 |
|
float vf; |
997 |
|
|
998 |
|
vf = colval(col,putprim); |
999 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
999 |
> |
if (swapbytes) |
1000 |
> |
swap32((char *)&vf, 1); |
1001 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
1002 |
|
|
1003 |
|
return(ferror(stdout) ? -1 : 0); |
1004 |
|
} |
1005 |
|
|
1006 |
|
|
1007 |
< |
putpdouble(col) /* put a double primary to stdout */ |
1008 |
< |
COLOR col; |
1007 |
> |
static int |
1008 |
> |
putpdouble( /* put a double primary to stdout */ |
1009 |
> |
COLOR col |
1010 |
> |
) |
1011 |
|
{ |
1012 |
|
double vd; |
1013 |
|
|
1014 |
|
vd = colval(col,putprim); |
1015 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
1015 |
> |
if (swapbytes) |
1016 |
> |
swap64((char *)&vd, 1); |
1017 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
1018 |
|
|
1019 |
|
return(ferror(stdout) ? -1 : 0); |
1020 |
|
} |
1021 |
|
|
1022 |
|
|
1023 |
< |
putpint(col) /* put an int primary to stdout */ |
1024 |
< |
COLOR col; |
1023 |
> |
static int |
1024 |
> |
putpint( /* put an int primary to stdout */ |
1025 |
> |
COLOR col |
1026 |
> |
) |
1027 |
|
{ |
1028 |
|
fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); |
1029 |
|
|
1031 |
|
} |
1032 |
|
|
1033 |
|
|
1034 |
< |
putpbyte(col) /* put a byte primary to stdout */ |
1035 |
< |
COLOR col; |
1034 |
> |
static int |
1035 |
> |
putpbyte( /* put a byte primary to stdout */ |
1036 |
> |
COLOR col |
1037 |
> |
) |
1038 |
|
{ |
1039 |
|
long i; |
1040 |
< |
BYTE vb; |
1040 |
> |
uby8 vb; |
1041 |
|
|
1042 |
|
i = colval(col,putprim)*256.; |
1043 |
|
vb = min(i,255); |
1044 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
1044 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
1045 |
|
|
1046 |
|
return(ferror(stdout) ? -1 : 0); |
1047 |
|
} |
1048 |
|
|
1049 |
|
|
1050 |
< |
putpword(col) /* put a 16-bit primary to stdout */ |
1051 |
< |
COLOR col; |
1050 |
> |
static int |
1051 |
> |
putpword( /* put a 16-bit primary to stdout */ |
1052 |
> |
COLOR col |
1053 |
> |
) |
1054 |
|
{ |
1055 |
|
long i; |
1056 |
|
uint16 vw; |
1058 |
|
i = colval(col,putprim)*65536.; |
1059 |
|
vw = min(i,65535); |
1060 |
|
if (swapbytes) |
1061 |
< |
swap16(&vw, 1); |
1062 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
1061 |
> |
swap16((char *)&vw, 1); |
1062 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
1063 |
|
|
1064 |
|
return(ferror(stdout) ? -1 : 0); |
1065 |
|
} |
1066 |
|
|
1067 |
|
|
1068 |
< |
set_io() /* set put and get functions */ |
1068 |
> |
static void |
1069 |
> |
set_io(void) /* set put and get functions */ |
1070 |
|
{ |
1071 |
|
switch (format) { |
1072 |
|
case 'a': /* ascii */ |
1163 |
|
if (fin2 == NULL) |
1164 |
|
goto namerr; |
1165 |
|
if (fseek(fin2, |
1166 |
< |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
1166 |
> |
(long)sizeof(uby8)*picres.xr*picres.yr, 1)) |
1167 |
|
goto seekerr; |
1168 |
|
if (fseek(fin3, |
1169 |
< |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
1169 |
> |
(long)sizeof(uby8)*2*picres.xr*picres.yr, 1)) |
1170 |
|
goto seekerr; |
1171 |
|
} |
1172 |
|
} |
1194 |
|
} |
1195 |
|
return; |
1196 |
|
} |
1197 |
< |
badopt: |
1197 |
> |
/* badopt: */ /* label not used */ |
1198 |
|
fprintf(stderr, "%s: botched file type\n", progname); |
1199 |
|
quit(1); |
1200 |
|
namerr: |