--- ray/src/px/pvalue.c 2003/10/22 02:06:35 2.24 +++ ray/src/px/pvalue.c 2004/10/01 07:46:26 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pvalue.c,v 2.24 2003/10/22 02:06:35 greg Exp $"; +static const char RCSid[] = "$Id: pvalue.c,v 2.28 2004/10/01 07:46:26 greg Exp $"; #endif /* * pvalue.c - program to print pixel values. @@ -11,6 +11,7 @@ static const char RCSid[] = "$Id: pvalue.c,v 2.24 2003 #include "standard.h" #include "color.h" #include "resolu.h" +#include "view.h" #define min(a,b) ((a)<(b)?(a):(b)) @@ -19,34 +20,20 @@ static const char RCSid[] = "$Id: pvalue.c,v 2.24 2003 #define BRIGHT 4 RESOLU picres; /* resolution of picture */ - int uniq = 0; /* print only unique values? */ - int doexposure = 0; /* exposure change? (>100 to print) */ - int dataonly = 0; /* data only format? */ - int putprim = ALL; /* what to put out */ - int reverse = 0; /* reverse conversion? */ - int format = 'a'; /* input/output format */ char *fmtid = "ascii"; /* format identifier for header */ - int header = 1; /* do header? */ - long skipbytes = 0; /* skip bytes in input? */ - int swapbytes = 0; /* swap bytes? */ - int interleave = 1; /* file is interleaved? */ - int resolution = 1; /* put/get resolution string? */ - int original = 0; /* convert to original values? */ - int wrongformat = 0; /* wrong input format? */ - double gamcor = 1.0; /* gamma correction */ int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ @@ -59,35 +46,58 @@ char *progname; FILE *fin; FILE *fin2 = NULL, *fin3 = NULL; /* for other color channels */ -int (*getval)(), (*putval)(); -double -rgb_bright(clr) -COLOR clr; +typedef int getfunc_t(COLOR col); +typedef int putfunc_t(COLOR col); +typedef double brightfunc_t(COLOR col); + +getfunc_t *getval; +putfunc_t *putval; +brightfunc_t *mybright; + +static gethfunc checkhead; +static brightfunc_t rgb_bright, xyz_bright; +static getfunc_t getbascii, getbint, getbdouble, getbfloat, getbbyte, getbword; +static getfunc_t getcascii, getcint, getcdouble, getcfloat, getcbyte, getcword; +static putfunc_t putbascii, putbint, putbdouble, putbfloat, putbbyte, putbword; +static putfunc_t putcascii, putcint, putcdouble, putcfloat, putcbyte, putcword; +static putfunc_t putpascii, putpint, putpdouble, putpfloat, putpbyte, putpword; + +static void set_io(void); +static void pixtoval(void); +static void valtopix(void); +static void swap16(uint16 *wp, int n); +static void swap32(uint32 *wp, int n); +static void swap64(char *wp, int n); + + +static double +rgb_bright( + COLOR clr +) { return(bright(clr)); } -double -xyz_bright(clr) -COLOR clr; +static double +xyz_bright( + COLOR clr +) { return(clr[CIEY]); } -double (*mybright)() = &rgb_bright; - - -main(argc, argv) -int argc; -char **argv; +int +main( + int argc, + char **argv +) { - extern int checkhead(); - extern long atol(); double d, expval = 1.0; int i; progname = argv[0]; + mybright = &rgb_bright; /* default */ for (i = 1; i < argc; i++) if (argv[i][0] == '-' || argv[i][0] == '+') @@ -350,25 +360,24 @@ unkopt: } quit(0); + return 0; /* pro forma return */ } -int -checkhead(line) /* deal with line from header */ -char *line; +static int +checkhead( /* deal with line from header */ + char *line, + void *p +) { char fmt[32]; double d; COLOR ctmp; if (formatval(fmt, line)) { - if (!strcmp(fmt, CIEFMT)) { + if (!strcmp(fmt, CIEFMT)) mybright = &xyz_bright; - if (original) { - scalecolor(exposure, 1./WHTEFFICACY); - doexposure++; - } - } else if (!strcmp(fmt, COLRFMT)) + else if (!strcmp(fmt, COLRFMT)) mybright = &rgb_bright; else wrongformat++; @@ -388,7 +397,8 @@ char *line; } -pixtoval() /* convert picture to values */ +static void +pixtoval(void) /* convert picture to values */ { register COLOR *scanln; int dogamma; @@ -461,7 +471,8 @@ pixtoval() /* convert picture to values */ } -valtopix() /* convert values to a pixel file */ +static void +valtopix(void) /* convert values to a pixel file */ { int dogamma; register COLOR *scanln; @@ -513,9 +524,11 @@ int code; } -swap16(wp, n) /* swap n 16-bit words */ -register uint16 *wp; -int n; +static void +swap16( /* swap n 16-bit words */ + register uint16 *wp, + int n +) { while (n-- > 0) { *wp = *wp << 8 | ((*wp >> 8) & 0xff); @@ -524,9 +537,11 @@ int n; } -swap32(wp, n) /* swap n 32-bit words */ -register uint32 *wp; -int n; +static void +swap32( /* swap n 32-bit words */ + register uint32 *wp, + int n +) { while (n-- > 0) { *wp = *wp << 24 | ((*wp >> 24) & 0xff) | @@ -536,9 +551,11 @@ int n; } -swap64(wp, n) /* swap n 64-bit words */ -register char *wp; -int n; +static void +swap64( /* swap n 64-bit words */ + register char *wp, + int n +) { register int t; @@ -552,8 +569,10 @@ int n; } -getcascii(col) /* get an ascii color value from stream(s) */ -COLOR col; +static int +getcascii( /* get an ascii color value from stream(s) */ + COLOR col +) { double vd[3]; @@ -571,8 +590,10 @@ COLOR col; } -getcdouble(col) /* get a double color value from stream(s) */ -COLOR col; +static int +getcdouble( /* get a double color value from stream(s) */ + COLOR col +) { double vd[3]; @@ -592,8 +613,10 @@ COLOR col; } -getcfloat(col) /* get a float color value from stream(s) */ -COLOR col; +static int +getcfloat( /* get a float color value from stream(s) */ + COLOR col +) { float vf[3]; @@ -613,8 +636,10 @@ COLOR col; } -getcint(col) /* get an int color value from stream(s) */ -COLOR col; +static int +getcint( /* get an int color value from stream(s) */ + COLOR col +) { int vi[3]; @@ -633,8 +658,10 @@ COLOR col; } -getcbyte(col) /* get a byte color value from stream(s) */ -COLOR col; +static int +getcbyte( /* get a byte color value from stream(s) */ + COLOR col +) { BYTE vb[3]; @@ -653,8 +680,10 @@ COLOR col; } -getcword(col) /* get a 16-bit color value from stream(s) */ -COLOR col; +static int +getcword( /* get a 16-bit color value from stream(s) */ + COLOR col +) { uint16 vw[3]; @@ -675,8 +704,10 @@ COLOR col; } -getbascii(col) /* get an ascii brightness value from fin */ -COLOR col; +static int +getbascii( /* get an ascii brightness value from fin */ + COLOR col +) { double vd; @@ -687,8 +718,10 @@ COLOR col; } -getbdouble(col) /* get a double brightness value from fin */ -COLOR col; +static int +getbdouble( /* get a double brightness value from fin */ + COLOR col +) { double vd; @@ -701,8 +734,10 @@ COLOR col; } -getbfloat(col) /* get a float brightness value from fin */ -COLOR col; +static int +getbfloat( /* get a float brightness value from fin */ + COLOR col +) { float vf; @@ -715,8 +750,10 @@ COLOR col; } -getbint(col) /* get an int brightness value from fin */ -COLOR col; +static int +getbint( /* get an int brightness value from fin */ + COLOR col +) { int vi; double d; @@ -729,8 +766,10 @@ COLOR col; } -getbbyte(col) /* get a byte brightness value from fin */ -COLOR col; +static int +getbbyte( /* get a byte brightness value from fin */ + COLOR col +) { BYTE vb; double d; @@ -743,8 +782,10 @@ COLOR col; } -getbword(col) /* get a 16-bit brightness value from fin */ -COLOR col; +static int +getbword( /* get a 16-bit brightness value from fin */ + COLOR col +) { uint16 vw; double d; @@ -759,8 +800,10 @@ COLOR col; } -putcascii(col) /* put an ascii color to stdout */ -COLOR col; +static int +putcascii( /* put an ascii color to stdout */ + COLOR col +) { fprintf(stdout, "%15.3e %15.3e %15.3e\n", colval(col,ord[0]), @@ -771,8 +814,10 @@ COLOR col; } -putcfloat(col) /* put a float color to stdout */ -COLOR col; +static int +putcfloat( /* put a float color to stdout */ + COLOR col +) { float vf[3]; @@ -787,8 +832,10 @@ COLOR col; } -putcdouble(col) /* put a double color to stdout */ -COLOR col; +static int +putcdouble( /* put a double color to stdout */ + COLOR col +) { double vd[3]; @@ -803,8 +850,10 @@ COLOR col; } -putcint(col) /* put an int color to stdout */ -COLOR col; +static int +putcint( /* put an int color to stdout */ + COLOR col +) { fprintf(stdout, "%d %d %d\n", (int)(colval(col,ord[0])*256.), @@ -815,8 +864,10 @@ COLOR col; } -putcbyte(col) /* put a byte color to stdout */ -COLOR col; +static int +putcbyte( /* put a byte color to stdout */ + COLOR col +) { long i; BYTE vb[3]; @@ -833,8 +884,10 @@ COLOR col; } -putcword(col) /* put a 16-bit color to stdout */ -COLOR col; +static int +putcword( /* put a 16-bit color to stdout */ + COLOR col +) { long i; uint16 vw[3]; @@ -853,8 +906,10 @@ COLOR col; } -putbascii(col) /* put an ascii brightness to stdout */ -COLOR col; +static int +putbascii( /* put an ascii brightness to stdout */ + COLOR col +) { fprintf(stdout, "%15.3e\n", (*mybright)(col)); @@ -862,8 +917,10 @@ COLOR col; } -putbfloat(col) /* put a float brightness to stdout */ -COLOR col; +static int +putbfloat( /* put a float brightness to stdout */ + COLOR col +) { float vf; @@ -876,8 +933,10 @@ COLOR col; } -putbdouble(col) /* put a double brightness to stdout */ -COLOR col; +static int +putbdouble( /* put a double brightness to stdout */ + COLOR col +) { double vd; @@ -890,8 +949,10 @@ COLOR col; } -putbint(col) /* put an int brightness to stdout */ -COLOR col; +static int +putbint( /* put an int brightness to stdout */ + COLOR col +) { fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); @@ -899,8 +960,10 @@ COLOR col; } -putbbyte(col) /* put a byte brightness to stdout */ -COLOR col; +static int +putbbyte( /* put a byte brightness to stdout */ + COLOR col +) { register int i; BYTE vb; @@ -913,8 +976,10 @@ COLOR col; } -putbword(col) /* put a 16-bit brightness to stdout */ -COLOR col; +static int +putbword( /* put a 16-bit brightness to stdout */ + COLOR col +) { long i; uint16 vw; @@ -929,8 +994,10 @@ COLOR col; } -putpascii(col) /* put an ascii primary to stdout */ -COLOR col; +static int +putpascii( /* put an ascii primary to stdout */ + COLOR col +) { fprintf(stdout, "%15.3e\n", colval(col,putprim)); @@ -938,8 +1005,10 @@ COLOR col; } -putpfloat(col) /* put a float primary to stdout */ -COLOR col; +static int +putpfloat( /* put a float primary to stdout */ + COLOR col +) { float vf; @@ -952,8 +1021,10 @@ COLOR col; } -putpdouble(col) /* put a double primary to stdout */ -COLOR col; +static int +putpdouble( /* put a double primary to stdout */ + COLOR col +) { double vd; @@ -966,8 +1037,10 @@ COLOR col; } -putpint(col) /* put an int primary to stdout */ -COLOR col; +static int +putpint( /* put an int primary to stdout */ + COLOR col +) { fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); @@ -975,8 +1048,10 @@ COLOR col; } -putpbyte(col) /* put a byte primary to stdout */ -COLOR col; +static int +putpbyte( /* put a byte primary to stdout */ + COLOR col +) { long i; BYTE vb; @@ -989,8 +1064,10 @@ COLOR col; } -putpword(col) /* put a 16-bit primary to stdout */ -COLOR col; +static int +putpword( /* put a 16-bit primary to stdout */ + COLOR col +) { long i; uint16 vw; @@ -1005,7 +1082,8 @@ COLOR col; } -set_io() /* set put and get functions */ +static void +set_io(void) /* set put and get functions */ { switch (format) { case 'a': /* ascii */ @@ -1133,7 +1211,7 @@ set_io() /* set put and get functions */ } return; } -badopt: +/* badopt: */ /* label not used */ fprintf(stderr, "%s: botched file type\n", progname); quit(1); namerr: