roentgen b75cab
.\" $Id: TIFFOpen.3tiff,v 1.2 2005-07-01 12:36:22 dron Exp $
roentgen b75cab
.\"
roentgen b75cab
.\" Copyright (c) 1988-1997 Sam Leffler
roentgen b75cab
.\" Copyright (c) 1991-1997 Silicon Graphics, Inc.
roentgen b75cab
.\"
roentgen b75cab
.\" Permission to use, copy, modify, distribute, and sell this software and 
roentgen b75cab
.\" its documentation for any purpose is hereby granted without fee, provided
roentgen b75cab
.\" that (i) the above copyright notices and this permission notice appear in
roentgen b75cab
.\" all copies of the software and related documentation, and (ii) the names of
roentgen b75cab
.\" Sam Leffler and Silicon Graphics may not be used in any advertising or
roentgen b75cab
.\" publicity relating to the software without the specific, prior written
roentgen b75cab
.\" permission of Sam Leffler and Silicon Graphics.
roentgen b75cab
.\" 
roentgen b75cab
.\" THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
roentgen b75cab
.\" EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
roentgen b75cab
.\" WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
roentgen b75cab
.\" 
roentgen b75cab
.\" IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
roentgen b75cab
.\" ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
roentgen b75cab
.\" OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
roentgen b75cab
.\" WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
roentgen b75cab
.\" LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
roentgen b75cab
.\" OF THIS SOFTWARE.
roentgen b75cab
.\"
roentgen b75cab
.if n .po 0
roentgen b75cab
.TH TIFFOpen 3TIFF "July 1, 2005" "libtiff"
roentgen b75cab
.SH NAME
roentgen b75cab
TIFFOpen, TIFFFdOpen, TIFFClientOpen \- open a
roentgen b75cab
.SM TIFF
roentgen b75cab
file for reading or writing
roentgen b75cab
.SH SYNOPSIS
roentgen b75cab
.B "#include <tiffio.h>"</tiffio.h>
roentgen b75cab
.sp
roentgen b75cab
.BI "TIFF* TIFFOpen(const char *" filename ", const char *" mode ")"
roentgen b75cab
.br
roentgen b75cab
.BI "TIFF* TIFFFdOpen(const int " fd ", const char *" filename ", const char *" mode ")"
roentgen b75cab
.sp
roentgen b75cab
.B "typedef tsize_t (*TIFFReadWriteProc)(thandle_t, tdata_t, tsize_t);"
roentgen b75cab
.br
roentgen b75cab
.B "typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int);"
roentgen b75cab
.br
roentgen b75cab
.B "typedef int (*TIFFCloseProc)(thandle_t);"
roentgen b75cab
.br
roentgen b75cab
.B "typedef toff_t (*TIFFSizeProc)(thandle_t);"
roentgen b75cab
.br
roentgen b75cab
.B "typedef int (*TIFFMapFileProc)(thandle_t, tdata_t*, toff_t*);"
roentgen b75cab
.br
roentgen b75cab
.B "typedef void (*TIFFUnmapFileProc)(thandle_t, tdata_t, toff_t);"
roentgen b75cab
.sp
roentgen b75cab
.BI "TIFF* TIFFClientOpen(const char *" filename ", const char *" mode ", thandle_t " clientdata ", TIFFReadWriteProc " readproc ", TIFFReadWriteProc " writeproc ", TIFFSeekProc " seekproc ", TIFFCloseProc " closeproc ", TIFFSizeProc " sizeproc ", TIFFMapFileProc " mapproc ", TIFFUnmapFileProc " unmapproc ")"
roentgen b75cab
.SH DESCRIPTION
roentgen b75cab
.IR TIFFOpen
roentgen b75cab
opens a
roentgen b75cab
.SM TIFF
roentgen b75cab
file whose name is
roentgen b75cab
.I filename
roentgen b75cab
and returns a handle to be used in subsequent calls to routines in
roentgen b75cab
.IR libtiff .
roentgen b75cab
If the open operation fails, then zero is returned.
roentgen b75cab
The
roentgen b75cab
.I mode
roentgen b75cab
parameter specifies if the file is to be opened for reading (``r''),
roentgen b75cab
writing (``w''), or appending (``a'') and, optionally, whether
roentgen b75cab
to override certain default aspects of library operation (see below).
roentgen b75cab
When a file is opened for appending, existing data will not
roentgen b75cab
be touched; instead new data will be written as additional subfiles.
roentgen b75cab
If an existing file is opened for writing, all previous data is
roentgen b75cab
overwritten.
roentgen b75cab
.PP
roentgen b75cab
If a file is opened for reading, the first
roentgen b75cab
.SM TIFF
roentgen b75cab
directory in the file is automatically read
roentgen b75cab
(also see
roentgen b75cab
.IR TIFFSetDirectory (3TIFF)
roentgen b75cab
for reading directories other than the first).
roentgen b75cab
If a file is opened for writing or appending, a default directory
roentgen b75cab
is automatically created for writing subsequent data.
roentgen b75cab
This directory has all the default values specified in
roentgen b75cab
.SM TIFF
roentgen b75cab
Revision 6.0:
roentgen b75cab
.IR BitsPerSample =1,
roentgen b75cab
.IR ThreshHolding "=bilevel art scan,"
roentgen b75cab
.IR FillOrder =1
roentgen b75cab
(most significant bit of each data byte is filled first),
roentgen b75cab
.IR Orientation =1
roentgen b75cab
(the 0th row represents the visual top of the image, and the 0th
roentgen b75cab
column represents the visual left hand side),
roentgen b75cab
.IR SamplesPerPixel =1,
roentgen b75cab
.IR RowsPerStrip =infinity,
roentgen b75cab
.IR ResolutionUnit =2
roentgen b75cab
(inches), and
roentgen b75cab
.IR Compression =1
roentgen b75cab
(no compression).
roentgen b75cab
To alter these values, or to define values for additional fields,
roentgen b75cab
.IR TIFFSetField (3TIFF)
roentgen b75cab
must be used.
roentgen b75cab
.PP
roentgen b75cab
.IR TIFFFdOpen
roentgen b75cab
is like
roentgen b75cab
.IR TIFFOpen
roentgen b75cab
except that it opens a
roentgen b75cab
.SM TIFF
roentgen b75cab
file given an open file descriptor
roentgen b75cab
.IR fd .
roentgen b75cab
The file's name and mode must reflect that of the open descriptor.
roentgen b75cab
The object associated with the file descriptor
roentgen b75cab
.BR "must support random access" .
roentgen b75cab
.PP
roentgen b75cab
.IR TIFFClientOpen
roentgen b75cab
is like
roentgen b75cab
.IR TIFFOpen
roentgen b75cab
except that the caller supplies a collection of functions that the
roentgen b75cab
library will use to do \s-1UNIX\s+1-like I/O operations. 
roentgen b75cab
The
roentgen b75cab
.I readproc
roentgen b75cab
and
roentgen b75cab
.I writeproc
roentgen b75cab
are called to read and write data at the current file position.
roentgen b75cab
.I seekproc
roentgen b75cab
is called to change the current file position a la
roentgen b75cab
.IR lseek (2).
roentgen b75cab
.I closeproc
roentgen b75cab
is invoked to release any resources associated with an open file.
roentgen b75cab
.I sizeproc
roentgen b75cab
is invoked to obtain the size in bytes of a file.
roentgen b75cab
.I mapproc
roentgen b75cab
and
roentgen b75cab
.I unmapproc
roentgen b75cab
are called to map and unmap a file's contents in memory; c.f.
roentgen b75cab
.IR mmap (2)
roentgen b75cab
and
roentgen b75cab
.IR munmap (2).
roentgen b75cab
The
roentgen b75cab
.I clientdata
roentgen b75cab
parameter is an opaque ``handle'' passed to the client-specified
roentgen b75cab
routines passed as parameters to
roentgen b75cab
.IR TIFFClientOpen .
roentgen b75cab
.SH OPTIONS
roentgen b75cab
The open mode parameter can include the following flags in
roentgen b75cab
addition to the ``r'', ``w'', and ``a'' flags.
roentgen b75cab
Note however that option flags must follow the read-write-append
roentgen b75cab
specification.
roentgen b75cab
.TP
roentgen b75cab
.B l
roentgen b75cab
When creating a new file force information be written with
roentgen b75cab
Little-Endian byte order (but see below).
roentgen b75cab
By default the library will create new files using the native
roentgen b75cab
.SM CPU
roentgen b75cab
byte order.
roentgen b75cab
.TP
roentgen b75cab
.B b
roentgen b75cab
When creating a new file force information be written with
roentgen b75cab
Big-Endian byte order (but see below).
roentgen b75cab
By default the library will create new files using the native
roentgen b75cab
.SM CPU
roentgen b75cab
byte order.
roentgen b75cab
.TP
roentgen b75cab
.B L
roentgen b75cab
Force image data that is read or written to be treated with
roentgen b75cab
bits filled from Least Significant Bit (\s-1LSB\s+1) to
roentgen b75cab
Most Significant Bit (\s-1MSB\s+1).
roentgen b75cab
Note that this is the opposite to the way the library has
roentgen b75cab
worked from its inception.
roentgen b75cab
.TP
roentgen b75cab
.B B
roentgen b75cab
Force image data that is read or written to be treated with
roentgen b75cab
bits filled from Most Significant Bit (\s-1MSB\s+1) to
roentgen b75cab
Least Significant Bit (\s-1LSB\s+1); this is the default.
roentgen b75cab
.TP
roentgen b75cab
.B H
roentgen b75cab
Force image data that is read or written to be treated with
roentgen b75cab
bits filled in the same order as the native 
roentgen b75cab
.SM CPU.
roentgen b75cab
.TP
roentgen b75cab
.B M
roentgen b75cab
Enable the use of memory-mapped files for images opened read-only.
roentgen b75cab
If the underlying system does not support memory-mapped files
roentgen b75cab
or if the specific image being opened cannot be memory-mapped
roentgen b75cab
then the library will fallback to using the normal system interface
roentgen b75cab
for reading information.
roentgen b75cab
By default the library will attempt to use memory-mapped files.
roentgen b75cab
.TP
roentgen b75cab
.B m
roentgen b75cab
Disable the use of memory-mapped files.
roentgen b75cab
.TP
roentgen b75cab
.B C
roentgen b75cab
Enable the use of ``strip chopping'' when reading images
roentgen b75cab
that are comprised of a single strip or tile of uncompressed data.
roentgen b75cab
Strip chopping is a mechanism by which the library will automatically
roentgen b75cab
convert the single-strip image to multiple strips,
roentgen b75cab
each of which has about 8 Kilobytes of data.
roentgen b75cab
This facility can be useful in reducing the amount of memory used
roentgen b75cab
to read an image because the library normally reads each strip
roentgen b75cab
in its entirety.
roentgen b75cab
Strip chopping does however alter the apparent contents of the
roentgen b75cab
image because when an image is divided into multiple strips it
roentgen b75cab
looks as though the underlying file contains multiple separate
roentgen b75cab
strips.
roentgen b75cab
Finally, note that default handling of strip chopping is a compile-time
roentgen b75cab
configuration parameter.
roentgen b75cab
The default behaviour, for backwards compatibility, is to enable
roentgen b75cab
strip chopping.
roentgen b75cab
.TP
roentgen b75cab
.B c
roentgen b75cab
Disable the use of strip chopping when reading images.
roentgen b75cab
.TP
roentgen b75cab
.B h
roentgen b75cab
Read TIFF header only, do not load the first image directory. That could be
roentgen b75cab
useful in case of the broken first directory. We can open the file and proceed
roentgen b75cab
to the other directories.
roentgen b75cab
.SH "BYTE ORDER"
roentgen b75cab
The 
roentgen b75cab
.SM TIFF
roentgen b75cab
specification (\fBall versions\fP) states that compliant readers
roentgen b75cab
.IR "must be capable of reading images written in either byte order" .
roentgen b75cab
Nonetheless some software that claims to support the reading of
roentgen b75cab
.SM TIFF
roentgen b75cab
images is incapable of reading images in anything but the native
roentgen b75cab
.SM CPU
roentgen b75cab
byte order on which the software was written.
roentgen b75cab
(Especially notorious
roentgen b75cab
are applications written to run on Intel-based machines.)
roentgen b75cab
By default the library will create new files with the native
roentgen b75cab
byte-order of the 
roentgen b75cab
.SM CPU
roentgen b75cab
on which the application is run.
roentgen b75cab
This ensures optimal performance and is portable to any application
roentgen b75cab
that conforms to the TIFF specification.
roentgen b75cab
To force the library to use a specific byte-order when creating
roentgen b75cab
a new file the ``b'' and ``l'' option flags may be included in
roentgen b75cab
the call to open a file; for example, ``wb'' or ``wl''.
roentgen b75cab
.SH "RETURN VALUES"
roentgen b75cab
Upon successful completion 
roentgen b75cab
.IR TIFFOpen ,
roentgen b75cab
.IR TIFFFdOpen ,
roentgen b75cab
and
roentgen b75cab
.IR TIFFClientOpen
roentgen b75cab
return a 
roentgen b75cab
.SM TIFF
roentgen b75cab
pointer.
roentgen b75cab
Otherwise, NULL is returned.
roentgen b75cab
.SH DIAGNOSTICS
roentgen b75cab
All error messages are directed to the
roentgen b75cab
.IR TIFFError (3TIFF)
roentgen b75cab
routine.
roentgen b75cab
Likewise, warning messages are directed to the
roentgen b75cab
.IR TIFFWarning (3TIFF)
roentgen b75cab
routine.
roentgen b75cab
.PP
roentgen b75cab
\fB"%s": Bad mode\fP.
roentgen b75cab
The specified
roentgen b75cab
.I mode
roentgen b75cab
parameter was not one of ``r'' (read), ``w'' (write), or ``a'' (append).
roentgen b75cab
.PP
roentgen b75cab
.BR "%s: Cannot open" .
roentgen b75cab
.IR TIFFOpen ()
roentgen b75cab
was unable to open the specified filename for read/writing.
roentgen b75cab
.PP
roentgen b75cab
.BR "Cannot read TIFF header" .
roentgen b75cab
An error occurred while attempting to read the header information.
roentgen b75cab
.PP
roentgen b75cab
.BR "Error writing TIFF header" .
roentgen b75cab
An error occurred while writing the default header information
roentgen b75cab
for a new file.
roentgen b75cab
.PP
roentgen b75cab
.BR "Not a TIFF file, bad magic number %d (0x%x)" .
roentgen b75cab
The magic number in the header was not (hex)
roentgen b75cab
0x4d4d or (hex) 0x4949.
roentgen b75cab
.PP
roentgen b75cab
.BR "Not a TIFF file, bad version number %d (0x%x)" .
roentgen b75cab
The version field in the header was not 42 (decimal).
roentgen b75cab
.PP
roentgen b75cab
.BR "Cannot append to file that has opposite byte ordering" .
roentgen b75cab
A file with a byte ordering opposite to the native byte
roentgen b75cab
ordering of the current machine was opened for appending (``a'').
roentgen b75cab
This is a limitation of the library.
roentgen b75cab
.SH "SEE ALSO"
roentgen b75cab
.IR libtiff (3TIFF),
roentgen b75cab
.IR TIFFClose (3TIFF)