--- ray/src/px/ra_pr.c 1990/03/12 15:14:40 1.8 +++ ray/src/px/ra_pr.c 2003/02/22 02:07:28 2.6 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_pr.c,v 2.6 2003/02/22 02:07:28 greg Exp $"; #endif - /* * ra_pr.c - program to convert between RADIANCE and pixrect picture format. * @@ -13,10 +10,16 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + +#include + #include "rasterfile.h" #include "color.h" +#include "resolu.h" + #include "pic.h" /* descriptor for a picture file or frame buffer */ @@ -37,9 +40,9 @@ extern char *ecalloc(), *emalloc(); extern long ftell(); -extern double atof(), pow(); +double gamcor = 2.2; /* gamma correction */ -double gamma = 2.0; /* gamma correction */ +int bradj = 0; /* brightness adjustment */ pic *inpic, *outpic; @@ -73,11 +76,16 @@ char *argv[]; dither = !dither; break; case 'g': - gamma = atof(argv[++i]); + gamcor = atof(argv[++i]); break; case 'b': greyscale = !greyscale; break; + case 'e': + if (argv[i+1][0] != '+' && argv[i+1][0] != '-') + goto userr; + bradj = atoi(argv[++i]); + break; case 'r': reverse = !reverse; break; @@ -113,13 +121,15 @@ char *argv[]; head.ras_depth != 8) quiterr("incompatible format"); /* put header */ + newheader("RADIANCE", stdout); printargs(i, argv, stdout); + fputformat(COLRFMT, stdout); putchar('\n'); - fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); + fprtresolu(xmax, ymax, stdout); /* convert file */ pr2ra(&head); } else { - if (i > argc-1 || i < argc-2) + if (i < argc-2 || (!greyscale && i > argc-1)) goto userr; if ((inpic = openinput(argv[i], &head)) == NULL) { sprintf(errmsg, "can't open input \"%s\"", argv[i]); @@ -139,9 +149,9 @@ char *argv[]; quiterr(NULL); userr: fprintf(stderr, - "Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n", + "Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n", progname); - fprintf(stderr, " Or: %s -r [-g gamma] [input [output]]\n", + fprintf(stderr, " Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n", progname); exit(1); } @@ -158,6 +168,7 @@ char *err; } +void eputs(s) char *s; { @@ -165,6 +176,7 @@ char *s; } +void quit(code) int code; { @@ -185,10 +197,10 @@ register struct rasterfile *h; p->fp = stdin; else if ((p->fp = fopen(fname, "r")) == NULL) return(NULL); - /* discard header */ - getheader(p->fp, NULL); - if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) - quiterr("bad picture size"); + /* check header */ + if (checkheader(p->fp, COLRFMT, NULL) < 0 || + fgetresolu(&xmax, &ymax, p->fp) < 0) + quiterr("bad picture format"); p->nexty = 0; p->bytes_line = 0; /* variable length lines */ p->pos.y = (long *)ecalloc(ymax, sizeof(long)); @@ -248,9 +260,11 @@ struct rasterfile *h; /* convert table */ for (i = 0; i < h->ras_maplength/3; i++) setcolr(ctab[i], - pow((cmap[0][i]+.5)/256.,gamma), - pow((cmap[1][i]+.5)/256.,gamma), - pow((cmap[2][i]+.5)/256.,gamma)); + pow((cmap[0][i]+.5)/256.,gamcor), + pow((cmap[1][i]+.5)/256.,gamcor), + pow((cmap[2][i]+.5)/256.,gamcor)); + if (bradj) + shiftcolrs(ctab, 256, bradj); /* convert file */ for (i = 0; i < ymax; i++) { for (j = 0; j < xmax; j++) { @@ -263,7 +277,7 @@ struct rasterfile *h; if (fwritecolrs(scanline, xmax, stdout) < 0) quiterr("error writing RADIANCE file"); } - free((char *)scanline); + free((void *)scanline); } @@ -291,7 +305,7 @@ register rgbpixel *l3; quiterr("read error in picreadline3"); inpic->nexty = y+1; /* convert scanline */ - normcolrs(inl, xmax, 0); + normcolrs(inl, xmax, bradj); for (i = 0; i < xmax; i++) { l3[i].r = inl[i][RED]; l3[i].g = inl[i][GRN]; @@ -349,7 +363,7 @@ colormap map; register int i, val; for (i = 0; i < 256; i++) { - val = pow(i/256.0, 1.0/gamma) * 256.0; + val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; map[0][i] = map[1][i] = map[2][i] = val; } }