Back to index

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

Go to the source code of this file.

Defines

#define abovethresh(c)

Functions

static void quiterr (char *err)
static void ra2hex (void)
int main (int argc, char *argv[])

Variables

static const char RCSid [] = "$Id: ra_hexbit.c,v 3.3 2004/03/28 20:33:14 schorsch Exp $"
char * progname
int xmax
int ymax
double thresh = 0.5
COLR threshclr

Define Documentation

#define abovethresh (   c)
Value:
((c)[EXP]>threshclr[EXP] || \
                     ((c)[EXP]==threshclr[EXP] && (c)[GRN]>threshclr[GRN]))

Definition at line 19 of file ra_hexbit.c.


Function Documentation

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

Definition at line 27 of file ra_hexbit.c.

{
       int  i;
       
       progname = argv[0];

       for (i = 1; i < argc; i++)
              if (argv[i][0] == '-')
                     switch (argv[i][1]) {
                     case 't':            /* threshold value */
                            thresh = atof(argv[++i]);
                            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);
       }
                            /* assign threshold color */
       setcolr(threshclr, thresh, thresh, thresh);
                            /* get our header */
       if (checkheader(stdin, COLRFMT, NULL) < 0 ||
                     fgetresolu(&xmax, &ymax, stdin) < 0)
              quiterr("bad picture format");
                            /* convert file */
       ra2hex();
       exit(0);
userr:
       fprintf(stderr,
              "Usage: %s [-t thresh] [input [output]]\n", progname);
       exit(1);
}

Here is the call graph for this function:

static void quiterr ( char *  err) [static]

Definition at line 77 of file ra_hexbit.c.

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

Definition at line 90 of file ra_hexbit.c.

{
       static char   cmap[] = "0123456789ABCDEF";
       COLR   *scanin;
       register int  x, c, t;
       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");
              c = 0;
              for (x = 0; x < xmax; x++)
                     if ((t = 03 - (x&03)))
                            c |= abovethresh(scanin[x]) << t;
                     else {
                            c |= abovethresh(scanin[x]);
                            putchar(cmap[c]);
                            c = 0;
                     }
              if (t)
                     fputc(cmap[c], stdout);
              fputc('\n', stdout);
              if (ferror(stdout))
                     quiterr("error writing hex bit file");
       }
                                          /* free scanline */
       free((void *)scanin);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* progname

Definition at line 14 of file ra_hexbit.c.

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

Definition at line 2 of file ra_hexbit.c.

double thresh = 0.5

Definition at line 16 of file ra_hexbit.c.

Definition at line 17 of file ra_hexbit.c.

int xmax

Definition at line 15 of file ra_hexbit.c.

int ymax

Definition at line 15 of file ra_hexbit.c.