Back to index

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

Go to the source code of this file.

Functions

 main (int argc, argv)
 quiterr (char *err)
 skel2ra ()
 ra2skel ()

Variables

static const char RCSid [] = "$Id: ra_skel.c,v 2.13 2006/03/10 19:40:13 schorsch Exp $"
double gamcor = 2.2
int bradj = 0
char * progname
int xmax
int ymax

Function Documentation

main ( int  argc,
argv   
)

Definition at line 35 of file ra_skel.c.

{
       int  reverse = 0;
       int  i;
       
       progname = argv[0];

       for (i = 1; i < argc; i++)
              if (argv[i][0] == '-')
                     switch (argv[i][1]) {
                     case 'g':            /* gamma correction */
                            gamcor = atof(argv[++i]);
                            break;
                     case 'e':            /* exposure adjustment */
                            if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
                                   goto userr;
                            bradj = atoi(argv[++i]);
                            break;
                     case 'r':            /* reverse conversion */
                            reverse = 1;
                            break;
                     default:
                            goto userr;
                     }
              else
                     break;

       if (i < argc-2)
              goto userr;
       if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
              fprintf(stderr, "%s: can't open input \"%s\"\n",
                            progname, argv[i]);
              exit(1);
       }
       if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
              fprintf(stderr, "%s: can't open output \"%s\"\n",
                            progname, argv[i+1]);
              exit(1);
       }
       SET_FILE_BINARY(stdin);
       SET_FILE_BINARY(stdout);
       setcolrgam(gamcor);         /* set up gamma correction */
       if (reverse) {
                                   /* get their image resolution */
              read_skel_head(&xmax, &ymax);
                                   /* put our header */
              newheader("RADIANCE", stdout);
              printargs(i, argv, stdout);
              fputformat(COLRFMT, stdout);
              putchar('\n');
              fprtresolu(xmax, ymax, stdout);
                                   /* convert file */
              skel2ra();
       } else {
                                   /* get our header */
              if (checkheader(stdin, COLRFMT, NULL) < 0 ||
                            fgetresolu(&xmax, &ymax, stdin) < 0)
                     quiterr("bad picture format");
                                   /* write their header */
              write_skel_head(xmax, ymax);
                                   /* convert file */
              ra2skel();
       }
       exit(0);
userr:
       fprintf(stderr,
              "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
                     progname);
       exit(1);
}

Here is the call graph for this function:

static void quiterr ( char *  err)

Definition at line 109 of file ra_skel.c.

{
       if (err != NULL) {
              fprintf(stderr, "%s: %s\n", progname, err);
              exit(1);
       }
       exit(0);
}

Here is the caller graph for this function:

ra2skel ( )

Definition at line 150 of file ra_skel.c.

{
       COLR   *scanin;
       register int  x;
       int    y;
                                          /* allocate scanline */
       scanin = (COLR *)malloc(xmax*sizeof(COLR));
       if (scanin == NULL)
              quiterr("out of memory in ra2skel");
                                          /* convert image */
       for (y = ymax-1; y >= 0; y--) {
              if (freadcolrs(scanin, xmax, stdin) < 0)
                     quiterr("error reading Radiance picture");
              if (bradj)                  /* adjust exposure */
                     shiftcolrs(scanin, xmax, bradj);
              colrs_gambs(scanin, xmax);  /* gamma correction */
              for (x = 0; x < xmax; x++) {
                     putc(scanin[x][RED], stdout);
                     putc(scanin[x][GRN], stdout);
                     putc(scanin[x][BLU], stdout);
              }
              if (ferror(stdout))
                     quiterr("error writing skel file");
       }
                                          /* free scanline */
       free((void *)scanin);
}

Here is the call graph for this function:

Here is the caller graph for this function:

skel2ra ( )

Definition at line 120 of file ra_skel.c.

{
       COLR   *scanout;
       register int  x;
       int    y;
                                          /* allocate scanline */
       scanout = (COLR *)malloc(xmax*sizeof(COLR));
       if (scanout == NULL)
              quiterr("out of memory in skel2ra");
                                          /* convert image */
       for (y = ymax-1; y >= 0; y--) {
              for (x = 0; x < xmax; x++) {
                     scanout[x][RED] = getc(stdin);
                     scanout[x][GRN] = getc(stdin);
                     scanout[x][BLU] = getc(stdin);
              }
              if (feof(stdin) | ferror(stdin))
                     quiterr("error reading skel image");
                                          /* undo gamma */
              gambs_colrs(scanout, xmax);
              if (bradj)                  /* adjust exposure */
                     shiftcolrs(scanout, xmax, bradj);
              if (fwritecolrs(scanout, xmax, stdout) < 0)
                     quiterr("error writing Radiance picture");
       }
                                          /* free scanline */
       free((void *)scanout);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int bradj = 0

Definition at line 28 of file ra_skel.c.

double gamcor = 2.2

Definition at line 26 of file ra_skel.c.

char* progname

Definition at line 30 of file ra_skel.c.

const char RCSid[] = "$Id: ra_skel.c,v 2.13 2006/03/10 19:40:13 schorsch Exp $" [static]

Definition at line 2 of file ra_skel.c.

int xmax

Definition at line 32 of file ra_skel.c.

int ymax

Definition at line 32 of file ra_skel.c.