--- ray/src/px/ra_gif.c 1994/03/30 14:24:52 2.1 +++ ray/src/px/ra_gif.c 1995/04/03 15:29:43 2.6 @@ -33,11 +33,14 @@ extern long ftell(); long picstart; -extern BYTE clrtab[][3]; +BYTE clrtab[256][3]; +extern int samplefac; + extern int getgifpix(); COLR *scanln; +BYTE *pixscan; int xmax, ymax; /* picture size */ @@ -45,8 +48,12 @@ double gamv = 2.2; /* gamma correction */ int greyscale = 0; /* convert to B&W? */ +int dither = 1; /* dither colors? */ + int bradj = 0; /* brightness adjustment */ +int ncolors = 0; /* number of colors requested */ + char *progname; @@ -54,7 +61,6 @@ main(argc, argv) int argc; char *argv[]; { - int ncolors = 0; int bitsperpix; int i; #ifdef MSDOS @@ -64,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] == '-') @@ -74,6 +81,9 @@ char *argv[]; case 'b': greyscale = 1; break; + case 'd': + dither = !dither; + break; case 'c': ncolors = atoi(argv[++i]); break; @@ -82,6 +92,9 @@ char *argv[]; goto userr; bradj = atoi(argv[++i]); break; + case 'n': + samplefac = atoi(argv[++i]); + break; default: goto userr; } @@ -130,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); } @@ -149,11 +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) + if (samplefac) + neu_dith_colrs(pixscan, scanln, xmax); + else + dith_colrs(pixscan, scanln, xmax); } @@ -162,17 +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) + goto memerr; + return; +memerr: + fprintf(stderr, "%s: out of memory\n", progname); + exit(1); } @@ -197,8 +229,10 @@ int x, y; getrow(y); if (greyscale) - return(normbright(scanln[x])); - return(map_pixel(scanln[x])); + return((normbright(scanln[x])*ncolors)>>8); + if (pixscan != NULL) + return(pixscan[x]); + return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x])); }