TIFFWRITEDIRECTORY(3tiff)
β¨ TIFFWRITEDIRECTORY β¨
okay bestie, gather round, because this one is from the LibTIFF manual (section 3tiff) and it's all about writing the current directory in an open TIFF file. yes it's giving Very Serious File Format Business and yes I'm obsessed π
π NAME π
TIFFWriteDirectory β write the current directory in an open TIFF file
πΈ SYNOPSIS πΈ
#include <tiffio.h>
int TIFFWriteDirectory(TIFF *tif)
int TIFFRewriteDirectory(TIFF *tif)
int TIFFCheckpointDirectory(TIFF *tif)
void TIFFSetWriteOffset(TIFF *tif, toff_t off)
int TIFFWriteCheck(TIFF *tif, int tiles, const char *module)
π¦ DESCRIPTION π¦
π
the main character: TIFFWriteDirectory()
TIFFWriteDirectory() writes the contents of the current directory (the IFD, bestie) to the file, and sets things up to create a new directory (IFD) using TIFFCreateDirectory().
here's the tea: apps only actually need to call TIFFWriteDirectory() when they're writing multiple subfiles (aka images) into a single TIFF file. that whole situation is called "multi-page TIFF" or "multi-image TIFF" (see Multi Page / Multi Image TIFF).
and also, like, TIFFWriteDirectory() gets called automatically by TIFFClose() and TIFFFlush() to write a modified directory, but only if the file is open for writing. so she's self-sufficient, we love that for her π
π₯ TIFFRewriteDirectory() β the glow-up version
TIFFRewriteDirectory() works similarly to TIFFWriteDirectory(), BUT it can be called with directories that were previously read or written and that already have an established location in the file.
she rewrites the directory, but instead of putting it back at its old location (which is what TIFFWriteDirectory() would do, if the size of the directory hasn't grown), she places it at the end of the file β and then corrects the pointer from the preceding directory or file header so it points to her new location.
this matters a lot when the size of the directory and the data it points to has grown, because then it won't fit in the space available at the old location. no cap. π«Ά
π TIFFCheckpointDirectory() β the lil save point
TIFFCheckpointDirectory() writes the current state of the tiff directory into the file, so that whatever is currently in the file is readable.
unlike TIFFWriteDirectory(), she does not free up the directory data structures in memory β which means they can be updated (as strips/tiles get written) and then written again.
so like, if you read such a partial file, the worst case is that you get a tiff read error for the first strip/tile you hit that's incomplete. but at least you get all the valid data in the file that came before it, so honestly? not the worst deal.
when the file is complete, just use TIFFWriteDirectory() as usual to finish it off cleanly. periodt.
π§ TIFFSetWriteOffset()
TIFFSetWriteOffset() sets the current write offset for image data (i.e. pixels). the offset for writing the directory (IFD) data is not affected.
β οΈ this should only be used to set the offset to a known previous location (very carefully), or to 0 so that the next write gets appended to the end of the file. tread lightly bestie, this is not a vibes-only function.
β TIFFWriteCheck()
TIFFWriteCheck() verifies the file is writable and that the directory information is set up properly. and in doing the latter, we also "freeze" the state of the directory so that important information doesn't get changed. locked in fr fr π
π RETURN VALUES π
1β returned when the contents are successfully written to the file π0β returned if an error was encountered when writing the directory contents π
π DIAGNOSTICS π
all error messages are directed to the TIFFErrorExtR() routine. here's the whole roster, no skips:
- "Error post-encoding before directory write" β before writing the contents of the current directory, any pending data are flushed. this message indicates that an error occurred while doing this.
- "Error flushing data before directory write" β before writing the contents of the current directory, any pending data are flushed. this message indicates that an error occurred while doing this.
- "Cannot write directory, out of space" β there was not enough space to allocate a temporary area for the directory that was to be written.
- "Error writing directory count" β a write error occurred when writing the count of fields in the directory.
- "Error writing directory contents" β a write error occurred when writing the directory fields.
- "Error writing directory link" β a write error occurred when writing the link to the next directory.
- Error writing data for field "%s" β a write error occurred when writing indirect data for the specified field.
- "Error writing TIFF header" β a write error occurred when re-writing the header at the front of the file.
- "Error fetching directory count" β a read error occurred when fetching the directory count field for a previous directory. this can occur when setting up a link to the directory that is being written.
- "Error fetching directory link" β a read error occurred when fetching the directory link field for a previous directory. this can occur when setting up a link to the directory that is being written.
π SEE ALSO π
TIFFquery(3tiff)TIFFOpen(3tiff)TIFFCreateDirectory(3tiff)TIFFCustomDirectory(3tiff)TIFFSetDirectory(3tiff)TIFFReadDirectory(3tiff)TIFFError(3tiff)- Multi Page / Multi Image TIFF
libtiff(3tiff)
π AUTHOR π
LibTIFF contributors (the collective, the icons, the group chat admins)
π COPYRIGHT π
1988-2025, LibTIFF contributors
and that's the whole page bestie!! π this was LibTIFF version 4.7, dated Jun 27, 2026 β so go forth, write your directories, freeze your state, and remember: TIFFWriteDirectory() said "multi-page TIFF rights" π
β¨π¦
π¦ 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