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 |
|
|
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; |
296 |
|
} |
297 |
|
|
298 |
|
if (reverse) { |
299 |
< |
#ifdef _WIN32 |
299 |
> |
#if defined(_WIN32) || defined(_WIN64) |
300 |
|
SET_FILE_BINARY(stdout); |
301 |
|
if (format != 'a' && format != 'i') |
302 |
|
SET_FILE_BINARY(fin); |
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 _WIN32 |
352 |
> |
#if defined(_WIN32) || defined(_WIN64) |
353 |
|
SET_FILE_BINARY(fin); |
354 |
|
if (format != 'a' && format != 'i') |
355 |
|
SET_FILE_BINARY(stdout); |
389 |
|
void *p |
390 |
|
) |
391 |
|
{ |
392 |
< |
char fmt[32]; |
392 |
> |
char fmt[MAXFMTLEN]; |
393 |
|
double d; |
394 |
|
COLOR ctmp; |
395 |
|
|
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 |
|
RREAL hv[2]; |
426 |
|
int startprim, endprim; |
427 |
|
long startpos; |
428 |
< |
int y; |
407 |
< |
register int x; |
428 |
> |
int x, y; |
429 |
|
|
430 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
431 |
|
if (scanln == NULL) { |
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); |
510 |
< |
} |
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 |
|
|
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) |
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) |
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., |
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) |
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); |
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); |
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); |
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((char *)&vw, 1); |
809 |
|
vf[2] = colval(col,ord[2]); |
810 |
|
if (swapbytes) |
811 |
|
swap32((char *)vf, 3); |
812 |
< |
fwrite((char *)vf, sizeof(float), 3, stdout); |
812 |
> |
putbinary(vf, sizeof(float), 3, stdout); |
813 |
|
|
814 |
|
return(ferror(stdout) ? -1 : 0); |
815 |
|
} |
827 |
|
vd[2] = colval(col,ord[2]); |
828 |
|
if (swapbytes) |
829 |
|
swap64((char *)vd, 3); |
830 |
< |
fwrite((char *)vd, sizeof(double), 3, stdout); |
830 |
> |
putbinary(vd, sizeof(double), 3, stdout); |
831 |
|
|
832 |
|
return(ferror(stdout) ? -1 : 0); |
833 |
|
} |
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 |
|
} |
883 |
|
vw[2] = min(i,65535); |
884 |
|
if (swapbytes) |
885 |
|
swap16((char *)vw, 3); |
886 |
< |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
886 |
> |
putbinary(vw, sizeof(uint16), 3, stdout); |
887 |
|
|
888 |
|
return(ferror(stdout) ? -1 : 0); |
889 |
|
} |
910 |
|
vf = (*mybright)(col); |
911 |
|
if (swapbytes) |
912 |
|
swap32((char *)&vf, 1); |
913 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
913 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
914 |
|
|
915 |
|
return(ferror(stdout) ? -1 : 0); |
916 |
|
} |
926 |
|
vd = (*mybright)(col); |
927 |
|
if (swapbytes) |
928 |
|
swap64((char *)&vd, 1); |
929 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
929 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
930 |
|
|
931 |
|
return(ferror(stdout) ? -1 : 0); |
932 |
|
} |
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 |
|
} |
971 |
|
vw = min(i,65535); |
972 |
|
if (swapbytes) |
973 |
|
swap16((char *)&vw, 1); |
974 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
974 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
975 |
|
|
976 |
|
return(ferror(stdout) ? -1 : 0); |
977 |
|
} |
998 |
|
vf = colval(col,putprim); |
999 |
|
if (swapbytes) |
1000 |
|
swap32((char *)&vf, 1); |
1001 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
1001 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
1002 |
|
|
1003 |
|
return(ferror(stdout) ? -1 : 0); |
1004 |
|
} |
1014 |
|
vd = colval(col,putprim); |
1015 |
|
if (swapbytes) |
1016 |
|
swap64((char *)&vd, 1); |
1017 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
1017 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
1018 |
|
|
1019 |
|
return(ferror(stdout) ? -1 : 0); |
1020 |
|
} |
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 |
|
} |
1059 |
|
vw = min(i,65535); |
1060 |
|
if (swapbytes) |
1061 |
|
swap16((char *)&vw, 1); |
1062 |
< |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
1062 |
> |
putbinary(&vw, sizeof(uint16), 1, stdout); |
1063 |
|
|
1064 |
|
return(ferror(stdout) ? -1 : 0); |
1065 |
|
} |
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 |
|
} |