ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_gif.c
(Generate patch)

Comparing ray/src/px/ra_gif.c (file contents):
Revision 2.1 by greg, Wed Mar 30 14:24:52 1994 UTC vs.
Revision 2.6 by greg, Mon Apr 3 15:29:43 1995 UTC

# Line 33 | Line 33 | extern long  ftell();
33  
34   long  picstart;
35  
36 < extern BYTE  clrtab[][3];
36 > BYTE  clrtab[256][3];
37  
38 + extern int  samplefac;
39 +
40   extern int  getgifpix();
41  
42   COLR    *scanln;
43 + BYTE    *pixscan;
44  
45   int  xmax, ymax;                        /* picture size */
46  
# Line 45 | Line 48 | double gamv = 2.2;                     /* gamma correction */
48  
49   int  greyscale = 0;                     /* convert to B&W? */
50  
51 + int  dither = 1;                        /* dither colors? */
52 +
53   int  bradj = 0;                         /* brightness adjustment */
54  
55 + int  ncolors = 0;                       /* number of colors requested */
56 +
57   char  *progname;
58  
59  
# Line 54 | Line 61 | main(argc, argv)
61   int  argc;
62   char  *argv[];
63   {
57        int  ncolors = 0;
64          int  bitsperpix;
65          int  i;
66   #ifdef MSDOS
# Line 64 | Line 70 | char  *argv[];
70          setmode(fileno(stdout), O_BINARY);
71   #endif
72          progname = argv[0];
73 +        samplefac = 0;
74  
75          for (i = 1; i < argc; i++)
76                  if (argv[i][0] == '-')
# Line 74 | Line 81 | char  *argv[];
81                          case 'b':
82                                  greyscale = 1;
83                                  break;
84 +                        case 'd':
85 +                                dither = !dither;
86 +                                break;
87                          case 'c':
88                                  ncolors = atoi(argv[++i]);
89                                  break;
# Line 82 | Line 92 | char  *argv[];
92                                          goto userr;
93                                  bradj = atoi(argv[++i]);
94                                  break;
95 +                        case 'n':
96 +                                samplefac = atoi(argv[++i]);
97 +                                break;
98                          default:
99                                  goto userr;
100                          }
# Line 130 | Line 143 | char  *argv[];
143          exit(0);
144   userr:
145          fprintf(stderr,
146 <        "Usage: %s [-b][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
146 >        "Usage: %s [-b][-d][-n samp][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
147                          progname);
148          exit(1);
149   }
# Line 149 | Line 162 | int  y;
162                  if (freadcolrs(scanln, xmax, stdin) < 0) {
163                          fprintf(stderr, "%s: error reading picture (y==%d)\n",
164                                          progname, ymax-1-y);
165 +                        exit(1);
166                  }
167          while (++currow < y);
168          if (bradj)
169                  shiftcolrs(scanln, xmax, bradj);
170          colrs_gambs(scanln, xmax);
171 +        if (pixscan != NULL)
172 +                if (samplefac)
173 +                        neu_dith_colrs(pixscan, scanln, xmax);
174 +                else
175 +                        dith_colrs(pixscan, scanln, xmax);
176   }
177  
178  
# Line 162 | Line 181 | int    nc;
181   {
182          register int    i;
183  
184 <        new_histo();
184 >        if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1)
185 >                goto memerr;
186          for (i = 0; i < ymax; i++) {
187                  getrow(i);
188 <                cnt_colrs(scanln, xmax);
188 >                if (samplefac)
189 >                        neu_colrs(scanln, xmax);
190 >                else
191 >                        cnt_colrs(scanln, xmax);
192          }
193 <        new_clrtab(nc);
193 >        if (samplefac)
194 >                neu_clrtab(nc);
195 >        else
196 >                new_clrtab(nc);
197          for (i = 0; i < nc; i++) {
198                  rmap[i] = clrtab[i][RED];
199                  gmap[i] = clrtab[i][GRN];
200                  bmap[i] = clrtab[i][BLU];
201          }
202 +        if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL)
203 +                goto memerr;
204 +        return;
205 + memerr:
206 +        fprintf(stderr, "%s: out of memory\n", progname);
207 +        exit(1);
208   }
209  
210  
# Line 197 | Line 229 | int  x, y;
229  
230          getrow(y);
231          if (greyscale)
232 <                return(normbright(scanln[x]));
233 <        return(map_pixel(scanln[x]));
232 >                return((normbright(scanln[x])*ncolors)>>8);
233 >        if (pixscan != NULL)
234 >                return(pixscan[x]);
235 >        return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x]));
236   }
237  
238  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines