--- ray/src/px/ra_gif.c 1994/05/20 11:44:19 2.3 +++ ray/src/px/ra_gif.c 2003/02/22 02:07:27 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1994 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_gif.c,v 2.7 2003/02/22 02:07:27 greg Exp $"; #endif - /* * Convert from Radiance picture file to Compuserve GIF. * Currently, we don't know how to get back. @@ -11,6 +8,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include "color.h" #include "resolu.h" @@ -33,8 +32,10 @@ extern long ftell(); long picstart; -extern BYTE clrtab[][3]; +BYTE clrtab[256][3]; +extern int samplefac; + extern int getgifpix(); COLR *scanln; @@ -50,6 +51,8 @@ int dither = 1; /* dither colors? */ int bradj = 0; /* brightness adjustment */ +int ncolors = 0; /* number of colors requested */ + char *progname; @@ -57,7 +60,6 @@ main(argc, argv) int argc; char *argv[]; { - int ncolors = 0; int bitsperpix; int i; #ifdef MSDOS @@ -67,6 +69,7 @@ char *argv[]; setmode(fileno(stdout), O_BINARY); #endif progname = argv[0]; + samplefac = 0; for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -88,6 +91,9 @@ char *argv[]; goto userr; bradj = atoi(argv[++i]); break; + case 'n': + samplefac = atoi(argv[++i]); + break; default: goto userr; } @@ -136,7 +142,7 @@ char *argv[]; exit(0); userr: fprintf(stderr, - "Usage: %s [-b][-c ncolors][-g gamv][-e +/-stops] input [output]\n", + "Usage: %s [-b][-d][-n samp][-c ncolors][-g gamv][-e +/-stops] input [output]\n", progname); exit(1); } @@ -162,7 +168,10 @@ int y; shiftcolrs(scanln, xmax, bradj); colrs_gambs(scanln, xmax); if (pixscan != NULL) - dith_colrs(pixscan, scanln, xmax); + if (samplefac) + neu_dith_colrs(pixscan, scanln, xmax); + else + dith_colrs(pixscan, scanln, xmax); } @@ -171,21 +180,30 @@ int nc; { register int i; - new_histo(); + if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) + goto memerr; for (i = 0; i < ymax; i++) { getrow(i); - cnt_colrs(scanln, xmax); + if (samplefac) + neu_colrs(scanln, xmax); + else + cnt_colrs(scanln, xmax); } - new_clrtab(nc); + if (samplefac) + neu_clrtab(nc); + else + new_clrtab(nc); for (i = 0; i < nc; i++) { rmap[i] = clrtab[i][RED]; gmap[i] = clrtab[i][GRN]; bmap[i] = clrtab[i][BLU]; } - if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } + if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL) + goto memerr; + return; +memerr: + fprintf(stderr, "%s: out of memory\n", progname); + exit(1); } @@ -210,10 +228,10 @@ int x, y; getrow(y); if (greyscale) - return(normbright(scanln[x])); + return((normbright(scanln[x])*ncolors)>>8); if (pixscan != NULL) return(pixscan[x]); - return(map_pixel(scanln[x])); + return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x])); }