97 |
|
TIFF *tif; |
98 |
|
unsigned short pconfig; |
99 |
|
unsigned short hi; |
100 |
– |
char *cp; |
100 |
|
register BYTE *scanin; |
101 |
|
register COLR *scanout; |
102 |
|
register int x; |
125 |
|
if (outf != NULL && strcmp(outf, "-") && |
126 |
|
freopen(outf, "w", stdout) == NULL) |
127 |
|
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 |
– |
} |
128 |
|
fputs(progname, stdout); |
129 |
|
if (bradj) |
130 |
|
printf(" -e %+d", bradj); |
172 |
|
} |
173 |
|
|
174 |
|
|
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 |
– |
|
175 |
|
ra2tiff(inpf, outf) /* convert Radiance file to 24-bit TIFF */ |
176 |
|
char *inpf, *outf; |
177 |
|
{ |
219 |
– |
char buf[64]; |
220 |
– |
struct hdinfo hd; |
178 |
|
TIFF *tif; |
179 |
|
int xmax, ymax; |
180 |
|
BYTE *scanout; |
184 |
|
/* open Radiance file */ |
185 |
|
if (strcmp(inpf, "-") && freopen(inpf, "r", stdin) == NULL) |
186 |
|
quiterr("cannot open Radiance input file"); |
187 |
< |
hd.buf = NULL; hd.fmt[0] = '\0'; |
188 |
< |
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)) |
187 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
188 |
> |
fgetresolu(&xmax, &ymax, stdin) != (YDECR|YMAJOR)) |
189 |
|
quiterr("bad Radiance picture"); |
190 |
|
/* open TIFF file */ |
191 |
|
if ((tif = TIFFOpen(outf, "w")) == NULL) |
196 |
|
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); |
197 |
|
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2); |
198 |
|
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1); |
250 |
– |
TIFFSetField(tif, TIFFTAG_IMAGEDESCRIPTION, hd.buf); |
199 |
|
/* allocate scanlines */ |
200 |
|
scanin = (COLR *)malloc(xmax*sizeof(COLR)); |
201 |
|
scanout = (BYTE *)malloc(TIFFScanlineSize(tif)); |
220 |
|
free((char *)scanin); |
221 |
|
free((char *)scanout); |
222 |
|
TIFFClose(tif); |
275 |
– |
free(hd.buf); |
223 |
|
} |