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.5 by greg, Mon Jul 14 04:56:54 2003 UTC vs.
Revision 3.11 by greg, Mon Nov 10 19:08:19 2008 UTC

# Line 8 | Line 8 | static const char      RCSid[] = "$Id$";
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 40 | Line 43 | typedef struct {
43          RESOLU  rs;             /* picture resolution */
44   } PICTURE;
45  
46 < extern PICTURE  *openpicture();
46 > uint16  comp = COMPRESSION_NONE;        /* TIFF compression mode */
47  
48   #define closepicture(p)         (fclose((p)->fp),free((void *)(p)))
49  
50 + static gethfunc headline;
51  
52 < main(argc, argv)
53 < int     argc;
54 < char    *argv[];
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          PICTURE *pin = NULL;
67          TIFF    *tin = NULL;
# Line 82 | Line 96 | char   *argv[];
96                          if (argc-i < 2) goto userr;
97                          lddyn = atof(argv[++i]);
98                          break;
99 +                case 'z':                       /* LZW compression */
100 +                        comp = COMPRESSION_LZW;
101 +                        break;
102                  case 'p':                       /* set display primaries */
103                          if (argc-i < 9) goto userr;
104                          myprims[RED][CIEX] = atof(argv[++i]);
# Line 120 | Line 137 | char   *argv[];
137          exit(rval==0 ? 0 : 1);
138   userr:
139          fprintf(stderr,
140 < "Usage: %s [-h][-s][-c][-l][-b][-g gv][-d ld][-u lm][-p xr yr xg yg xb yb xw yw] input.{tif|pic} output.tif\n",
140 > "Usage: %s [-h][-s][-c][-l][-b][-g gv][-d ld][-u lm][-z][-p xr yr xg yg xb yb xw yw] input.{tif|hdr} output.tif\n",
141                          argv[0]);
142          exit(1);
143   }
144  
145  
146 < int
147 < headline(s, pp)                         /* process line from header */
148 < char    *s;
149 < register PICTURE        *pp;
146 > static int
147 > headline(                               /* process line from header */
148 >        char    *s,
149 >        void *pp
150 > )
151   {
152          register char   *cp;
153  
# Line 137 | Line 155 | register PICTURE       *pp;
155                  if (*cp & 0x80)
156                          return(-1);     /* non-ascii in header */
157          if (isaspect(s))
158 <                pp->pa *= aspectval(s);
158 >                ((PICTURE *)pp)->pa *= aspectval(s);
159          else
160 <                formatval(pp->fmt, s);
160 >                formatval(((PICTURE *)pp)->fmt, s);
161          return(0);
162   }
163  
164  
165 < PICTURE *
166 < openpicture(fname)                      /* open/check Radiance picture file */
167 < char    *fname;
165 > static PICTURE *
166 > openpicture(                    /* open/check Radiance picture file */
167 >        char    *fname
168 > )
169   {
170          FILE    *fp;
171          register PICTURE        *pp;
# Line 170 | Line 189 | char   *fname;
189                  return(NULL);           /* serious error -- should exit? */
190          pp->fp = fp; pp->fmt[0] = '\0'; pp->pa = 1.;
191                                          /* load header */
192 <        if (getheader(fp, headline, (char *)pp) < 0) {
192 >        if (getheader(fp, headline, pp) < 0) {
193                  closepicture(pp);
194                  return(NULL);
195          }
# Line 185 | Line 204 | char   *fname;
204   }
205  
206  
207 < int
208 < tmap_picture(fname, pp)                 /* tone map Radiance picture */
209 < char    *fname;
210 < register PICTURE        *pp;
207 > static int
208 > tmap_picture(                   /* tone map Radiance picture */
209 >        char    *fname,
210 >        register PICTURE        *pp
211 > )
212   {
213          uint16  orient;
214 +        double  paspect = (pp->rs.rt & YMAJOR) ? pp->pa : 1./pp->pa;
215          int     xsiz, ysiz;
216          BYTE    *pix;
217                                          /* read and tone map picture */
# Line 204 | Line 225 | register PICTURE       *pp;
225          orient++;
226                                          /* put out our image */
227          if (putimage(orient, (uint32)xsiz, (uint32)ysiz,
228 <                        72., 72./pp->pa, 2, pix) != 0)
228 >                        72., 72./paspect, 2, pix) != 0)
229                  return(-1);
230                                          /* free data and we're done */
231          free((void *)pix);
# Line 212 | Line 233 | register PICTURE       *pp;
233   }
234  
235  
236 < tmap_tiff(fname, tp)                    /* tone map SGILOG TIFF */
237 < char    *fname;
238 < TIFF    *tp;
236 > static int
237 > tmap_tiff(                      /* tone map SGILOG TIFF */
238 >        char    *fname,
239 >        TIFF    *tp
240 > )
241   {
242          float   xres, yres;
243          uint16  orient, resunit, phot;
# Line 222 | Line 245 | TIFF   *tp;
245          BYTE    *pix;
246                                          /* check to make sure it's SGILOG */
247          TIFFGetFieldDefaulted(tp, TIFFTAG_PHOTOMETRIC, &phot);
248 <        if (phot == PHOTOMETRIC_LOGL | phot == PHOTOMETRIC_MINISBLACK)
248 >        if ((phot == PHOTOMETRIC_LOGL) | (phot == PHOTOMETRIC_MINISBLACK))
249                  flags |= TM_F_BW;
250                                          /* read and tone map TIFF */
251          if (tmMapTIFF(&pix, &xsiz, &ysiz, flags,
# Line 243 | Line 266 | TIFF   *tp;
266   }
267  
268  
269 < putimage(or, xs, ys, xr, yr, ru, pd)    /* write out our image */
270 < uint16  or;
271 < uint32  xs, ys;
272 < float   xr, yr;
273 < uint16 ru;
274 < BYTE    *pd;
269 > static int
270 > putimage(       /* write out our image */
271 >        uint16  or,
272 >        uint32  xs,
273 >        uint32  ys,
274 >        float   xr,
275 >        float   yr,
276 >        uint16  ru,
277 >        BYTE    *pd
278 > )
279   {
280          register int    y;
281          uint32  rowsperstrip;
# Line 271 | Line 298 | BYTE   *pd;
298          TIFFSetField(tifout, TIFFTAG_IMAGEWIDTH, xs);
299          TIFFSetField(tifout, TIFFTAG_IMAGELENGTH, ys);
300          TIFFSetField(tifout, TIFFTAG_RESOLUTIONUNIT, ru);
301 +        TIFFSetField(tifout, TIFFTAG_COMPRESSION, comp);
302          TIFFSetField(tifout, TIFFTAG_XRESOLUTION, xr);
303          TIFFSetField(tifout, TIFFTAG_YRESOLUTION, yr);
304          TIFFSetField(tifout, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines