9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
#include <math.h> |
12 |
+ |
#include <ctype.h> |
13 |
|
#include <time.h> |
14 |
|
#include "tiffio.h" |
15 |
|
#include "color.h" |
30 |
|
|
31 |
|
struct { |
32 |
|
uint16 flags; /* conversion flags (defined above) */ |
33 |
+ |
char capdate[20]; /* capture date/time */ |
34 |
+ |
char owner[256]; /* content owner */ |
35 |
|
uint16 comp; /* TIFF compression type */ |
36 |
|
uint16 phot; /* TIFF photometric type */ |
37 |
|
uint16 pconf; /* TIFF planar configuration */ |
58 |
|
} t; /* TIFF scanline */ |
59 |
|
void (*tf)(); /* translation procedure */ |
60 |
|
} cvts = { /* conversion structure */ |
61 |
< |
0, COMPRESSION_NONE, PHOTOMETRIC_RGB, |
61 |
> |
0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, |
62 |
|
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., |
63 |
|
}; |
64 |
|
|
89 |
|
|
90 |
|
#define pixorder() ortab[cvts.orient-1] |
91 |
|
|
92 |
+ |
extern char TMSTR[]; /* "CAPDATE=" from header.c */ |
93 |
+ |
char OWNSTR[] = "OWNER="; |
94 |
+ |
|
95 |
|
char *progname; |
96 |
|
|
97 |
|
|
161 |
|
if (i != argc-2) |
162 |
|
goto userr; |
163 |
|
/* consistency checks */ |
164 |
< |
if (CHK(C_GRY)) |
164 |
> |
if (CHK(C_GRY)) { |
165 |
|
if (cvts.phot == PHOTOMETRIC_RGB) |
166 |
|
cvts.phot = PHOTOMETRIC_MINISBLACK; |
167 |
|
else { |
168 |
|
cvts.phot = PHOTOMETRIC_LOGL; |
169 |
|
cvts.comp = COMPRESSION_SGILOG; |
170 |
|
} |
171 |
+ |
} |
172 |
|
if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT)) |
173 |
|
goto userr; |
174 |
|
|
208 |
|
(CHK(C_GRY) ? 1 : 3); |
209 |
|
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
210 |
|
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
211 |
< |
if (cvts.r.p == NULL | cvts.t.p == NULL) |
211 |
> |
if ((cvts.r.p == NULL) | (cvts.t.p == NULL)) |
212 |
|
quiterr("no memory to allocate scanline buffers"); |
213 |
|
} |
214 |
|
|
216 |
|
initfromtif() /* initialize conversion from TIFF input */ |
217 |
|
{ |
218 |
|
uint16 hi; |
219 |
+ |
char *cp; |
220 |
|
float *fa, f1, f2; |
221 |
|
|
222 |
|
CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM); |
346 |
|
|
347 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) |
348 |
|
cvts.stonits = 1.; |
349 |
+ |
|
350 |
+ |
if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp)) |
351 |
+ |
cvts.capdate[0] = '\0'; |
352 |
+ |
else { |
353 |
+ |
strncpy(cvts.capdate, cp, 19); |
354 |
+ |
cvts.capdate[19] = '\0'; |
355 |
+ |
} |
356 |
+ |
if (!TIFFGetField(cvts.tif, TIFFTAG_ARTIST, &cp)) |
357 |
+ |
cvts.owner[0] = '\0'; |
358 |
+ |
else { |
359 |
+ |
strncpy(cvts.owner, cp, sizeof(cvts.owner)); |
360 |
+ |
cvts.owner[sizeof(cvts.owner)-1] = '\0'; |
361 |
+ |
} |
362 |
|
/* add to Radiance header */ |
363 |
|
if (cvts.pixrat < .99 || cvts.pixrat > 1.01) |
364 |
|
fputaspect(cvts.pixrat, cvts.rfp); |
372 |
|
cvts.rfp); |
373 |
|
fputformat(COLRFMT, cvts.rfp); |
374 |
|
} |
375 |
+ |
if (cvts.capdate[0]) |
376 |
+ |
fprintf(cvts.rfp, "%s %s\n", TMSTR, cvts.capdate); |
377 |
+ |
if (cvts.owner[0]) |
378 |
+ |
fprintf(cvts.rfp, "%s %s\n", OWNSTR, cvts.owner); |
379 |
|
|
380 |
|
allocbufs(); /* allocate scanline buffers */ |
381 |
|
} |
415 |
|
headline(s) /* process Radiance input header line */ |
416 |
|
char *s; |
417 |
|
{ |
418 |
+ |
static int tmstrlen = 0; |
419 |
+ |
static int ownstrlen = 0; |
420 |
|
char fmt[32]; |
421 |
|
|
422 |
+ |
if (!tmstrlen) |
423 |
+ |
tmstrlen = strlen(TMSTR); |
424 |
+ |
if (!ownstrlen) |
425 |
+ |
ownstrlen = strlen(OWNSTR); |
426 |
|
if (formatval(fmt, s)) { |
427 |
|
if (!strcmp(fmt, COLRFMT)) |
428 |
|
CLR(C_XYZE); |
445 |
|
SET(C_PRIM); |
446 |
|
return(1); |
447 |
|
} |
448 |
+ |
if (isdate(s)) { |
449 |
+ |
if (s[tmstrlen] == ' ') |
450 |
+ |
strncpy(cvts.capdate, s+tmstrlen+1, 19); |
451 |
+ |
else |
452 |
+ |
strncpy(cvts.capdate, s+tmstrlen, 19); |
453 |
+ |
cvts.capdate[19] = '\0'; |
454 |
+ |
return(1); |
455 |
+ |
} |
456 |
+ |
if (!strncmp(s, OWNSTR, ownstrlen)) { |
457 |
+ |
register char *cp = s + ownstrlen; |
458 |
+ |
|
459 |
+ |
while (isspace(*cp)) |
460 |
+ |
++cp; |
461 |
+ |
strncpy(cvts.owner, cp, sizeof(cvts.owner)); |
462 |
+ |
cvts.owner[sizeof(cvts.owner)-1] = '\0'; |
463 |
+ |
for (cp = cvts.owner; *cp; cp++) |
464 |
+ |
; |
465 |
+ |
while (cp > cvts.owner && isspace(cp[-1])) |
466 |
+ |
*--cp = '\0'; |
467 |
+ |
return(1); |
468 |
+ |
} |
469 |
|
return(0); |
470 |
|
} |
471 |
|
|
475 |
|
int i1, i2, po; |
476 |
|
/* read Radiance header */ |
477 |
|
CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM); |
478 |
+ |
cvts.capdate[0] = '\0'; |
479 |
+ |
cvts.owner[0] = '\0'; |
480 |
|
cvts.stonits = 1.; |
481 |
|
cvts.pixrat = 1.; |
482 |
|
cvts.pconf = PLANARCONFIG_CONTIG; |
543 |
|
cvts.tf = Color2RRGGBB; |
544 |
|
SET(C_RFLT); |
545 |
|
} else if (CHK(C_TFLT)) { |
546 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
547 |
+ |
SAMPLEFORMAT_IEEEFP); |
548 |
|
cvts.tf = Color2RfGfBf; |
549 |
|
SET(C_RFLT); |
550 |
|
} else |
557 |
|
cvts.tf = Color2GGry; |
558 |
|
SET(C_RFLT); |
559 |
|
} else if (CHK(C_TFLT)) { |
560 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
561 |
+ |
SAMPLEFORMAT_IEEEFP); |
562 |
|
cvts.tf = Color2Gryf; |
563 |
|
SET(C_RFLT); |
564 |
|
} else |
581 |
|
TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf); |
582 |
|
TIFFSetField(cvts.tif, TIFFTAG_STONITS, |
583 |
|
cvts.stonits/pow(2.,(double)cvts.bradj)); |
584 |
+ |
if (cvts.capdate[0]) |
585 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_DATETIME, cvts.capdate); |
586 |
+ |
if (cvts.owner[0]) |
587 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_ARTIST, cvts.owner); |
588 |
|
if (cvts.comp == COMPRESSION_NONE) |
589 |
|
i1 = TIFFScanlineSize(cvts.tif); |
590 |
|
else |
660 |
|
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
661 |
|
uint32 y; |
662 |
|
{ |
663 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
663 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
664 |
|
register double d; |
665 |
|
register int x; |
666 |
|
|
807 |
|
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
808 |
|
uint32 y; |
809 |
|
{ |
810 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
810 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
811 |
|
double m; |
812 |
|
register double d; |
813 |
|
register int x; |
837 |
|
Color2GGry(y) /* read/convert/write COLOR->G16 scanline */ |
838 |
|
uint32 y; |
839 |
|
{ |
840 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
840 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
841 |
|
float m = pow(2.,(double)cvts.bradj); |
842 |
|
register int x; |
843 |
|
|
926 |
|
Color2RRGGBB(y) /* read/convert/write COLOR->RGB16 scanline */ |
927 |
|
uint32 y; |
928 |
|
{ |
929 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
929 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
930 |
|
float m = pow(2.,(double)cvts.bradj); |
931 |
|
register int x, i; |
932 |
|
|