36 |
|
int wrongformat = 0; /* wrong input format? */ |
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 |
|
|
69 |
|
static void set_io(void); |
70 |
|
static void pixtoval(void); |
71 |
|
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 |
93 |
|
char **argv |
94 |
|
) |
95 |
|
{ |
96 |
< |
double d, expval = 1.0; |
97 |
< |
int i; |
96 |
> |
const char *inpmode = "r"; |
97 |
> |
double d, expval = 1.0; |
98 |
> |
int i; |
99 |
|
|
100 |
|
progname = argv[0]; |
101 |
|
mybright = &rgb_bright; /* default */ |
150 |
|
case 'b': /* brightness values */ |
151 |
|
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
152 |
|
break; |
153 |
< |
case 'p': /* put primary */ |
153 |
> |
case 'p': /* primary controls */ |
154 |
|
switch (argv[i][2]) { |
155 |
+ |
/* these two options affect -r conversion */ |
156 |
+ |
case '\0': |
157 |
+ |
myprims[RED][CIEX] = atof(argv[++i]); |
158 |
+ |
myprims[RED][CIEY] = atof(argv[++i]); |
159 |
+ |
myprims[GRN][CIEX] = atof(argv[++i]); |
160 |
+ |
myprims[GRN][CIEY] = atof(argv[++i]); |
161 |
+ |
myprims[BLU][CIEX] = atof(argv[++i]); |
162 |
+ |
myprims[BLU][CIEY] = atof(argv[++i]); |
163 |
+ |
myprims[WHT][CIEX] = atof(argv[++i]); |
164 |
+ |
myprims[WHT][CIEY] = atof(argv[++i]); |
165 |
+ |
outprims = myprims; |
166 |
+ |
break; |
167 |
+ |
case 'x': case 'X': outprims = NULL; break; |
168 |
+ |
/* the following options affect +r only */ |
169 |
|
case 'r': case 'R': putprim = RED; break; |
170 |
|
case 'g': case 'G': putprim = GRN; break; |
171 |
|
case 'b': case 'B': putprim = BLU; break; |
252 |
|
else |
253 |
|
fmtid = "16-bit_grey"; |
254 |
|
} |
255 |
+ |
if (!reverse || (format != 'a') & (format != 'i')) |
256 |
+ |
inpmode = "rb"; |
257 |
|
/* assign reverse ordering */ |
258 |
|
rord[ord[0]] = 0; |
259 |
|
rord[ord[1]] = 1; |
260 |
|
rord[ord[2]] = 2; |
261 |
|
/* get input */ |
262 |
|
if (i == argc) { |
263 |
+ |
long n = skipbytes; |
264 |
+ |
if (inpmode[1] == 'b') |
265 |
+ |
SET_FILE_BINARY(stdin); |
266 |
+ |
while (n-- > 0) |
267 |
+ |
if (getchar() == EOF) { |
268 |
+ |
fprintf(stderr, |
269 |
+ |
"%s: cannot skip %ld bytes on standard input\n", |
270 |
+ |
progname, skipbytes); |
271 |
+ |
quit(1); |
272 |
+ |
} |
273 |
|
fin = stdin; |
274 |
|
} else if (i < argc) { |
275 |
< |
if ((fin = fopen(argv[i], "r")) == NULL) { |
275 |
> |
if ((fin = fopen(argv[i], inpmode)) == NULL) { |
276 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
277 |
|
progname, argv[i]); |
278 |
|
quit(1); |
279 |
|
} |
280 |
|
if (reverse && putprim != BRIGHT && i == argc-3) { |
281 |
< |
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
281 |
> |
if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) { |
282 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
283 |
|
progname, argv[i+1]); |
284 |
|
quit(1); |
285 |
|
} |
286 |
< |
if ((fin3 = fopen(argv[i+2], "r")) == NULL) { |
286 |
> |
if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) { |
287 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
288 |
|
progname, argv[i+2]); |
289 |
|
quit(1); |
292 |
|
} else if (i != argc-1) |
293 |
|
fin = NULL; |
294 |
|
if (reverse && putprim != BRIGHT && !interleave) { |
295 |
< |
fin2 = fopen(argv[i], "r"); |
296 |
< |
fin3 = fopen(argv[i], "r"); |
295 |
> |
fin2 = fopen(argv[i], inpmode); |
296 |
> |
fin3 = fopen(argv[i], inpmode); |
297 |
|
} |
298 |
< |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
299 |
< |
(fseek(fin2, skipbytes, 0) || |
300 |
< |
fseek(fin3, skipbytes, 0))))) { |
298 |
> |
if (skipbytes && (fseek(fin, skipbytes, SEEK_SET) || (fin2 != NULL && |
299 |
> |
fseek(fin2, skipbytes, SEEK_SET) | |
300 |
> |
fseek(fin3, skipbytes, SEEK_SET)))) { |
301 |
|
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
302 |
|
progname, skipbytes); |
303 |
|
quit(1); |
309 |
|
} |
310 |
|
|
311 |
|
if (reverse) { |
285 |
– |
#ifdef _WIN32 |
312 |
|
SET_FILE_BINARY(stdout); |
287 |
– |
if (format != 'a' && format != 'i') |
288 |
– |
SET_FILE_BINARY(fin); |
289 |
– |
#endif |
313 |
|
/* get header */ |
314 |
|
if (header) { |
315 |
< |
if (checkheader(fin, fmtid, stdout) < 0) { |
316 |
< |
fprintf(stderr, "%s: wrong input format\n", |
317 |
< |
progname); |
315 |
> |
getheader(fin, checkhead, stdout); |
316 |
> |
if (wrongformat) { |
317 |
> |
fprintf(stderr, "%s: wrong input format (expected %s)\n", |
318 |
> |
progname, fmtid); |
319 |
|
quit(1); |
320 |
|
} |
321 |
|
if (fin2 != NULL) { |
349 |
|
printargs(i, argv, stdout); |
350 |
|
if (expval < .99 || expval > 1.01) |
351 |
|
fputexpos(expval, stdout); |
352 |
< |
fputformat(COLRFMT, stdout); |
352 |
> |
if (outprims != NULL) { |
353 |
> |
if (outprims != stdprims) |
354 |
> |
fputprims(outprims, stdout); |
355 |
> |
fputformat(COLRFMT, stdout); |
356 |
> |
} else /* XYZ data */ |
357 |
> |
fputformat(CIEFMT, stdout); |
358 |
|
putchar('\n'); |
359 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
360 |
|
valtopix(); |
361 |
|
} else { |
362 |
< |
#ifdef _WIN32 |
334 |
< |
SET_FILE_BINARY(fin); |
335 |
< |
if (format != 'a' && format != 'i') |
362 |
> |
if ((format != 'a') & (format != 'i')) |
363 |
|
SET_FILE_BINARY(stdout); |
337 |
– |
#endif |
364 |
|
/* get header */ |
365 |
< |
getheader(fin, checkhead, NULL); |
365 |
> |
getheader(fin, checkhead, header ? stdout : (FILE *)NULL); |
366 |
|
if (wrongformat) { |
367 |
|
fprintf(stderr, |
368 |
|
"%s: input not a Radiance RGBE picture\n", |
377 |
|
printargs(i, argv, stdout); |
378 |
|
if (expval < .99 || expval > 1.01) |
379 |
|
fputexpos(expval, stdout); |
380 |
+ |
if (swapbytes) { |
381 |
+ |
if (nativebigendian()) |
382 |
+ |
puts("BigEndian=0"); |
383 |
+ |
else |
384 |
+ |
puts("BigEndian=1"); |
385 |
+ |
} else if ((format != 'a') & (format != 'i')) |
386 |
+ |
fputendian(stdout); |
387 |
|
fputformat(fmtid, stdout); |
388 |
|
putchar('\n'); |
389 |
|
} |
403 |
|
void *p |
404 |
|
) |
405 |
|
{ |
406 |
< |
char fmt[32]; |
406 |
> |
FILE *fout = (FILE *)p; |
407 |
> |
char fmt[MAXFMTLEN]; |
408 |
|
double d; |
409 |
|
COLOR ctmp; |
410 |
+ |
int rv; |
411 |
|
|
412 |
|
if (formatval(fmt, line)) { |
413 |
< |
if (!strcmp(fmt, CIEFMT)) |
413 |
> |
if (reverse) |
414 |
> |
wrongformat = strcmp(fmt, fmtid); |
415 |
> |
else if (!strcmp(fmt, CIEFMT)) |
416 |
|
mybright = &xyz_bright; |
417 |
|
else if (!strcmp(fmt, COLRFMT)) |
418 |
|
mybright = &rgb_bright; |
428 |
|
colval(exposure,GRN)/colval(ctmp,GRN), |
429 |
|
colval(exposure,BLU)/colval(ctmp,BLU)); |
430 |
|
doexposure++; |
431 |
< |
} else if (header) |
432 |
< |
fputs(line, stdout); |
431 |
> |
} else if ((rv = isbigendian(line)) >= 0) { |
432 |
> |
if (reverse) |
433 |
> |
swapbytes = (nativebigendian() != rv); |
434 |
> |
} else if (fout != NULL) |
435 |
> |
fputs(line, fout); |
436 |
|
return(0); |
437 |
|
} |
438 |
|
|
440 |
|
static void |
441 |
|
pixtoval(void) /* convert picture to values */ |
442 |
|
{ |
443 |
< |
register COLOR *scanln; |
443 |
> |
COLOR *scanln; |
444 |
|
int dogamma; |
445 |
|
COLOR lastc; |
446 |
|
RREAL hv[2]; |
447 |
|
int startprim, endprim; |
448 |
|
long startpos; |
449 |
< |
int y; |
410 |
< |
register int x; |
449 |
> |
int x, y; |
450 |
|
|
451 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
452 |
|
if (scanln == NULL) { |
454 |
|
quit(1); |
455 |
|
} |
456 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
457 |
< |
if (putprim == ALL && !interleave) { |
457 |
> |
if ((putprim == ALL) & !interleave) { |
458 |
|
startprim = RED; endprim = BLU; |
459 |
|
startpos = ftell(fin); |
460 |
|
} else { |
461 |
|
startprim = putprim; endprim = putprim; |
462 |
|
} |
463 |
|
for (putprim = startprim; putprim <= endprim; putprim++) { |
464 |
< |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
464 |
> |
if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) { |
465 |
|
fprintf(stderr, "%s: seek error on input file\n", |
466 |
|
progname); |
467 |
|
quit(1); |
513 |
|
static void |
514 |
|
valtopix(void) /* convert values to a pixel file */ |
515 |
|
{ |
516 |
< |
int dogamma; |
517 |
< |
register COLOR *scanln; |
518 |
< |
int y; |
519 |
< |
register int x; |
516 |
> |
int dogamma; |
517 |
> |
COLOR *scanln; |
518 |
> |
COLR rgbe; |
519 |
> |
int x, y; |
520 |
|
|
521 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
522 |
|
if (scanln == NULL) { |
545 |
|
pow(colval(scanln[x],BLU), gamcor)); |
546 |
|
if (doexposure) |
547 |
|
multcolor(scanln[x], exposure); |
548 |
+ |
if (uniq) { /* uncompressed? */ |
549 |
+ |
setcolr(rgbe, scanln[x][RED], |
550 |
+ |
scanln[x][GRN], |
551 |
+ |
scanln[x][BLU]); |
552 |
+ |
if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1) |
553 |
+ |
goto writerr; |
554 |
+ |
} |
555 |
|
} |
556 |
< |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
557 |
< |
fprintf(stderr, "%s: write error\n", progname); |
558 |
< |
quit(1); |
513 |
< |
} |
556 |
> |
/* write scan if compressed */ |
557 |
> |
if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0) |
558 |
> |
goto writerr; |
559 |
|
} |
560 |
|
free((void *)scanln); |
561 |
+ |
return; |
562 |
+ |
writerr: |
563 |
+ |
fprintf(stderr, "%s: write error\n", progname); |
564 |
+ |
quit(1); |
565 |
|
} |
566 |
|
|
567 |
|
|
573 |
|
} |
574 |
|
|
575 |
|
|
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); |
535 |
– |
wp++; |
536 |
– |
} |
537 |
– |
} |
538 |
– |
|
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 |
– |
|
576 |
|
static int |
577 |
|
getcascii( /* get an ascii color value from stream(s) */ |
578 |
|
COLOR col |
602 |
|
double vd[3]; |
603 |
|
|
604 |
|
if (fin2 == NULL) { |
605 |
< |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
605 |
> |
if (getbinary(vd, sizeof(double), 3, fin) != 3) |
606 |
|
return(-1); |
607 |
|
} else { |
608 |
< |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
609 |
< |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
610 |
< |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
608 |
> |
if (getbinary(vd, sizeof(double), 1, fin) != 1 || |
609 |
> |
getbinary(vd+1, sizeof(double), 1, fin2) != 1 || |
610 |
> |
getbinary(vd+2, sizeof(double), 1, fin3) != 1) |
611 |
|
return(-1); |
612 |
|
} |
613 |
|
if (swapbytes) |
625 |
|
float vf[3]; |
626 |
|
|
627 |
|
if (fin2 == NULL) { |
628 |
< |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
628 |
> |
if (getbinary(vf, sizeof(float), 3, fin) != 3) |
629 |
|
return(-1); |
630 |
|
} else { |
631 |
< |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
632 |
< |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
633 |
< |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
631 |
> |
if (getbinary(vf, sizeof(float), 1, fin) != 1 || |
632 |
> |
getbinary(vf+1, sizeof(float), 1, fin2) != 1 || |
633 |
> |
getbinary(vf+2, sizeof(float), 1, fin3) != 1) |
634 |
|
return(-1); |
635 |
|
} |
636 |
|
if (swapbytes) |
637 |
< |
swap32((uint32 *)vf, 3); |
637 |
> |
swap32((char *)vf, 3); |
638 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
639 |
|
return(0); |
640 |
|
} |
667 |
|
COLOR col |
668 |
|
) |
669 |
|
{ |
670 |
< |
BYTE vb[3]; |
670 |
> |
uby8 vb[3]; |
671 |
|
|
672 |
|
if (fin2 == NULL) { |
673 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
673 |
> |
if (getbinary(vb, sizeof(uby8), 3, fin) != 3) |
674 |
|
return(-1); |
675 |
|
} else { |
676 |
< |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
677 |
< |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
678 |
< |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
676 |
> |
if (getbinary(vb, sizeof(uby8), 1, fin) != 1 || |
677 |
> |
getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 || |
678 |
> |
getbinary(vb+2, sizeof(uby8), 1, fin3) != 1) |
679 |
|
return(-1); |
680 |
|
} |
681 |
|
setcolor(col, (vb[rord[RED]]+.5)/256., |
692 |
|
uint16 vw[3]; |
693 |
|
|
694 |
|
if (fin2 == NULL) { |
695 |
< |
if (fread((char *)vw, sizeof(uint16), 3, fin) != 3) |
695 |
> |
if (getbinary(vw, sizeof(uint16), 3, fin) != 3) |
696 |
|
return(-1); |
697 |
|
} else { |
698 |
< |
if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 || |
699 |
< |
fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 || |
700 |
< |
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
698 |
> |
if (getbinary(vw, sizeof(uint16), 1, fin) != 1 || |
699 |
> |
getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 || |
700 |
> |
getbinary(vw+2, sizeof(uint16), 1, fin3) != 1) |
701 |
|
return(-1); |
702 |
|
} |
703 |
|
if (swapbytes) |
704 |
< |
swap16(vw, 3); |
704 |
> |
swap16((char *)vw, 3); |
705 |
|
setcolor(col, (vw[rord[RED]]+.5)/65536., |
706 |
|
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
707 |
|
return(0); |
729 |
|
{ |
730 |
|
double vd; |
731 |
|
|
732 |
< |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
732 |
> |
if (getbinary(&vd, sizeof(double), 1, fin) != 1) |
733 |
|
return(-1); |
734 |
|
if (swapbytes) |
735 |
|
swap64((char *)&vd, 1); |
745 |
|
{ |
746 |
|
float vf; |
747 |
|
|
748 |
< |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
748 |
> |
if (getbinary(&vf, sizeof(float), 1, fin) != 1) |
749 |
|
return(-1); |
750 |
|
if (swapbytes) |
751 |
< |
swap32((uint32 *)&vf, 1); |
751 |
> |
swap32((char *)&vf, 1); |
752 |
|
setcolor(col, vf, vf, vf); |
753 |
|
return(0); |
754 |
|
} |
775 |
|
COLOR col |
776 |
|
) |
777 |
|
{ |
778 |
< |
BYTE vb; |
778 |
> |
uby8 vb; |
779 |
|
double d; |
780 |
|
|
781 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
781 |
> |
if (getbinary(&vb, sizeof(uby8), 1, fin) != 1) |
782 |
|
return(-1); |
783 |
|
d = (vb+.5)/256.; |
784 |
|
setcolor(col, d, d, d); |
794 |
|
uint16 vw; |
795 |
|
double d; |
796 |
|
|
797 |
< |
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
797 |
> |
if (getbinary(&vw, sizeof(uint16), 1, fin) != 1) |
798 |
|
return(-1); |
799 |
|
if (swapbytes) |
800 |
< |
swap16(&vw, 1); |
800 |
> |
swap16((char *)&vw, 1); |
801 |
|
d = (vw+.5)/65536.; |
802 |
|
setcolor(col, d, d, d); |
803 |
|
return(0); |
829 |
|
vf[1] = colval(col,ord[1]); |
830 |
|
vf[2] = colval(col,ord[2]); |
831 |
|
if (swapbytes) |
832 |
< |
swap32((uint32 *)vf, 3); |
833 |
< |
fwrite((char *)vf, sizeof(float), 3, stdout); |
832 |
> |
swap32((char *)vf, 3); |
833 |
> |
putbinary(vf, sizeof(float), 3, stdout); |
834 |
|
|
835 |
|
return(ferror(stdout) ? -1 : 0); |
836 |
|
} |
848 |
|
vd[2] = colval(col,ord[2]); |
849 |
|
if (swapbytes) |
850 |
|
swap64((char *)vd, 3); |
851 |
< |
fwrite((char *)vd, sizeof(double), 3, stdout); |
851 |
> |
putbinary(vd, sizeof(double), 3, stdout); |
852 |
|
|
853 |
|
return(ferror(stdout) ? -1 : 0); |
854 |
|
} |
874 |
|
) |
875 |
|
{ |
876 |
|
long i; |
877 |
< |
BYTE vb[3]; |
877 |
> |
uby8 vb[3]; |
878 |
|
|
879 |
|
i = colval(col,ord[0])*256.; |
880 |
|
vb[0] = min(i,255); |
882 |
|
vb[1] = min(i,255); |
883 |
|
i = colval(col,ord[2])*256.; |
884 |
|
vb[2] = min(i,255); |
885 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
885 |
> |
putbinary(vb, sizeof(uby8), 3, stdout); |
886 |
|
|
887 |
|
return(ferror(stdout) ? -1 : 0); |
888 |
|
} |
903 |
|
i = colval(col,ord[2])*65536.; |
904 |
|
vw[2] = min(i,65535); |
905 |
|
if (swapbytes) |
906 |
< |
swap16(vw, 3); |
907 |
< |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
906 |
> |
swap16((char *)vw, 3); |
907 |
> |
putbinary(vw, sizeof(uint16), 3, stdout); |
908 |
|
|
909 |
|
return(ferror(stdout) ? -1 : 0); |
910 |
|
} |
930 |
|
|
931 |
|
vf = (*mybright)(col); |
932 |
|
if (swapbytes) |
933 |
< |
swap32((uint32 *)&vf, 1); |
934 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
933 |
> |
swap32((char *)&vf, 1); |
934 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
935 |
|
|
936 |
|
return(ferror(stdout) ? -1 : 0); |
937 |
|
} |
947 |
|
vd = (*mybright)(col); |
948 |
|
if (swapbytes) |
949 |
|
swap64((char *)&vd, 1); |
950 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
950 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
951 |
|
|
952 |
|
return(ferror(stdout) ? -1 : 0); |
953 |
|
} |
969 |
|
COLOR col |
970 |
|
) |
971 |
|
{ |
972 |
< |
register int i; |
973 |
< |
BYTE vb; |
972 |
> |
int i; |
973 |
> |
uby8 vb; |
974 |
|
|
975 |
|
i = (*mybright)(col)*256.; |
976 |
|
vb = min(i,255); |
977 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
977 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
978 |
|
|
979 |
|
return(ferror(stdout) ? -1 : 0); |
980 |
|
} |
991 |
|
i = (*mybright)(col)*65536.; |
992 |
|
vw = min(i,65535); |
993 |
|
if (swapbytes) |
994 |
< |
swap16(&vw, 1); |
995 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
994 |
> |
swap16((char *)&vw, 1); |
995 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
996 |
|
|
997 |
|
return(ferror(stdout) ? -1 : 0); |
998 |
|
} |
1018 |
|
|
1019 |
|
vf = colval(col,putprim); |
1020 |
|
if (swapbytes) |
1021 |
< |
swap32((uint32 *)&vf, 1); |
1022 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
1021 |
> |
swap32((char *)&vf, 1); |
1022 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
1023 |
|
|
1024 |
|
return(ferror(stdout) ? -1 : 0); |
1025 |
|
} |
1035 |
|
vd = colval(col,putprim); |
1036 |
|
if (swapbytes) |
1037 |
|
swap64((char *)&vd, 1); |
1038 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
1038 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
1039 |
|
|
1040 |
|
return(ferror(stdout) ? -1 : 0); |
1041 |
|
} |
1058 |
|
) |
1059 |
|
{ |
1060 |
|
long i; |
1061 |
< |
BYTE vb; |
1061 |
> |
uby8 vb; |
1062 |
|
|
1063 |
|
i = colval(col,putprim)*256.; |
1064 |
|
vb = min(i,255); |
1065 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
1065 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
1066 |
|
|
1067 |
|
return(ferror(stdout) ? -1 : 0); |
1068 |
|
} |
1079 |
|
i = colval(col,putprim)*65536.; |
1080 |
|
vw = min(i,65535); |
1081 |
|
if (swapbytes) |
1082 |
< |
swap16(&vw, 1); |
1083 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
1082 |
> |
swap16((char *)&vw, 1); |
1083 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
1084 |
|
|
1085 |
|
return(ferror(stdout) ? -1 : 0); |
1086 |
|
} |
1122 |
|
if (fin2 == NULL) |
1123 |
|
goto namerr; |
1124 |
|
if (fseek(fin2, |
1125 |
< |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
1125 |
> |
(long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR)) |
1126 |
|
goto seekerr; |
1127 |
|
if (fseek(fin3, |
1128 |
< |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
1128 |
> |
(long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR)) |
1129 |
|
goto seekerr; |
1130 |
|
} |
1131 |
|
} |
1144 |
|
if (fin2 == NULL) |
1145 |
|
goto namerr; |
1146 |
|
if (fseek(fin2, |
1147 |
< |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1147 |
> |
(long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR)) |
1148 |
|
goto seekerr; |
1149 |
|
if (fseek(fin3, |
1150 |
< |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1150 |
> |
(long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR)) |
1151 |
|
goto seekerr; |
1152 |
|
} |
1153 |
|
} |
1184 |
|
if (fin2 == NULL) |
1185 |
|
goto namerr; |
1186 |
|
if (fseek(fin2, |
1187 |
< |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
1187 |
> |
(long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR)) |
1188 |
|
goto seekerr; |
1189 |
|
if (fseek(fin3, |
1190 |
< |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
1190 |
> |
(long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR)) |
1191 |
|
goto seekerr; |
1192 |
|
} |
1193 |
|
} |
1206 |
|
if (fin2 == NULL) |
1207 |
|
goto namerr; |
1208 |
|
if (fseek(fin2, |
1209 |
< |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
1209 |
> |
(long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR)) |
1210 |
|
goto seekerr; |
1211 |
|
if (fseek(fin3, |
1212 |
< |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
1212 |
> |
(long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR)) |
1213 |
|
goto seekerr; |
1214 |
|
} |
1215 |
|
} |