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) { |
348 |
|
printargs(i, argv, stdout); |
349 |
|
if (expval < .99 || expval > 1.01) |
350 |
|
fputexpos(expval, stdout); |
351 |
< |
fputformat(COLRFMT, stdout); |
351 |
> |
if (outprims != NULL) { |
352 |
> |
if (outprims != stdprims) |
353 |
> |
fputprims(outprims, stdout); |
354 |
> |
fputformat(COLRFMT, stdout); |
355 |
> |
} else /* XYZ data */ |
356 |
> |
fputformat(CIEFMT, stdout); |
357 |
|
putchar('\n'); |
358 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
359 |
|
valtopix(); |
360 |
|
} else { |
361 |
< |
#ifdef _WIN32 |
334 |
< |
SET_FILE_BINARY(fin); |
335 |
< |
if (format != 'a' && format != 'i') |
361 |
> |
if ((format != 'a') & (format != 'i')) |
362 |
|
SET_FILE_BINARY(stdout); |
337 |
– |
#endif |
363 |
|
/* get header */ |
364 |
|
getheader(fin, checkhead, NULL); |
365 |
|
if (wrongformat) { |
376 |
|
printargs(i, argv, stdout); |
377 |
|
if (expval < .99 || expval > 1.01) |
378 |
|
fputexpos(expval, stdout); |
379 |
+ |
if (swapbytes) { |
380 |
+ |
if (nativebigendian()) |
381 |
+ |
puts("BigEndian=0"); |
382 |
+ |
else |
383 |
+ |
puts("BigEndian=1"); |
384 |
+ |
} else if ((format != 'a') & (format != 'i')) |
385 |
+ |
fputendian(stdout); |
386 |
|
fputformat(fmtid, stdout); |
387 |
|
putchar('\n'); |
388 |
|
} |
402 |
|
void *p |
403 |
|
) |
404 |
|
{ |
405 |
< |
char fmt[32]; |
405 |
> |
char fmt[MAXFMTLEN]; |
406 |
|
double d; |
407 |
|
COLOR ctmp; |
408 |
+ |
int rv; |
409 |
|
|
410 |
|
if (formatval(fmt, line)) { |
411 |
|
if (!strcmp(fmt, CIEFMT)) |
417 |
|
} else if (original && isexpos(line)) { |
418 |
|
d = 1.0/exposval(line); |
419 |
|
scalecolor(exposure, d); |
387 |
– |
fprintf(stderr, "scaled exposure by %f, now at %f\n", d, bright(exposure)); |
420 |
|
doexposure++; |
421 |
|
} else if (original && iscolcor(line)) { |
422 |
|
colcorval(ctmp, line); |
424 |
|
colval(exposure,GRN)/colval(ctmp,GRN), |
425 |
|
colval(exposure,BLU)/colval(ctmp,BLU)); |
426 |
|
doexposure++; |
427 |
+ |
} else if (reverse && (rv = isbigendian(line)) >= 0) { |
428 |
+ |
swapbytes = (nativebigendian() != rv); |
429 |
|
} else if (header) |
430 |
|
fputs(line, stdout); |
431 |
|
return(0); |
435 |
|
static void |
436 |
|
pixtoval(void) /* convert picture to values */ |
437 |
|
{ |
438 |
< |
register COLOR *scanln; |
438 |
> |
COLOR *scanln; |
439 |
|
int dogamma; |
440 |
|
COLOR lastc; |
441 |
|
RREAL hv[2]; |
442 |
|
int startprim, endprim; |
443 |
|
long startpos; |
444 |
< |
int y; |
411 |
< |
register int x; |
444 |
> |
int x, y; |
445 |
|
|
446 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
447 |
|
if (scanln == NULL) { |
449 |
|
quit(1); |
450 |
|
} |
451 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
452 |
< |
if (putprim == ALL && !interleave) { |
452 |
> |
if ((putprim == ALL) & !interleave) { |
453 |
|
startprim = RED; endprim = BLU; |
454 |
|
startpos = ftell(fin); |
455 |
|
} else { |
456 |
|
startprim = putprim; endprim = putprim; |
457 |
|
} |
458 |
|
for (putprim = startprim; putprim <= endprim; putprim++) { |
459 |
< |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
459 |
> |
if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) { |
460 |
|
fprintf(stderr, "%s: seek error on input file\n", |
461 |
|
progname); |
462 |
|
quit(1); |
508 |
|
static void |
509 |
|
valtopix(void) /* convert values to a pixel file */ |
510 |
|
{ |
511 |
< |
int dogamma; |
512 |
< |
register COLOR *scanln; |
513 |
< |
int y; |
514 |
< |
register int x; |
511 |
> |
int dogamma; |
512 |
> |
COLOR *scanln; |
513 |
> |
COLR rgbe; |
514 |
> |
int x, y; |
515 |
|
|
516 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
517 |
|
if (scanln == NULL) { |
540 |
|
pow(colval(scanln[x],BLU), gamcor)); |
541 |
|
if (doexposure) |
542 |
|
multcolor(scanln[x], exposure); |
543 |
+ |
if (uniq) { /* uncompressed? */ |
544 |
+ |
setcolr(rgbe, scanln[x][RED], |
545 |
+ |
scanln[x][GRN], |
546 |
+ |
scanln[x][BLU]); |
547 |
+ |
if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1) |
548 |
+ |
goto writerr; |
549 |
+ |
} |
550 |
|
} |
551 |
< |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
552 |
< |
fprintf(stderr, "%s: write error\n", progname); |
553 |
< |
quit(1); |
514 |
< |
} |
551 |
> |
/* write scan if compressed */ |
552 |
> |
if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0) |
553 |
> |
goto writerr; |
554 |
|
} |
555 |
|
free((void *)scanln); |
556 |
+ |
return; |
557 |
+ |
writerr: |
558 |
+ |
fprintf(stderr, "%s: write error\n", progname); |
559 |
+ |
quit(1); |
560 |
|
} |
561 |
|
|
562 |
|
|
568 |
|
} |
569 |
|
|
570 |
|
|
528 |
– |
static void |
529 |
– |
swap16( /* swap n 16-bit words */ |
530 |
– |
register uint16 *wp, |
531 |
– |
int n |
532 |
– |
) |
533 |
– |
{ |
534 |
– |
while (n-- > 0) { |
535 |
– |
*wp = *wp << 8 | ((*wp >> 8) & 0xff); |
536 |
– |
wp++; |
537 |
– |
} |
538 |
– |
} |
539 |
– |
|
540 |
– |
|
541 |
– |
static void |
542 |
– |
swap32( /* swap n 32-bit words */ |
543 |
– |
register uint32 *wp, |
544 |
– |
int n |
545 |
– |
) |
546 |
– |
{ |
547 |
– |
while (n-- > 0) { |
548 |
– |
*wp = *wp << 24 | ((*wp >> 24) & 0xff) | |
549 |
– |
(*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8; |
550 |
– |
wp++; |
551 |
– |
} |
552 |
– |
} |
553 |
– |
|
554 |
– |
|
555 |
– |
static void |
556 |
– |
swap64( /* swap n 64-bit words */ |
557 |
– |
register char *wp, |
558 |
– |
int n |
559 |
– |
) |
560 |
– |
{ |
561 |
– |
register int t; |
562 |
– |
|
563 |
– |
while (n-- > 0) { |
564 |
– |
t = wp[0]; wp[0] = wp[7]; wp[7] = t; |
565 |
– |
t = wp[1]; wp[1] = wp[6]; wp[6] = t; |
566 |
– |
t = wp[2]; wp[2] = wp[5]; wp[5] = t; |
567 |
– |
t = wp[3]; wp[3] = wp[4]; wp[4] = t; |
568 |
– |
wp += 8; |
569 |
– |
} |
570 |
– |
} |
571 |
– |
|
572 |
– |
|
571 |
|
static int |
572 |
|
getcascii( /* get an ascii color value from stream(s) */ |
573 |
|
COLOR col |
597 |
|
double vd[3]; |
598 |
|
|
599 |
|
if (fin2 == NULL) { |
600 |
< |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
600 |
> |
if (getbinary(vd, sizeof(double), 3, fin) != 3) |
601 |
|
return(-1); |
602 |
|
} else { |
603 |
< |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
604 |
< |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
605 |
< |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
603 |
> |
if (getbinary(vd, sizeof(double), 1, fin) != 1 || |
604 |
> |
getbinary(vd+1, sizeof(double), 1, fin2) != 1 || |
605 |
> |
getbinary(vd+2, sizeof(double), 1, fin3) != 1) |
606 |
|
return(-1); |
607 |
|
} |
608 |
|
if (swapbytes) |
620 |
|
float vf[3]; |
621 |
|
|
622 |
|
if (fin2 == NULL) { |
623 |
< |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
623 |
> |
if (getbinary(vf, sizeof(float), 3, fin) != 3) |
624 |
|
return(-1); |
625 |
|
} else { |
626 |
< |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
627 |
< |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
628 |
< |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
626 |
> |
if (getbinary(vf, sizeof(float), 1, fin) != 1 || |
627 |
> |
getbinary(vf+1, sizeof(float), 1, fin2) != 1 || |
628 |
> |
getbinary(vf+2, sizeof(float), 1, fin3) != 1) |
629 |
|
return(-1); |
630 |
|
} |
631 |
|
if (swapbytes) |
632 |
< |
swap32((uint32 *)vf, 3); |
632 |
> |
swap32((char *)vf, 3); |
633 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
634 |
|
return(0); |
635 |
|
} |
662 |
|
COLOR col |
663 |
|
) |
664 |
|
{ |
665 |
< |
BYTE vb[3]; |
665 |
> |
uby8 vb[3]; |
666 |
|
|
667 |
|
if (fin2 == NULL) { |
668 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
668 |
> |
if (getbinary(vb, sizeof(uby8), 3, fin) != 3) |
669 |
|
return(-1); |
670 |
|
} else { |
671 |
< |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
672 |
< |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
673 |
< |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
671 |
> |
if (getbinary(vb, sizeof(uby8), 1, fin) != 1 || |
672 |
> |
getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 || |
673 |
> |
getbinary(vb+2, sizeof(uby8), 1, fin3) != 1) |
674 |
|
return(-1); |
675 |
|
} |
676 |
|
setcolor(col, (vb[rord[RED]]+.5)/256., |
687 |
|
uint16 vw[3]; |
688 |
|
|
689 |
|
if (fin2 == NULL) { |
690 |
< |
if (fread((char *)vw, sizeof(uint16), 3, fin) != 3) |
690 |
> |
if (getbinary(vw, sizeof(uint16), 3, fin) != 3) |
691 |
|
return(-1); |
692 |
|
} else { |
693 |
< |
if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 || |
694 |
< |
fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 || |
695 |
< |
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
693 |
> |
if (getbinary(vw, sizeof(uint16), 1, fin) != 1 || |
694 |
> |
getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 || |
695 |
> |
getbinary(vw+2, sizeof(uint16), 1, fin3) != 1) |
696 |
|
return(-1); |
697 |
|
} |
698 |
|
if (swapbytes) |
699 |
< |
swap16(vw, 3); |
699 |
> |
swap16((char *)vw, 3); |
700 |
|
setcolor(col, (vw[rord[RED]]+.5)/65536., |
701 |
|
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
702 |
|
return(0); |
724 |
|
{ |
725 |
|
double vd; |
726 |
|
|
727 |
< |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
727 |
> |
if (getbinary(&vd, sizeof(double), 1, fin) != 1) |
728 |
|
return(-1); |
729 |
|
if (swapbytes) |
730 |
|
swap64((char *)&vd, 1); |
740 |
|
{ |
741 |
|
float vf; |
742 |
|
|
743 |
< |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
743 |
> |
if (getbinary(&vf, sizeof(float), 1, fin) != 1) |
744 |
|
return(-1); |
745 |
|
if (swapbytes) |
746 |
< |
swap32((uint32 *)&vf, 1); |
746 |
> |
swap32((char *)&vf, 1); |
747 |
|
setcolor(col, vf, vf, vf); |
748 |
|
return(0); |
749 |
|
} |
770 |
|
COLOR col |
771 |
|
) |
772 |
|
{ |
773 |
< |
BYTE vb; |
773 |
> |
uby8 vb; |
774 |
|
double d; |
775 |
|
|
776 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
776 |
> |
if (getbinary(&vb, sizeof(uby8), 1, fin) != 1) |
777 |
|
return(-1); |
778 |
|
d = (vb+.5)/256.; |
779 |
|
setcolor(col, d, d, d); |
789 |
|
uint16 vw; |
790 |
|
double d; |
791 |
|
|
792 |
< |
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
792 |
> |
if (getbinary(&vw, sizeof(uint16), 1, fin) != 1) |
793 |
|
return(-1); |
794 |
|
if (swapbytes) |
795 |
< |
swap16(&vw, 1); |
795 |
> |
swap16((char *)&vw, 1); |
796 |
|
d = (vw+.5)/65536.; |
797 |
|
setcolor(col, d, d, d); |
798 |
|
return(0); |
824 |
|
vf[1] = colval(col,ord[1]); |
825 |
|
vf[2] = colval(col,ord[2]); |
826 |
|
if (swapbytes) |
827 |
< |
swap32((uint32 *)vf, 3); |
828 |
< |
fwrite((char *)vf, sizeof(float), 3, stdout); |
827 |
> |
swap32((char *)vf, 3); |
828 |
> |
putbinary(vf, sizeof(float), 3, stdout); |
829 |
|
|
830 |
|
return(ferror(stdout) ? -1 : 0); |
831 |
|
} |
843 |
|
vd[2] = colval(col,ord[2]); |
844 |
|
if (swapbytes) |
845 |
|
swap64((char *)vd, 3); |
846 |
< |
fwrite((char *)vd, sizeof(double), 3, stdout); |
846 |
> |
putbinary(vd, sizeof(double), 3, stdout); |
847 |
|
|
848 |
|
return(ferror(stdout) ? -1 : 0); |
849 |
|
} |
869 |
|
) |
870 |
|
{ |
871 |
|
long i; |
872 |
< |
BYTE vb[3]; |
872 |
> |
uby8 vb[3]; |
873 |
|
|
874 |
|
i = colval(col,ord[0])*256.; |
875 |
|
vb[0] = min(i,255); |
877 |
|
vb[1] = min(i,255); |
878 |
|
i = colval(col,ord[2])*256.; |
879 |
|
vb[2] = min(i,255); |
880 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
880 |
> |
putbinary(vb, sizeof(uby8), 3, stdout); |
881 |
|
|
882 |
|
return(ferror(stdout) ? -1 : 0); |
883 |
|
} |
898 |
|
i = colval(col,ord[2])*65536.; |
899 |
|
vw[2] = min(i,65535); |
900 |
|
if (swapbytes) |
901 |
< |
swap16(vw, 3); |
902 |
< |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
901 |
> |
swap16((char *)vw, 3); |
902 |
> |
putbinary(vw, sizeof(uint16), 3, stdout); |
903 |
|
|
904 |
|
return(ferror(stdout) ? -1 : 0); |
905 |
|
} |
925 |
|
|
926 |
|
vf = (*mybright)(col); |
927 |
|
if (swapbytes) |
928 |
< |
swap32((uint32 *)&vf, 1); |
929 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
928 |
> |
swap32((char *)&vf, 1); |
929 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
930 |
|
|
931 |
|
return(ferror(stdout) ? -1 : 0); |
932 |
|
} |
942 |
|
vd = (*mybright)(col); |
943 |
|
if (swapbytes) |
944 |
|
swap64((char *)&vd, 1); |
945 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
945 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
946 |
|
|
947 |
|
return(ferror(stdout) ? -1 : 0); |
948 |
|
} |
964 |
|
COLOR col |
965 |
|
) |
966 |
|
{ |
967 |
< |
register int i; |
968 |
< |
BYTE vb; |
967 |
> |
int i; |
968 |
> |
uby8 vb; |
969 |
|
|
970 |
|
i = (*mybright)(col)*256.; |
971 |
|
vb = min(i,255); |
972 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
972 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
973 |
|
|
974 |
|
return(ferror(stdout) ? -1 : 0); |
975 |
|
} |
986 |
|
i = (*mybright)(col)*65536.; |
987 |
|
vw = min(i,65535); |
988 |
|
if (swapbytes) |
989 |
< |
swap16(&vw, 1); |
990 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
989 |
> |
swap16((char *)&vw, 1); |
990 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
991 |
|
|
992 |
|
return(ferror(stdout) ? -1 : 0); |
993 |
|
} |
1013 |
|
|
1014 |
|
vf = colval(col,putprim); |
1015 |
|
if (swapbytes) |
1016 |
< |
swap32((uint32 *)&vf, 1); |
1017 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
1016 |
> |
swap32((char *)&vf, 1); |
1017 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
1018 |
|
|
1019 |
|
return(ferror(stdout) ? -1 : 0); |
1020 |
|
} |
1030 |
|
vd = colval(col,putprim); |
1031 |
|
if (swapbytes) |
1032 |
|
swap64((char *)&vd, 1); |
1033 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
1033 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
1034 |
|
|
1035 |
|
return(ferror(stdout) ? -1 : 0); |
1036 |
|
} |
1053 |
|
) |
1054 |
|
{ |
1055 |
|
long i; |
1056 |
< |
BYTE vb; |
1056 |
> |
uby8 vb; |
1057 |
|
|
1058 |
|
i = colval(col,putprim)*256.; |
1059 |
|
vb = min(i,255); |
1060 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
1060 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
1061 |
|
|
1062 |
|
return(ferror(stdout) ? -1 : 0); |
1063 |
|
} |
1074 |
|
i = colval(col,putprim)*65536.; |
1075 |
|
vw = min(i,65535); |
1076 |
|
if (swapbytes) |
1077 |
< |
swap16(&vw, 1); |
1078 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
1077 |
> |
swap16((char *)&vw, 1); |
1078 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
1079 |
|
|
1080 |
|
return(ferror(stdout) ? -1 : 0); |
1081 |
|
} |
1117 |
|
if (fin2 == NULL) |
1118 |
|
goto namerr; |
1119 |
|
if (fseek(fin2, |
1120 |
< |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
1120 |
> |
(long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR)) |
1121 |
|
goto seekerr; |
1122 |
|
if (fseek(fin3, |
1123 |
< |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
1123 |
> |
(long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR)) |
1124 |
|
goto seekerr; |
1125 |
|
} |
1126 |
|
} |
1139 |
|
if (fin2 == NULL) |
1140 |
|
goto namerr; |
1141 |
|
if (fseek(fin2, |
1142 |
< |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1142 |
> |
(long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR)) |
1143 |
|
goto seekerr; |
1144 |
|
if (fseek(fin3, |
1145 |
< |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1145 |
> |
(long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR)) |
1146 |
|
goto seekerr; |
1147 |
|
} |
1148 |
|
} |
1179 |
|
if (fin2 == NULL) |
1180 |
|
goto namerr; |
1181 |
|
if (fseek(fin2, |
1182 |
< |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
1182 |
> |
(long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR)) |
1183 |
|
goto seekerr; |
1184 |
|
if (fseek(fin3, |
1185 |
< |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
1185 |
> |
(long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR)) |
1186 |
|
goto seekerr; |
1187 |
|
} |
1188 |
|
} |
1201 |
|
if (fin2 == NULL) |
1202 |
|
goto namerr; |
1203 |
|
if (fseek(fin2, |
1204 |
< |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
1204 |
> |
(long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR)) |
1205 |
|
goto seekerr; |
1206 |
|
if (fseek(fin3, |
1207 |
< |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
1207 |
> |
(long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR)) |
1208 |
|
goto seekerr; |
1209 |
|
} |
1210 |
|
} |