TIFF image reading, writing, and multi-page support.
More...
|
| 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...
|
| |
|
| typedef struct gdTiffReadStruct * | gdTiffReadPtr |
| | Opaque TIFF multi-page reader handle.
|
| |
|
| typedef struct gdTiffWriteStruct * | gdTiffWritePtr |
| | Opaque TIFF writer handle.
|
| |
|
| 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.
|
| |
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);
}
fclose(in);
if (reader == NULL) {
fprintf(stderr, "cannot read TIFF\n");
exit(1);
}
printf("pages: %d, first page: %dx%d\n",
}
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
◆ gdTiffReadPtr
◆ gdTiffWritePtr
◆ 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.
|
◆ 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
-
| inFile | Pointer 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
-
| infile | Pointer 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
-
| size | Size of the TIFF memory buffer in bytes. |
| data | Pointer 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
-
| im | The image to write. |
| outFile | Pointer 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
-
| image | The image to write. |
| out | Pointer 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
-
| im | The image to write. |
| size | Pointer 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
-
| fd | Pointer 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
-
| in | Pointer 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
-
| size | Size of the TIFF memory buffer in bytes. |
| data | Pointer to the TIFF memory buffer. |
- Returns
- Returns 1 for multi-page TIFF, 0 for single-page TIFF, or -1 on error.
◆ gdTiffReadClose()
Close a TIFF multi-page reader.
- Parameters
-
| tiff | TIFF reader handle to close, or NULL. |
◆ gdTiffReadGetInfo()
Get TIFF file information from a reader.
- Parameters
-
| tiff | TIFF reader handle. |
| info | Pointer 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()
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
-
| tiff | TIFF reader handle. |
| info | Pointer to a gdTiffPageInfo structure to receive page information, or NULL. |
| image | Pointer 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()
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
-
| fd | Pointer to the input FILE stream. |
| options | Pointer to read options, or NULL for defaults. |
- Returns
- Returns a TIFF reader handle on success, or NULL on failure.
◆ gdTiffReadOpenCtx()
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
-
| in | Pointer to the gdIOCtx input context. |
| options | Pointer to read options, or NULL for defaults. |
- Returns
- Returns a TIFF reader handle on success, or NULL on failure.
◆ gdTiffReadOpenPtr()
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
-
| size | Size of the TIFF memory buffer in bytes. |
| data | Pointer to the TIFF memory buffer. |
| options | Pointer to read options, or NULL for defaults. |
- Returns
- Returns a TIFF reader handle on success, or NULL on failure.
◆ gdTiffReadOptionsInit()
Initialize TIFF read options with defaults.
- Parameters
-
| options | Pointer to the options structure to initialize. |
◆ gdTiffWriteAddImage()
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
-
| write | TIFF writer handle. |
| image | Image to add as the next page. |
- Returns
- Returns 1 on success, or 0 on failure.
◆ gdTiffWriteClose()
◆ gdTiffWriteOpen()
Open a TIFF writer for a stdio file.
gdTiffWriteOpen() does not close outFile. The returned handle must be closed with gdTiffWriteClose().
- Parameters
-
| outFile | Pointer to the output FILE stream. |
| options | Pointer to write options, or NULL for defaults. |
- Returns
- Returns a TIFF writer handle on success, or NULL on failure.
◆ gdTiffWriteOpenCtx()
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
-
| out | Pointer to the gdIOCtx output context. |
| options | Pointer to write options, or NULL for defaults. |
- Returns
- Returns a TIFF writer handle on success, or NULL on failure.
◆ gdTiffWriteOpenPtr()
Open a TIFF writer that returns a memory buffer.
The returned handle must be finished with gdTiffWritePtrFinish().
- Parameters
-
| options | Pointer to write options, or NULL for defaults. |
- Returns
- Returns a TIFF memory writer handle on success, or NULL on failure.
◆ gdTiffWriteOptionsInit()
Initialize TIFF write options with defaults.
- Parameters
-
| options | Pointer to the options structure to initialize. |
◆ gdTiffWritePtrFinish()
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
-
| write | TIFF memory writer handle returned by gdTiffWriteOpenPtr(). |
| size | Pointer to an integer that receives the returned buffer size. |
- Returns
- Returns a pointer to the newly allocated TIFF buffer, or NULL on failure.