Back to index

radiance  4R0+20100331
Defines | Typedefs | Functions | Variables
pvalue.c File Reference
#include "platform.h"
#include "standard.h"
#include "color.h"
#include "resolu.h"
#include "view.h"

Go to the source code of this file.

Defines

#define min(a, b)   ((a)<(b)?(a):(b))
#define ALL   3
#define BRIGHT   4

Typedefs

typedef int getfunc_t (COLOR col)
typedef int putfunc_t (COLOR col)
typedef double brightfunc_t (COLOR col)

Functions

static void set_io (void)
static void pixtoval (void)
static void valtopix (void)
static double rgb_bright (COLOR clr)
static double xyz_bright (COLOR clr)
int main (int argc, char **argv)
static int checkhead (char *line, void *p)
void quit (int code)
static int getcascii (COLOR col)
static int getcdouble (COLOR col)
static int getcfloat (COLOR col)
static int getcint (COLOR col)
static int getcbyte (COLOR col)
static int getcword (COLOR col)
static int getbascii (COLOR col)
static int getbdouble (COLOR col)
static int getbfloat (COLOR col)
static int getbint (COLOR col)
static int getbbyte (COLOR col)
static int getbword (COLOR col)
static int putcascii (COLOR col)
static int putcfloat (COLOR col)
static int putcdouble (COLOR col)
static int putcint (COLOR col)
static int putcbyte (COLOR col)
static int putcword (COLOR col)
static int putbascii (COLOR col)
static int putbfloat (COLOR col)
static int putbdouble (COLOR col)
static int putbint (COLOR col)
static int putbbyte (COLOR col)
static int putbword (COLOR col)
static int putpascii (COLOR col)
static int putpfloat (COLOR col)
static int putpdouble (COLOR col)
static int putpint (COLOR col)
static int putpbyte (COLOR col)
static int putpword (COLOR col)

Variables

static const char RCSid [] = "$Id: pvalue.c,v 2.29 2006/12/23 17:27:46 greg Exp $"
RESOLU picres
int uniq = 0
int doexposure = 0
int dataonly = 0
int putprim = ALL
int reverse = 0
int format = 'a'
char * fmtid = "ascii"
int header = 1
long skipbytes = 0
int swapbytes = 0
int interleave = 1
int resolution = 1
int original = 0
int wrongformat = 0
double gamcor = 1.0
int ord [3] = {RED, GRN, BLU}
int rord [4]
COLOR exposure = WHTCOLOR
char * progname
FILE * fin
FILE * fin2 = NULL
FILE * fin3 = NULL
getfunc_tgetval
putfunc_tputval
brightfunc_tmybright
static gethfunc checkhead
static brightfunc_t rgb_bright
static brightfunc_t xyz_bright
static getfunc_t getbascii
static getfunc_t getbint
static getfunc_t getbdouble
static getfunc_t getbfloat
static getfunc_t getbbyte
static getfunc_t getbword
static getfunc_t getcascii
static getfunc_t getcint
static getfunc_t getcdouble
static getfunc_t getcfloat
static getfunc_t getcbyte
static getfunc_t getcword
static putfunc_t putbascii
static putfunc_t putbint
static putfunc_t putbdouble
static putfunc_t putbfloat
static putfunc_t putbbyte
static putfunc_t putbword
static putfunc_t putcascii
static putfunc_t putcint
static putfunc_t putcdouble
static putfunc_t putcfloat
static putfunc_t putcbyte
static putfunc_t putcword
static putfunc_t putpascii
static putfunc_t putpint
static putfunc_t putpdouble
static putfunc_t putpfloat
static putfunc_t putpbyte
static putfunc_t putpword

Define Documentation

#define ALL   3

Definition at line 19 of file pvalue.c.

#define BRIGHT   4

Definition at line 20 of file pvalue.c.

#define min (   a,
 
)    ((a)<(b)?(a):(b))

Definition at line 16 of file pvalue.c.


Typedef Documentation

typedef double brightfunc_t(COLOR col)

Definition at line 52 of file pvalue.c.

typedef int getfunc_t(COLOR col)

Definition at line 50 of file pvalue.c.

typedef int putfunc_t(COLOR col)

Definition at line 51 of file pvalue.c.


Function Documentation

static int checkhead ( char *  line,
void *  p 
) [static]

Definition at line 365 of file pvalue.c.

{
       char   fmt[32];
       double d;
       COLOR  ctmp;

       if (formatval(fmt, line)) {
              if (!strcmp(fmt, CIEFMT))
                     mybright = &xyz_bright;
              else if (!strcmp(fmt, COLRFMT))
                     mybright = &rgb_bright;
              else
                     wrongformat++;
       } else if (original && isexpos(line)) {
              d = 1.0/exposval(line);
              scalecolor(exposure, d);
              doexposure++;
       } else if (original && iscolcor(line)) {
              colcorval(ctmp, line);
              setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
                            colval(exposure,GRN)/colval(ctmp,GRN),
                            colval(exposure,BLU)/colval(ctmp,BLU));
              doexposure++;
       } else if (header)
              fputs(line, stdout);
       return(0);
}

Here is the call graph for this function:

static int getbascii ( COLOR  col) [static]

Definition at line 660 of file pvalue.c.

{
       double vd;

       if (fscanf(fin, "%lf", &vd) != 1)
              return(-1);
       setcolor(col, vd, vd, vd);
       return(0);
}
static int getbbyte ( COLOR  col) [static]

Definition at line 722 of file pvalue.c.

{
       BYTE  vb;
       double d;

       if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1)
              return(-1);
       d = (vb+.5)/256.;
       setcolor(col, d, d, d);
       return(0);
}
static int getbdouble ( COLOR  col) [static]

Definition at line 674 of file pvalue.c.

{
       double vd;

       if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
              return(-1);
       if (swapbytes)
              swap64((char *)&vd, 1);
       setcolor(col, vd, vd, vd);
       return(0);
}

Here is the call graph for this function:

static int getbfloat ( COLOR  col) [static]

Definition at line 690 of file pvalue.c.

{
       float  vf;

       if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
              return(-1);
       if (swapbytes)
              swap32((char *)&vf, 1);
       setcolor(col, vf, vf, vf);
       return(0);
}

Here is the call graph for this function:

static int getbint ( COLOR  col) [static]

Definition at line 706 of file pvalue.c.

{
       int  vi;
       double d;

       if (fscanf(fin, "%d", &vi) != 1)
              return(-1);
       d = (vi+.5)/256.;
       setcolor(col, d, d, d);
       return(0);
}
static int getbword ( COLOR  col) [static]

Definition at line 738 of file pvalue.c.

{
       uint16  vw;
       double d;

       if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
              return(-1);
       if (swapbytes)
              swap16((char *)&vw, 1);
       d = (vw+.5)/65536.;
       setcolor(col, d, d, d);
       return(0);
}

Here is the call graph for this function:

static int getcascii ( COLOR  col) [static]

Definition at line 525 of file pvalue.c.

{
       double vd[3];

       if (fin2 == NULL) {
              if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
                     return(-1);
       } else {
              if (fscanf(fin, "%lf", &vd[0]) != 1 ||
                            fscanf(fin2, "%lf", &vd[1]) != 1 ||
                            fscanf(fin3, "%lf", &vd[2]) != 1)
                     return(-1);
       }
       setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
       return(0);
}
static int getcbyte ( COLOR  col) [static]

Definition at line 614 of file pvalue.c.

{
       BYTE  vb[3];

       if (fin2 == NULL) {
              if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
                     return(-1);
       } else {
              if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
                     fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
                     fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
                     return(-1);
       }
       setcolor(col, (vb[rord[RED]]+.5)/256.,
                     (vb[rord[GRN]]+.5)/256., (vb[rord[BLU]]+.5)/256.);
       return(0);
}
static int getcdouble ( COLOR  col) [static]

Definition at line 546 of file pvalue.c.

{
       double vd[3];

       if (fin2 == NULL) {
              if (fread((char *)vd, sizeof(double), 3, fin) != 3)
                     return(-1);
       } else {
              if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
                     fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
                     fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
                     return(-1);
       }
       if (swapbytes)
              swap64((char *)vd, 3);
       setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
       return(0);
}

Here is the call graph for this function:

static int getcfloat ( COLOR  col) [static]

Definition at line 569 of file pvalue.c.

{
       float  vf[3];

       if (fin2 == NULL) {
              if (fread((char *)vf, sizeof(float), 3, fin) != 3)
                     return(-1);
       } else {
              if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
                     fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
                     fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
                     return(-1);
       }
       if (swapbytes)
              swap32((char *)vf, 3);
       setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
       return(0);
}

Here is the call graph for this function:

static int getcint ( COLOR  col) [static]

Definition at line 592 of file pvalue.c.

{
       int  vi[3];

       if (fin2 == NULL) {
              if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
                     return(-1);
       } else {
              if (fscanf(fin, "%d", &vi[0]) != 1 ||
                            fscanf(fin2, "%d", &vi[1]) != 1 ||
                            fscanf(fin3, "%d", &vi[2]) != 1)
                     return(-1);
       }
       setcolor(col, (vi[rord[RED]]+.5)/256.,
                     (vi[rord[GRN]]+.5)/256., (vi[rord[BLU]]+.5)/256.);
       return(0);
}
static int getcword ( COLOR  col) [static]

Definition at line 636 of file pvalue.c.

{
       uint16  vw[3];

       if (fin2 == NULL) {
              if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
                     return(-1);
       } else {
              if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
                     fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
                     fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
                     return(-1);
       }
       if (swapbytes)
              swap16((char *)vw, 3);
       setcolor(col, (vw[rord[RED]]+.5)/65536.,
                     (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
       return(0);
}

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 88 of file pvalue.c.

{
       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] == '+')
                     switch (argv[i][1]) {
                     case 'h':            /* header */
                            header = argv[i][0] == '+';
                            break;
                     case 'H':            /* resolution string */
                            resolution = argv[i][0] == '+';
                            break;
                     case 's':            /* skip bytes in header */
                            skipbytes = atol(argv[++i]);
                            break;
                     case 'u':            /* unique values */
                            uniq = argv[i][0] == '-';
                            break;
                     case 'o':            /* original values */
                            original = argv[i][0] == '-';
                            break;
                     case 'g':            /* gamma correction */
                            gamcor = atof(argv[i+1]);
                            if (argv[i][0] == '+')
                                   gamcor = 1.0/gamcor;
                            i++;
                            break;
                     case 'e':            /* exposure correction */
                            d = atof(argv[i+1]);
                            if (argv[i+1][0] == '-' || argv[i+1][0] == '+')
                                   d = pow(2.0, d);
                            if (argv[i][0] == '-')
                                   expval *= d;
                            scalecolor(exposure, d);
                            doexposure++;
                            i++;
                            break;
                     case 'R':            /* reverse byte sequence */
                            if (argv[i][0] == '-') {
                                   ord[0]=BLU; ord[1]=GRN; ord[2]=RED;
                            } else {
                                   ord[0]=RED; ord[1]=GRN; ord[2]=BLU;
                            }
                            break;
                     case 'r':            /* reverse conversion */
                            reverse = argv[i][0] == '-';
                            break;
                     case 'n':            /* non-interleaved RGB */
                            interleave = argv[i][0] == '+';
                            break;
                     case 'b':            /* brightness values */
                            putprim = argv[i][0] == '-' ? BRIGHT : ALL;
                            break;
                     case 'p':            /* put primary */
                            switch (argv[i][2]) {
                            case 'r': case 'R': putprim = RED; break;
                            case 'g': case 'G': putprim = GRN; break;
                            case 'b': case 'B': putprim = BLU; break;
                            default: goto unkopt;
                            }
                            break;
                     case 'd':            /* data only (no indices) */
                            dataonly = argv[i][0] == '-';
                            switch (argv[i][2]) {
                            case '\0':
                            case 'a':            /* ascii */
                                   format = 'a';
                                   fmtid = "ascii";
                                   break;
                            case 'i':            /* integer */
                                   format = 'i';
                                   fmtid = "ascii";
                                   break;
                            case 'b':            /* byte */
                                   dataonly = 1;
                                   format = 'b';
                                   fmtid = "byte";
                                   break;
                            case 'W':            /* 16-bit swapped */
                                   swapbytes = 1;
                            case 'w':            /* 16-bit */
                                   dataonly = 1;
                                   format = 'w';
                                   fmtid = "16-bit";
                                   break;
                            case 'F':            /* swapped floats */
                                   swapbytes = 1;
                            case 'f':            /* float */
                                   dataonly = 1;
                                   format = 'f';
                                   fmtid = "float";
                                   break;
                            case 'D':            /* swapped doubles */
                                   swapbytes = 1;
                            case 'd':            /* double */
                                   dataonly = 1;
                                   format = 'd';
                                   fmtid = "double";
                                   break;
                            default:
                                   goto unkopt;
                            }
                            break;
                     case 'x':            /* x resolution */
                     case 'X':            /* x resolution */
                            resolution = 0;
                            if (argv[i][0] == '-')
                                   picres.rt |= XDECR;
                            picres.xr = atoi(argv[++i]);
                            break;
                     case 'y':            /* y resolution */
                     case 'Y':            /* y resolution */
                            resolution = 0;
                            if (argv[i][0] == '-')
                                   picres.rt |= YDECR;
                            if (picres.xr == 0)
                                   picres.rt |= YMAJOR;
                            picres.yr = atoi(argv[++i]);
                            break;
                     default:
unkopt:
                            fprintf(stderr, "%s: unknown option: %s\n",
                                          progname, argv[i]);
                            quit(1);
                            break;
                     }
              else
                     break;
                                   /* recognize special formats */
       if (dataonly && format == 'b') {
              if (putprim == ALL)
                     fmtid = "24-bit_rgb";
              else
                     fmtid = "8-bit_grey";
       }
       if (dataonly && format == 'w') {
              if (putprim == ALL)
                     fmtid = "48-bit_rgb";
              else
                     fmtid = "16-bit_grey";
       }
                                   /* assign reverse ordering */
       rord[ord[0]] = 0;
       rord[ord[1]] = 1;
       rord[ord[2]] = 2;
                                   /* get input */
       if (i == argc) {
              fin = stdin;
       } else if (i < argc) {
              if ((fin = fopen(argv[i], "r")) == NULL) {
                     fprintf(stderr, "%s: can't open file \"%s\"\n",
                                          progname, argv[i]);
                     quit(1);
              }
              if (reverse && putprim != BRIGHT && i == argc-3) {
                     if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
                            fprintf(stderr, "%s: can't open file \"%s\"\n",
                                          progname, argv[i+1]);
                            quit(1);
                     }
                     if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
                            fprintf(stderr, "%s: can't open file \"%s\"\n",
                                          progname, argv[i+2]);
                            quit(1);
                     }
                     interleave = -1;
              } else if (i != argc-1)
                     fin = NULL;
              if (reverse && putprim != BRIGHT && !interleave) {
                     fin2 = fopen(argv[i], "r");
                     fin3 = fopen(argv[i], "r");
              }
              if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
                            (fseek(fin2, skipbytes, 0) ||
                            fseek(fin3, skipbytes, 0))))) {
                     fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
                                   progname, skipbytes);
                     quit(1);
              }
       }
       if (fin == NULL) {
              fprintf(stderr, "%s: bad # file arguments\n", progname);
              quit(1);
       }

       if (reverse) {
#ifdef _WIN32
              SET_FILE_BINARY(stdout);
              if (format != 'a' && format != 'i')
                     SET_FILE_BINARY(fin);
#endif
                                   /* get header */
              if (header) {
                     if (checkheader(fin, fmtid, stdout) < 0) {
                            fprintf(stderr, "%s: wrong input format\n",
                                          progname);
                            quit(1);
                     }
                     if (fin2 != NULL) {
                            getheader(fin2, NULL, NULL);
                            getheader(fin3, NULL, NULL);
                     }
              } else
                     newheader("RADIANCE", stdout);
                                   /* get resolution */
              if ((resolution && !fgetsresolu(&picres, fin)) ||
                            picres.xr <= 0 || picres.yr <= 0) {
                     fprintf(stderr, "%s: missing resolution\n", progname);
                     quit(1);
              }
              if (resolution && fin2 != NULL) {
                     RESOLU  pres2;
                     if (!fgetsresolu(&pres2, fin2) ||
                                   pres2.rt != picres.rt ||
                                   pres2.xr != picres.xr ||
                                   pres2.yr != picres.yr ||
                                   !fgetsresolu(&pres2, fin3) ||
                                   pres2.rt != picres.rt ||
                                   pres2.xr != picres.xr ||
                                   pres2.yr != picres.yr) {
                            fprintf(stderr, "%s: resolution mismatch\n",
                                          progname);
                            quit(1);
                     }
              }
                                          /* add to header */
              printargs(i, argv, stdout);
              if (expval < .99 || expval > 1.01)
                     fputexpos(expval, stdout);
              fputformat(COLRFMT, stdout);
              putchar('\n');
              fputsresolu(&picres, stdout);      /* always put resolution */
              valtopix();
       } else {
#ifdef _WIN32
              SET_FILE_BINARY(fin);
              if (format != 'a' && format != 'i')
                     SET_FILE_BINARY(stdout);
#endif
                                          /* get header */
              getheader(fin, checkhead, NULL);
              if (wrongformat) {
                     fprintf(stderr,
                            "%s: input not a Radiance RGBE picture\n",
                                   progname);
                     quit(1);
              }
              if (!fgetsresolu(&picres, fin)) {
                     fprintf(stderr, "%s: missing resolution\n", progname);
                     quit(1);
              }
              if (header) {
                     printargs(i, argv, stdout);
                     if (expval < .99 || expval > 1.01)
                            fputexpos(expval, stdout);
                     fputformat(fmtid, stdout);
                     putchar('\n');
              }
              if (resolution)                    /* put resolution */
                     fputsresolu(&picres, stdout);
              pixtoval();
       }

       quit(0);
       return 0; /* pro forma return */
}

Here is the call graph for this function:

static void pixtoval ( void  ) [static]

Definition at line 398 of file pvalue.c.

{
       register COLOR       *scanln;
       int  dogamma;
       COLOR  lastc;
       RREAL  hv[2];
       int  startprim, endprim;
       long  startpos;
       int  y;
       register int  x;

       scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
       if (scanln == NULL) {
              fprintf(stderr, "%s: out of memory\n", progname);
              quit(1);
       }
       dogamma = gamcor < .95 || gamcor > 1.05;
       if (putprim == ALL && !interleave) {
              startprim = RED; endprim = BLU;
              startpos = ftell(fin);
       } else {
              startprim = putprim; endprim = putprim;
       }
       for (putprim = startprim; putprim <= endprim; putprim++) {
              if (putprim != startprim && fseek(fin, startpos, 0)) {
                     fprintf(stderr, "%s: seek error on input file\n",
                                   progname);
                     quit(1);
              }
              set_io();
              setcolor(lastc, 0.0, 0.0, 0.0);
              for (y = 0; y < numscans(&picres); y++) {
                     if (freadscan(scanln, scanlen(&picres), fin) < 0) {
                            fprintf(stderr, "%s: read error\n", progname);
                            quit(1);
                     }
                     for (x = 0; x < scanlen(&picres); x++) {
                            if (uniq) {
                                   if (   colval(scanln[x],RED) ==
                                                 colval(lastc,RED) &&
                                          colval(scanln[x],GRN) ==
                                                 colval(lastc,GRN) &&
                                          colval(scanln[x],BLU) ==
                                                 colval(lastc,BLU)    )
                                          continue;
                                   else
                                          copycolor(lastc, scanln[x]);
                            }
                            if (doexposure)
                                   multcolor(scanln[x], exposure);
                            if (dogamma)
                                   setcolor(scanln[x],
                                   pow(colval(scanln[x],RED), 1.0/gamcor),
                                   pow(colval(scanln[x],GRN), 1.0/gamcor),
                                   pow(colval(scanln[x],BLU), 1.0/gamcor));
                            if (!dataonly) {
                                   pix2loc(hv, &picres, x, y);
                                   printf("%7d %7d ",
                                                 (int)(hv[0]*picres.xr),
                                                 (int)(hv[1]*picres.yr));
                            }
                            if ((*putval)(scanln[x]) < 0) {
                                   fprintf(stderr, "%s: write error\n",
                                                 progname);
                                   quit(1);
                            }
                     }
              }
       }
       free((void *)scanln);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int putbascii ( COLOR  col) [static]

Definition at line 862 of file pvalue.c.

{
       fprintf(stdout, "%15.3e\n", (*mybright)(col));

       return(ferror(stdout) ? -1 : 0);
}
static int putbbyte ( COLOR  col) [static]

Definition at line 916 of file pvalue.c.

{
       register int  i;
       BYTE  vb;

       i = (*mybright)(col)*256.;
       vb = min(i,255);
       fwrite((char *)&vb, sizeof(BYTE), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}
static int putbdouble ( COLOR  col) [static]

Definition at line 889 of file pvalue.c.

{
       double vd;

       vd = (*mybright)(col);
       if (swapbytes)
              swap64((char *)&vd, 1);
       fwrite((char *)&vd, sizeof(double), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putbfloat ( COLOR  col) [static]

Definition at line 873 of file pvalue.c.

{
       float  vf;

       vf = (*mybright)(col);
       if (swapbytes)
              swap32((char *)&vf, 1);
       fwrite((char *)&vf, sizeof(float), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putbint ( COLOR  col) [static]

Definition at line 905 of file pvalue.c.

{
       fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));

       return(ferror(stdout) ? -1 : 0);
}
static int putbword ( COLOR  col) [static]

Definition at line 932 of file pvalue.c.

{
       long  i;
       uint16  vw;

       i = (*mybright)(col)*65536.;
       vw = min(i,65535);
       if (swapbytes)
              swap16((char *)&vw, 1);
       fwrite((char *)&vw, sizeof(uint16), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putcascii ( COLOR  col) [static]

Definition at line 756 of file pvalue.c.

{
       fprintf(stdout, "%15.3e %15.3e %15.3e\n",
                     colval(col,ord[0]),
                     colval(col,ord[1]),
                     colval(col,ord[2]));

       return(ferror(stdout) ? -1 : 0);
}
static int putcbyte ( COLOR  col) [static]

Definition at line 820 of file pvalue.c.

{
       long  i;
       BYTE  vb[3];

       i = colval(col,ord[0])*256.;
       vb[0] = min(i,255);
       i = colval(col,ord[1])*256.;
       vb[1] = min(i,255);
       i = colval(col,ord[2])*256.;
       vb[2] = min(i,255);
       fwrite((char *)vb, sizeof(BYTE), 3, stdout);

       return(ferror(stdout) ? -1 : 0);
}
static int putcdouble ( COLOR  col) [static]

Definition at line 788 of file pvalue.c.

{
       double vd[3];

       vd[0] = colval(col,ord[0]);
       vd[1] = colval(col,ord[1]);
       vd[2] = colval(col,ord[2]);
       if (swapbytes)
              swap64((char *)vd, 3);
       fwrite((char *)vd, sizeof(double), 3, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putcfloat ( COLOR  col) [static]

Definition at line 770 of file pvalue.c.

{
       float  vf[3];

       vf[0] = colval(col,ord[0]);
       vf[1] = colval(col,ord[1]);
       vf[2] = colval(col,ord[2]);
       if (swapbytes)
              swap32((char *)vf, 3);
       fwrite((char *)vf, sizeof(float), 3, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putcint ( COLOR  col) [static]

Definition at line 806 of file pvalue.c.

{
       fprintf(stdout, "%d %d %d\n",
                     (int)(colval(col,ord[0])*256.),
                     (int)(colval(col,ord[1])*256.),
                     (int)(colval(col,ord[2])*256.));

       return(ferror(stdout) ? -1 : 0);
}
static int putcword ( COLOR  col) [static]

Definition at line 840 of file pvalue.c.

{
       long  i;
       uint16  vw[3];

       i = colval(col,ord[0])*65536.;
       vw[0] = min(i,65535);
       i = colval(col,ord[1])*65536.;
       vw[1] = min(i,65535);
       i = colval(col,ord[2])*65536.;
       vw[2] = min(i,65535);
       if (swapbytes)
              swap16((char *)vw, 3);
       fwrite((char *)vw, sizeof(uint16), 3, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putpascii ( COLOR  col) [static]

Definition at line 950 of file pvalue.c.

{
       fprintf(stdout, "%15.3e\n", colval(col,putprim));

       return(ferror(stdout) ? -1 : 0);
}
static int putpbyte ( COLOR  col) [static]

Definition at line 1004 of file pvalue.c.

{
       long  i;
       BYTE  vb;

       i = colval(col,putprim)*256.;
       vb = min(i,255);
       fwrite((char *)&vb, sizeof(BYTE), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}
static int putpdouble ( COLOR  col) [static]

Definition at line 977 of file pvalue.c.

{
       double vd;

       vd = colval(col,putprim);
       if (swapbytes)
              swap64((char *)&vd, 1);
       fwrite((char *)&vd, sizeof(double), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putpfloat ( COLOR  col) [static]

Definition at line 961 of file pvalue.c.

{
       float  vf;

       vf = colval(col,putprim);
       if (swapbytes)
              swap32((char *)&vf, 1);
       fwrite((char *)&vf, sizeof(float), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

static int putpint ( COLOR  col) [static]

Definition at line 993 of file pvalue.c.

{
       fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));

       return(ferror(stdout) ? -1 : 0);
}
static int putpword ( COLOR  col) [static]

Definition at line 1020 of file pvalue.c.

{
       long  i;
       uint16  vw;

       i = colval(col,putprim)*65536.;
       vw = min(i,65535);
       if (swapbytes)
              swap16((char *)&vw, 1);
       fwrite((char *)&vw, sizeof(uint16), 1, stdout);

       return(ferror(stdout) ? -1 : 0);
}

Here is the call graph for this function:

void quit ( int  code)

Definition at line 517 of file pvalue.c.

{
       exit(code);
}
static double rgb_bright ( COLOR  clr) [static]

Definition at line 72 of file pvalue.c.

{
       return(bright(clr));
}
static void set_io ( void  ) [static]

Definition at line 1038 of file pvalue.c.

{
       switch (format) {
       case 'a':                                 /* ascii */
              if (putprim == BRIGHT) {
                     getval = getbascii;
                     putval = putbascii;
              } else if (putprim != ALL) {
                     getval = getbascii;
                     putval = putpascii;
              } else {
                     getval = getcascii;
                     putval = putcascii;
                     if (reverse && !interleave) {
                            fprintf(stderr,
                            "%s: ASCII input files must be interleaved\n",
                                          progname);
                            quit(1);
                     }
              }
              return;
       case 'f':                                 /* binary float */
              if (putprim == BRIGHT) {
                     getval = getbfloat;
                     putval = putbfloat;
              } else if (putprim != ALL) {
                     getval = getbfloat;
                     putval = putpfloat;
              } else {
                     getval = getcfloat;
                     putval = putcfloat;
                     if (reverse && !interleave) {
                            if (fin2 == NULL)
                                   goto namerr;
                            if (fseek(fin2,
                            (long)sizeof(float)*picres.xr*picres.yr, 1))
                                   goto seekerr;
                            if (fseek(fin3,
                            (long)sizeof(float)*2*picres.xr*picres.yr, 1))
                                   goto seekerr;
                     }
              }
              return;
       case 'd':                                 /* binary double */
              if (putprim == BRIGHT) {
                     getval = getbdouble;
                     putval = putbdouble;
              } else if (putprim != ALL) {
                     getval = getbdouble;
                     putval = putpdouble;
              } else {
                     getval = getcdouble;
                     putval = putcdouble;
                     if (reverse && !interleave) {
                            if (fin2 == NULL)
                                   goto namerr;
                            if (fseek(fin2,
                            (long)sizeof(double)*picres.xr*picres.yr, 1))
                                   goto seekerr;
                            if (fseek(fin3,
                            (long)sizeof(double)*2*picres.xr*picres.yr, 1))
                                   goto seekerr;
                     }
              }
              return;
       case 'i':                                 /* integer */
              if (putprim == BRIGHT) {
                     getval = getbint;
                     putval = putbint;
              } else if (putprim != ALL) {
                     getval = getbint;
                     putval = putpint;
              } else {
                     getval = getcint;
                     putval = putcint;
                     if (reverse && !interleave) {
                            fprintf(stderr,
                            "%s: integer input files must be interleaved\n",
                                          progname);
                            quit(1);
                     }
              }
              return;
       case 'b':                                 /* byte */
              if (putprim == BRIGHT) {
                     getval = getbbyte;
                     putval = putbbyte;
              } else if (putprim != ALL) {
                     getval = getbbyte;
                     putval = putpbyte;
              } else {
                     getval = getcbyte;
                     putval = putcbyte;
                     if (reverse && !interleave) {
                            if (fin2 == NULL)
                                   goto namerr;
                            if (fseek(fin2,
                            (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
                                   goto seekerr;
                            if (fseek(fin3,
                            (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
                                   goto seekerr;
                     }
              }
              return;
       case 'w':                                 /* 16-bit */
              if (putprim == BRIGHT) {
                     getval = getbword;
                     putval = putbword;
              } else if (putprim != ALL) {
                     getval = getbword;
                     putval = putpword;
              } else {
                     getval = getcword;
                     putval = putcword;
                     if (reverse && !interleave) {
                            if (fin2 == NULL)
                                   goto namerr;
                            if (fseek(fin2,
                            (long)sizeof(uint16)*picres.xr*picres.yr, 1))
                                   goto seekerr;
                            if (fseek(fin3,
                            (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
                                   goto seekerr;
                     }
              }
              return;
       }
/* badopt: */ /* label not used */
       fprintf(stderr, "%s: botched file type\n", progname);
       quit(1);
namerr:
       fprintf(stderr, "%s: non-interleaved file(s) must be named\n",
                     progname);
       quit(1);
seekerr:
       fprintf(stderr, "%s: cannot seek on interleaved input file\n",
                     progname);
       quit(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void valtopix ( void  ) [static]

Definition at line 472 of file pvalue.c.

{
       int  dogamma;
       register COLOR       *scanln;
       int  y;
       register int  x;

       scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
       if (scanln == NULL) {
              fprintf(stderr, "%s: out of memory\n", progname);
              quit(1);
       }
       dogamma = gamcor < .95 || gamcor > 1.05;
       set_io();
       for (y = 0; y < numscans(&picres); y++) {
              for (x = 0; x < scanlen(&picres); x++) {
                     if (!dataonly) {
                            fscanf(fin, "%*d %*d");
                            if (fin2 != NULL) {
                                   fscanf(fin2, "%*d %*d");
                                   fscanf(fin3, "%*d %*d");
                            }
                     }
                     if ((*getval)(scanln[x]) < 0) {
                            fprintf(stderr, "%s: read error\n", progname);
                            quit(1);
                     }
                     if (dogamma)
                            setcolor(scanln[x],
                                   pow(colval(scanln[x],RED), gamcor),
                                   pow(colval(scanln[x],GRN), gamcor),
                                   pow(colval(scanln[x],BLU), gamcor));
                     if (doexposure)
                            multcolor(scanln[x], exposure);
              }
              if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
                     fprintf(stderr, "%s: write error\n", progname);
                     quit(1);
              }
       }
       free((void *)scanln);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static double xyz_bright ( COLOR  clr) [static]

Definition at line 80 of file pvalue.c.

{
       return(clr[CIEY]);
}

Variable Documentation

gethfunc checkhead [static]

Definition at line 58 of file pvalue.c.

int dataonly = 0

Definition at line 25 of file pvalue.c.

int doexposure = 0

Definition at line 24 of file pvalue.c.

Definition at line 42 of file pvalue.c.

FILE* fin

Definition at line 46 of file pvalue.c.

FILE* fin2 = NULL

Definition at line 47 of file pvalue.c.

FILE * fin3 = NULL

Definition at line 47 of file pvalue.c.

char* fmtid = "ascii"

Definition at line 29 of file pvalue.c.

int format = 'a'

Definition at line 28 of file pvalue.c.

double gamcor = 1.0

Definition at line 37 of file pvalue.c.

getfunc_t getbascii [static]

Definition at line 60 of file pvalue.c.

getfunc_t getbbyte [static]

Definition at line 60 of file pvalue.c.

Definition at line 60 of file pvalue.c.

getfunc_t getbfloat [static]

Definition at line 60 of file pvalue.c.

getfunc_t getbint [static]

Definition at line 60 of file pvalue.c.

getfunc_t getbword [static]

Definition at line 60 of file pvalue.c.

getfunc_t getcascii [static]

Definition at line 61 of file pvalue.c.

getfunc_t getcbyte [static]

Definition at line 61 of file pvalue.c.

Definition at line 61 of file pvalue.c.

getfunc_t getcfloat [static]

Definition at line 61 of file pvalue.c.

getfunc_t getcint [static]

Definition at line 61 of file pvalue.c.

getfunc_t getcword [static]

Definition at line 61 of file pvalue.c.

Definition at line 54 of file pvalue.c.

int header = 1

Definition at line 30 of file pvalue.c.

int interleave = 1

Definition at line 33 of file pvalue.c.

Definition at line 56 of file pvalue.c.

int ord[3] = {RED, GRN, BLU}

Definition at line 39 of file pvalue.c.

int original = 0

Definition at line 35 of file pvalue.c.

Definition at line 22 of file pvalue.c.

char* progname

Definition at line 44 of file pvalue.c.

putfunc_t putbascii [static]

Definition at line 62 of file pvalue.c.

putfunc_t putbbyte [static]

Definition at line 62 of file pvalue.c.

Definition at line 62 of file pvalue.c.

putfunc_t putbfloat [static]

Definition at line 62 of file pvalue.c.

putfunc_t putbint [static]

Definition at line 62 of file pvalue.c.

putfunc_t putbword [static]

Definition at line 62 of file pvalue.c.

putfunc_t putcascii [static]

Definition at line 63 of file pvalue.c.

putfunc_t putcbyte [static]

Definition at line 63 of file pvalue.c.

Definition at line 63 of file pvalue.c.

putfunc_t putcfloat [static]

Definition at line 63 of file pvalue.c.

putfunc_t putcint [static]

Definition at line 63 of file pvalue.c.

putfunc_t putcword [static]

Definition at line 63 of file pvalue.c.

putfunc_t putpascii [static]

Definition at line 64 of file pvalue.c.

putfunc_t putpbyte [static]

Definition at line 64 of file pvalue.c.

Definition at line 64 of file pvalue.c.

putfunc_t putpfloat [static]

Definition at line 64 of file pvalue.c.

putfunc_t putpint [static]

Definition at line 64 of file pvalue.c.

int putprim = ALL

Definition at line 26 of file pvalue.c.

putfunc_t putpword [static]

Definition at line 64 of file pvalue.c.

Definition at line 55 of file pvalue.c.

const char RCSid[] = "$Id: pvalue.c,v 2.29 2006/12/23 17:27:46 greg Exp $" [static]

Definition at line 2 of file pvalue.c.

int resolution = 1

Definition at line 34 of file pvalue.c.

int reverse = 0

Definition at line 27 of file pvalue.c.

Definition at line 59 of file pvalue.c.

int rord[4]

Definition at line 40 of file pvalue.c.

long skipbytes = 0

Definition at line 31 of file pvalue.c.

int swapbytes = 0

Definition at line 32 of file pvalue.c.

int uniq = 0

Definition at line 23 of file pvalue.c.

int wrongformat = 0

Definition at line 36 of file pvalue.c.

Definition at line 59 of file pvalue.c.