--- ray/src/px/ra_pr.c 1991/10/14 17:09:36 1.12 +++ ray/src/px/ra_pr.c 2004/03/28 20:33:14 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_pr.c,v 2.7 2004/03/28 20:33:14 schorsch Exp $"; #endif - /* * ra_pr.c - program to convert between RADIANCE and pixrect picture format. * @@ -12,11 +9,13 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include +#include +#include "rtmisc.h" #include "rasterfile.h" - #include "color.h" - +#include "resolu.h" #include "pic.h" /* descriptor for a picture file or frame buffer */ @@ -31,32 +30,23 @@ typedef struct { } pos; /* position(s) */ } pic; -extern pic *openinput(), *openoutput(); -extern char *ecalloc(), *emalloc(); - -extern long ftell(); - -extern double atof(), pow(); - -double gamma = 2.2; /* gamma correction */ - +double gamcor = 2.2; /* gamma correction */ int bradj = 0; /* brightness adjustment */ - pic *inpic, *outpic; - char *progname; - char errmsg[128]; - COLR *inl; - int xmax, ymax; +static void quiterr(char *err); +static pic * openinput(char *fname, struct rasterfile *h); +static pic * openoutput(char *fname, struct rasterfile *h); +static void pr2ra(struct rasterfile *h); -main(argc, argv) -int argc; -char *argv[]; + +int +main(int argc, char *argv[]) { colormap rasmap; struct rasterfile head; @@ -75,7 +65,7 @@ char *argv[]; dither = !dither; break; case 'g': - gamma = atof(argv[++i]); + gamcor = atof(argv[++i]); break; case 'b': greyscale = !greyscale; @@ -120,10 +110,11 @@ 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 { @@ -155,8 +146,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); @@ -166,6 +159,7 @@ char *err; } +void eputs(s) char *s; { @@ -173,6 +167,7 @@ char *s; } +void quit(code) int code; { @@ -180,10 +175,11 @@ int code; } -pic * -openinput(fname, h) /* open RADIANCE input file */ -char *fname; -register struct rasterfile *h; +static pic * +openinput( /* open RADIANCE input file */ + char *fname, + register struct rasterfile *h +) { register pic *p; @@ -195,7 +191,7 @@ register struct rasterfile *h; return(NULL); /* check header */ if (checkheader(p->fp, COLRFMT, NULL) < 0 || - fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) + fgetresolu(&xmax, &ymax, p->fp) < 0) quiterr("bad picture format"); p->nexty = 0; p->bytes_line = 0; /* variable length lines */ @@ -217,10 +213,11 @@ register struct rasterfile *h; } -pic * -openoutput(fname, h) /* open output rasterfile */ -char *fname; -register struct rasterfile *h; +static pic * +openoutput( /* open output rasterfile */ + char *fname, + register struct rasterfile *h +) { register pic *p; @@ -240,8 +237,10 @@ register struct rasterfile *h; } -pr2ra(h) /* pixrect file to RADIANCE file */ -struct rasterfile *h; +static void +pr2ra( /* pixrect file to RADIANCE file */ + struct rasterfile *h +) { BYTE cmap[3][256]; COLR ctab[256]; @@ -256,9 +255,9 @@ 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 */ @@ -273,13 +272,15 @@ struct rasterfile *h; if (fwritecolrs(scanline, xmax, stdout) < 0) quiterr("error writing RADIANCE file"); } - free((char *)scanline); + free((void *)scanline); } -picreadline3(y, l3) /* read in 3-byte scanline */ -int y; -register rgbpixel *l3; +extern void +picreadline3( /* read in 3-byte scanline */ + int y, + register rgbpixel *l3 +) { register int i; @@ -310,9 +311,11 @@ register rgbpixel *l3; } -picwriteline(y, l) /* write out scanline */ -int y; -register pixel *l; +extern void +picwriteline( /* write out scanline */ + int y, + register pixel *l +) { if (outpic->nexty != y) { /* seek to scanline */ if (outpic->bytes_line == 0) { @@ -334,8 +337,10 @@ register pixel *l; } -picwritecm(cm) /* write out color map */ -colormap cm; +extern void +picwritecm( /* write out color map */ + colormap cm +) { register int i, j; @@ -353,13 +358,15 @@ colormap cm; } -picreadcm(map) /* do gamma correction if requested */ -colormap map; +extern void +picreadcm( /* do gamma correction if requested */ + colormap map +) { register int i, val; for (i = 0; i < 256; i++) { - val = pow((i+0.5)/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; } }