TIFFOPEN(3tiff)
NAME π
okay so bestie, welcome to the TIFFOPEN(3tiff) page from LibTIFF π this one is the whole "how do I even open a TIFF file" situation, and honestly? it's giving main character energy.
TIFFOpen β open a TIFF file for reading or writing β¨
SYNOPSIS π¦
like, here's the whole friend group, no cap:
#include <tiffio.h>
TIFF *TIFFOpen(const char *filename, const char *mode)
TIFF *TIFFOpenW(const wchar_t *name, const char *mode)
TIFF *TIFFFdOpen(const int fd, const char *filename, const char *mode)
TIFF *TIFFOpenExt(const char *filename, const char *mode,
TIFFOpenOptions *opts)
TIFF *TIFFOpenWExt(const wchar_t *name, const char *mode,
TIFFOpenOptions *opts)
TIFF *TIFFFdOpenExt(const int fd, const char *filename, const char
*mode, TIFFOpenOptions *opts)
const char *TIFFSetFileName(TIFF *tif)
int TIFFSetFileno(TIFF *tif, int fd)
int TIFFSetMode(TIFF *tif, int mode)
typedef tmsize_t (*TIFFReadWriteProc)(thandle_t, void*, tmsize_t)
typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int)
typedef int (*TIFFCloseProc)(thandle_t)
typedef toff_t (*TIFFSizeProc)(thandle_t)
typedef int (*TIFFMapFileProc)(thandle_t, void **base, toff_t *size)
typedef void (*TIFFUnmapFileProc)(thandle_t, void *base, toff_t size)
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)
TIFF *TIFFClientOpenExt(const char *filename, const char *mode,
thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc
writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc
sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc,
TIFFOpenOptions *opts)
thandle_t TIFFClientdata(TIFF *tif)
thandle_t TIFFSetClientdata(TIFF *tif, thandle_t newvalue)
DESCRIPTION π
so TIFFOpen() opens a TIFF file whose name is filename and hands you back a handle you use in all the later calls to libtiff routines. if the open operation fails? you get NULL (0) back. sad. π the mode parameter is the vibe check that says whether the file is being opened for reading (r) or (r+), writing (w), or appending (a) and, optionally, whether to override certain default aspects of library operation (scroll down to Options, iykyk).
The mode r opens only an existing file for reading, and r+ is for reading and writing. when a file is opened for appending, the existing data does not get touched β instead new data gets written as additional subfiles β¨. but if an existing file is opened for writing, all previous data is overwritten. gone. poof. π
If a file is opened for reading, the first TIFF directory in the file is automatically read, no effort required, slay. if a file is opened for writing or appending, a default directory is automatically created for writing subsequent data π. this directory has all the default values specified in TIFF Revision 6.0:
BitsPerSample= 1,ThreshHolding= "bilevel art scan"FillOrder= 1 (most significant bit of each data byte is filled first)Orientation= 1 (the 0th row represents the visual top of the image, and the 0th column represents the visual left hand side),SamplesPerPixel= 1,RowsPerStrip= β,ResolutionUnit= 2 (inches), andCompression= 1 (no compression).
To alter these values, or to define values for additional fields, TIFFSetField() must be used. periodt.
TIFFOpenW() opens a TIFF file with a Unicode filename, for read/writing π.
TIFFFdOpen() is like TIFFOpen() except that it opens a TIFF file given an open file descriptor fd. the mode must reflect that of the open descriptor. the file name is used for warning and error messages. and listen β even for write-only mode, libtiff needs read permissions because some of its functions need to read back the partially written TIFF file π. the object associated with the file descriptor must support random access. and to close a TIFF file opened with TIFFFdOpen() you first call TIFFCleanup() to free the internal TIFF structure without closing the file handle, and afterwards the file should be closed using its file descriptor fd.
TIFFOpenExt() (added in libtiff 4.5) is like TIFFOpen(), but options β such as re-entrant error and warning handlers and a limit in byte that libtiff internal memory allocation functions are allowed to request per call β may be passed with the opts argument. the opts argument may be NULL. refer to TIFFOpenOptions for allocating and filling the opts argument parameters. the allocated memory for TIFFOpenOptions can be released straight after successful execution of the related "TIFFOpenExt" functions π
TIFFOpenWExt() (added in libtiff 4.5) is like TIFFOpenExt(), but opens a TIFF file with a Unicode filename πΈ
TIFFFdOpenExt() (added in libtiff 4.5) is like TIFFFdOpen(), but options argument opts like for TIFFOpenExt() can be passed.
TIFFSetFileName() sets the file name in the tif-structure and returns the old file name.
TIFFSetFileno() overwrites a copy of the open file's I/O descriptor, that was saved when the TIFF file was first opened, and returns the previous value. see the note below π
TIFFSetMode() sets the libtiff open mode in the tif-structure and returns the old mode.
TIFFClientOpen() is like TIFFOpen() except that the caller supplies a whole collection of functions that the library will use to do UNIX-like I/O operations π«Ά the readproc and writeproc functions are called to read and write data at the current file position. seekproc is called to change the current file position Γ la lseek() (2). closeproc is invoked to release any resources associated with an open file. sizeproc is invoked to obtain the size in bytes of a file. mapproc and unmapproc are called to map and unmap a file's contents in memory; c.f. mmap() (2) and munmap() (2). the clientdata parameter is an opaque "handle" passed to the client-specified routines passed as parameters to TIFFClientOpen().
NOTE π€
In contrast to the return values ofmmap()(2) andmunmap()(2), the return values ofmapprocandunmapprocmust be:TRUEfor success andFALSEto indicate an error. libtiff built in functions_tiffMapProc()and_tiffUnmapProc()can be found intif_unix.cas well as intif_win32.c.
TIFFClientOpenExt() (added in libtiff 4.5) is like TIFFClientOpen(), but options argument opts like for TIFFOpenExt() can be passed.
TIFFClientdata() returns open file's clientdata handle, which is the real open file's I/O descriptor used by libtiff π note: within tif_unix.c this handle is converted into an integer file descriptor.
TIFFSetClientdata() sets open file's clientdata, and returns the previous value. the clientdata is used as open file's I/O descriptor within libtiff.
NOTE π§
clientdatais used as file descriptor or handle of the opened TIFF file within libtif, whereas the file descriptorfd(changeable byTIFFSetFileno()) is only set once to the value ofclientdataconverted to an integer (intif_win32.cas well as intif_unix.c). when updating the file'sclientdatawithTIFFSetClientdata(), thefdvalue is not updated. bestie, it just isn't. π
OPTIONS β¨
The open mode parameter can include the following flags in addition to the r, r+, w, and a flags π note however that option flags must follow the read-write-append specification. order matters, babes.
Note 2: also for w the file will be opened with read access rights because libtiff needs to read back the partially written TIFF file for some of its functions. yeah, it's a whole thing.
lβ when creating a new file, force information be written with Little-Endian byte order (but see below). by default the library will create new files using the native CPU byte order.bβ when creating a new file, force information be written with Big-Endian byte order (but see below). by default the library will create new files using the native CPU byte order.Lβ force image data that is read or written to be treated with bits filled from Least Significant Bit (LSB) to Most Significant Bit (MSB). note that this is the opposite to the way the library has worked from its inception. iconic, honestly.Bβ force image data that is read or written to be treated with bits filled from Most Significant Bit (MSB) to Least Significant Bit (LSB); this is the default βHβ force image data that is read or written to be treated with bits filled in the same order as the native CPU.Mβ enable the use of memory-mapped files for images opened read-only. if the underlying system does not support memory-mapped files, or if the specific image being opened cannot be memory-mapped, then the library will fallback to using the normal system interface for reading information. by default the library will attempt to use memory-mapped files.mβ disable the use of memory-mapped files.Cβ enable the use of "strip chopping" when reading images that are comprised of a single strip or tile of uncompressed data. strip chopping is a mechanism by which the library will automatically convert the single-strip image to multiple strips, each of which has about 8 Kilobytes of data π this facility can be useful in reducing the amount of memory used to read an image because the library normally reads each strip in its entirety. strip chopping does however alter the apparent contents of the image because when an image is divided into multiple strips it looks as though the underlying file contains multiple separate strips π finally, note that default handling of strip chopping is a compile-time configuration parameter. the default behaviour, for backwards compatibility, is to enable strip chopping.cβ disable the use of strip chopping when reading images.hβ read TIFF header only, do not load the first image directory. that could be useful in case of the broken first directory. we can open the file and proceed to the other directories π4β ClassicTIFF for creating a file (default)8β BigTIFF for creating a file.Dβ enable use of deferred strip/tile offset/bytecount array loading. they will be loaded the first time they are accessed to. this loading will be done in its entirety unless theOflag is also specified.Oβ on-demand loading of values of the strip/tile offset/bytecount arrays, limited to the requested strip/tile, instead of whole array loading (impliesD)
π BYTE ORDER π
ok so this is the part everyone fights about π the TIFF specification β and yes, all versions of it β literally says that compliant readers "must be capable of reading images written in either byte order". Like, that's the rule, bestie. It's in the spec.
but π some software that claims it supports reading TIFF images is genuinely incapable of reading anything except images in the native CPU byte order the software was written on. and the especially notorious offenders?? applications written to run on Intel-based machines. not naming names but. we're all thinking it. π
so here's the vibe: by default, the library creates new files using the native byte-order of the CPU the app is running on. and that's actually the move β¨ it guarantees optimal performance and it's still portable to any application that conforms to the TIFF specification. slay.
but if you need to force the library into a specific byte-order when creating a new file? you can drop the b and l option flags into the call that opens the file. for example: wb or wl. that's it. that's the whole trick π
π«Ά RETURN VALUES π«Ά
upon successful completion, TIFFOpen(), TIFFFdOpen(), and TIFFClientOpen() hand you back a TIFF pointer. iconic behavior honestly.
otherwise?? NULL. no pointer. no TIFF. no nothing. π
π DIAGNOSTICS π
all error messages get routed to the TIFFErrorExtR() routine. and likewise, all warning messages go to TIFFWarningExtR(). those two are the ones holding the receipts.
here's every message, no cap:
"%s": Bad modeβ themodeparameter you specified was not one ofr(read),w(write), ora(append). pick one, bestie."%s: Cannot open"βTIFFOpen()was unable to open the specified filename for read/writing."Cannot read TIFF header"β an error went down while attempting to read the header information."Error writing TIFF header"β an error went down while writing the default header information for a new file."Not a TIFF file, bad magic number %d (0x%x)"β the magic number in the header was not (hex)0x4d4dor (hex)0x4949."Not a TIFF file, bad version number %d (0x%x)"β the version field in the header was not42(decimal)."Cannot append to file that has opposite byte ordering"β a file with a byte ordering opposite to the native byte ordering of the current machine was opened for appending (a). this one is a limitation of the library, so don't come for it, it already knows.
fr fr if you see any of these, the file is either not a TIFF, not the right version, or you're trying to append across byte orders and the library simply will not. periodt. π
π SEE ALSO π
libtiff(3tiff)TIFFClose(3tiff)TIFFStrileQuery(3tiff)TIFFOpenOptions
π AUTHOR π
LibTIFF contributors π
π COPYRIGHT π
1988-2025, LibTIFF contributors
and that's the whole page, bestie, we did it ππ¦ this was LibTIFF version 4.7, dated Jun 27, 2026 β go open some TIFFs, you absolute main character πβπ
π¦ where this page comes from
- fedora 43: libtiff-devel 4.7.2-1.fc43
- fedora 43: libtiff-devel 4.7.2-1.fc43
- fedora 43: libtiff-devel 4.7.2-3.fc43 Β· libtiff
- fedora 43: libtiff-devel 4.7.2-3.fc43 Β· libtiff
- fedora 44: libtiff-devel 4.7.2-1.fc44
- fedora 44: libtiff-devel 4.7.2-1.fc44
- fedora 44: libtiff-devel 4.7.2-3.fc44 Β· libtiff
- fedora 44: libtiff-devel 4.7.2-3.fc44 Β· libtiff
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms