1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevtifs.h 8022 2007-06-05 22:23:38Z giles $ */
15
/* Definitions for writing TIFF file formats. */
17
#ifndef gdevtifs_INCLUDED
18
# define gdevtifs_INCLUDED
20
/* ================ TIFF specification ================ */
22
/* Based on TIFF specification version 6.0 obtained from */
23
/* sgi.com:graphics/tiff/TIFF6.ps.Z. */
26
* The sizes of TIFF data types are system-independent. Therefore,
27
* we cannot use short, long, etc., but must use types of known sizes.
29
#if arch_sizeof_short == 2
30
typedef short TIFF_short; /* no plausible alternative */
31
typedef unsigned short TIFF_ushort;
34
#if arch_sizeof_int == 4
35
typedef int TIFF_long;
36
typedef unsigned int TIFF_ulong;
39
# if arch_sizeof_long == 4
40
typedef long TIFF_long;
41
typedef unsigned long TIFF_ulong;
47
* Define the TIFF file header.
49
typedef struct TIFF_header_s {
50
TIFF_ushort magic; /* magic number (defines byte order) */
51
TIFF_ushort version; /* TIFF version number */
52
TIFF_ulong diroff; /* byte offset to first directory */
55
#define TIFF_magic_big_endian 0x4d4d /* 'MM' */
56
#define TIFF_magic_little_endian 0x4949 /* 'II' */
58
#define TIFF_version_value 42
61
* Define an individual entry in a TIFF directory. Within a directory,
62
* the entries must be sorted by increasing tag value.
64
* The value field contains either the offset of the field data in the file,
65
* or, if the value fits in 32 bits, the value itself, left-justified.
66
* Field data may appear anywhere in the file, so long as each data block is
67
* aligned on a 32-bit boundary and is disjoint from all other data blocks.
69
typedef struct TIFF_dir_entry_s {
70
TIFF_ushort tag; /* TIFF_tag */
71
TIFF_ushort type; /* TIFF_data_type */
72
TIFF_ulong count; /* number of items (spec calls this 'length') */
73
TIFF_ulong value; /* byte offset to field data, */
74
/* or actual value if <=4 bytes */
78
* Define the tag data type values.
81
TIFF_BYTE = 1, /* 8-bit unsigned integer */
82
TIFF_ASCII = 2, /* 8-bit bytes with last byte null */
83
TIFF_SHORT = 3, /* 16-bit unsigned integer */
84
TIFF_LONG = 4, /* 32-bit unsigned integer */
85
TIFF_RATIONAL = 5, /* 64-bit unsigned fraction */
86
/* (ratio of two 32-bit unsigned integers) */
87
TIFF_SBYTE = 6, /* 8-bit signed integer */
88
TIFF_UNDEFINED = 7, /* 8-bit untyped data */
89
TIFF_SSHORT = 8, /* 16-bit signed integer */
90
TIFF_SLONG = 9, /* 32-bit signed integer */
91
TIFF_SRATIONAL = 10, /* 64-bit signed fraction */
92
/* (ratio of two 32-bit signed integers) */
93
TIFF_FLOAT = 11, /* 32-bit IEEE floating point */
94
TIFF_DOUBLE = 12, /* 64-bit IEEE floating point */
95
/* A flag to indicate the value is indirect. */
96
/* This is only used internally; it is not part of the */
97
/* TIFF specification (although it should be!). */
102
* Define the tag values we need. Note that this is only a very small subset
103
* of all the values defined in the TIFF specification; we will add more
104
* as the need arises.
107
TIFFTAG_SubFileType = 254, /* subfile data descriptor */
108
#define SubFileType_reduced_image 0x1 /* reduced resolution version */
109
#define SubFileType_page 0x2 /* one page of many */
110
#define SubFileType_mask 0x4 /* transparency mask */
111
TIFFTAG_ImageWidth = 256, /* image width in pixels */
112
TIFFTAG_ImageLength = 257, /* image height in pixels */
113
TIFFTAG_BitsPerSample = 258, /* bits per channel (sample) */
114
TIFFTAG_Compression = 259, /* data compression technique */
115
#define Compression_none 1 /* dump mode */
116
#define Compression_CCITT_RLE 2 /* CCITT modified Huffman RLE */
117
#define Compression_CCITT_T4 3 /* CCITT T.4 fax encoding */
118
#define Compression_CCITT_T6 4 /* CCITT T.6 fax encoding */
119
#define Compression_LZW 5 /* Lempel-Ziv & Welch */
120
#define Compression_JPEG 6 /* !JPEG compression */
121
#define Compression_NeXT 32766 /* NeXT 2-bit RLE */
122
#define Compression_CCITT_RLEW 32771 /* #1 w/ word alignment */
123
#define Compression_PackBits 32773 /* Macintosh RLE */
124
#define Compression_Thunderscan 32809 /* ThunderScan RLE */
125
TIFFTAG_Photometric = 262, /* photometric interpretation */
126
#define Photometric_min_is_white 0 /* min value is white */
127
#define Photometric_min_is_black 1 /* min value is black */
128
#define Photometric_RGB 2 /* RGB color model */
129
#define Photometric_palette 3 /* color map indexed */
130
#define Photometric_mask 4 /* $holdout mask */
131
#define Photometric_separated 5 /* !color separations */
132
#define Photometric_YCbCr 6 /* !CCIR 601 */
133
#define Photometric_CIE_Lab 8 /* !1976 CIE L*a*b* */
134
TIFFTAG_FillOrder = 266, /* data order within a byte */
135
#define FillOrder_MSB2LSB 1 /* most significant -> least */
136
#define FillOrder_LSB2MSB 2 /* least significant -> most */
137
TIFFTAG_StripOffsets = 273, /* offsets to data strips */
138
TIFFTAG_Orientation = 274, /* +image Orientation */
139
#define Orientation_top_left 1 /* row 0 top, col 0 lhs */
140
#define Orientation_top_right 2 /* row 0 top, col 0 rhs */
141
#define Orientation_bot_right 3 /* row 0 bottom, col 0 rhs */
142
#define Orientation_bot_left 4 /* row 0 bottom, col 0 lhs */
143
#define Orientation_left_top 5 /* row 0 lhs, col 0 top */
144
#define Orientation_right_top 6 /* row 0 rhs, col 0 top */
145
#define Orientation_right_bot 7 /* row 0 rhs, col 0 bottom */
146
#define Orientation_left_bot 8 /* row 0 lhs, col 0 bottom */
147
TIFFTAG_SamplesPerPixel = 277, /* samples per pixel */
148
TIFFTAG_RowsPerStrip = 278, /* rows per strip of data */
149
TIFFTAG_StripByteCounts = 279, /* bytes counts for strips */
150
TIFFTAG_XResolution = 282, /* pixels/resolution in x */
151
TIFFTAG_YResolution = 283, /* pixels/resolution in y */
152
TIFFTAG_PlanarConfig = 284, /* storage organization */
153
#define PlanarConfig_contig 1 /* single image plane */
154
#define PlanarConfig_separate 2 /* separate planes of data */
155
TIFFTAG_T4Options = 292, /* 32 flag bits */
156
#define T4Options_2D_encoding 0x1 /* 2-dimensional coding */
157
#define T4Options_uncompressed 0x2 /* data not compressed */
158
#define T4Options_fill_bits 0x4 /* fill to byte boundary */
159
TIFFTAG_T6Options = 293, /* 32 flag bits */
160
#define T6Options_uncompressed 0x2 /* data not compressed */
161
TIFFTAG_ResolutionUnit = 296, /* units of resolutions */
162
#define ResolutionUnit_none 1 /* no meaningful units */
163
#define ResolutionUnit_inch 2 /* english */
164
#define ResolutionUnit_centimeter 3 /* metric */
165
TIFFTAG_PageNumber = 297, /* page number if multi-page */
166
TIFFTAG_Software = 305, /* software name & release */
167
TIFFTAG_DateTime = 306, /* creation date and time */
169
* The CleanFaxData tag isn't in the TIFF 6 documentation, and many
170
* TIFF-reading applications don't recognize it. Don't use it!
172
TIFFTAG_CleanFaxData = 327 /* regenerated line info */
173
#define CleanFaxData_clean 0 /* no errors detected */
174
#define CleanFaxData_regenerated 1 /* receiver regenerated lines */
175
#define CleanFaxData_unclean 2 /* uncorrected errors exist */
178
/* ================ Implementation ================ */
181
* Define the added driver state for TIFF writing. Note that we provide
182
* no GC descriptor, so this structure must exist only on the stack,
183
* never in allocated storage.
185
typedef struct gdev_tiff_state_s {
187
long prev_dir; /* file offset of previous directory offset */
188
long dir_off; /* file offset of next write */
189
int ntags; /* # of tags in directory */
190
long strip_index; /* current strip being output, 0 = first */
193
/* Record offsets of values - these may be indirect if more than one strip */
194
int offset_StripOffsets;
195
int offset_StripByteCounts;
196
TIFF_ulong *StripOffsets;
197
TIFF_ulong *StripByteCounts;
201
* Begin writing a TIFF page. This procedure supplies a standard set of
202
* tags; the client can provide additional tags (pre-sorted) and
205
int gdev_tiff_begin_page(gx_device_printer * pdev, gdev_tiff_state * tifs,
207
const TIFF_dir_entry * entries, int entry_count,
208
const byte * values, int value_size,
209
long max_strip_size);
212
* Finish writing a TIFF strip. All data written since begin or last
213
* end_strip is considered to be a single strip.
215
int gdev_tiff_end_strip(gdev_tiff_state * tifs, FILE * fp);
218
* Finish writing a TIFF page. StripOffsets and StripByteCounts are
219
* patched into the file.
221
int gdev_tiff_end_page(gdev_tiff_state * tifs, FILE * fp);
223
#endif /* gdevtifs_INCLUDED */