--- ray/src/px/ra_pr24.c 1991/08/07 08:36:33 1.7 +++ ray/src/px/ra_pr24.c 1992/09/21 12:15:02 2.3 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,14 +10,22 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#ifdef MSDOS +#include +#endif + #include "rasterfile.h" #include "color.h" -extern double atof(), pow(); +#include "resolu.h" -double gamma = 2.0; /* gamma correction */ +extern double pow(); +extern char *malloc(); + +double gamma = 2.2; /* gamma correction */ + int bradj = 0; /* brightness adjustment */ char *progname; @@ -32,9 +40,15 @@ char *argv[]; struct rasterfile head; int reverse = 0; int i; - +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif progname = argv[0]; + head.ras_type = RT_STANDARD; for (i = 1; i < argc; i++) if (argv[i][0] == '-') switch (argv[i][1]) { @@ -47,7 +61,10 @@ char *argv[]; bradj = atoi(argv[++i]); break; case 'r': - reverse = !reverse; + if (!strcmp(argv[i], "-rgb")) + head.ras_type = RT_FORMAT_RGB; + else + reverse = 1; break; default: goto userr; @@ -85,13 +102,13 @@ char *argv[]; printargs(i, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); - fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); + fprtresolu(xmax, ymax, stdout); /* convert file */ pr2ra(head.ras_type); } else { /* get header info. */ if (checkheader(stdin, COLRFMT, NULL) < 0 || - fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) + fgetresolu(&xmax, &ymax, stdin) < 0) quiterr("bad picture format"); /* write rasterfile header */ head.ras_magic = RAS_MAGIC; @@ -99,12 +116,11 @@ char *argv[]; head.ras_height = ymax; head.ras_depth = 24; head.ras_length = xmax*ymax*3; - head.ras_type = RT_STANDARD; head.ras_maptype = RMT_NONE; head.ras_maplength = 0; fwrite((char *)&head, sizeof(head), 1, stdout); /* convert file */ - ra2pr(); + ra2pr(head.ras_type); } exit(0); userr: @@ -137,12 +153,14 @@ int rf; quiterr("out of memory in pr2ra"); /* convert image */ for (y = ymax-1; y >= 0; y--) { - for (x = 0; x < xmax; x++) - if (rf == RT_FORMAT_RGB) { + if (rf == RT_FORMAT_RGB) + for (x = 0; x < xmax; x++) { scanout[x][RED] = getc(stdin); scanout[x][GRN] = getc(stdin); scanout[x][BLU] = getc(stdin); - } else { + } + else + for (x = 0; x < xmax; x++) { scanout[x][BLU] = getc(stdin); scanout[x][GRN] = getc(stdin); scanout[x][RED] = getc(stdin); @@ -160,7 +178,8 @@ int rf; } -ra2pr() /* convert Radiance scanlines to 24-bit rasterfile */ +ra2pr(rf) /* convert Radiance scanlines to 24-bit rasterfile */ +int rf; { COLR *scanin; register int x; @@ -168,7 +187,7 @@ ra2pr() /* convert Radiance scanlines to 24-bit rast /* allocate scanline */ scanin = (COLR *)malloc(xmax*sizeof(COLR)); if (scanin == NULL) - quiterr("out of memory in pr2ra"); + quiterr("out of memory in ra2pr"); /* convert image */ for (y = ymax-1; y >= 0; y--) { if (freadcolrs(scanin, xmax, stdin) < 0) @@ -176,11 +195,18 @@ ra2pr() /* convert Radiance scanlines to 24-bit rast if (bradj) shiftcolrs(scanin, xmax, bradj); colrs_gambs(scanin, xmax); - for (x = 0; x < xmax; x++) { - putc(scanin[x][BLU], stdout); - putc(scanin[x][GRN], stdout); - putc(scanin[x][RED], stdout); - } + if (rf == RT_FORMAT_RGB) + for (x = 0; x < xmax; x++) { + putc(scanin[x][RED], stdout); + putc(scanin[x][GRN], stdout); + putc(scanin[x][BLU], stdout); + } + else + for (x = 0; x < xmax; x++) { + putc(scanin[x][BLU], stdout); + putc(scanin[x][GRN], stdout); + putc(scanin[x][RED], stdout); + } if (ferror(stdout)) quiterr("error writing rasterfile"); }