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 |
|
|
43 |
|
RESOLU rs; /* picture resolution */ |
44 |
|
} PICTURE; |
45 |
|
|
46 |
< |
extern PICTURE *openpicture(); |
46 |
> |
//extern PICTURE *openpicture(); |
47 |
|
|
48 |
< |
#define closepicture(p) (fclose((p)->fp),free((char *)(p))) |
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; |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
< |
int |
144 |
< |
headline(s, pp) /* process line from header */ |
145 |
< |
char *s; |
146 |
< |
register PICTURE *pp; |
143 |
> |
static int |
144 |
> |
headline( /* process line from header */ |
145 |
> |
char *s, |
146 |
> |
void *pp |
147 |
> |
) |
148 |
|
{ |
149 |
|
register char *cp; |
150 |
|
|
152 |
|
if (*cp & 0x80) |
153 |
|
return(-1); /* non-ascii in header */ |
154 |
|
if (isaspect(s)) |
155 |
< |
pp->pa *= aspectval(s); |
155 |
> |
((PICTURE *)pp)->pa *= aspectval(s); |
156 |
|
else |
157 |
< |
formatval(pp->fmt, s); |
157 |
> |
formatval(((PICTURE *)pp)->fmt, s); |
158 |
|
return(0); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
< |
PICTURE * |
163 |
< |
openpicture(fname) /* open/check Radiance picture file */ |
164 |
< |
char *fname; |
162 |
> |
static PICTURE * |
163 |
> |
openpicture( /* open/check Radiance picture file */ |
164 |
> |
char *fname |
165 |
> |
) |
166 |
|
{ |
167 |
|
FILE *fp; |
168 |
|
register PICTURE *pp; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
< |
int |
205 |
< |
tmap_picture(fname, pp) /* tone map Radiance picture */ |
206 |
< |
char *fname; |
207 |
< |
register PICTURE *pp; |
204 |
> |
static int |
205 |
> |
tmap_picture( /* tone map Radiance picture */ |
206 |
> |
char *fname, |
207 |
> |
register PICTURE *pp |
208 |
> |
) |
209 |
|
{ |
210 |
|
uint16 orient; |
211 |
|
int xsiz, ysiz; |
216 |
|
return(-1); |
217 |
|
/* figure out TIFF orientation */ |
218 |
|
for (orient = 8; --orient; ) |
219 |
< |
if (ortab[orient] == pp->rs.or) |
219 |
> |
if (ortab[orient] == pp->rs.rt) |
220 |
|
break; |
221 |
|
orient++; |
222 |
|
/* put out our image */ |
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; |
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) { |
231 |
< |
if (!(flags & TM_F_NOSTDERR)) { |
232 |
< |
fputs(fname, stderr); |
233 |
< |
fputs(": TIFF must be in SGILOG format\n", stderr); |
234 |
< |
} |
235 |
< |
return(-1); |
236 |
< |
} |
237 |
< |
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, |
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; |