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.4 by greg, Thu Aug 15 14:48:55 1991 UTC

# Line 18 | Line 18 | extern double  atof();
18  
19   extern char  *malloc(), *realloc();
20  
21 + int  lzcomp = 0;                        /* use Lempel-Ziv compression? */
22 +
23   double  gamma = 2.2;                    /* gamma correction */
24  
25   int  bradj = 0;                         /* brightness adjustment */
# Line 37 | Line 39 | char  *argv[];
39          for (i = 1; i < argc; i++)
40                  if (argv[i][0] == '-')
41                          switch (argv[i][1]) {
40                        /* not allowed to reset gamma...
42                          case 'g':
43                                  gamma = atof(argv[++i]);
44                                  break;
45 <                        */
45 >                        case 'z':
46 >                                lzcomp = !lzcomp;
47 >                                break;
48                          case 'e':
49                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
50                                          goto userr;
# Line 73 | Line 76 | doneopts:
76  
77          exit(0);
78   userr:
79 <        fprintf(stderr, "Usage: %s [-r][-e +/-stops] input output\n",
79 >        fprintf(stderr,
80 >                "Usage: %s [-r][-z][-e +/-stops][-g gamma] input output\n",
81                          progname);
82          exit(1);
83   }
# Line 97 | Line 101 | char   *inpf, *outf;
101          TIFF    *tif;
102          unsigned short  pconfig;
103          unsigned short  hi;
100        char    *cp;
104          register BYTE   *scanin;
105          register COLR   *scanout;
106          register int    x;
# Line 126 | Line 129 | char   *inpf, *outf;
129          if (outf != NULL && strcmp(outf, "-") &&
130                          freopen(outf, "w", stdout) == NULL)
131                  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        }
132          fputs(progname, stdout);
133          if (bradj)
134                  printf(" -e %+d", bradj);
# Line 182 | Line 176 | readerr:
176   }
177  
178  
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
179   ra2tiff(inpf, outf)             /* convert Radiance file to 24-bit TIFF */
180   char    *inpf, *outf;
181   {
219        char    buf[64];
220        struct hdinfo   hd;
182          TIFF    *tif;
183          int     xmax, ymax;
184          BYTE    *scanout;
# Line 227 | Line 188 | char   *inpf, *outf;
188                                                  /* open Radiance file */
189          if (strcmp(inpf, "-") && freopen(inpf, "r", stdin) == NULL)
190                  quiterr("cannot open Radiance input file");
191 <        hd.buf = NULL; hd.fmt[0] = '\0';
192 <        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))
191 >        if (checkheader(stdin, COLRFMT, NULL) < 0 ||
192 >                        fgetresolu(&xmax, &ymax, stdin) != (YDECR|YMAJOR))
193                  quiterr("bad Radiance picture");
194                                                  /* open TIFF file */
195          if ((tif = TIFFOpen(outf, "w")) == NULL)
# Line 247 | Line 200 | char   *inpf, *outf;
200          TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
201          TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2);
202          TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
203 <        TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, hd.buf);
203 >        if (lzcomp)
204 >                TIFFSetField(tif, TIFFTAG_COMPRESSION, (unsigned short)5);
205                                                  /* allocate scanlines */
206          scanin = (COLR *)malloc(xmax*sizeof(COLR));
207          scanout = (BYTE *)malloc(TIFFScanlineSize(tif));
# Line 272 | Line 226 | char   *inpf, *outf;
226          free((char *)scanin);
227          free((char *)scanout);
228          TIFFClose(tif);
275        free(hd.buf);
229   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines