LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
Data Structures
TIFF

TIFF image reading, writing, and multi-page support. More...

Collaboration diagram for TIFF:

Data Structures

struct  gdTiffReadOptions
 Options for reading TIFF data with the gdTiffRead*() API. More...
 
struct  gdTiffInfo
 TIFF file information from the first page and container. More...
 
struct  gdTiffPageInfo
 TIFF page information returned while reading pages. More...
 
struct  gdTiffWriteOptions
 Options for writing TIFF data with the gdTiffWrite*() API. More...
 

TIFF Constants

enum  gdTiffColorSpace { GD_TIFF_RGB = 1 , GD_TIFF_RGBA = 2 , GD_TIFF_GRAY = 3 , GD_TIFF_BILEVEL = 4 }
 TIFF writer color spaces. More...
 
enum  gdTiffCompression {
  GD_TIFF_COMPRESSION_NONE = 1 , GD_TIFF_COMPRESSION_CCITT_RLE = 2 , GD_TIFF_COMPRESSION_CCITT_FAX3 = 3 , GD_TIFF_COMPRESSION_CCITT_FAX4 = 4 ,
  GD_TIFF_COMPRESSION_LZW = 5 , GD_TIFF_COMPRESSION_JPEG = 7 , GD_TIFF_COMPRESSION_ADOBE_DEFLATE = 8 , GD_TIFF_COMPRESSION_DEFLATE = 32946 ,
  GD_TIFF_COMPRESSION_PACKBITS = 32773
}
 TIFF compression tag values. More...
 
enum  gdTiffPhotometric {
  GD_TIFF_PHOTOMETRIC_MINISWHITE = 0 , GD_TIFF_PHOTOMETRIC_MINISBLACK = 1 , GD_TIFF_PHOTOMETRIC_RGB = 2 , GD_TIFF_PHOTOMETRIC_PALETTE = 3 ,
  GD_TIFF_PHOTOMETRIC_TRANSPARENCY_MASK = 4 , GD_TIFF_PHOTOMETRIC_SEPARATED = 5 , GD_TIFF_PHOTOMETRIC_YCBCR = 6 , GD_TIFF_PHOTOMETRIC_CIELAB = 8
}
 TIFF photometric interpretation tag values. More...
 
enum  gdTiffPlanarConfig { GD_TIFF_PLANARCONFIG_CONTIG = 1 , GD_TIFF_PLANARCONFIG_SEPARATE = 2 }
 TIFF planar configuration tag values. More...
 
enum  gdTiffResolutionUnit { GD_TIFF_RESUNIT_NONE = 1 , GD_TIFF_RESUNIT_INCH = 2 , GD_TIFF_RESUNIT_CENTIMETER = 3 }
 TIFF resolution unit tag values. More...
 
enum  gdTiffAlphaType { GD_TIFF_ALPHA_UNASSOCIATED = 1 , GD_TIFF_ALPHA_ASSOCIATED = 2 }
 TIFF alpha sample types. More...
 

TIFF Reading Types

typedef struct gdTiffReadStruct * gdTiffReadPtr
 Opaque TIFF multi-page reader handle.
 

TIFF Writing Types

typedef struct gdTiffWriteStruct * gdTiffWritePtr
 Opaque TIFF writer handle.
 

TIFF Single-Image Reading

gdImagePtr gdImageCreateFromTiff (FILE *inFile)
 Create an image from a TIFF stdio file.
 
gdImagePtr gdImageCreateFromTiffCtx (gdIOCtxPtr infile)
 Create an image from TIFF data read through a gdIOCtx.
 
gdImagePtr gdImageCreateFromTiffPtr (int size, void *data)
 Create an image from a TIFF memory buffer.
 

TIFF Multi-Page Reading

int gdTiffIsMultiPage (FILE *fd)
 Test whether a TIFF stdio file has more than one page.
 
int gdTiffIsMultiPageCtx (gdIOCtxPtr in)
 Test whether TIFF data read through a seekable gdIOCtx has more than one page.
 
int gdTiffIsMultiPagePtr (int size, void *data)
 Test whether a TIFF memory buffer has more than one page.
 
void gdTiffReadOptionsInit (gdTiffReadOptions *options)
 Initialize TIFF read options with defaults.
 
gdTiffReadPtr gdTiffReadOpen (FILE *fd, const gdTiffReadOptions *options)
 Open a TIFF multi-page reader from a stdio file.
 
gdTiffReadPtr gdTiffReadOpenCtx (gdIOCtxPtr in, const gdTiffReadOptions *options)
 Open a TIFF multi-page reader from a gdIOCtx.
 
gdTiffReadPtr gdTiffReadOpenPtr (int size, void *data, const gdTiffReadOptions *options)
 Open a TIFF multi-page reader from a memory buffer.
 
void gdTiffReadClose (gdTiffReadPtr tiff)
 Close a TIFF multi-page reader.
 
int gdTiffReadGetInfo (gdTiffReadPtr tiff, gdTiffInfo *info)
 Get TIFF file information from a reader.
 
int gdTiffReadGetMetadata (gdTiffReadPtr tiff, gdImageMetadata *metadata)
 
int gdTiffReadNextImage (gdTiffReadPtr tiff, gdTiffPageInfo *info, gdImagePtr *image)
 Read the next TIFF page image.
 

TIFF Multi-Page Writing

void gdTiffWriteOptionsInit (gdTiffWriteOptions *options)
 Initialize TIFF write options with defaults.
 
gdTiffWritePtr gdTiffWriteOpen (FILE *outFile, const gdTiffWriteOptions *options)
 Open a TIFF writer for a stdio file.
 
gdTiffWritePtr gdTiffWriteOpenCtx (gdIOCtxPtr out, const gdTiffWriteOptions *options)
 Open a TIFF writer for a gdIOCtx.
 
gdTiffWritePtr gdTiffWriteOpenPtr (const gdTiffWriteOptions *options)
 Open a TIFF writer that returns a memory buffer.
 
int gdTiffWriteAddImage (gdTiffWritePtr write, gdImagePtr image)
 Add an image as the next TIFF page.
 
void gdTiffWriteClose (gdTiffWritePtr write)
 Close a file or gdIOCtx TIFF writer.
 
void * gdTiffWritePtrFinish (gdTiffWritePtr write, int *size)
 Finish a TIFF memory writer and return the encoded buffer.
 

TIFF Single-Image Writing

void gdImageTiff (gdImagePtr im, FILE *outFile)
 Write an image as TIFF data to a stdio file.
 
void * gdImageTiffPtr (gdImagePtr im, int *size)
 Write an image as TIFF data to a newly allocated memory buffer.
 
void gdImageTiffCtx (gdImagePtr image, gdIOCtxPtr out)
 Write an image as TIFF data to a gdIOCtx.
 

Detailed Description

TIFF image reading, writing, and multi-page support.

TIFF support reads single images through the gdImageCreateFromTiff*() functions and reads multi-page TIFF files through gdTiffRead*() readers. The multi-page reader returns one caller-owned gd image per page. TIFF writers can write one or more truecolor images using explicit bit-depth, colorspace, compression, alpha, and resolution options.

gdImagePtr image;
FILE *in;
in = fopen("input.tif", "rb");
if (in == NULL) {
fprintf(stderr, "cannot open input.tif\n");
exit(1);
}
reader = gdTiffReadOpen(in, NULL);
fclose(in);
if (reader == NULL) {
fprintf(stderr, "cannot read TIFF\n");
exit(1);
}
if (gdTiffReadGetInfo(reader, &info)) {
printf("pages: %d, first page: %dx%d\n",
info.pageCount, info.width, info.height);
}
while (gdTiffReadNextImage(reader, &page, &image) == 1) {
printf("page %d: %dx%d\n", page.pageIndex, page.width, page.height);
gdImageDestroy(image);
}
int gdTiffReadGetInfo(gdTiffReadPtr tiff, gdTiffInfo *info)
Get TIFF file information from a reader.
Definition gd_tiff.c:2591
struct gdTiffReadStruct * gdTiffReadPtr
Opaque TIFF multi-page reader handle.
Definition gd.h:3760
int gdTiffReadNextImage(gdTiffReadPtr tiff, gdTiffPageInfo *info, gdImagePtr *image)
Read the next TIFF page image.
Definition gd_tiff.c:2600
gdTiffReadPtr gdTiffReadOpen(FILE *fd, const gdTiffReadOptions *options)
Open a TIFF multi-page reader from a stdio file.
Definition gd_tiff.c:2560
void gdTiffReadClose(gdTiffReadPtr tiff)
Close a TIFF multi-page reader.
Definition gd_tiff.c:2585
TIFF file information from the first page and container.
Definition gd.h:3774
int height
Definition gd.h:3776
int width
Definition gd.h:3775
TIFF page information returned while reading pages.
Definition gd.h:3790
int width
Definition gd.h:3792
int height
Definition gd.h:3793

Typedef Documentation

◆ gdTiffReadPtr

typedef struct gdTiffReadStruct* gdTiffReadPtr

Opaque TIFF multi-page reader handle.

Handles returned by gdTiffReadOpen(), gdTiffReadOpenCtx(), or gdTiffReadOpenPtr() must be closed with gdTiffReadClose().

◆ gdTiffWritePtr

typedef struct gdTiffWriteStruct* gdTiffWritePtr

Opaque TIFF writer handle.

Handles returned by gdTiffWriteOpen() or gdTiffWriteOpenCtx() must be closed with gdTiffWriteClose(). Handles returned by gdTiffWriteOpenPtr() must be finished with gdTiffWritePtrFinish().

Enumeration Type Documentation

◆ gdTiffAlphaType

TIFF alpha sample types.

Enumerator
GD_TIFF_ALPHA_UNASSOCIATED 

TIFF alpha samples are unassociated with color samples.

GD_TIFF_ALPHA_ASSOCIATED 

TIFF alpha samples are premultiplied into color samples.

◆ gdTiffColorSpace

TIFF writer color spaces.

Enumerator
GD_TIFF_RGB 

Write RGB TIFF data.

GD_TIFF_RGBA 

Write RGBA TIFF data with an alpha extra sample.

GD_TIFF_GRAY 

Write grayscale TIFF data.

GD_TIFF_BILEVEL 

Write 1-bit bilevel TIFF data.

◆ gdTiffCompression

TIFF compression tag values.

Enumerator
GD_TIFF_COMPRESSION_NONE 

No TIFF compression.

GD_TIFF_COMPRESSION_CCITT_RLE 

CCITT modified Huffman run-length encoding compression.

GD_TIFF_COMPRESSION_CCITT_FAX3 

CCITT Group 3 fax compression.

GD_TIFF_COMPRESSION_CCITT_FAX4 

CCITT Group 4 fax compression.

GD_TIFF_COMPRESSION_LZW 

LZW compression.

GD_TIFF_COMPRESSION_JPEG 

JPEG compression.

GD_TIFF_COMPRESSION_ADOBE_DEFLATE 

Adobe-style Deflate compression.

GD_TIFF_COMPRESSION_DEFLATE 

Deflate compression.

GD_TIFF_COMPRESSION_PACKBITS 

PackBits compression.

◆ gdTiffPhotometric

TIFF photometric interpretation tag values.

Enumerator
GD_TIFF_PHOTOMETRIC_MINISWHITE 

White is the minimum sample value.

GD_TIFF_PHOTOMETRIC_MINISBLACK 

Black is the minimum sample value.

GD_TIFF_PHOTOMETRIC_RGB 

RGB photometric interpretation.

GD_TIFF_PHOTOMETRIC_PALETTE 

Palette color photometric interpretation.

GD_TIFF_PHOTOMETRIC_TRANSPARENCY_MASK 

Transparency mask photometric interpretation.

GD_TIFF_PHOTOMETRIC_SEPARATED 

Separated photometric interpretation.

GD_TIFF_PHOTOMETRIC_YCBCR 

YCbCr photometric interpretation.

GD_TIFF_PHOTOMETRIC_CIELAB 

CIE L*a*b* photometric interpretation.

◆ gdTiffPlanarConfig

TIFF planar configuration tag values.

Enumerator
GD_TIFF_PLANARCONFIG_CONTIG 

Store samples for each pixel contiguously.

GD_TIFF_PLANARCONFIG_SEPARATE 

Store samples in separate planes.

◆ gdTiffResolutionUnit

TIFF resolution unit tag values.

Enumerator
GD_TIFF_RESUNIT_NONE 

Resolution values have no absolute unit.

GD_TIFF_RESUNIT_INCH 

Resolution values are pixels per inch.

GD_TIFF_RESUNIT_CENTIMETER 

Resolution values are pixels per centimeter.

Function Documentation

◆ gdImageCreateFromTiff()

gdImagePtr gdImageCreateFromTiff ( FILE *  inFile)

Create an image from a TIFF stdio file.

gdImageCreateFromTiff() does not close inFile. The returned image is caller-owned and must be destroyed with gdImageDestroy.

Parameters
inFilePointer to the input FILE stream.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromTiffCtx()

gdImagePtr gdImageCreateFromTiffCtx ( gdIOCtxPtr  infile)

Create an image from TIFF data read through a gdIOCtx.

gdImageCreateFromTiffCtx() does not close infile. The returned image is caller-owned and must be destroyed with gdImageDestroy.

Parameters
infilePointer to the gdIOCtx input context.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromTiffPtr()

gdImagePtr gdImageCreateFromTiffPtr ( int  size,
void *  data 
)

Create an image from a TIFF memory buffer.

The data buffer is borrowed for the duration of the call. The returned image is caller-owned and must be destroyed with gdImageDestroy.

Parameters
sizeSize of the TIFF memory buffer in bytes.
dataPointer to the TIFF memory buffer.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageTiff()

void gdImageTiff ( gdImagePtr  im,
FILE *  outFile 
)

Write an image as TIFF data to a stdio file.

gdImageTiff() does not close outFile. The image is borrowed for the duration of the call.

Parameters
imThe image to write.
outFilePointer to the output FILE stream.

◆ gdImageTiffCtx()

void gdImageTiffCtx ( gdImagePtr  image,
gdIOCtxPtr  out 
)

Write an image as TIFF data to a gdIOCtx.

gdImageTiffCtx() does not close out. The image is borrowed for the duration of the call.

Parameters
imageThe image to write.
outPointer to the gdIOCtx output context.

◆ gdImageTiffPtr()

void * gdImageTiffPtr ( gdImagePtr  im,
int *  size 
)

Write an image as TIFF data to a newly allocated memory buffer.

The image is borrowed for the duration of the call. The returned buffer is caller-owned and must be freed with gdFree().

Parameters
imThe image to write.
sizePointer to an integer that receives the returned buffer size.
Returns
Returns a pointer to the newly allocated TIFF buffer, or NULL on failure.

◆ gdTiffIsMultiPage()

int gdTiffIsMultiPage ( FILE *  fd)

Test whether a TIFF stdio file has more than one page.

gdTiffIsMultiPage() reads from fd and attempts to restore its stream position before returning. It does not close fd.

Parameters
fdPointer to the input FILE stream.
Returns
Returns 1 for multi-page TIFF, 0 for single-page TIFF, or -1 on error.

◆ gdTiffIsMultiPageCtx()

int gdTiffIsMultiPageCtx ( gdIOCtxPtr  in)

Test whether TIFF data read through a seekable gdIOCtx has more than one page.

gdTiffIsMultiPageCtx() reads from in and attempts to restore its position before returning. It does not close in.

Parameters
inPointer to the gdIOCtx input context.
Returns
Returns 1 for multi-page TIFF, 0 for single-page TIFF, or -1 on error.

◆ gdTiffIsMultiPagePtr()

int gdTiffIsMultiPagePtr ( int  size,
void *  data 
)

Test whether a TIFF memory buffer has more than one page.

The data buffer is borrowed for the duration of the call.

Parameters
sizeSize of the TIFF memory buffer in bytes.
dataPointer to the TIFF memory buffer.
Returns
Returns 1 for multi-page TIFF, 0 for single-page TIFF, or -1 on error.

◆ gdTiffReadClose()

void gdTiffReadClose ( gdTiffReadPtr  tiff)

Close a TIFF multi-page reader.

Parameters
tiffTIFF reader handle to close, or NULL.

◆ gdTiffReadGetInfo()

int gdTiffReadGetInfo ( gdTiffReadPtr  tiff,
gdTiffInfo info 
)

Get TIFF file information from a reader.

Parameters
tiffTIFF reader handle.
infoPointer to a gdTiffInfo structure to receive file information.
Returns
Returns 1 on success, or 0 on failure.

◆ gdTiffReadGetMetadata()

int gdTiffReadGetMetadata ( gdTiffReadPtr  tiff,
gdImageMetadata *  metadata 
)

Collect opaque metadata from the first TIFF directory.

◆ gdTiffReadNextImage()

int gdTiffReadNextImage ( gdTiffReadPtr  tiff,
gdTiffPageInfo info,
gdImagePtr *  image 
)

Read the next TIFF page image.

When image is not NULL and the function returns 1, *image receives a caller-owned gd image that must be destroyed with gdImageDestroy. Passing NULL for image advances the reader without returning the decoded image.

Parameters
tiffTIFF reader handle.
infoPointer to a gdTiffPageInfo structure to receive page information, or NULL.
imagePointer to receive the caller-owned page image, or NULL.
Returns
Returns 1 when a page is read, 0 at end of file, or -1 on error.

◆ gdTiffReadOpen()

gdTiffReadPtr gdTiffReadOpen ( FILE *  fd,
const gdTiffReadOptions options 
)

Open a TIFF multi-page reader from a stdio file.

gdTiffReadOpen() reads the TIFF data into the reader and does not close fd. The returned handle must be closed with gdTiffReadClose().

Parameters
fdPointer to the input FILE stream.
optionsPointer to read options, or NULL for defaults.
Returns
Returns a TIFF reader handle on success, or NULL on failure.

◆ gdTiffReadOpenCtx()

gdTiffReadPtr gdTiffReadOpenCtx ( gdIOCtxPtr  in,
const gdTiffReadOptions options 
)

Open a TIFF multi-page reader from a gdIOCtx.

gdTiffReadOpenCtx() reads the TIFF data into the reader and does not close in. The returned handle must be closed with gdTiffReadClose().

Parameters
inPointer to the gdIOCtx input context.
optionsPointer to read options, or NULL for defaults.
Returns
Returns a TIFF reader handle on success, or NULL on failure.

◆ gdTiffReadOpenPtr()

gdTiffReadPtr gdTiffReadOpenPtr ( int  size,
void *  data,
const gdTiffReadOptions options 
)

Open a TIFF multi-page reader from a memory buffer.

The data buffer is borrowed for the duration of the call. The returned reader owns its copy of the TIFF data and must be closed with gdTiffReadClose().

Parameters
sizeSize of the TIFF memory buffer in bytes.
dataPointer to the TIFF memory buffer.
optionsPointer to read options, or NULL for defaults.
Returns
Returns a TIFF reader handle on success, or NULL on failure.

◆ gdTiffReadOptionsInit()

void gdTiffReadOptionsInit ( gdTiffReadOptions options)

Initialize TIFF read options with defaults.

Parameters
optionsPointer to the options structure to initialize.

◆ gdTiffWriteAddImage()

int gdTiffWriteAddImage ( gdTiffWritePtr  write,
gdImagePtr  image 
)

Add an image as the next TIFF page.

The image is borrowed for the duration of the call and remains owned by the caller. This writer API accepts truecolor images only.

Parameters
writeTIFF writer handle.
imageImage to add as the next page.
Returns
Returns 1 on success, or 0 on failure.

◆ gdTiffWriteClose()

void gdTiffWriteClose ( gdTiffWritePtr  write)

Close a file or gdIOCtx TIFF writer.

Use this for handles returned by gdTiffWriteOpen() or gdTiffWriteOpenCtx(). For memory writers returned by gdTiffWriteOpenPtr(), use gdTiffWritePtrFinish().

Parameters
writeTIFF writer handle to close, or NULL.

◆ gdTiffWriteOpen()

gdTiffWritePtr gdTiffWriteOpen ( FILE *  outFile,
const gdTiffWriteOptions options 
)

Open a TIFF writer for a stdio file.

gdTiffWriteOpen() does not close outFile. The returned handle must be closed with gdTiffWriteClose().

Parameters
outFilePointer to the output FILE stream.
optionsPointer to write options, or NULL for defaults.
Returns
Returns a TIFF writer handle on success, or NULL on failure.

◆ gdTiffWriteOpenCtx()

gdTiffWritePtr gdTiffWriteOpenCtx ( gdIOCtxPtr  out,
const gdTiffWriteOptions options 
)

Open a TIFF writer for a gdIOCtx.

The output context is borrowed and is not closed by gdTiffWriteClose(). The returned handle must be closed with gdTiffWriteClose().

Parameters
outPointer to the gdIOCtx output context.
optionsPointer to write options, or NULL for defaults.
Returns
Returns a TIFF writer handle on success, or NULL on failure.

◆ gdTiffWriteOpenPtr()

gdTiffWritePtr gdTiffWriteOpenPtr ( const gdTiffWriteOptions options)

Open a TIFF writer that returns a memory buffer.

The returned handle must be finished with gdTiffWritePtrFinish().

Parameters
optionsPointer to write options, or NULL for defaults.
Returns
Returns a TIFF memory writer handle on success, or NULL on failure.

◆ gdTiffWriteOptionsInit()

void gdTiffWriteOptionsInit ( gdTiffWriteOptions options)

Initialize TIFF write options with defaults.

Parameters
optionsPointer to the options structure to initialize.

◆ gdTiffWritePtrFinish()

void * gdTiffWritePtrFinish ( gdTiffWritePtr  write,
int *  size 
)

Finish a TIFF memory writer and return the encoded buffer.

This closes write whether encoding succeeds or fails. The returned buffer is caller-owned and must be freed with gdFree().

Parameters
writeTIFF memory writer handle returned by gdTiffWriteOpenPtr().
sizePointer to an integer that receives the returned buffer size.
Returns
Returns a pointer to the newly allocated TIFF buffer, or NULL on failure.