Blame man/TIFFOpen.3tiff

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