--- ray/src/px/ra_avs.c 1993/06/04 14:45:59 2.3 +++ ray/src/px/ra_avs.c 2004/03/28 20:33:14 2.11 @@ -1,37 +1,38 @@ -/* Copyright (c) 1993 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_avs.c,v 2.11 2004/03/28 20:33:14 schorsch Exp $"; #endif - /* * Convert Radiance file to/from AVS file. */ #include #include -#ifdef MSDOS -#include -#endif +#include + +#include "platform.h" +#include "rtio.h" #include "color.h" #include "resolu.h" -extern char *malloc(); +double gamcor = 2.2; /* gamma correction */ -double gamma = 2.2; /* gamma correction */ - int bradj = 0; /* brightness adjustment */ char *progname; int xmax, ymax; +static void quiterr(char *err); +static void avs2ra(void); +static void ra2avs(void); -main(argc, argv) -int argc; -char *argv[]; + +int +main( + int argc, + char *argv[] +) { - extern long getint(); int reverse = 0; int i; @@ -41,7 +42,7 @@ char *argv[]; if (argv[i][0] == '-') switch (argv[i][1]) { case 'g': /* gamma correction */ - gamma = atof(argv[++i]); + gamcor = atof(argv[++i]); break; case 'e': /* exposure adjustment */ if (argv[i+1][0] != '+' && argv[i+1][0] != '-') @@ -65,20 +66,21 @@ char *argv[]; exit(1); } if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { - fprintf(stderr, "can't open output \"%s\"\n", + fprintf(stderr, "%s: can't open output \"%s\"\n", progname, argv[i+1]); exit(1); } -#ifdef MSDOS - setmode(fileno(stdin), O_BINARY); - setmode(fileno(stdout), O_BINARY); -#endif - setcolrgam(gamma); /* set up gamma correction */ + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); + setcolrgam(gamcor); /* set up gamma correction */ if (reverse) { /* get their image resolution */ xmax = getint(4, stdin); ymax = getint(4, stdin); + if (feof(stdin)) + quiterr("empty input file"); /* put our header */ + newheader("RADIANCE", stdout); printargs(i, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); @@ -105,8 +107,10 @@ userr: } -quiterr(err) /* print message and exit */ -char *err; +static void +quiterr( /* print message and exit */ + char *err +) { if (err != NULL) { fprintf(stderr, "%s: %s\n", progname, err); @@ -116,7 +120,8 @@ char *err; } -avs2ra() /* convert 24-bit scanlines to Radiance picture */ +static void +avs2ra(void) /* convert 24-bit scanlines to Radiance picture */ { COLR *scanout; register int x; @@ -127,11 +132,13 @@ avs2ra() /* convert 24-bit scanlines to Radiance pict quiterr("out of memory in avs2ra"); /* convert image */ for (y = ymax-1; y >= 0; y--) { - (void)getc(stdin); /* toss alpha */ - scanout[x][RED] = getc(stdin); - scanout[x][GRN] = getc(stdin); - scanout[x][BLU] = getc(stdin); - if (feof(stdin) || ferror(stdin)) + for (x = 0; x < xmax; x++) { + (void)getc(stdin); /* toss alpha */ + scanout[x][RED] = getc(stdin); + scanout[x][GRN] = getc(stdin); + scanout[x][BLU] = getc(stdin); + } + if (feof(stdin) | ferror(stdin)) quiterr("error reading AVS image"); /* undo gamma */ gambs_colrs(scanout, xmax); @@ -141,11 +148,12 @@ avs2ra() /* convert 24-bit scanlines to Radiance pict quiterr("error writing Radiance picture"); } /* free scanline */ - free((char *)scanout); + free((void *)scanout); } -ra2avs() /* convert Radiance scanlines to 24-bit */ +static void +ra2avs(void) /* convert Radiance scanlines to 24-bit */ { COLR *scanin; register int x; @@ -171,5 +179,5 @@ ra2avs() /* convert Radiance scanlines to 24-bit */ quiterr("error writing AVS file"); } /* free scanline */ - free((char *)scanin); + free((void *)scanin); }