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

Comparing ray/src/px/ra_tiff.c (file contents):
Revision 1.1 by greg, Thu Aug 15 13:34:58 1991 UTC vs.
Revision 1.3 by greg, Thu Aug 15 14:04:21 1991 UTC

# Line 37 | Line 37 | char  *argv[];
37          for (i = 1; i < argc; i++)
38                  if (argv[i][0] == '-')
39                          switch (argv[i][1]) {
40                        /* not allowed to reset gamma...
40                          case 'g':
41                                  gamma = atof(argv[++i]);
42                                  break;
44                        */
43                          case 'e':
44                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
45                                          goto userr;
# Line 97 | Line 95 | char   *inpf, *outf;
95          TIFF    *tif;
96          unsigned short  pconfig;
97          unsigned short  hi;
100        char    *cp;
98          register BYTE   *scanin;
99          register COLR   *scanout;
100          register int    x;
# Line 126 | Line 123 | char   *inpf, *outf;
123          if (outf != NULL && strcmp(outf, "-") &&
124                          freopen(outf, "w", stdout) == NULL)
125                  quiterr("cannot open Radiance output file");
129        if (TIFFGetField(tif, TIFFTAG_IMAGEDESCRIPTION, &cp)) {
130                while (*cp && *cp == '\n')
131                        cp++;
132                for (x = 0; cp[x]; x++)
133                        if (cp[x] != '\n' || cp[x+1] != '\n')
134                                putchar(cp[x]);
135                if (x && cp[x-1] != '\n')
136                        putchar('\n');
137        }
126          fputs(progname, stdout);
127          if (bradj)
128                  printf(" -e %+d", bradj);
# Line 182 | Line 170 | readerr:
170   }
171  
172  
185 struct hdinfo {
186        char    *buf;           /* header buffer */
187        char    *pos;           /* buffer position */
188        char    fmt[64];        /* format type */
189 };
190
191
192 headline(s, hd)                 /* add header line to buffer */
193 register char   *s;
194 register struct hdinfo  *hd;
195 {
196        register int    i;
197
198        if (isformat(s)) {
199                formatval(hd->fmt, s);
200                return;
201        }
202        if (hd->buf == NULL)
203                hd->pos = hd->buf = malloc(strlen(s)+1);
204        else {
205                i = hd->pos - hd->buf;
206                hd->buf = realloc(hd->buf, i+strlen(s)+1);
207                hd->pos = hd->buf + i;
208        }
209        if (hd->buf == NULL)
210                quiterr("out of memory in headline");
211        while (*hd->pos++ = *s++)
212                ;
213 }
214
215
173   ra2tiff(inpf, outf)             /* convert Radiance file to 24-bit TIFF */
174   char    *inpf, *outf;
175   {
219        char    buf[64];
220        struct hdinfo   hd;
176          TIFF    *tif;
177          int     xmax, ymax;
178          BYTE    *scanout;
# Line 227 | Line 182 | char   *inpf, *outf;
182                                                  /* open Radiance file */
183          if (strcmp(inpf, "-") && freopen(inpf, "r", stdin) == NULL)
184                  quiterr("cannot open Radiance input file");
185 <        hd.buf = NULL; hd.fmt[0] = '\0';
186 <        getheader(stdin, headline, &hd);
232 <        if (bradj)
233 <                sprintf(buf, "%s -e %+d\n", progname, bradj);
234 <        else
235 <                sprintf(buf, "%s\n", progname);
236 <        headline(buf, &hd);
237 <        if (hd.fmt[0] && strcmp(hd.fmt, COLRFMT))
238 <                quiterr("input not a Radiance picture");
239 <        if (fgetresolu(&xmax, &ymax, stdin) != (YDECR|YMAJOR))
185 >        if (checkheader(stdin, COLRFMT, NULL) < 0 ||
186 >                        fgetresolu(&xmax, &ymax, stdin) != (YDECR|YMAJOR))
187                  quiterr("bad Radiance picture");
188                                                  /* open TIFF file */
189          if ((tif = TIFFOpen(outf, "w")) == NULL)
# Line 247 | Line 194 | char   *inpf, *outf;
194          TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
195          TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2);
196          TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
250        TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, hd.buf);
197                                                  /* allocate scanlines */
198          scanin = (COLR *)malloc(xmax*sizeof(COLR));
199          scanout = (BYTE *)malloc(TIFFScanlineSize(tif));
# Line 272 | Line 218 | char   *inpf, *outf;
218          free((char *)scanin);
219          free((char *)scanout);
220          TIFFClose(tif);
275        free(hd.buf);
221   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines