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.7 by greg, Sat Feb 22 02:07:27 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert from Radiance picture file to Compuserve GIF.
6   * Currently, we don't know how to get back.
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8  
9   #include  <stdio.h>
10  
11 + #include  <time.h>
12 +
13   #include  "color.h"
14  
15   #include  "resolu.h"
# Line 33 | Line 32 | extern long  ftell();
32  
33   long  picstart;
34  
35 < extern BYTE  clrtab[][3];
35 > BYTE  clrtab[256][3];
36  
37 + extern int  samplefac;
38 +
39   extern int  getgifpix();
40  
41   COLR    *scanln;
42 + BYTE    *pixscan;
43  
44   int  xmax, ymax;                        /* picture size */
45  
# Line 45 | Line 47 | double gamv = 2.2;                     /* gamma correction */
47  
48   int  greyscale = 0;                     /* convert to B&W? */
49  
50 + int  dither = 1;                        /* dither colors? */
51 +
52   int  bradj = 0;                         /* brightness adjustment */
53  
54 + int  ncolors = 0;                       /* number of colors requested */
55 +
56   char  *progname;
57  
58  
# Line 54 | Line 60 | main(argc, argv)
60   int  argc;
61   char  *argv[];
62   {
57        int  ncolors = 0;
63          int  bitsperpix;
64          int  i;
65   #ifdef MSDOS
# Line 64 | Line 69 | char  *argv[];
69          setmode(fileno(stdout), O_BINARY);
70   #endif
71          progname = argv[0];
72 +        samplefac = 0;
73  
74          for (i = 1; i < argc; i++)
75                  if (argv[i][0] == '-')
# Line 74 | Line 80 | char  *argv[];
80                          case 'b':
81                                  greyscale = 1;
82                                  break;
83 +                        case 'd':
84 +                                dither = !dither;
85 +                                break;
86                          case 'c':
87                                  ncolors = atoi(argv[++i]);
88                                  break;
# Line 82 | Line 91 | char  *argv[];
91                                          goto userr;
92                                  bradj = atoi(argv[++i]);
93                                  break;
94 +                        case 'n':
95 +                                samplefac = atoi(argv[++i]);
96 +                                break;
97                          default:
98                                  goto userr;
99                          }
# Line 130 | Line 142 | char  *argv[];
142          exit(0);
143   userr:
144          fprintf(stderr,
145 <        "Usage: %s [-b][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
145 >        "Usage: %s [-b][-d][-n samp][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
146                          progname);
147          exit(1);
148   }
# Line 149 | Line 161 | int  y;
161                  if (freadcolrs(scanln, xmax, stdin) < 0) {
162                          fprintf(stderr, "%s: error reading picture (y==%d)\n",
163                                          progname, ymax-1-y);
164 +                        exit(1);
165                  }
166          while (++currow < y);
167          if (bradj)
168                  shiftcolrs(scanln, xmax, bradj);
169          colrs_gambs(scanln, xmax);
170 +        if (pixscan != NULL)
171 +                if (samplefac)
172 +                        neu_dith_colrs(pixscan, scanln, xmax);
173 +                else
174 +                        dith_colrs(pixscan, scanln, xmax);
175   }
176  
177  
# Line 162 | Line 180 | int    nc;
180   {
181          register int    i;
182  
183 <        new_histo();
183 >        if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1)
184 >                goto memerr;
185          for (i = 0; i < ymax; i++) {
186                  getrow(i);
187 <                cnt_colrs(scanln, xmax);
187 >                if (samplefac)
188 >                        neu_colrs(scanln, xmax);
189 >                else
190 >                        cnt_colrs(scanln, xmax);
191          }
192 <        new_clrtab(nc);
192 >        if (samplefac)
193 >                neu_clrtab(nc);
194 >        else
195 >                new_clrtab(nc);
196          for (i = 0; i < nc; i++) {
197                  rmap[i] = clrtab[i][RED];
198                  gmap[i] = clrtab[i][GRN];
199                  bmap[i] = clrtab[i][BLU];
200          }
201 +        if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL)
202 +                goto memerr;
203 +        return;
204 + memerr:
205 +        fprintf(stderr, "%s: out of memory\n", progname);
206 +        exit(1);
207   }
208  
209  
# Line 197 | Line 228 | int  x, y;
228  
229          getrow(y);
230          if (greyscale)
231 <                return(normbright(scanln[x]));
232 <        return(map_pixel(scanln[x]));
231 >                return((normbright(scanln[x])*ncolors)>>8);
232 >        if (pixscan != NULL)
233 >                return(pixscan[x]);
234 >        return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x]));
235   }
236  
237  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines