--- ray/src/px/ra_pict.c 1991/11/21 11:34:10 2.2 +++ ray/src/px/ra_pict.c 2004/03/28 20:33:14 2.10 @@ -1,10 +1,7 @@ #ifndef lint -static char SCCSid[] = "$SunId$ Auckuni"; +static const char RCSid[] = "$Id: ra_pict.c,v 2.10 2004/03/28 20:33:14 schorsch Exp $"; #endif - -/* - * rad2pict - - * Convert an Radiance image to APPLE pict format. +/* Convert an Radiance image to APPLE pict format. * * Orginally Iris to PICT by Paul Haeberli - 1990 * Hacked into Rad to PICT by Russell Street 1990 @@ -20,8 +17,10 @@ static char SCCSid[] = "$SunId$ Auckuni"; */ #include -#include +#include +#include +#include "platform.h" #include "pict.h" #include "color.h" #include "resolu.h" @@ -29,13 +28,29 @@ static char SCCSid[] = "$SunId$ Auckuni"; int outbytes; /* This had better be 32 bits! */ char *progname; int verbose = 0; -float gamma = 2.0; +float gamcor = 2.0; int bradj = 0; - /* First some utility routines */ +static void putrect(int xorg, int yorg, int xsize, int ysize); +static void putfprect(int xorg, int yorg, int xsize, int ysize); +static void putalong(long l); +static void putashort(short s); +static void putbyte(int b); +static void putbytes(unsigned char *buf, int n ); +static void putpict(int xsize, int ysize); +static void getrow(FILE *in, char *cbuf, int xsize); +static int packbits(unsigned char *ibits, unsigned char *pbits, int nbits); +static void usage(void); -putrect(xorg,yorg,xsize,ysize) -int xorg, yorg, xsize, ysize; + + /* First some utility routines */ +static void +putrect( + int xorg, + int yorg, + int xsize, + int ysize +) { putashort(yorg); putashort(xorg); @@ -43,8 +58,13 @@ int xorg, yorg, xsize, ysize; putashort(xsize); } -putfprect(xorg,yorg,xsize,ysize) -int xorg, yorg, xsize, ysize; +static void +putfprect( + int xorg, + int yorg, + int xsize, + int ysize +) { putalong(yorg<<16); putalong(xorg<<16); @@ -52,8 +72,10 @@ int xorg, yorg, xsize, ysize; putalong(xsize<<16); } -putalong(l) -long l; +static void +putalong( + long l +) { putbyte((l>>24)&0xff); putbyte((l>>16)&0xff); @@ -61,15 +83,19 @@ long l; putbyte((l>>0)&0xff); } -putashort(s) -short s; +static void +putashort( + short s +) { putbyte((s>>8)&0xff); putbyte((s>>0)&0xff); } -putbyte(b) -int b; +static void +putbyte( + int b +) { if (putc(b,stdout) == EOF && ferror(stdout)) { fprintf(stderr,"%s: error on write\n", progname); @@ -78,9 +104,11 @@ int b; outbytes++; } -putbytes(buf,n) -unsigned char *buf; -int n; +static void +putbytes( + unsigned char *buf, + int n +) { if(!fwrite(buf,n,1,stdout)) { fprintf(stderr,"%s: error on write\n", progname); @@ -89,20 +117,24 @@ int n; outbytes+=n; } -main(argc,argv) -int argc; -char **argv; +int +main( + int argc, + char **argv +) { int xsize, ysize; int i, picsize; int ssizepos, lsizepos; - + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); progname = argv[0]; for (i = 1; i < argc ; i++) - if (argv[i][0] == '-') + if (argv[i][0] == '-') switch (argv[i][1]) { - case 'g': gamma = atof(argv[++i]); + case 'g': gamcor = atof(argv[++i]); break; case 'e': if (argv[i+1][0] != '+' && argv[i+1][0] != '-') @@ -122,7 +154,8 @@ char **argv; goto outofparse; break; /* NOTREACHED */ - otherwise: usage(); + default: + usage(); break; } else @@ -147,46 +180,46 @@ outofparse: #ifdef DEBUG fprintf(stderr, "Input file: %s\n", i <= argc - 1 ? argv[i] : "stdin"); - fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" ); - fprintf(stderr, "Gamma: %f\n", gamma); + fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" ); + fprintf(stderr, "Gamma: %f\n", gamcor); fprintf(stderr, "Brightness adjust: %d\n", bradj); - fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off"); + fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off"); #endif - /* OK. Now we read the size of the Radiance picture */ + /* OK. Now we read the size of the Radiance picture */ if (checkheader(stdin, COLRFMT, NULL) < 0 || - fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) { - fprintf(stderr, "%s: not a radiance picture\n", progname); - exit(1); + fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) { + fprintf(stderr, "%s: not a radiance picture\n", progname); + exit(1); } /* Set the gamma correction */ - setcolrgam(gamma); + setcolrgam(gamcor); for(i=0; i