--- ray/src/px/ra_gif.c 1994/05/03 10:06:32 2.2 +++ ray/src/px/ra_gif.c 1995/04/03 15:29:43 2.6 @@ -33,8 +33,10 @@ extern long ftell(); long picstart; -extern BYTE clrtab[][3]; +BYTE clrtab[256][3]; +extern int samplefac; + extern int getgifpix(); COLR *scanln; @@ -50,6 +52,8 @@ int dither = 1; /* dither colors? */ int bradj = 0; /* brightness adjustment */ +int ncolors = 0; /* number of colors requested */ + char *progname; @@ -57,7 +61,6 @@ main(argc, argv) int argc; char *argv[]; { - int ncolors = 0; int bitsperpix; int i; #ifdef MSDOS @@ -67,6 +70,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 +92,9 @@ char *argv[]; goto userr; bradj = atoi(argv[++i]); break; + case 'n': + samplefac = atoi(argv[++i]); + break; default: goto userr; } @@ -136,7 +143,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 +162,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 +181,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 +229,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])); }