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.13 by greg, Fri May 20 02:06:39 2011 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 "platform.h"
14   #include "tiffio.h"
15   #include "color.h"
16   #include "tonemap.h"
17 + #include "tmaptiff.h"
18   #include "resolu.h"
19  
20  
# Line 40 | Line 44 | typedef struct {
44          RESOLU  rs;             /* picture resolution */
45   } PICTURE;
46  
47 < extern PICTURE  *openpicture();
47 > uint16  comp = COMPRESSION_NONE;        /* TIFF compression mode */
48  
49   #define closepicture(p)         (fclose((p)->fp),free((void *)(p)))
50  
51 + static gethfunc headline;
52  
53 < main(argc, argv)
54 < int     argc;
55 < char    *argv[];
53 > static int headline(char *s, void *pp);
54 > static PICTURE *openpicture(char *fname);
55 > static int tmap_picture(char *fname, PICTURE *pp);
56 > static int tmap_tiff(char *fname, TIFF *tp);
57 > static int putimage(uint16 or, uint32 xs, uint32 ys, float xr, float yr,
58 >        uint16 ru, uby8 *pd);
59 >
60 >
61 > int
62 > main(
63 >        int     argc,
64 >        char    *argv[]
65 > )
66   {
67          PICTURE *pin = NULL;
68          TIFF    *tin = NULL;
# Line 82 | Line 97 | char   *argv[];
97                          if (argc-i < 2) goto userr;
98                          lddyn = atof(argv[++i]);
99                          break;
100 +                case 'z':                       /* LZW compression */
101 +                        comp = COMPRESSION_LZW;
102 +                        break;
103                  case 'p':                       /* set display primaries */
104                          if (argc-i < 9) goto userr;
105                          myprims[RED][CIEX] = atof(argv[++i]);
# Line 120 | Line 138 | char   *argv[];
138          exit(rval==0 ? 0 : 1);
139   userr:
140          fprintf(stderr,
141 < "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",
141 > "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",
142                          argv[0]);
143          exit(1);
144   }
145  
146  
147 < int
148 < headline(s, pp)                         /* process line from header */
149 < char    *s;
150 < register PICTURE        *pp;
147 > static int
148 > headline(                               /* process line from header */
149 >        char    *s,
150 >        void *pp
151 > )
152   {
153          register char   *cp;
154  
# Line 137 | Line 156 | register PICTURE       *pp;
156                  if (*cp & 0x80)
157                          return(-1);     /* non-ascii in header */
158          if (isaspect(s))
159 <                pp->pa *= aspectval(s);
159 >                ((PICTURE *)pp)->pa *= aspectval(s);
160          else
161 <                formatval(pp->fmt, s);
161 >                formatval(((PICTURE *)pp)->fmt, s);
162          return(0);
163   }
164  
165  
166 < PICTURE *
167 < openpicture(fname)                      /* open/check Radiance picture file */
168 < char    *fname;
166 > static PICTURE *
167 > openpicture(                    /* open/check Radiance picture file */
168 >        char    *fname
169 > )
170   {
171          FILE    *fp;
172          register PICTURE        *pp;
# Line 165 | Line 185 | char   *fname;
185                                          /* else try opening it */
186          if ((fp = fopen(fname, "r")) == NULL)
187                  return(NULL);
188 +        SET_FILE_BINARY(fp);
189                                          /* allocate struct */
190          if ((pp = (PICTURE *)malloc(sizeof(PICTURE))) == NULL)
191                  return(NULL);           /* serious error -- should exit? */
192          pp->fp = fp; pp->fmt[0] = '\0'; pp->pa = 1.;
193                                          /* load header */
194 <        if (getheader(fp, headline, (char *)pp) < 0) {
194 >        if (getheader(fp, headline, pp) < 0) {
195                  closepicture(pp);
196                  return(NULL);
197          }
# Line 185 | Line 206 | char   *fname;
206   }
207  
208  
209 < int
210 < tmap_picture(fname, pp)                 /* tone map Radiance picture */
211 < char    *fname;
212 < register PICTURE        *pp;
209 > static int
210 > tmap_picture(                   /* tone map Radiance picture */
211 >        char    *fname,
212 >        register PICTURE        *pp
213 > )
214   {
215          uint16  orient;
216 +        double  paspect = (pp->rs.rt & YMAJOR) ? pp->pa : 1./pp->pa;
217          int     xsiz, ysiz;
218 <        BYTE    *pix;
218 >        uby8    *pix;
219                                          /* read and tone map picture */
220          if (tmMapPicture(&pix, &xsiz, &ysiz, flags,
221                          rgbp, gamv, lddyn, ldmax, fname, pp->fp) != TM_E_OK)
# Line 204 | Line 227 | register PICTURE       *pp;
227          orient++;
228                                          /* put out our image */
229          if (putimage(orient, (uint32)xsiz, (uint32)ysiz,
230 <                        72., 72./pp->pa, 2, pix) != 0)
230 >                        72., 72./paspect, 2, pix) != 0)
231                  return(-1);
232                                          /* free data and we're done */
233          free((void *)pix);
# Line 212 | Line 235 | register PICTURE       *pp;
235   }
236  
237  
238 < tmap_tiff(fname, tp)                    /* tone map SGILOG TIFF */
239 < char    *fname;
240 < TIFF    *tp;
238 > static int
239 > tmap_tiff(                      /* tone map SGILOG TIFF */
240 >        char    *fname,
241 >        TIFF    *tp
242 > )
243   {
244          float   xres, yres;
245          uint16  orient, resunit, phot;
246          int     xsiz, ysiz;
247 <        BYTE    *pix;
247 >        uby8    *pix;
248                                          /* check to make sure it's SGILOG */
249          TIFFGetFieldDefaulted(tp, TIFFTAG_PHOTOMETRIC, &phot);
250 <        if (phot == PHOTOMETRIC_LOGL | phot == PHOTOMETRIC_MINISBLACK)
250 >        if ((phot == PHOTOMETRIC_LOGL) | (phot == PHOTOMETRIC_MINISBLACK))
251                  flags |= TM_F_BW;
252                                          /* read and tone map TIFF */
253          if (tmMapTIFF(&pix, &xsiz, &ysiz, flags,
# Line 243 | Line 268 | TIFF   *tp;
268   }
269  
270  
271 < putimage(or, xs, ys, xr, yr, ru, pd)    /* write out our image */
272 < uint16  or;
273 < uint32  xs, ys;
274 < float   xr, yr;
275 < uint16 ru;
276 < BYTE    *pd;
271 > static int
272 > putimage(       /* write out our image */
273 >        uint16  or,
274 >        uint32  xs,
275 >        uint32  ys,
276 >        float   xr,
277 >        float   yr,
278 >        uint16  ru,
279 >        uby8    *pd
280 > )
281   {
282          register int    y;
283          uint32  rowsperstrip;
# Line 271 | Line 300 | BYTE   *pd;
300          TIFFSetField(tifout, TIFFTAG_IMAGEWIDTH, xs);
301          TIFFSetField(tifout, TIFFTAG_IMAGELENGTH, ys);
302          TIFFSetField(tifout, TIFFTAG_RESOLUTIONUNIT, ru);
303 +        TIFFSetField(tifout, TIFFTAG_COMPRESSION, comp);
304          TIFFSetField(tifout, TIFFTAG_XRESOLUTION, xr);
305          TIFFSetField(tifout, TIFFTAG_YRESOLUTION, yr);
306          TIFFSetField(tifout, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines