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.10 by schorsch, Sun Jul 27 22:12:03 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.
7   */
8  
9   #include  <stdio.h>
10 + #include  <time.h>
11 + #include  <math.h>
12  
13 + #include  "platform.h"
14   #include  "color.h"
15
15   #include  "resolu.h"
16  
18 #ifdef MSDOS
19 #include  <fcntl.h>
20 #endif
21
22 #include  <math.h>
23
17   #define MAXCOLORS               256
18  
19   int rmap[MAXCOLORS];
# Line 33 | Line 26 | extern long  ftell();
26  
27   long  picstart;
28  
29 < extern BYTE  clrtab[][3];
29 > BYTE  clrtab[256][3];
30  
31 + extern int  samplefac;
32 +
33   extern int  getgifpix();
34  
35   COLR    *scanln;
36 + BYTE    *pixscan;
37  
38   int  xmax, ymax;                        /* picture size */
39  
# Line 45 | Line 41 | double gamv = 2.2;                     /* gamma correction */
41  
42   int  greyscale = 0;                     /* convert to B&W? */
43  
44 + int  dither = 1;                        /* dither colors? */
45 +
46   int  bradj = 0;                         /* brightness adjustment */
47  
48 + int  ncolors = 0;                       /* number of colors requested */
49 +
50   char  *progname;
51  
52  
# Line 54 | Line 54 | main(argc, argv)
54   int  argc;
55   char  *argv[];
56   {
57        int  ncolors = 0;
57          int  bitsperpix;
58          int  i;
59 < #ifdef MSDOS
60 <        extern int  _fmode;
61 <        _fmode = O_BINARY;
63 <        setmode(fileno(stdin), O_BINARY);
64 <        setmode(fileno(stdout), O_BINARY);
65 < #endif
59 >        SET_DEFAULT_BINARY();
60 >        SET_FILE_BINARY(stdin);
61 >        SET_FILE_BINARY(stdout);
62          progname = argv[0];
63 +        samplefac = 0;
64  
65          for (i = 1; i < argc; i++)
66                  if (argv[i][0] == '-')
# Line 74 | Line 71 | char  *argv[];
71                          case 'b':
72                                  greyscale = 1;
73                                  break;
74 +                        case 'd':
75 +                                dither = !dither;
76 +                                break;
77                          case 'c':
78                                  ncolors = atoi(argv[++i]);
79                                  break;
# Line 82 | Line 82 | char  *argv[];
82                                          goto userr;
83                                  bradj = atoi(argv[++i]);
84                                  break;
85 +                        case 'n':
86 +                                samplefac = atoi(argv[++i]);
87 +                                break;
88                          default:
89                                  goto userr;
90                          }
# Line 115 | Line 118 | char  *argv[];
118                                  /* set up gamma correction */
119          setcolrgam(gamv);
120                                  /* figure out the bits per pixel */
121 <        if (ncolors < 2 | ncolors > MAXCOLORS)
121 >        if ((ncolors < 2) | (ncolors > MAXCOLORS))
122                  ncolors = MAXCOLORS;
123          for (bitsperpix = 1; ncolors > 1<<bitsperpix; bitsperpix++)
124                  ;
# Line 130 | Line 133 | char  *argv[];
133          exit(0);
134   userr:
135          fprintf(stderr,
136 <        "Usage: %s [-b][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
136 >        "Usage: %s [-b][-d][-n samp][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
137                          progname);
138          exit(1);
139   }
# Line 149 | Line 152 | int  y;
152                  if (freadcolrs(scanln, xmax, stdin) < 0) {
153                          fprintf(stderr, "%s: error reading picture (y==%d)\n",
154                                          progname, ymax-1-y);
155 +                        exit(1);
156                  }
157          while (++currow < y);
158          if (bradj)
159                  shiftcolrs(scanln, xmax, bradj);
160          colrs_gambs(scanln, xmax);
161 +        if (pixscan != NULL) {
162 +                if (samplefac)
163 +                        neu_dith_colrs(pixscan, scanln, xmax);
164 +                else
165 +                        dith_colrs(pixscan, scanln, xmax);
166 +        }
167   }
168  
169  
# Line 162 | Line 172 | int    nc;
172   {
173          register int    i;
174  
175 <        new_histo();
175 >        if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1)
176 >                goto memerr;
177          for (i = 0; i < ymax; i++) {
178                  getrow(i);
179 <                cnt_colrs(scanln, xmax);
179 >                if (samplefac)
180 >                        neu_colrs(scanln, xmax);
181 >                else
182 >                        cnt_colrs(scanln, xmax);
183          }
184 <        new_clrtab(nc);
184 >        if (samplefac)
185 >                neu_clrtab(nc);
186 >        else
187 >                new_clrtab(nc);
188          for (i = 0; i < nc; i++) {
189                  rmap[i] = clrtab[i][RED];
190                  gmap[i] = clrtab[i][GRN];
191                  bmap[i] = clrtab[i][BLU];
192          }
193 +        if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL)
194 +                goto memerr;
195 +        return;
196 + memerr:
197 +        fprintf(stderr, "%s: out of memory\n", progname);
198 +        exit(1);
199   }
200  
201  
# Line 197 | Line 220 | int  x, y;
220  
221          getrow(y);
222          if (greyscale)
223 <                return(normbright(scanln[x]));
224 <        return(map_pixel(scanln[x]));
223 >                return((normbright(scanln[x])*ncolors)>>8);
224 >        if (pixscan != NULL)
225 >                return(pixscan[x]);
226 >        return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x]));
227   }
228  
229  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines