| 1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* pvalue.c - program to print pixel values. |
| 6 |
|
* |
| 11 |
|
|
| 12 |
|
#include "color.h" |
| 13 |
|
|
| 14 |
+ |
#include <time.h> |
| 15 |
+ |
|
| 16 |
|
#include "resolu.h" |
| 17 |
|
|
| 18 |
+ |
typedef unsigned short uint16; /* sizeof (uint16) must == 2 */ |
| 19 |
+ |
|
| 20 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
| 21 |
|
|
| 22 |
|
/* what to put out (also RED, GRN, BLU) */ |
| 44 |
|
|
| 45 |
|
long skipbytes = 0; /* skip bytes in input? */ |
| 46 |
|
|
| 47 |
+ |
int swapbytes = 0; /* swap bytes in 16-bit words? */ |
| 48 |
+ |
|
| 49 |
|
int interleave = 1; /* file is interleaved? */ |
| 50 |
|
|
| 51 |
|
int resolution = 1; /* put/get resolution string? */ |
| 68 |
|
|
| 69 |
|
int (*getval)(), (*putval)(); |
| 70 |
|
|
| 71 |
+ |
double |
| 72 |
+ |
rgb_bright(clr) |
| 73 |
+ |
COLOR clr; |
| 74 |
+ |
{ |
| 75 |
+ |
return(bright(clr)); |
| 76 |
+ |
} |
| 77 |
|
|
| 78 |
+ |
double |
| 79 |
+ |
xyz_bright(clr) |
| 80 |
+ |
COLOR clr; |
| 81 |
+ |
{ |
| 82 |
+ |
return(clr[CIEY]); |
| 83 |
+ |
} |
| 84 |
+ |
|
| 85 |
+ |
double (*mybright)() = &rgb_bright; |
| 86 |
+ |
|
| 87 |
+ |
|
| 88 |
|
main(argc, argv) |
| 89 |
|
int argc; |
| 90 |
|
char **argv; |
| 171 |
|
format = 'b'; |
| 172 |
|
fmtid = "byte"; |
| 173 |
|
break; |
| 174 |
+ |
case 'W': /* 16-bit swapped */ |
| 175 |
+ |
swapbytes = 1; |
| 176 |
+ |
case 'w': /* 16-bit */ |
| 177 |
+ |
dataonly = 1; |
| 178 |
+ |
format = 'w'; |
| 179 |
+ |
fmtid = "16-bit"; |
| 180 |
+ |
break; |
| 181 |
|
case 'f': /* float */ |
| 182 |
|
dataonly = 1; |
| 183 |
|
format = 'f'; |
| 196 |
|
case 'X': /* x resolution */ |
| 197 |
|
resolution = 0; |
| 198 |
|
if (argv[i][0] == '-') |
| 199 |
< |
picres.or |= XDECR; |
| 199 |
> |
picres.rt |= XDECR; |
| 200 |
|
picres.xr = atoi(argv[++i]); |
| 201 |
|
break; |
| 202 |
|
case 'y': /* y resolution */ |
| 203 |
|
case 'Y': /* y resolution */ |
| 204 |
|
resolution = 0; |
| 205 |
|
if (argv[i][0] == '-') |
| 206 |
< |
picres.or |= YDECR; |
| 206 |
> |
picres.rt |= YDECR; |
| 207 |
|
if (picres.xr == 0) |
| 208 |
< |
picres.or |= YMAJOR; |
| 208 |
> |
picres.rt |= YMAJOR; |
| 209 |
|
picres.yr = atoi(argv[++i]); |
| 210 |
|
break; |
| 211 |
|
default: |
| 223 |
|
fmtid = "8-bit_grey"; |
| 224 |
|
else |
| 225 |
|
fmtid = "24-bit_rgb"; |
| 226 |
+ |
if (dataonly && format == 'w') |
| 227 |
+ |
if (brightonly) |
| 228 |
+ |
fmtid = "16-bit_grey"; |
| 229 |
+ |
else |
| 230 |
+ |
fmtid = "48-bit_rgb"; |
| 231 |
|
/* assign reverse ordering */ |
| 232 |
|
rord[ord[0]] = 0; |
| 233 |
|
rord[ord[1]] = 1; |
| 300 |
|
if (resolution && fin2 != NULL) { |
| 301 |
|
RESOLU pres2; |
| 302 |
|
if (!fgetsresolu(&pres2, fin2) || |
| 303 |
< |
pres2.or != picres.or || |
| 303 |
> |
pres2.rt != picres.rt || |
| 304 |
|
pres2.xr != picres.xr || |
| 305 |
|
pres2.yr != picres.yr || |
| 306 |
|
!fgetsresolu(&pres2, fin3) || |
| 307 |
< |
pres2.or != picres.or || |
| 307 |
> |
pres2.rt != picres.rt || |
| 308 |
|
pres2.xr != picres.xr || |
| 309 |
|
pres2.yr != picres.yr) { |
| 310 |
|
fprintf(stderr, "%s: resolution mismatch\n", |
| 329 |
|
/* get header */ |
| 330 |
|
getheader(fin, checkhead, NULL); |
| 331 |
|
if (wrongformat) { |
| 332 |
< |
fprintf(stderr, "%s: input not a Radiance picture\n", |
| 332 |
> |
fprintf(stderr, |
| 333 |
> |
"%s: input not a Radiance RGBE picture\n", |
| 334 |
|
progname); |
| 335 |
|
quit(1); |
| 336 |
|
} |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
|
| 357 |
+ |
int |
| 358 |
|
checkhead(line) /* deal with line from header */ |
| 359 |
|
char *line; |
| 360 |
|
{ |
| 362 |
|
double d; |
| 363 |
|
COLOR ctmp; |
| 364 |
|
|
| 365 |
< |
if (formatval(fmt, line)) |
| 366 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
| 367 |
< |
else if (original && isexpos(line)) { |
| 365 |
> |
if (formatval(fmt, line)) { |
| 366 |
> |
if (!strcmp(fmt, CIEFMT)) { |
| 367 |
> |
mybright = &xyz_bright; |
| 368 |
> |
if (original) { |
| 369 |
> |
scalecolor(exposure, 1./WHTEFFICACY); |
| 370 |
> |
doexposure++; |
| 371 |
> |
} |
| 372 |
> |
} else if (!strcmp(fmt, COLRFMT)) |
| 373 |
> |
mybright = &rgb_bright; |
| 374 |
> |
else |
| 375 |
> |
wrongformat++; |
| 376 |
> |
} else if (original && isexpos(line)) { |
| 377 |
|
d = 1.0/exposval(line); |
| 378 |
|
scalecolor(exposure, d); |
| 379 |
|
doexposure++; |
| 385 |
|
doexposure++; |
| 386 |
|
} else if (header) |
| 387 |
|
fputs(line, stdout); |
| 388 |
+ |
return(0); |
| 389 |
|
} |
| 390 |
|
|
| 391 |
|
|
| 457 |
|
} |
| 458 |
|
} |
| 459 |
|
} |
| 460 |
< |
free((char *)scanln); |
| 460 |
> |
free((void *)scanln); |
| 461 |
|
} |
| 462 |
|
|
| 463 |
|
|
| 501 |
|
quit(1); |
| 502 |
|
} |
| 503 |
|
} |
| 504 |
< |
free((char *)scanln); |
| 504 |
> |
free((void *)scanln); |
| 505 |
|
} |
| 506 |
|
|
| 507 |
|
|
| 508 |
+ |
void |
| 509 |
|
quit(code) |
| 510 |
|
int code; |
| 511 |
|
{ |
| 513 |
|
} |
| 514 |
|
|
| 515 |
|
|
| 516 |
+ |
swap16(wp, n) /* swap n 16-bit words */ |
| 517 |
+ |
register uint16 *wp; |
| 518 |
+ |
int n; |
| 519 |
+ |
{ |
| 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 |
|
{ |
| 620 |
|
} |
| 621 |
|
|
| 622 |
|
|
| 623 |
+ |
getcword(col) /* get a 16-bit color value from stream(s) */ |
| 624 |
+ |
COLOR col; |
| 625 |
+ |
{ |
| 626 |
+ |
uint16 vw[3]; |
| 627 |
+ |
|
| 628 |
+ |
if (fin2 == NULL) { |
| 629 |
+ |
if (fread((char *)vw, sizeof(uint16), 3, fin) != 3) |
| 630 |
+ |
return(-1); |
| 631 |
+ |
} else { |
| 632 |
+ |
if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 || |
| 633 |
+ |
fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 || |
| 634 |
+ |
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
| 635 |
+ |
return(-1); |
| 636 |
+ |
} |
| 637 |
+ |
if (swapbytes) |
| 638 |
+ |
swap16(vw, 3); |
| 639 |
+ |
setcolor(col, (vw[rord[RED]]+.5)/65536., |
| 640 |
+ |
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
| 641 |
+ |
return(0); |
| 642 |
+ |
} |
| 643 |
+ |
|
| 644 |
+ |
|
| 645 |
|
getbascii(col) /* get an ascii brightness value from fin */ |
| 646 |
|
COLOR col; |
| 647 |
|
{ |
| 706 |
|
} |
| 707 |
|
|
| 708 |
|
|
| 709 |
+ |
getbword(col) /* get a 16-bit brightness value from fin */ |
| 710 |
+ |
COLOR col; |
| 711 |
+ |
{ |
| 712 |
+ |
uint16 vw; |
| 713 |
+ |
double d; |
| 714 |
+ |
|
| 715 |
+ |
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
| 716 |
+ |
return(-1); |
| 717 |
+ |
if (swapbytes) |
| 718 |
+ |
swap16(&vw, 1); |
| 719 |
+ |
d = (vw+.5)/65536.; |
| 720 |
+ |
setcolor(col, d, d, d); |
| 721 |
+ |
return(0); |
| 722 |
+ |
} |
| 723 |
+ |
|
| 724 |
+ |
|
| 725 |
|
putcascii(col) /* put an ascii color to stdout */ |
| 726 |
|
COLOR col; |
| 727 |
|
{ |
| 777 |
|
putcbyte(col) /* put a byte color to stdout */ |
| 778 |
|
COLOR col; |
| 779 |
|
{ |
| 780 |
< |
register int i; |
| 780 |
> |
long i; |
| 781 |
|
BYTE vb[3]; |
| 782 |
|
|
| 783 |
|
i = colval(col,ord[0])*256.; |
| 792 |
|
} |
| 793 |
|
|
| 794 |
|
|
| 795 |
+ |
putcword(col) /* put a 16-bit color to stdout */ |
| 796 |
+ |
COLOR col; |
| 797 |
+ |
{ |
| 798 |
+ |
long i; |
| 799 |
+ |
uint16 vw[3]; |
| 800 |
+ |
|
| 801 |
+ |
i = colval(col,ord[0])*65536.; |
| 802 |
+ |
vw[0] = min(i,65535); |
| 803 |
+ |
i = colval(col,ord[1])*65536.; |
| 804 |
+ |
vw[1] = min(i,65535); |
| 805 |
+ |
i = colval(col,ord[2])*65536.; |
| 806 |
+ |
vw[2] = min(i,65535); |
| 807 |
+ |
if (swapbytes) |
| 808 |
+ |
swap16(vw, 3); |
| 809 |
+ |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
| 810 |
+ |
|
| 811 |
+ |
return(ferror(stdout) ? -1 : 0); |
| 812 |
+ |
} |
| 813 |
+ |
|
| 814 |
+ |
|
| 815 |
|
putbascii(col) /* put an ascii brightness to stdout */ |
| 816 |
|
COLOR col; |
| 817 |
|
{ |
| 818 |
< |
fprintf(stdout, "%15.3e\n", bright(col)); |
| 818 |
> |
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
| 819 |
|
|
| 820 |
|
return(ferror(stdout) ? -1 : 0); |
| 821 |
|
} |
| 826 |
|
{ |
| 827 |
|
float vf; |
| 828 |
|
|
| 829 |
< |
vf = bright(col); |
| 829 |
> |
vf = (*mybright)(col); |
| 830 |
|
fwrite((char *)&vf, sizeof(float), 1, stdout); |
| 831 |
|
|
| 832 |
|
return(ferror(stdout) ? -1 : 0); |
| 838 |
|
{ |
| 839 |
|
double vd; |
| 840 |
|
|
| 841 |
< |
vd = bright(col); |
| 841 |
> |
vd = (*mybright)(col); |
| 842 |
|
fwrite((char *)&vd, sizeof(double), 1, stdout); |
| 843 |
|
|
| 844 |
|
return(ferror(stdout) ? -1 : 0); |
| 848 |
|
putbint(col) /* put an int brightness to stdout */ |
| 849 |
|
COLOR col; |
| 850 |
|
{ |
| 851 |
< |
fprintf(stdout, "%d\n", (int)(bright(col)*256.)); |
| 851 |
> |
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
| 852 |
|
|
| 853 |
|
return(ferror(stdout) ? -1 : 0); |
| 854 |
|
} |
| 860 |
|
register int i; |
| 861 |
|
BYTE vb; |
| 862 |
|
|
| 863 |
< |
i = bright(col)*256.; |
| 863 |
> |
i = (*mybright)(col)*256.; |
| 864 |
|
vb = min(i,255); |
| 865 |
|
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
| 866 |
|
|
| 868 |
|
} |
| 869 |
|
|
| 870 |
|
|
| 871 |
+ |
putbword(col) /* put a 16-bit brightness to stdout */ |
| 872 |
+ |
COLOR col; |
| 873 |
+ |
{ |
| 874 |
+ |
long i; |
| 875 |
+ |
uint16 vw; |
| 876 |
+ |
|
| 877 |
+ |
i = (*mybright)(col)*65536.; |
| 878 |
+ |
vw = min(i,65535); |
| 879 |
+ |
if (swapbytes) |
| 880 |
+ |
swap16(&vw, 1); |
| 881 |
+ |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
| 882 |
+ |
|
| 883 |
+ |
return(ferror(stdout) ? -1 : 0); |
| 884 |
+ |
} |
| 885 |
+ |
|
| 886 |
+ |
|
| 887 |
|
putpascii(col) /* put an ascii primary to stdout */ |
| 888 |
|
COLOR col; |
| 889 |
|
{ |
| 929 |
|
putpbyte(col) /* put a byte primary to stdout */ |
| 930 |
|
COLOR col; |
| 931 |
|
{ |
| 932 |
< |
register int i; |
| 932 |
> |
long i; |
| 933 |
|
BYTE vb; |
| 934 |
|
|
| 935 |
|
i = colval(col,putprim)*256.; |
| 940 |
|
} |
| 941 |
|
|
| 942 |
|
|
| 943 |
+ |
putpword(col) /* put a 16-bit primary to stdout */ |
| 944 |
+ |
COLOR col; |
| 945 |
+ |
{ |
| 946 |
+ |
long i; |
| 947 |
+ |
uint16 vw; |
| 948 |
+ |
|
| 949 |
+ |
i = colval(col,putprim)*65536.; |
| 950 |
+ |
vw = min(i,65535); |
| 951 |
+ |
if (swapbytes) |
| 952 |
+ |
swap16(&vw, 1); |
| 953 |
+ |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
| 954 |
+ |
|
| 955 |
+ |
return(ferror(stdout) ? -1 : 0); |
| 956 |
+ |
} |
| 957 |
+ |
|
| 958 |
+ |
|
| 959 |
|
set_io() /* set put and get functions */ |
| 960 |
|
{ |
| 961 |
|
switch (format) { |
| 1057 |
|
goto seekerr; |
| 1058 |
|
if (fseek(fin3, |
| 1059 |
|
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
| 1060 |
+ |
goto seekerr; |
| 1061 |
+ |
} |
| 1062 |
+ |
} |
| 1063 |
+ |
return; |
| 1064 |
+ |
case 'w': /* 16-bit */ |
| 1065 |
+ |
if (putprim == BRIGHT) { |
| 1066 |
+ |
getval = getbword; |
| 1067 |
+ |
putval = putbword; |
| 1068 |
+ |
} else if (putprim != ALL) { |
| 1069 |
+ |
getval = getbword; |
| 1070 |
+ |
putval = putpword; |
| 1071 |
+ |
} else { |
| 1072 |
+ |
getval = getcword; |
| 1073 |
+ |
putval = putcword; |
| 1074 |
+ |
if (reverse && !interleave) { |
| 1075 |
+ |
if (fin2 == NULL) |
| 1076 |
+ |
goto namerr; |
| 1077 |
+ |
if (fseek(fin2, |
| 1078 |
+ |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
| 1079 |
+ |
goto seekerr; |
| 1080 |
+ |
if (fseek(fin3, |
| 1081 |
+ |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
| 1082 |
|
goto seekerr; |
| 1083 |
|
} |
| 1084 |
|
} |