Back to index

radiance  4R0+20100331
Defines | Functions | Variables
ra_rgbe.c File Reference
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "platform.h"
#include "rtprocess.h"
#include "color.h"
#include "resolu.h"

Go to the source code of this file.

Defines

#define dumpheader(fp)   fwrite(headlines, 1, headlen, fp)

Functions

static int transfer (char *ospec)
static int loadheader (FILE *fp)
int main (int argc, char *argv[])
static int addhline (char *s, void *p)

Variables

static const char RCSid [] = "$Id: ra_rgbe.c,v 2.17 2004/03/28 20:33:14 schorsch Exp $"
int bradj = 0
int doflat = 1
int force = 0
int findframe = 0
int frameno = 0
int fmterr = 0
char * headlines
int headlen
char * progname
static gethfunc addhline

Define Documentation

#define dumpheader (   fp)    fwrite(headlines, 1, headlen, fp)

Definition at line 18 of file ra_rgbe.c.


Function Documentation

static int addhline ( char *  s,
void *  p 
) [static]

Definition at line 195 of file ra_rgbe.c.

{
       char   fmt[32];
       int    n;

       if (formatval(fmt, s))
              fmterr += !globmatch(PICFMT, fmt);
       else if (!strncmp(s, "FRAME=", 6))
              frameno = atoi(s+6);
       n = strlen(s);
       if (headlen)
              headlines = (char *)realloc((void *)headlines, headlen+n+1);
       else
              headlines = (char *)malloc(n+1);
       if (headlines == NULL) {
              perror(progname);
              exit(1);
       }
       strcpy(headlines+headlen, s);
       headlen += n;
       return(0);
}

Here is the call graph for this function:

static int loadheader ( FILE *  fp) [static]

Definition at line 223 of file ra_rgbe.c.

{
       fmterr = 0; frameno = 0;
       if (headlen) {                     /* free old header */
              free(headlines);
              headlen = 0;
       }
       if (getheader(fp, addhline, NULL) < 0)
              return(0);
       if (fmterr)
              return(-1);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 37 of file ra_rgbe.c.

{
       char   *ospec;
       int  i;

       progname = argv[0];

       for (i = 1; i < argc; i++)
              if (argv[i][0] == '-')
                     switch (argv[i][1]) {
                     case 'r':
                            doflat = !doflat;
                            break;
                     case 'e':
                            if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
                                   goto userr;
                            bradj = atoi(argv[++i]);
                            break;
                     case 'n':
                            findframe = atoi(argv[++i]);
                            break;
                     case 'f':
                            force++;
                            break;
                     case '\0':
                            goto gotfile;
                     default:
                            goto userr;
                     }
              else
                     break;
gotfile:
       if (i < argc-2)
              goto userr;
       if (i <= argc-1 && strcmp(argv[i], "-") &&
                     freopen(argv[i], "r", stdin) == NULL) {
              fprintf(stderr, "%s: can't open input \"%s\"\n",
                            progname, argv[i]);
              exit(1);
       }
       SET_FILE_BINARY(stdin);
       ospec = i==argc-2 ? argv[i+1] : (char *)NULL;
       while (transfer(ospec))
              ;
       exit(0);
userr:
       fprintf(stderr,
       "Usage: %s [-r][-e +/-stops][-f][-n frame] [input [outspec]]\n",
                     progname);
       exit(1);
}

Here is the call graph for this function:

static int transfer ( char *  ospec) [static]

Definition at line 91 of file ra_rgbe.c.

{
       char   oname[PATH_MAX];
       FILE   *fp;
       int    order;
       int    xmax, ymax;
       COLR   *scanin;
       int    y;
                                   /* get header info. */
       if (!(y = loadheader(stdin)))
              return(0);
       if (y < 0 || (order = fgetresolu(&xmax, &ymax, stdin)) < 0) {
              fprintf(stderr, "%s: bad input format\n", progname);
              exit(1);
       }
                                   /* did we pass the target frame? */
       if (findframe && findframe < frameno)
              return(0);
                                   /* allocate scanline */
       scanin = (COLR *)tempbuffer(xmax*sizeof(COLR));
       if (scanin == NULL) {
              perror(progname);
              exit(1);
       }
                                   /* skip frame? */
       if (findframe > frameno) {
              for (y = ymax; y--; )
                     if (freadcolrs(scanin, xmax, stdin) < 0) {
                            fprintf(stderr,
                                   "%s: error reading input picture\n",
                                          progname);
                            exit(1);
                     }
              return(1);
       }
                                   /* open output file/command */
       if (ospec == NULL) {
              strcpy(oname, "<stdout>");
              fp = stdout;
       } else {
              sprintf(oname, ospec, frameno);
              if (oname[0] == '!') {
                     if ((fp = popen(oname+1, "w")) == NULL) {
                            fprintf(stderr, "%s: cannot start \"%s\"\n",
                                          progname, oname);
                            exit(1);
                     }
              } else {
                     if (!force && access(oname, 0) >= 0) {
                            fprintf(stderr,
                                   "%s: output file \"%s\" exists\n",
                                          progname, oname);
                            exit(1);
                     }
                     if ((fp = fopen(oname, "w")) == NULL) {
                            fprintf(stderr, "%s: ", progname);
                            perror(oname);
                            exit(1);
                     }
              }
       }
       SET_FILE_BINARY(fp);
       dumpheader(fp);                    /* put out header */
       fputs(progname, fp);
       if (bradj)
              fprintf(fp, " -e %+d", bradj);
       if (!doflat)
              fputs(" -r", fp);
       fputc('\n', fp);
       if (bradj)
              fputexpos(pow(2.0, (double)bradj), fp);
       fputc('\n', fp);
       fputresolu(order, xmax, ymax, fp);
                                   /* transfer picture */
       for (y = ymax; y--; ) {
              if (freadcolrs(scanin, xmax, stdin) < 0) {
                     fprintf(stderr, "%s: error reading input picture\n",
                                   progname);
                     exit(1);
              }
              if (bradj)
                     shiftcolrs(scanin, xmax, bradj);
              if (doflat)
                     fwrite((char *)scanin, sizeof(COLR), xmax, fp);
              else
                     fwritecolrs(scanin, xmax, fp);
              if (ferror(fp)) {
                     fprintf(stderr, "%s: error writing output to \"%s\"\n",
                                   progname, oname);
                     exit(1);
              }
       }
                                   /* clean up */
       if (oname[0] == '!')
              pclose(fp);
       else if (ospec != NULL)
              fclose(fp);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gethfunc addhline [static]

Definition at line 31 of file ra_rgbe.c.

int bradj = 0

Definition at line 20 of file ra_rgbe.c.

int doflat = 1

Definition at line 21 of file ra_rgbe.c.

int findframe = 0

Definition at line 23 of file ra_rgbe.c.

int fmterr = 0

Definition at line 25 of file ra_rgbe.c.

int force = 0

Definition at line 22 of file ra_rgbe.c.

int frameno = 0

Definition at line 24 of file ra_rgbe.c.

int headlen

Definition at line 27 of file ra_rgbe.c.

char* headlines

Definition at line 26 of file ra_rgbe.c.

char* progname

Definition at line 29 of file ra_rgbe.c.

const char RCSid[] = "$Id: ra_rgbe.c,v 2.17 2004/03/28 20:33:14 schorsch Exp $" [static]

Definition at line 2 of file ra_rgbe.c.