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

Comparing ray/src/px/normtiff.c (file contents):
Revision 3.2 by gwlarson, Mon Oct 26 17:30:50 1998 UTC vs.
Revision 3.8 by schorsch, Sun Mar 28 20:33:14 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Tone map SGILOG TIFF or Radiance picture and output 24-bit RGB TIFF
6   */
7  
11 #undef NOPROTO
12 #define NOPROTO 1
13
8   #include <stdio.h>
9   #include <math.h>
10 + #include <time.h>
11 + #include <string.h>
12 +
13   #include "tiffio.h"
14   #include "color.h"
15   #include "tonemap.h"
16 + #include "tmaptiff.h"
17   #include "resolu.h"
18  
19  
# Line 38 | Line 36 | short  ortab[8] = {            /* orientation conversion table */
36          0
37   };
38  
39 < extern FILE     *openpicture();
39 > typedef struct {
40 >        FILE    *fp;            /* file pointer */
41 >        char    fmt[32];        /* picture format */
42 >        double  pa;             /* pixel aspect ratio */
43 >        RESOLU  rs;             /* picture resolution */
44 > } PICTURE;
45  
46 + //extern PICTURE        *openpicture();
47  
48 < main(argc, argv)
49 < int     argc;
50 < char    *argv[];
48 > #define closepicture(p)         (fclose((p)->fp),free((void *)(p)))
49 >
50 > static gethfunc headline;
51 >
52 > static int headline(char        *s, void *pp);
53 > static PICTURE * openpicture(char       *fname);
54 > static int tmap_picture(char    *fname, PICTURE *pp);
55 > static int tmap_tiff(char       *fname, TIFF    *tp);
56 > static int putimage(uint16      or, uint32      xs, uint32      ys, float       xr, float       yr,
57 >        uint16 ru, BYTE *pd);
58 >
59 >
60 > int
61 > main(
62 >        int     argc,
63 >        char    *argv[]
64 > )
65   {
66 <        FILE    *fin = NULL;
66 >        PICTURE *pin = NULL;
67          TIFF    *tin = NULL;
68          int     i, rval;
69  
# Line 94 | Line 112 | char   *argv[];
112                          goto userr;
113                  }
114          if (argc-i < 2) goto userr;
115 <        if ((fin = openpicture(argv[i])) == NULL &&
115 >        if ((pin = openpicture(argv[i])) == NULL &&
116                          (tin = TIFFOpen(argv[i], "r")) == NULL) {
117                  fprintf(stderr, "%s: cannot open or interpret file \"%s\"\n",
118                                  argv[0], argv[i]);
# Line 105 | Line 123 | char   *argv[];
123                                  argv[0], argv[i+1]);
124                  exit(1);
125          }
126 <        if (fin != NULL) {
127 <                rval = tmap_picture(argv[i], fin);
128 <                fclose(fin);
126 >        if (pin != NULL) {
127 >                rval = tmap_picture(argv[i], pin);
128 >                closepicture(pin);
129          } else {
130                  rval = tmap_tiff(argv[i], tin);
131                  TIFFClose(tin);
# Line 122 | Line 140 | userr:
140   }
141  
142  
143 < FILE *
144 < openpicture(fname)                      /* open/check Radiance picture file */
145 < char    *fname;
143 > static int
144 > headline(                               /* process line from header */
145 >        char    *s,
146 >        void *pp
147 > )
148   {
149 +        register char   *cp;
150 +
151 +        for (cp = s; *cp; cp++)
152 +                if (*cp & 0x80)
153 +                        return(-1);     /* non-ascii in header */
154 +        if (isaspect(s))
155 +                ((PICTURE *)pp)->pa *= aspectval(s);
156 +        else
157 +                formatval(((PICTURE *)pp)->fmt, s);
158 +        return(0);
159 + }
160 +
161 +
162 + static PICTURE *
163 + openpicture(                    /* open/check Radiance picture file */
164 +        char    *fname
165 + )
166 + {
167          FILE    *fp;
168 <        char    inpfmt[32];
131 <        int     xsiz, ysiz;
168 >        register PICTURE        *pp;
169          register char   *cp;
170                                          /* check filename suffix */
171          if (fname == NULL) return(NULL);
# Line 144 | Line 181 | char   *fname;
181                                          /* else try opening it */
182          if ((fp = fopen(fname, "r")) == NULL)
183                  return(NULL);
184 <                                        /* check format */
185 <        strcpy(inpfmt, PICFMT);
186 <        if (checkheader(fp, inpfmt, NULL) < 0 ||
187 <                        fgetresolu(&xsiz, &ysiz, fp) < 0) {
188 <                fclose(fp);             /* failed test -- close file */
184 >                                        /* allocate struct */
185 >        if ((pp = (PICTURE *)malloc(sizeof(PICTURE))) == NULL)
186 >                return(NULL);           /* serious error -- should exit? */
187 >        pp->fp = fp; pp->fmt[0] = '\0'; pp->pa = 1.;
188 >                                        /* load header */
189 >        if (getheader(fp, headline, pp) < 0) {
190 >                closepicture(pp);
191                  return(NULL);
192          }
193 +        if (!pp->fmt[0])                /* assume RGBE if unspecified */
194 +                strcpy(pp->fmt, COLRFMT);
195 +        if (!globmatch(PICFMT, pp->fmt) || !fgetsresolu(&pp->rs, fp)) {
196 +                closepicture(pp);       /* failed test -- close file */
197 +                return(NULL);
198 +        }
199          rewind(fp);                     /* passed test -- rewind file */
200 <        return(fp);
200 >        return(pp);
201   }
202  
203  
204 < getpixrat(s, pr)                        /* get pixel aspect ratio */
205 < char    *s;
206 < double  *pr;
204 > static int
205 > tmap_picture(                   /* tone map Radiance picture */
206 >        char    *fname,
207 >        register PICTURE        *pp
208 > )
209   {
163        if (isaspect(s))
164                *pr *= aspectval(s);
165 }
166
167
168 int
169 tmap_picture(fname, fp)                 /* tone map Radiance picture */
170 char    *fname;
171 FILE    *fp;
172 {
173        double  pixrat;
174        int     ord;
210          uint16  orient;
211          int     xsiz, ysiz;
212          BYTE    *pix;
213                                          /* read and tone map picture */
214          if (tmMapPicture(&pix, &xsiz, &ysiz, flags,
215 <                        rgbp, gamv, lddyn, ldmax, fname, fp) != TM_E_OK)
215 >                        rgbp, gamv, lddyn, ldmax, fname, pp->fp) != TM_E_OK)
216                  return(-1);
217 <                                        /* get relevant header info. */
218 <        rewind(fp);
219 <        pixrat = 1.;
220 <        getheader(fp, getpixrat, &pixrat);
186 <        if ((ord = fgetresolu(&xsiz, &ysiz, fp)) < 0)
187 <                orient = 0;
188 <        else
189 <                for (orient = 8; --orient; )
190 <                        if (ortab[orient] == ord)
191 <                                break;
217 >                                        /* figure out TIFF orientation */
218 >        for (orient = 8; --orient; )
219 >                if (ortab[orient] == pp->rs.rt)
220 >                        break;
221          orient++;
222                                          /* put out our image */
223          if (putimage(orient, (uint32)xsiz, (uint32)ysiz,
224 <                        72., 72./pixrat, 2, pix) != 0)
224 >                        72., 72./pp->pa, 2, pix) != 0)
225                  return(-1);
226                                          /* free data and we're done */
227 <        free((char *)pix);
227 >        free((void *)pix);
228          return(0);
229   }
230  
231  
232 < tmap_tiff(fname, tp)                    /* tone map SGILOG TIFF */
233 < char    *fname;
234 < TIFF    *tp;
232 > static int
233 > tmap_tiff(                      /* tone map SGILOG TIFF */
234 >        char    *fname,
235 >        TIFF    *tp
236 > )
237   {
238          float   xres, yres;
239          uint16  orient, resunit, phot;
# Line 210 | Line 241 | TIFF   *tp;
241          BYTE    *pix;
242                                          /* check to make sure it's SGILOG */
243          TIFFGetFieldDefaulted(tp, TIFFTAG_PHOTOMETRIC, &phot);
244 <        if (phot != PHOTOMETRIC_LOGLUV && phot != PHOTOMETRIC_LOGL) {
214 <                if (!(flags & TM_F_NOSTDERR)) {
215 <                        fputs(fname, stderr);
216 <                        fputs(": TIFF must be in SGILOG format\n", stderr);
217 <                }
218 <                return(-1);
219 <        }
220 <        if (phot == PHOTOMETRIC_LOGL)
244 >        if ((phot == PHOTOMETRIC_LOGL) | (phot == PHOTOMETRIC_MINISBLACK))
245                  flags |= TM_F_BW;
246                                          /* read and tone map TIFF */
247          if (tmMapTIFF(&pix, &xsiz, &ysiz, flags,
# Line 233 | Line 257 | TIFF   *tp;
257                          xres, yres, resunit, pix) != 0)
258                  return(-1);
259                                          /* free data and we're done */
260 <        free((char *)pix);
260 >        free((void *)pix);
261          return(0);
262   }
263  
264  
265 < putimage(or, xs, ys, xr, yr, ru, pd)    /* write out our image */
266 < uint16  or;
267 < uint32  xs, ys;
268 < float   xr, yr;
269 < uint16 ru;
270 < BYTE    *pd;
265 > static int
266 > putimage(       /* write out our image */
267 >        uint16  or,
268 >        uint32  xs,
269 >        uint32  ys,
270 >        float   xr,
271 >        float   yr,
272 >        uint16 ru,
273 >        BYTE    *pd
274 > )
275   {
276          register int    y;
277          uint32  rowsperstrip;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines