1 | /*
|
---|
2 |
|
---|
3 | gbmtifh.h - Interface to TIFF file handling stuff
|
---|
4 |
|
---|
5 | Added #defines for many more tags.
|
---|
6 | Added #defines for most of the new TIFF 6.0 tags.
|
---|
7 | Added #defines for the new tag field types.
|
---|
8 | Reading numeric tags will now accept signed field types too.
|
---|
9 |
|
---|
10 | */
|
---|
11 |
|
---|
12 | #define TE_OK 0
|
---|
13 | #define TE_MEM 1
|
---|
14 | #define TE_VERSION 2
|
---|
15 | #define TE_N_TAGS 3
|
---|
16 | #define TE_TAG_TYPE 4
|
---|
17 | #define TE_N_IFD 5
|
---|
18 |
|
---|
19 | /*
|
---|
20 | Image tags used in TIFF files. The types given with each one is what they
|
---|
21 | usually are. A program should not assume that this is always the case.
|
---|
22 | The most sensible way of handling things that could be short or long is to
|
---|
23 | use the numeric_tag() predicate and the value_of_tag() functions.
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*...stags:0:*/
|
---|
27 | #define T_NEWSUBFILETYPE 254 /* data is long */
|
---|
28 | #define T_SUBFILETYPE 255 /* data is short */
|
---|
29 | #define T_IMAGEWIDTH 256 /* data is a short */
|
---|
30 | #define T_IMAGELENGTH 257 /* data is a short */
|
---|
31 | #define T_BITSPERSAMPLE 258 /* data is a short */
|
---|
32 | #define T_COMPRESSION 259 /* data is a short */
|
---|
33 | #define T_PHOTOMETRIC 262 /* data is short */
|
---|
34 | #define T_THRESHOLDING 263 /* data is short */
|
---|
35 | #define T_CELLWIDTH 264
|
---|
36 | #define T_CELLLENGTH 265
|
---|
37 | #define T_FILLORDER 266 /* data is short */
|
---|
38 | #define T_DOCNAME 269 /* data is ASCII */
|
---|
39 | #define T_DESCRIPTION 270 /* data is ASCII */
|
---|
40 | #define T_MAKE 271 /* data is ASCII */
|
---|
41 | #define T_MODEL 272 /* data is ASCII */
|
---|
42 | #define T_STRIPOFFSETS 273 /* data is short or long */
|
---|
43 | #define T_ORIENTATION 274 /* data is short */
|
---|
44 | #define T_SAMPLESPERPIXEL 277 /* data is short */
|
---|
45 | #define T_ROWSPERSTRIP 278 /* data is short or long */
|
---|
46 | #define T_STRIPBYTECOUNTS 279 /* data is short */
|
---|
47 | #define T_MINSAMPLEVALUE 280 /* data is short or long */
|
---|
48 | #define T_MAXSAMPLEVALUE 281 /* data is short or long */
|
---|
49 | #define T_XRESOLUTION 282 /* data is rational */
|
---|
50 | #define T_YRESOLUTION 283 /* data is rational */
|
---|
51 | #define T_PLANARCONFIG 284 /* data is short */
|
---|
52 | #define T_PAGENAME 285 /* data is ASCII */
|
---|
53 | #define T_XPOSITION 286
|
---|
54 | #define T_YPOSITION 287
|
---|
55 | #define T_FREEOFFSETS 288
|
---|
56 | #define T_FREEBYTECOUNTS 289
|
---|
57 | #define T_GRAYRESPONSEUNIT 290 /* data is a short */
|
---|
58 | #define T_GRAYRESPONSECURVE 291 /* data is a set of shorts */
|
---|
59 | #define T_GROUP3OPTIONS 292 /* data is a long */
|
---|
60 | #define T_GROUP4OPTIONS 293 /* data is a long */
|
---|
61 | #define T_RESOLUTIONUNIT 296 /* data is short */
|
---|
62 | #define T_PAGENUMBER 297 /* data is 2 shorts */
|
---|
63 | #define T_COLORRESPONSECURVES 301 /* data is 3 sets of shorts */
|
---|
64 | #define T_SOFTWARE 305 /* data is ASCII */
|
---|
65 | #define T_DATETIME 306
|
---|
66 | #define T_ARTIST 315 /* data is ASCII */
|
---|
67 | #define T_HOSTCOMPUTER 316 /* data is ASCII */
|
---|
68 | #define T_PREDICTOR 317 /* data is a short */
|
---|
69 | #define T_WHITEPOINT 318
|
---|
70 | #define T_PRIMARYCHROMA 319 /* data us 6 rationals */
|
---|
71 | #define T_COLORMAP 320 /* data is 3 sets of shorts */
|
---|
72 | #define T_HALFTONEHINTS 321 /* data is 2 shorts */
|
---|
73 | #define T_TILEWIDTH 322 /* data is 1 short */
|
---|
74 | #define T_TILELENGTH 323 /* data is 1 short */
|
---|
75 | #define T_TILEOFFSETS 324 /* data is # tiles long */
|
---|
76 | #define T_TILEBYTECOUNTS 325 /* data is # tiles long */
|
---|
77 | #define T_INKSET 332 /* data is 1 short */
|
---|
78 | #define T_INKNAMES 333 /* data is ASCII */
|
---|
79 | #define T_NUMBEROFINKS 334 /* data is 1 short */
|
---|
80 | #define T_DOTRANGE 336 /* data is 2 or 2 * samples per pixel bytes or shorts */
|
---|
81 | #define T_TARGETPRINTER 337 /* data is ASCII */
|
---|
82 | #define T_EXTRASAMPLES 338 /* data is 1 short */
|
---|
83 | #define T_SAMPLEFORMAT 339 /* data is samples per pixel shorts */
|
---|
84 | #define T_SMINSAMPLEVALUE 340 /* data is samples per pixel ? */
|
---|
85 | #define T_SMAXSAMPLEVALUE 341 /* data is samples per pixel ? */
|
---|
86 | #define T_TRANSFERRANGE 342 /* data is 6 shorts */
|
---|
87 | #define T_JPEGPROC 512 /* data is 1 short */
|
---|
88 | #define T_JPEGINTERCHANGEFMT 513 /* data is 1 long */
|
---|
89 | #define T_JPEGINTERCHANGEFMTLEN 514 /* data is 1 long */
|
---|
90 | #define T_JPEGRESTARTINTERVAL 515 /* data is 1 short */
|
---|
91 | #define T_JPEGLOSSLESSPRED 517 /* data is samples per pixel shorts */
|
---|
92 | #define T_JPEGPOINTTRANSFORMS 518 /* data is samples per pixel shorts */
|
---|
93 | #define T_JPEGOTABLES 519 /* data is samples per pixel longs */
|
---|
94 | #define T_JPEGDCTABLES 520 /* data is samples per pixel longs */
|
---|
95 | #define T_JPEGACTABLES 521 /* data is samples per pixel longs */
|
---|
96 | #define T_COEFFICIENTS 529 /* data is 3 rationals */
|
---|
97 | #define T_SUBSAMPLING 530 /* data is 2 shorts */
|
---|
98 | #define T_REFERENCEBLACKWHITE 532 /* data is 6 rationals */
|
---|
99 | /*...e*/
|
---|
100 |
|
---|
101 | typedef struct { long numerator, denominator; } rational;
|
---|
102 |
|
---|
103 | #define D_BYTE 1 /* data is unsigned 8 bit */
|
---|
104 | #define D_ASCII 2 /* data is ASCIIZ string */
|
---|
105 | #define D_SHORT 3 /* data is unsigned 16 bit */
|
---|
106 | #define D_LONG 4 /* data is unsigned 32 bit */
|
---|
107 | #define D_RATIONAL 5 /* data is 2 LONGs */
|
---|
108 | #define D_SBYTE 6 /* data is signed 8 bit */
|
---|
109 | #define D_UNDEFINED 7 /* data 8 bit anything */
|
---|
110 | #define D_SSHORT 8 /* data is signed 16 bit */
|
---|
111 | #define D_SLONG 9 /* data is signed 32 bit */
|
---|
112 | #define D_SRATIONAL 10 /* data is 2 SLONGs */
|
---|
113 | #define D_FLOAT 11 /* data is 4-byte IEEE format */
|
---|
114 | #define D_DOUBLE 12 /* data is 8-byte IEEE format */
|
---|
115 |
|
---|
116 | typedef struct
|
---|
117 | {
|
---|
118 | short type;
|
---|
119 | short data_type;
|
---|
120 | long length;
|
---|
121 | void *value;
|
---|
122 | } TAG;
|
---|
123 |
|
---|
124 | #define MAX_TAGS 200
|
---|
125 |
|
---|
126 | typedef struct
|
---|
127 | {
|
---|
128 | short n_tags;
|
---|
129 | TAG tags [MAX_TAGS];
|
---|
130 | } IFD;
|
---|
131 |
|
---|
132 | typedef struct
|
---|
133 | {
|
---|
134 | short byte_order;
|
---|
135 | short version_no;
|
---|
136 | IFD *ifd;
|
---|
137 | } IFH;
|
---|
138 |
|
---|
139 | #ifndef _GBMTIFH_
|
---|
140 |
|
---|
141 | /*
|
---|
142 | Proposed method for loading a TIFF file :-
|
---|
143 | 1) Open file.
|
---|
144 | 2) Use read_ifh_and_ifd() to get header.
|
---|
145 | If an error occurs returned error code not TE_OK.
|
---|
146 | 3) Use locate_tag() and value_of_tag() etc. to test presence and
|
---|
147 | validity of tags.
|
---|
148 | 4) In particular use value_of_tag_n() to get at T_STRIPOFFSETS,
|
---|
149 | to extract the offsets into the file where the raw data is.
|
---|
150 | 5) Read the raw data.
|
---|
151 | 6) Close the file.
|
---|
152 | 7) Free the IFH structure using free_ifh().
|
---|
153 | */
|
---|
154 |
|
---|
155 | extern int read_ifh_and_ifd(int fd, int n_ifds_to_skip, IFH **ifh_return);
|
---|
156 | extern BOOLEAN numeric_tag(TAG *tag);
|
---|
157 | extern long value_of_tag(TAG *tag);
|
---|
158 | extern long value_of_tag_n(TAG *tag, int n);
|
---|
159 | extern TAG *locate_tag(IFD *ifd, short type);
|
---|
160 | extern void free_ifh(IFH *ifh);
|
---|
161 |
|
---|
162 | /*
|
---|
163 | Proposed method for saving a TIFF file :-
|
---|
164 | 1) Open file
|
---|
165 | If fails use tiff_errno.
|
---|
166 | 2) Use make_ifh() to create an empty IFH (and its IFD).
|
---|
167 | If fails then out of memory.
|
---|
168 | 3) Setup all the tags - those that you don't know set to 0.
|
---|
169 | If fails then out of memory.
|
---|
170 | 4) Use write_ifh_and_ifd() to write the IFH.
|
---|
171 | If fails look at tiff_errno.
|
---|
172 | 5) Write all the raw data to the file, using ftell() to
|
---|
173 | keep a record of where strips start and how long they are.
|
---|
174 | 6) In particular update tags T_STRIPOFFSETS and T_STRIPBYTECOUNTS.
|
---|
175 | 7) Use write_ifd() to rewrite the IFD.
|
---|
176 | 8) Close the file.
|
---|
177 | 9) Use free_ifh() to deallocate the IFH.
|
---|
178 |
|
---|
179 | It is important to realise that a second write of the IFD is necessary since
|
---|
180 | the StripOffsets and StripByteCounts tags cannot be known until the compressed
|
---|
181 | data has actually been written. Although the TIFF spec allows us to write the
|
---|
182 | compressed data BEFORE we write the IFD, I find that some programs (notably
|
---|
183 | the IBM utility IDUCNVT.EXE) insist that the IFD is before the data).
|
---|
184 | */
|
---|
185 |
|
---|
186 | extern IFH *make_ifh(void);
|
---|
187 | extern BOOLEAN add_byte_tag(IFD *ifd, short type, byte *value, int n);
|
---|
188 | extern BOOLEAN add_ascii_tag(IFD *ifd, short type, char *value);
|
---|
189 | extern BOOLEAN add_short_tag(IFD *ifd, short type, short *value, int n);
|
---|
190 | extern BOOLEAN add_long_tag(IFD *ifd, short type, long *value, int n);
|
---|
191 | extern BOOLEAN add_rational_tag(IFD *ifd, short type, rational *value, int n);
|
---|
192 | extern BOOLEAN write_ifh_and_ifd(IFH *ifh, int fd);
|
---|
193 | extern void update_byte_tag(IFD *ifd, short type, byte *value);
|
---|
194 | extern void update_ascii_tag(IFD *ifd, short type, char *value);
|
---|
195 | extern void update_short_tag(IFD *ifd, short type, short *value);
|
---|
196 | extern void update_long_tag(IFD *ifd, short type, long *value);
|
---|
197 | extern void update_rational_tag(IFD *ifd, short type, rational *value);
|
---|
198 | extern BOOLEAN update_ifd(IFD *ifd, int fd);
|
---|
199 |
|
---|
200 | #endif
|
---|