--- ray/src/px/ra_avs.c 1993/06/01 17:36:55 2.1 +++ ray/src/px/ra_avs.c 1993/11/18 09:55:29 2.6 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include #ifdef MSDOS #include #endif @@ -17,7 +18,7 @@ static char SCCSid[] = "$SunId$ LBL"; extern char *malloc(); -double gamma = 2.2; /* gamma correction */ +double gamcor = 2.2; /* gamma correction */ int bradj = 0; /* brightness adjustment */ @@ -30,6 +31,7 @@ main(argc, argv) int argc; char *argv[]; { + extern long getint(); int reverse = 0; int i; @@ -39,7 +41,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] != '-') @@ -63,7 +65,7 @@ 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); } @@ -71,11 +73,11 @@ char *argv[]; setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); #endif - setcolrgam(gamma); /* set up gamma correction */ + setcolrgam(gamcor); /* set up gamma correction */ if (reverse) { /* get their image resolution */ - fread((char *)&xmax, sizeof(int), 1, stdin); - fread((char *)&ymax, sizeof(int), 1, stdin); + xmax = getint(4, stdin); + ymax = getint(4, stdin); /* put our header */ printargs(i, argv, stdout); fputformat(COLRFMT, stdout); @@ -89,8 +91,8 @@ char *argv[]; fgetresolu(&xmax, &ymax, stdin) < 0) quiterr("bad picture format"); /* write their header */ - fwrite((char *)&xmax, sizeof(int), 1, stdout); - fwrite((char *)&ymax, sizeof(int), 1, stdout); + putint((long)xmax, 4, stdout); + putint((long)ymax, 4, stdout); /* convert file */ ra2avs(); } @@ -125,11 +127,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);