--- ray/src/px/ra_pr24.c 1991/04/18 14:35:40 1.5 +++ ray/src/px/ra_pr24.c 1991/10/14 17:09:39 1.10 @@ -1,4 +1,4 @@ -/* Copyright (c) 1990 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -16,8 +16,10 @@ static char SCCSid[] = "$SunId$ LBL"; extern double atof(), pow(); -double gamma = 2.0; /* gamma correction */ +double gamma = 2.2; /* gamma correction */ +int bradj = 0; /* brightness adjustment */ + char *progname; int xmax, ymax; @@ -33,14 +35,23 @@ char *argv[]; progname = argv[0]; + head.ras_type = RT_STANDARD; for (i = 1; i < argc; i++) if (argv[i][0] == '-') switch (argv[i][1]) { case 'g': gamma = atof(argv[++i]); break; + case 'e': + if (argv[i+1][0] != '+' && argv[i+1][0] != '-') + goto userr; + 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; @@ -69,9 +80,10 @@ char *argv[]; quiterr("bad raster format"); xmax = head.ras_width; ymax = head.ras_height; - if (head.ras_type != RT_STANDARD || - head.ras_maptype != RMT_NONE || - head.ras_depth != 24) + if ((head.ras_type != RT_STANDARD + && head.ras_type != RT_FORMAT_RGB) + || head.ras_maptype != RMT_NONE + || head.ras_depth != 24) quiterr("incompatible format"); /* put header */ printargs(i, argv, stdout); @@ -79,7 +91,7 @@ char *argv[]; putchar('\n'); fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); /* convert file */ - pr2ra(); + pr2ra(head.ras_type); } else { /* get header info. */ if (checkheader(stdin, COLRFMT, NULL) < 0 || @@ -91,16 +103,15 @@ 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: - fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n", + fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n", progname); exit(1); } @@ -117,7 +128,8 @@ char *err; } -pr2ra() /* convert 24-bit scanlines to Radiance picture */ +pr2ra(rf) /* convert 24-bit scanlines to Radiance picture */ +int rf; { COLR *scanout; register int x; @@ -128,14 +140,23 @@ pr2ra() /* convert 24-bit scanlines to Radiance pict quiterr("out of memory in pr2ra"); /* convert image */ for (y = ymax-1; y >= 0; y--) { - for (x = 0; x < xmax; x++) { - scanout[x][BLU] = getc(stdin); - scanout[x][GRN] = getc(stdin); - scanout[x][RED] = getc(stdin); - } + 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 + for (x = 0; x < xmax; x++) { + scanout[x][BLU] = getc(stdin); + scanout[x][GRN] = getc(stdin); + scanout[x][RED] = getc(stdin); + } if (feof(stdin) || ferror(stdin)) quiterr("error reading rasterfile"); gambs_colrs(scanout, xmax); + if (bradj) + shiftcolrs(scanout, xmax, bradj); if (fwritecolrs(scanout, xmax, stdout) < 0) quiterr("error writing Radiance picture"); } @@ -144,7 +165,8 @@ pr2ra() /* convert 24-bit scanlines to Radiance pict } -ra2pr() /* convert Radiance scanlines to 24-bit rasterfile */ +ra2pr(rf) /* convert Radiance scanlines to 24-bit rasterfile */ +int rf; { COLR *scanin; register int x; @@ -152,17 +174,26 @@ 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) quiterr("error reading Radiance picture"); + 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"); }