3. Image File Format
Image files should be in the TIFF-B format which is the bi-level subclass of TIFF. TIFF and TIFF-B are described in reference [3], cited at the end of this document. Images should be compressed using MMR (the G4 compression scheme) because it offers superior compression ratios. However, images may also be compressed using MH or MR (the G3 methods). MMR offers much better compression ratios than these (which are used in G3 fax because of the lack of an error-free communications path).
TIFF-F, described in [4], is the proposed subclass of TIFF-B for fax images. However, since TIFF-F was intended for use with G3, it recommends against certain features we recommend. Specifically, it suggests not using MMR or MR compression (we recommend MMR and allow MR) and prohibits uncompressed mode (which we allow and suggest for some photographic images). Apart from these, the TIFF-F restrictions should be followed. (Complete compatibility between the format specified here and TIFF-F can only be guaranteed for MH compressed images.)
[NOTE: Aldus Corp., the TIFF Developer, considers fax applications to be outside the scope of mainstream TIFF since it is not a part of general publishing which is what TIFF was originally designed for. They specify the LZW [5] compression scheme rather than MMR. We, however, are concerned with the transmission and storage of images rather than publishing. Therefore, we are more concerned with compression ratios and compatibility with CCITT fax than Aldus is.]
TIFF itself allows for gray-scale and color images. Image files should be restricted to TIFF-B for now because most of the currently available hardware is bi-level (1 bit per pixel). In the future, when gray-scale or color scanners, printers, and fax becomes available, the file format suggested here can already accommodate it. (For example, though JPEG is not currently a TIFF defined compression type, work is currently underway for including it as such.)
[NOTE: In this document, we will use the term "reader" or "TIFF reader" to refer to the process or device which reads and parses a TIFF file.]
3.A. TIFF File Format
Figure 1 below (reproduced here from Figure 1 of reference [3]) depicts the structure of a TIFF file.
TIFF files start with a file header which specifies the byte order used in the file (i.e., Big or Little Endian), the TIFF version number, and points to the first "Image File Directory" (IFD). If the first two bytes are hex 4D4D, the byte order is from most to least significant for both 16 and 32 bit integers (Big Endian). If the first two bytes are hex 4949, the byte order is from least to most significant (Little Endian). In both formats, character strings are stored into sequential bytes and are null terminated.
The next two bytes (called the TIFF Version) must be 42 (hex 002A). This does not refer to the current TIFF revision number. The following 4 bytes contain the offset (in bytes from the beginning of the file) to the first IFD.
An IFD contains a 2 byte count of the number of entries in the IFD, a sequence of 12 byte directory entries, and a 4 byte pointer to the next IFD. One of these fields (StripOffsets) points to (parts of) an image in the file. There may be more than one image in the file (e.g., a "multi-page" TIFF file) and therefore more then one IFD. IFD field entries may appear in any order.
Each directory entry is 12 bytes and consists of a tag, its type, a length, and an offset to its value. If the value can fit into 4 bytes (i.e., if the type is BYTE, SHORT, or LONG), the actual value rather than an offset is given. If the value is less than 4 bytes (i.e., if the type is BYTE or SHORT), it is left-justified within the 4 byte value offset. More details about directory entries and the possible tags will be given in Section 3.C.
All pointers (called offsets in the TIFF reference [3]) are the number of bytes from the beginning of the file and are 4 bytes long. The first byte of the file has an offset of 0. In the case of only one image per file, there should therefore be only one IFD. The last IFD's pointer to the next IFD is set to hex 00000000 (32 bits).
The entries in an IFD must be sorted in ascending order by Tag.
Header
+--------+--------+ Directory Entry
0 | | | Byte Order +--------+--------+
+--------+--------| X | | | Tag
2 | | | Version(42) +--------+--------|
+--------+--------| X+2 | | | Type
4 | | | Offset of +--------+--------|
+- - A - -+ 0th IFD X+4 | | |
6 | | | +- -+ Length
+--------+--------+ | | |
| +--------+--------+
| X+8 | | | Value
| +- - Y - -+ or
V | | | Value
+--------+--------+ Offset
IFD
+--------+--------+ |
A | - B - | Entry Count |
+--------+--------| |
| | | V
A+2 Entry 0
| | | +--------+--------+
+--------+--------+ | | |
| | | Y Value
A+14 Entry 1 | | |
| | | +--------+--------|
+--------+--------+
| | |
A+26 Entry 2
| | |
+--------+--------+
| | | .
.
| | | .
+--------+--------+
| | |
Entry B-1
| | |
+--------+--------+
| | | Offset of
A+2+B*12 - C - + Next IFD
| | |
+--------+--------+
|
V
(next IFD)
Figure 1: The Structure of a TIFF File
3.B. Image Format and Encoding Issues
Images in TIFF files are organized as horizontal strips for fast access to individual rows. One can specify how many rows there are in each strip and all of the strips are the same size (except possibly the last one). Each strip must begin on a byte boundary but successive rows are not so required. For two-dimensional G3 compression (MR), each strip must begin with an "absolute" one-dimensional line. For MMR (G4) compression, each strip must be encoded as if it were a separate image.
For a variety of reasons, each page must be a single strip (e.g., not broken up into multiple strips).
One problem with multiple strips per page is that images which come from G4 fax machines as well as most scanned images will be generated as a single strip per page. These would have to be decoded and re-encoded as multiple strips (remember that for MMR compression, each strip must be start with a one-dimensionally encoded line).
Another problem with multiple strips per page arises in MR compression. Here, there MAY be at most k-1 two-dimensionally encoded lines following a one-dimensionally encoded line, but this is not required. It is possible to have one-dimensional lines more frequently than every k lines. However, since each strip (except possibly the last one) is required to be the same size, it may be necessary to re-encode the image to insure that each strip starts with a one-dimensional line. This is not a problem if each page is a single strip.
[NOTE: The TIFF document [3] suggests using strips which are about 8K bytes long. However, TIFF-F [4] recommends that each page be a single strip regardless of its size. The format specified in this document follows the TIFF-F recommendation.]
Also, as TIFF-F recommends, all G3 encoded images (MH and MR) should be "byte-aligned." This means that extra zero bits (fill bits) are added before each EOL (end-of-line) so that every line starts on a byte boundary.
In addition, as in the TIFF-F specification, the RTC (Return to Control signal which consists of 6 continuous EOL's) of G3 shall not be included at the end of G3 encoded documents. RTC is to be considered part of the G3 transmission protocol and not part of the encoding. Most, if not all, G3 fax modems attach RTC to outgoing images and remove it from incoming ones.
For MMR (G4) encoded files, readers should be able to read images with only one EOFB (End Of Facsimile Block) at the end of the page and should not assume that Facsimile Blocks are of any particular size. (It has been reported that some MMR readers assume that all Facsimile Blocks are the maximum size.)
Systems may optionally choose to store the entire image uncompressed if the compression increases the size of the image file. Also, uncompressed mode (specified in Group3Options or Group4Options, see below) allows portions of the image to be uncompressed.
The multi-page capability of TIFF is supported and should be used for multi-page documents. TIFF files which have multiple pages have an IFD for each page of the document each of which describes and points to a single page image. (Note: though the current TIFF specification does not specifically prohibit having a single IFD point to an image which is actually multiple pages, with one strip for each page, most if not all TIFF readers would probably not be able to read such a file. Therefore, this should not be done.)
A NOTE ON TIFF AND MULTI-PAGE DOCUMENTS:
Since most publications (e.g., reports, books, and magazine articles) are composed of more than a single page, multi-page TIFF files should be used where appropriate. However, many current TIFF implementations now only handle single-page files.
It is hoped that in the future, more TIFF implementations will handle multi-page files correctly. In the meantime, it would be useful to develop a utility program which could join several single-page TIFF files into a single multi-page file and also separate a multi-page TIFF file into several single page files.
For example, the utility could take a single TIFF file with N pages, called doc.tif, and create the files doc.000, doc.001, doc.002, ..., doc.N. doc.000 would be an ASCII listing of the files created. This naming scheme is compatible with that used by the image systems we have seen which only handle single page files.
In going the other way, the N+1 single page files could be combined into a single multi-page TIFF file. In this case, if the file doc.000 exists but contains information contrary to what is found in looking for the files doc.001, doc.002, ..., the program would notify the user.]
3.C. TIFF Fields
TIFF is tag or field based. The various fields and their format are listed in [3]. There are Basic Fields (common to all TIFF files), Informational Fields (which provide useful information to a user), Facsimile Fields (used here), and Private Fields.
Each directory entry contains:
- The Tag for the field (2 bytes)
- The field Type (2 bytes)
- The field Length (4 bytes) (This is in terms of the data type, not in bytes. For example, a single 16-bit word or SHORT has a Length of 1, not 2)
- The Value Offset (4 bytes) (Pointer to the actual value, which must begin on a word boundary. Therefore, this offset will always be an even number. If the Value fits into 4 bytes, the Value Offset contains the Value instead. If the Value takes less than 4 bytes, it is left justified)
The allowed types and their codes are:
1 = BYTE 8-bit unsigned integer (1 byte)
2 = ASCII 8-bit ASCII terminated with a null (variable
length)
3 = SHORT 16-bit unsigned integer (2 bytes)
4 = LONG 32-bit unsigned integer (4 bytes)
5 = RATIONAL Two LONGs (64 bits) representing the
numerator and denominator of a fraction.
In this document, RATIONAL's will be written
as numerator/denominator. (8 bytes)
For ASCII, the Length specifies the number of characters and includes the null. It does not, however, include padding if such is necessary.
(Note that ASCII strings of length 3 or less may be stored in the Value Offset field instead of being pointed to.)
The following fields should be used in a TIFF image file. Only the Basic Fields are mandatory; the others are optional (except that for MH and MR encoded files, the Group3Options Facsimile Field is mandatory). The optional fields have default values which are given in the TIFF specification. (Note that the TIFF reference [3] recommends not relying on the default values.)
Some fields contain one or more flag bits all stored as one value. In these cases, the bit labeled 0 is the least significant bit (i.e., Little Endian order). Where there is more than one suggested value for a tag, the possible values are separated by |.
Note that some fields (such as ImageLength or ImageWidth) can be of more than one type.
It would be useful to develop a TIFF viewer and editor which would allow one to read, add, and edit the fields in a TIFF file. Such an editor would display fields in sorted order and force the inclusion of all mandatory fields. Also, resolution and position should always be displayed or specified together with their units.
3.C.1. Basic Fields (Mandatory)
Basic Fields are those which are fundamental to the pixel architecture or visual characteristics of an image. The following Basic Fields should be included in a TIFF image file:
FIELD NAME
(TAG in hex, TYPE) VALUE DESCRIPTION
------------------ ----- -----------
BitsPerSample 1 Number of bits
(0102, SHORT) per pixel (bi-level for
now, but may allow
more later)
Compression 4 Type of Compression
(0103, SHORT) (could also be 1 = Uncompressed
1 or 3) 3 = G3 (MH or MR)
4 = G4 (MMR)
Use 4 if possible
ImageLength <image's length> Length of the Image
(0101, SHORT in scan lines
or LONG)
ImageWidth <image's width> Width of the Image
(0100, SHORT in pixels
or LONG)
NewSubFileType 0 usually Flag bits indicating
(00FE, LONG) bit 0: 1 if the kind of image.
reduced (see the TIFF
resolution of reference [3])
another image
bit 1: 1 if
single page of a
multi-page image
bit 2: 1 if
image defines a
transparency
mask
Photometric- 0 for positive
Interpretation image (0 imaged
(0106, SHORT) as white, 1 as
black)
1 means reverse
black and white
RowsPerStrip <Number of Rows> Number of Rows in
(0116, SHORT Each Strip. Each
or LONG) page should be a
single strip.
SamplesPerPixel 1 (since are Bi-level
(0115, SHORT) images)
StripByteCounts count1, count2... Number of Bytes in
(0117, SHORTs each strip of the
or LONGs) images. (The Value
is an offset which
points to a series
of counts, each of
which is the same
Type, LONG or SHORT.
The Length is the
same as the number
of strips.)
StripOffsets off1, off2,... Pointers to the strips
(0111, SHORTs of the image (remember,
or LONGs) one strip per page).
(The Value is an offset
which points to a
series of offsets,
each of which points
to the actual image
data for the strip.)
ResolutionUnit 2 | 3 Units of Resolution
(0128, SHORT) See Below, 3.C.6 2: Inches
3: Centimeters
XResolution See Below, 3.C.6 Resolution in the X
(011A, RATIONAL) direction in pixels
per ResolutionUnit
(we suggest 400 dots
per inch when possible)
YResolution See Below, 3.C.6 Resolution in the Y
(011B, RATIONAL) direction in pixels
per ResolutionUnit
(we suggest 400 dots
per inch when possible)
3.C.2. Informational Fields (Optional)
The following Informational Fields are optional. They provide useful information to a user. All Field values are ASCII strings.
NAME (TAG in hex) DESCRIPTION
---------------- -----------
Artist (013B) Person Who Created the Image
DateTime (0132) Date and Time of Image Creation
HostComputer (013C) Name of Computer Image was Created On
ImageDescription A Short Text Description
(010E)
Make (010F) Manufacturer of Hardware (Scanner) Used
Model (0110) Model Number of Hardware (Scanner) Used
Software (0131) Software Package that Created the Image
3.C.3. Facsimile Fields (Optional, Mandatory for G3 Compression)
In addition to the above, the Facsimile Fields below should be used. The TIFF document recommends that they not be used for interchange between applications, but they are now in wide enough use for just that. These fields are optional and default to 0 (all bits off).
FIELD NAME
(TAG in hex, TYPE) VALUE DESCRIPTION
------------------ ----- -----------
Group3Options bit 0: 1 for Flag bits indicating
(0124, LONG) 2-dimensional Options for G3
coding
(i.e., MR with
k > 1)
bit 1: 1 if
uncompressed
mode MAY be used,
0 if uncompressed
mode IS NOT used.
bit 2: 1 if fill (As allowed by the G3
bits have been protocol, fill bits
added may be added between
each line of data
and the EOL. Since
fill bits are used to
"byte-align" G3 image
files, bit 2 should be
set to 1 for these
images.)
Group4Options bit 0: unused Flag bits indicating
(0125, LONG) bit 1: 1 if Options for G4
uncompressed
mode MAY be used,
if this bit is 0
it means that
uncompressed mode
IS NOT used.
3.C.4. Storage and Retrieval Fields (Optional)
The following fields are optional and may be useful for document storage and retrieval.
FIELD NAME
(TAG in hex, TYPE) DESCRIPTION
------------------ -----------
DocumentName Name of the Document
(010D, ASCII)
PageName Name of the Page
(011D, ASCII)
PageNumber Page Number in a Multi-Page Document
(0129, SHORTs) Two SHORT Values are specified, the
first is the page number and the
second is the total number of pages
in the document. The first page
is page 0. (NOTE: This does not
necessarily correspond to page
numbers which may be printed
in the image.)
XPosition X Offset of the Left Side of
(011E, RATIONAL) the Image, in ResolutionUnits
YPosition Y Offset of the Top of
(011F, RATIONAL) the Image, in ResolutionUnits
3.C.5. TIFF-F Fields (NOT Recommended)
TIFF-F defines the following new fields for G3 (MH) encoded images. Since these fields are not defined in TIFF-B itself, their use is not recommended. However, since TIFF-F files may include these tags for image data which came from a G3 fax machine, readers should be prepared for them.
These three fields deal with corrupted image data which is due to the fact that G3 devices may not perform error correction on bad data.
FIELD NAME
(TAG in hex, TYPE) DESCRIPTION
------------------ -----------
BadFaxLines Number of Bad fax scan lines
(0146, SHORT or LONG) encountered during fax reception
(but not necessarily in the file)
CleanFaxData 0 means no bad lines received
(0147, SHORT) 1 means bad lines were regenerated
by the receiving device
2 means bad lines were detected
but not regenerated
ConsecutiveBadFaxLines The maximum number of consecutive
(0148, SHORT or LONG) bad fax lines (but not necessarily
in the file)
3.C.6. More on Representing Resolutions
The tags XResolution and YResolution are both RATIONALs, i.e., the ratio of two LONGS. G3 fax resolutions are actually specified in dots (or lines) per mm while G4 is in dots per inch (actually, dots per 25.4 mm).
For example, G3 horizontal resolution is defined to be 1728 dots per 215 mm which comes out to 80.4 dots per cm or about 203 dots per inch. It is frequently referred to as just 200 dpi. To avoid any possibility of problems due to round off error, this should be represented by having XResolution = 17280/215 and ResolutionUnit = 3 (cm). However when reading, 204/1 or even 200/1 with ResolutionUnit = 2 (inches) should be recognized as representing the same resolution.
For G4, on the other hand, the resolution 400 dots/inch should be represented by an XResolution of 400/1 and ResolutionUnit = 2.
The following table shows various ways of representing the standard resolutions in order of preference:
ResolutionUnit XResolution YResolution
-------------- ----------- -----------
G3 normal 3 17280/215 3850/100
3 80/1 3850/100
3 17280/215 385/10
3 80/1 385/10
2 2042/10 9779/100
2 204/1 98/1
2 200/1 100/1
G3 fine 3 17280/215 77/1
3 80/1 77/1
2 2042/10 19558/100
2 204/1 196/1
2 200/1 200/1
G4 200 dpi 2 200/1 200/1
G4 300 dpi 2 300/1 300/1
Other 300 dpi 2 300/1 300/1
G4 400 dpi 2 400/1 400/1
600 dpi 2 600/1 600/1
It is suggested that Image readers be able to handle all of the above representations.