--- ray/src/px/ra_gif.c 1994/05/03 10:06:32 2.2 +++ ray/src/px/ra_gif.c 2003/06/05 19:29:34 2.8 @@ -1,26 +1,19 @@ -/* 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.8 2003/06/05 19:29:34 schorsch Exp $"; #endif - /* * Convert from Radiance picture file to Compuserve GIF. * Currently, we don't know how to get back. */ #include +#include +#include +#include "platform.h" #include "color.h" - #include "resolu.h" -#ifdef MSDOS -#include -#endif - -#include - #define MAXCOLORS 256 int rmap[MAXCOLORS]; @@ -33,8 +26,10 @@ extern long ftell(); long picstart; -extern BYTE clrtab[][3]; +BYTE clrtab[256][3]; +extern int samplefac; + extern int getgifpix(); COLR *scanln; @@ -50,6 +45,8 @@ int dither = 1; /* dither colors? */ int bradj = 0; /* brightness adjustment */ +int ncolors = 0; /* number of colors requested */ + char *progname; @@ -57,16 +54,13 @@ main(argc, argv) int argc; char *argv[]; { - int ncolors = 0; int bitsperpix; int i; -#ifdef MSDOS - extern int _fmode; - _fmode = O_BINARY; - setmode(fileno(stdin), O_BINARY); - setmode(fileno(stdout), O_BINARY); -#endif + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); progname = argv[0]; + samplefac = 0; for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -88,6 +82,9 @@ char *argv[]; goto userr; bradj = atoi(argv[++i]); break; + case 'n': + samplefac = atoi(argv[++i]); + break; default: goto userr; } @@ -136,7 +133,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); } @@ -155,13 +152,17 @@ int y; if (freadcolrs(scanln, xmax, stdin) < 0) { fprintf(stderr, "%s: error reading picture (y==%d)\n", progname, ymax-1-y); + exit(1); } while (++currow < y); if (bradj) 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); } @@ -170,21 +171,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); } @@ -209,10 +219,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])); }