11 |
|
#include <math.h> |
12 |
|
#include <ctype.h> |
13 |
|
#include <time.h> |
14 |
+ |
#include <string.h> |
15 |
+ |
|
16 |
|
#include "tiffio.h" |
17 |
|
#include "color.h" |
18 |
|
#include "resolu.h" |
30 |
|
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
31 |
|
#define C_PRIM 0x100 /* has assigned primaries */ |
32 |
|
|
33 |
+ |
typedef void colcvf_t(uint32 y); |
34 |
+ |
|
35 |
|
struct { |
36 |
|
uint16 flags; /* conversion flags (defined above) */ |
37 |
|
char capdate[20]; /* capture date/time */ |
60 |
|
float *fp; /* float pointer */ |
61 |
|
char *p; /* generic pointer */ |
62 |
|
} t; /* TIFF scanline */ |
63 |
< |
void (*tf)(); /* translation procedure */ |
63 |
> |
colcvf_t *tf; /* translation procedure */ |
64 |
|
} cvts = { /* conversion structure */ |
65 |
|
0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, |
66 |
|
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., |
71 |
|
#define CLR(f) (cvts.flags &= ~(f)) |
72 |
|
#define TGL(f) (cvts.flags ^= (f)) |
73 |
|
|
74 |
< |
void Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
75 |
< |
void Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
76 |
< |
void RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry(); |
74 |
> |
static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr; |
75 |
> |
static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry; |
76 |
> |
static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry; |
77 |
|
|
78 |
+ |
static gethfunc headline; |
79 |
+ |
static void quiterr(char *err); |
80 |
+ |
static void allocbufs(void); |
81 |
+ |
static void initfromtif(void); |
82 |
+ |
static void tiff2ra(int ac, char *av[]); |
83 |
+ |
static void initfromrad(void); |
84 |
+ |
static void ra2tiff(int ac, char *av[]); |
85 |
+ |
|
86 |
+ |
|
87 |
+ |
|
88 |
|
#define RfGfBf2Color Luv2Color |
89 |
|
#define Gryf2Color L2Color |
90 |
|
#define Color2Gryf Color2L |
109 |
|
char *progname; |
110 |
|
|
111 |
|
|
112 |
< |
main(argc, argv) |
113 |
< |
int argc; |
100 |
< |
char *argv[]; |
112 |
> |
int |
113 |
> |
main(int argc, char *argv[]) |
114 |
|
{ |
115 |
|
int reverse = 0; |
116 |
|
int i; |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
< |
quiterr(err) /* print message and exit */ |
204 |
< |
char *err; |
203 |
> |
static void |
204 |
> |
quiterr( /* print message and exit */ |
205 |
> |
char *err |
206 |
> |
) |
207 |
|
{ |
208 |
|
if (err != NULL) { |
209 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
< |
allocbufs() /* allocate scanline buffers */ |
216 |
> |
static void |
217 |
> |
allocbufs(void) /* allocate scanline buffers */ |
218 |
|
{ |
219 |
|
int rsiz, tsiz; |
220 |
|
|
224 |
|
(CHK(C_GRY) ? 1 : 3); |
225 |
|
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
226 |
|
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
227 |
< |
if (cvts.r.p == NULL | cvts.t.p == NULL) |
227 |
> |
if ((cvts.r.p == NULL) | (cvts.t.p == NULL)) |
228 |
|
quiterr("no memory to allocate scanline buffers"); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
< |
initfromtif() /* initialize conversion from TIFF input */ |
232 |
> |
static void |
233 |
> |
initfromtif(void) /* initialize conversion from TIFF input */ |
234 |
|
{ |
235 |
|
uint16 hi; |
236 |
|
char *cp; |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
< |
tiff2ra(ac, av) /* convert TIFF image to Radiance picture */ |
402 |
< |
int ac; |
403 |
< |
char *av[]; |
401 |
> |
static void |
402 |
> |
tiff2ra( /* convert TIFF image to Radiance picture */ |
403 |
> |
int ac, |
404 |
> |
char *av[] |
405 |
> |
) |
406 |
|
{ |
407 |
|
int32 y; |
408 |
|
/* open TIFF input */ |
430 |
|
} |
431 |
|
|
432 |
|
|
433 |
< |
int |
434 |
< |
headline(s) /* process Radiance input header line */ |
435 |
< |
char *s; |
433 |
> |
static int |
434 |
> |
headline( /* process Radiance input header line */ |
435 |
> |
char *s, |
436 |
> |
void *p |
437 |
> |
) |
438 |
|
{ |
439 |
|
static int tmstrlen = 0; |
440 |
|
static int ownstrlen = 0; |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
< |
initfromrad() /* initialize input from a Radiance picture */ |
494 |
> |
static void |
495 |
> |
initfromrad(void) /* initialize input from a Radiance picture */ |
496 |
|
{ |
497 |
|
int i1, i2, po; |
498 |
|
/* read Radiance header */ |
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
< |
ra2tiff(ac, av) /* convert Radiance picture to TIFF image */ |
623 |
< |
int ac; |
624 |
< |
char *av[]; |
622 |
> |
static void |
623 |
> |
ra2tiff( /* convert Radiance picture to TIFF image */ |
624 |
> |
int ac, |
625 |
> |
char *av[] |
626 |
> |
) |
627 |
|
{ |
628 |
|
uint32 y; |
629 |
|
/* open Radiance file */ |
645 |
|
} |
646 |
|
|
647 |
|
|
648 |
< |
void |
649 |
< |
Luv2Color(y) /* read/convert/write Luv->COLOR scanline */ |
650 |
< |
uint32 y; |
648 |
> |
static void |
649 |
> |
Luv2Color( /* read/convert/write Luv->COLOR scanline */ |
650 |
> |
uint32 y |
651 |
> |
) |
652 |
|
{ |
653 |
|
register int x; |
654 |
|
|
681 |
|
} |
682 |
|
|
683 |
|
|
684 |
< |
void |
685 |
< |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
686 |
< |
uint32 y; |
684 |
> |
static void |
685 |
> |
RRGGBB2Color( /* read/convert/write RGB16->COLOR scanline */ |
686 |
> |
uint32 y |
687 |
> |
) |
688 |
|
{ |
689 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
689 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
690 |
|
register double d; |
691 |
|
register int x; |
692 |
|
|
724 |
|
} |
725 |
|
|
726 |
|
|
727 |
< |
void |
728 |
< |
L2Color(y) /* read/convert/write Lfloat->COLOR scanline */ |
729 |
< |
uint32 y; |
727 |
> |
static void |
728 |
> |
L2Color( /* read/convert/write Lfloat->COLOR scanline */ |
729 |
> |
uint32 y |
730 |
> |
) |
731 |
|
{ |
732 |
|
float m = pow(2., (double)cvts.bradj); |
733 |
|
register int x; |
748 |
|
} |
749 |
|
|
750 |
|
|
751 |
< |
void |
752 |
< |
RGB2Colr(y) /* read/convert/write RGB->COLR scanline */ |
753 |
< |
uint32 y; |
751 |
> |
static void |
752 |
> |
RGB2Colr( /* read/convert/write RGB->COLR scanline */ |
753 |
> |
uint32 y |
754 |
> |
) |
755 |
|
{ |
756 |
|
COLOR ctmp; |
757 |
|
register int x; |
805 |
|
} |
806 |
|
|
807 |
|
|
808 |
< |
void |
809 |
< |
Gry2Colr(y) /* read/convert/write G8->COLR scanline */ |
810 |
< |
uint32 y; |
808 |
> |
static void |
809 |
> |
Gry2Colr( /* read/convert/write G8->COLR scanline */ |
810 |
> |
uint32 y |
811 |
> |
) |
812 |
|
{ |
813 |
|
register int x; |
814 |
|
|
832 |
|
} |
833 |
|
|
834 |
|
|
835 |
< |
void |
836 |
< |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
837 |
< |
uint32 y; |
835 |
> |
static void |
836 |
> |
GGry2Color( /* read/convert/write G16->COLOR scanline */ |
837 |
> |
uint32 y |
838 |
> |
) |
839 |
|
{ |
840 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
840 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
841 |
|
double m; |
842 |
|
register double d; |
843 |
|
register int x; |
863 |
|
} |
864 |
|
|
865 |
|
|
866 |
< |
void |
867 |
< |
Color2GGry(y) /* read/convert/write COLOR->G16 scanline */ |
868 |
< |
uint32 y; |
866 |
> |
static void |
867 |
> |
Color2GGry( /* read/convert/write COLOR->G16 scanline */ |
868 |
> |
uint32 y |
869 |
> |
) |
870 |
|
{ |
871 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
871 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
872 |
|
float m = pow(2.,(double)cvts.bradj); |
873 |
|
register int x; |
874 |
|
|
898 |
|
} |
899 |
|
|
900 |
|
|
901 |
< |
void |
902 |
< |
Color2L(y) /* read/convert/write COLOR->Lfloat scanline */ |
903 |
< |
uint32 y; |
901 |
> |
static void |
902 |
> |
Color2L( /* read/convert/write COLOR->Lfloat scanline */ |
903 |
> |
uint32 y |
904 |
> |
) |
905 |
|
{ |
906 |
|
float m = pow(2.,(double)cvts.bradj); |
907 |
|
register int x; |
921 |
|
} |
922 |
|
|
923 |
|
|
924 |
< |
void |
925 |
< |
Color2Luv(y) /* read/convert/write COLOR->Luv scanline */ |
926 |
< |
uint32 y; |
924 |
> |
static void |
925 |
> |
Color2Luv( /* read/convert/write COLOR->Luv scanline */ |
926 |
> |
uint32 y |
927 |
> |
) |
928 |
|
{ |
929 |
|
register int x; |
930 |
|
|
955 |
|
} |
956 |
|
|
957 |
|
|
958 |
< |
void |
959 |
< |
Color2RRGGBB(y) /* read/convert/write COLOR->RGB16 scanline */ |
960 |
< |
uint32 y; |
958 |
> |
static void |
959 |
> |
Color2RRGGBB( /* read/convert/write COLOR->RGB16 scanline */ |
960 |
> |
uint32 y |
961 |
> |
) |
962 |
|
{ |
963 |
< |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
963 |
> |
int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); |
964 |
|
float m = pow(2.,(double)cvts.bradj); |
965 |
|
register int x, i; |
966 |
|
|
989 |
|
} |
990 |
|
|
991 |
|
|
992 |
< |
void |
993 |
< |
Colr2Gry(y) /* read/convert/write COLR->RGB scanline */ |
994 |
< |
uint32 y; |
992 |
> |
static void |
993 |
> |
Colr2Gry( /* read/convert/write COLR->RGB scanline */ |
994 |
> |
uint32 y |
995 |
> |
) |
996 |
|
{ |
997 |
|
register int x; |
998 |
|
|
1016 |
|
} |
1017 |
|
|
1018 |
|
|
1019 |
< |
void |
1020 |
< |
Colr2RGB(y) /* read/convert/write COLR->RGB scanline */ |
1021 |
< |
uint32 y; |
1019 |
> |
static void |
1020 |
> |
Colr2RGB( /* read/convert/write COLR->RGB scanline */ |
1021 |
> |
uint32 y |
1022 |
> |
) |
1023 |
|
{ |
1024 |
|
COLOR ctmp; |
1025 |
|
register int x; |