![]() |
Leptonica 1.85.0
Image processing and image analysis suite
|
#include <string.h>#include <math.h>#include <sys/types.h>#include <unistd.h>#include <fcntl.h>#include "allheaders.h"#include "tiff.h"#include "tiffio.h"Go to the source code of this file.
Data Structures | |
| struct | tiff_transform |
| struct | L_Memstream |
Typedefs | |
| typedef struct L_Memstream | L_MEMSTREAM |
Functions | |
| static PIX * | pixReadFromTiffStream (TIFF *tif) |
| static l_int32 | getTiffStreamResolution (TIFF *tif, l_int32 *pxres, l_int32 *pyres) |
| static l_int32 | tiffReadHeaderTiff (TIFF *tif, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat) |
| static l_int32 | writeCustomTiffTags (TIFF *tif, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes) |
| static l_int32 | pixWriteToTiffStream (TIFF *tif, PIX *pix, l_int32 comptype, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes) |
| static TIFF * | fopenTiff (FILE *fp, const char *modestring) |
| static TIFF * | openTiff (const char *filename, const char *modestring) |
| static l_int32 | getTiffCompressedFormat (l_uint16 tiffcomp) |
| static TIFF * | fopenTiffMemstream (const char *filename, const char *operation, l_uint8 **pdata, size_t *pdatasize) |
| static tsize_t | lept_read_proc (thandle_t cookie, tdata_t buff, tsize_t size) |
| static tsize_t | lept_write_proc (thandle_t cookie, tdata_t buff, tsize_t size) |
| static toff_t | lept_seek_proc (thandle_t cookie, toff_t offs, int whence) |
| static int | lept_close_proc (thandle_t cookie) |
| static toff_t | lept_size_proc (thandle_t cookie) |
| PIX * | pixReadTiff (const char *filename, l_int32 n) |
| PIX * | pixReadStreamTiff (FILE *fp, l_int32 n) |
| l_ok | pixWriteTiff (const char *filename, PIX *pix, l_int32 comptype, const char *modestr) |
| l_ok | pixWriteTiffCustom (const char *filename, PIX *pix, l_int32 comptype, const char *modestr, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes) |
| l_ok | pixWriteStreamTiff (FILE *fp, PIX *pix, l_int32 comptype) |
| l_ok | pixWriteStreamTiffWA (FILE *fp, PIX *pix, l_int32 comptype, const char *modestr) |
| PIX * | pixReadFromMultipageTiff (const char *fname, size_t *poffset) |
| PIXA * | pixaReadMultipageTiff (const char *filename) |
| l_ok | pixaWriteMultipageTiff (const char *fname, PIXA *pixa) |
| l_ok | writeMultipageTiff (const char *dirin, const char *substr, const char *fileout) |
| l_ok | writeMultipageTiffSA (SARRAY *sa, const char *fileout) |
| l_ok | fprintTiffInfo (FILE *fpout, const char *tiffile) |
| l_ok | tiffGetCount (FILE *fp, l_int32 *pn) |
| l_ok | getTiffResolution (FILE *fp, l_int32 *pxres, l_int32 *pyres) |
| l_ok | readHeaderTiff (const char *filename, l_int32 n, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat) |
| l_ok | freadHeaderTiff (FILE *fp, l_int32 n, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat) |
| l_ok | readHeaderMemTiff (const l_uint8 *cdata, size_t size, l_int32 n, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *pres, l_int32 *pcmap, l_int32 *pformat) |
| l_ok | findTiffCompression (FILE *fp, l_int32 *pcomptype) |
| l_ok | extractG4DataFromFile (const char *filein, l_uint8 **pdata, size_t *pnbytes, l_int32 *pw, l_int32 *ph, l_int32 *pminisblack) |
| static L_MEMSTREAM * | memstreamCreateForRead (l_uint8 *indata, size_t pinsize) |
| static L_MEMSTREAM * | memstreamCreateForWrite (l_uint8 **poutdata, size_t *poutsize) |
| static tsize_t | tiffReadCallback (thandle_t handle, tdata_t data, tsize_t length) |
| static tsize_t | tiffWriteCallback (thandle_t handle, tdata_t data, tsize_t length) |
| static toff_t | tiffSeekCallback (thandle_t handle, toff_t offset, l_int32 whence) |
| static l_int32 | tiffCloseCallback (thandle_t handle) |
| static toff_t | tiffSizeCallback (thandle_t handle) |
| static l_int32 | tiffMapCallback (thandle_t handle, tdata_t *data, toff_t *length) |
| static void | tiffUnmapCallback (thandle_t handle, tdata_t data, toff_t length) |
| PIX * | pixReadMemTiff (const l_uint8 *cdata, size_t size, l_int32 n) |
| PIX * | pixReadMemFromMultipageTiff (const l_uint8 *cdata, size_t size, size_t *poffset) |
| PIXA * | pixaReadMemMultipageTiff (const l_uint8 *data, size_t size) |
| l_ok | pixaWriteMemMultipageTiff (l_uint8 **pdata, size_t *psize, PIXA *pixa) |
| l_ok | pixWriteMemTiff (l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 comptype) |
| l_ok | pixWriteMemTiffCustom (l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 comptype, NUMA *natags, SARRAY *savals, SARRAY *satypes, NUMA *nasizes) |
Variables | |
| static const l_int32 | DefaultResolution = 300 |
| static const l_int32 | ManyPagesInTiffFile = 3000 |
| static const l_int32 | MaxTiffWidth = 1 << 20 |
| static const l_int32 | MaxTiffHeight = 1 << 20 |
| static const size_t | MaxNumTiffBytes = (1 << 28) - 1 |
| static struct tiff_transform | tiff_orientation_transforms [] |
| static struct tiff_transform | tiff_partial_orientation_transforms [] |
TIFFClientOpen() wrappers for FILE*:
static tsize_t lept_read_proc()
static tsize_t lept_write_proc()
static toff_t lept_seek_proc()
static int lept_close_proc()
static toff_t lept_size_proc()
Reading tiff:
PIX *pixReadTiff() [ special top level ]
PIX *pixReadStreamTiff()
static PIX *pixReadFromTiffStream()
Writing tiff:
l_int32 pixWriteTiff() [ special top level ]
l_int32 pixWriteTiffCustom() [ special top level ]
l_int32 pixWriteStreamTiff()
l_int32 pixWriteStreamTiffWA()
static l_int32 pixWriteToTiffStream()
static l_int32 writeCustomTiffTags()
Reading and writing multipage tiff
PIX *pixReadFromMultipageTiff()
PIXA *pixaReadMultipageTiff() [ special top level ]
l_int32 pixaWriteMultipageTiff() [ special top level ]
l_int32 writeMultipageTiff() [ special top level ]
l_int32 writeMultipageTiffSA()
Information about tiff file
l_int32 fprintTiffInfo()
l_int32 tiffGetCount()
l_int32 getTiffResolution()
static l_int32 getTiffStreamResolution()
l_int32 readHeaderTiff()
l_int32 freadHeaderTiff()
l_int32 readHeaderMemTiff()
static l_int32 tiffReadHeaderTiff()
l_int32 findTiffCompression()
static l_int32 getTiffCompressedFormat()
Extraction of tiff g4 data:
l_int32 extractG4DataFromFile()
Open tiff stream from file stream
static TIFF *fopenTiff()
Wrapper for TIFFOpen:
static TIFF *openTiff()
Memory I/O: reading memory --> pix and writing pix --> memory
Ten static low-level memstream functions
static L_MEMSTREAM *memstreamCreateForRead()
static L_MEMSTREAM *memstreamCreateForWrite()
static tsize_t tiffReadCallback()
static tsize_t tiffWriteCallback()
static toff_t tiffSeekCallback()
static l_int32 tiffCloseCallback()
static toff_t tiffSizeCallback()
static l_int32 tiffMapCallback()
static void tiffUnmapCallback()
static TIFF *fopenTiffMemstream()
PIX *pixReadMemTiff();
PIX *pixReadMemFromMultipageTiff();
PIXA *pixaReadMemMultipageTiff() [ special top level ]
l_int32 pixaWriteMemMultipageTiff() [ special top level ]
l_int32 pixWriteMemTiff();
l_int32 pixWriteMemTiffCustom();
Note 1: To include all necessary functions, use libtiff version 3.7.4
(from 2005) or later.
Note 2: What compression methods in tiff are supported?
* We support most methods that are fully implemented in the
tiff library, such as G3, G4, RLE and LZW.
* The exception is the old-style jpeg tiff format (OJPEG), which
is not supported.
* We support two formats requiring external libraries: ZIP and JPEG
All computers should have the zip library.
* At present we do not support WEBP in tiff, which uses
libwebp and was added in tifflib 4.1.0 in 2019.
Note 3: We set the pad bits to 0 before writing in pixWriteToTiffStream().
Although they don't affect the raster image after decompression,
it is sometimes convenient to use a golden file with a
byte-by-byte check to verify invariance. The issue came up
on Windows for 2 and 4 bpp images.
Definition in file tiffio.c.
| typedef struct L_Memstream L_MEMSTREAM |
| l_ok extractG4DataFromFile | ( | const char * | filein, |
| l_uint8 ** | pdata, | ||
| size_t * | pnbytes, | ||
| l_int32 * | pw, | ||
| l_int32 * | ph, | ||
| l_int32 * | pminisblack ) |
| [in] | filein | |
| [out] | pdata | binary data of ccitt g4 encoded stream |
| [out] | pnbytes | size of binary data |
| [out] | pw | [optional] image width |
| [out] | ph | [optional] image height |
| [out] | pminisblack | [optional] boolean |
Definition at line 2115 of file tiffio.c.
References openTiff().
| l_ok findTiffCompression | ( | FILE * | fp, |
| l_int32 * | pcomptype ) |
| [in] | fp | file stream; must be rewound to BOF |
| [out] | pcomptype | compression type |
Notes:
(1) The returned compression type is that defined in
the enum in imageio.h. It is not the tiff flag value.
(2) The compression type is initialized to IFF_UNKNOWN.
If it is not one of the specified types, the returned
type is IFF_TIFF, which indicates no compression.
(3) When this function is called, the stream must be at BOF.
If the opened stream is to be used again to read the
file, it must be rewound to BOF after calling this function.
Definition at line 2029 of file tiffio.c.
References fopenTiff(), and getTiffCompressedFormat().
|
static |
| [in] | fp | file stream |
| [in] | modestring | "r", "w", ... |
Notes:
(1) Why is this here? Leffler did not provide a function that
takes a stream and gives a TIFF. He only gave one that
generates a TIFF starting with a file descriptor. So we
need to make it here, because it is useful to have functions
that take a stream as input.
(2) We use TIFFClientOpen() together with a set of static wrapper
functions which map TIFF read, write, seek, close and size.
to functions expecting a cookie of type stream (i.e. FILE *).
This implementation was contributed by Jürgen Buchmüller.
Definition at line 2240 of file tiffio.c.
Referenced by findTiffCompression(), freadHeaderTiff(), getTiffResolution(), pixaReadMultipageTiff(), pixReadStreamTiff(), pixWriteStreamTiffWA(), and tiffGetCount().
|
static |
| [in] | filename | for error output; can be "" |
| [in] | operation | "w" for write, "r" for read |
| [out] | pdata | written data |
| [out] | pdatasize | size of written data |
Notes:
(1) This wraps up a number of callbacks for either:
* reading from tiff in memory buffer --> pix
* writing from pix --> tiff in memory buffer
(2) After use, the memstream is automatically destroyed when
TIFFClose() is called. TIFFCleanup() doesn't free the memstream.
(3) This does not work in append mode, and in write mode it
does not append.
Definition at line 2542 of file tiffio.c.
Referenced by pixReadMemFromMultipageTiff(), pixReadMemTiff(), pixWriteMemTiffCustom(), and readHeaderMemTiff().
| l_ok fprintTiffInfo | ( | FILE * | fpout, |
| const char * | tiffile ) |
| [in] | fpout | stream for output of tag data |
| [in] | tiffile | input |
Definition at line 1606 of file tiffio.c.
References openTiff().
| l_ok freadHeaderTiff | ( | FILE * | fp, |
| l_int32 | n, | ||
| l_int32 * | pw, | ||
| l_int32 * | ph, | ||
| l_int32 * | pbps, | ||
| l_int32 * | pspp, | ||
| l_int32 * | pres, | ||
| l_int32 * | pcmap, | ||
| l_int32 * | pformat ) |
| [in] | fp | file stream |
| [in] | n | page image number: 0-based |
| [out] | pw | [optional] width |
| [out] | ph | [optional] height |
| [out] | pbps | [optional] bits per sample – 1, 2, 4 or 8 |
| [out] | pspp | [optional] samples per pixel – 1 or 3 |
| [out] | pres | [optional] resolution in x dir; NULL to ignore |
| [out] | pcmap | [optional] colormap exists; input NULL to ignore |
| [out] | pformat | [optional] tiff format; input NULL to ignore |
Notes:
(1) If there is a colormap, cmap is returned as 1; else 0.
(2) If n is equal to or greater than the number of images, returns 1.
Definition at line 1835 of file tiffio.c.
References fopenTiff(), and tiffReadHeaderTiff().
Referenced by readHeaderTiff().
|
static |
| [in] | tiffcomp | defined in tiff.h |
Notes:
(1) The input must be the actual tiff compression type
returned by a tiff library call. It should always be
a valid tiff type.
(2) The return type is defined in the enum in imageio.h.
Definition at line 2065 of file tiffio.c.
Referenced by findTiffCompression(), pixReadFromTiffStream(), and tiffReadHeaderTiff().
| l_ok getTiffResolution | ( | FILE * | fp, |
| l_int32 * | pxres, | ||
| l_int32 * | pyres ) |
| [in] | fp | file stream opened for read |
| [out] | pxres,pyres | resolution in ppi |
Notes:
(1) If neither resolution field is set, this is not an error;
the returned resolution values are 0 (designating 'unknown').
Definition at line 1683 of file tiffio.c.
References fopenTiff(), and getTiffStreamResolution().
|
static |
| [in] | tif | TIFF handle opened for read |
| [out] | pxres,pyres | resolution in ppi |
Notes:
(1) If neither resolution field is set, this is not an error;
the returned resolution values are 0 (designating 'unknown').
Definition at line 1717 of file tiffio.c.
Referenced by getTiffResolution(), pixReadFromTiffStream(), and tiffReadHeaderTiff().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| [in] | filename | |
| [in] | modestring | "r", "w", ... |
Notes:
(1) This handles multi-platform file naming.
Definition at line 2274 of file tiffio.c.
Referenced by extractG4DataFromFile(), fprintTiffInfo(), pixReadFromMultipageTiff(), and pixWriteTiffCustom().
| PIXA * pixaReadMemMultipageTiff | ( | const l_uint8 * | data, |
| size_t | size ) |
| [in] | data | const; multiple pages; tiff-encoded |
| [in] | size | size of cdata |
Notes:
(1) This is an O(n) read-from-memory version of pixaReadMultipageTiff().
Definition at line 2720 of file tiffio.c.
References L_INSERT, and pixReadMemFromMultipageTiff().
| PIXA * pixaReadMultipageTiff | ( | const char * | filename | ) |
| [in] | filename | input tiff file |
Definition at line 1408 of file tiffio.c.
References fopenTiff(), L_INSERT, pixReadFromTiffStream(), and tiffGetCount().
| l_ok pixaWriteMemMultipageTiff | ( | l_uint8 ** | pdata, |
| size_t * | psize, | ||
| PIXA * | pixa ) |
| [out] | pdata | const; tiff-encoded |
| [out] | psize | size of data |
| [in] | pixa | any depth; colormap will be removed |
Notes:
(1) fopenTiffMemstream() does not work in append mode, so we
must work-around with a temporary file.
(2) Getting a file stream from
open_memstream((char **)pdata, psize)
does not work with the tiff directory.
Definition at line 2758 of file tiffio.c.
References L_CLONE, and pixWriteStreamTiffWA().
| l_ok pixaWriteMultipageTiff | ( | const char * | fname, |
| PIXA * | pixa ) |
| [in] | fname | input tiff file |
| [in] | pixa | any depth; colormap will be removed |
Notes:
(1) The tiff directory overhead is O(n^2). I have not been
able to reduce it to O(n). The overhead for n = 2000 is
about 1 second.
Definition at line 1469 of file tiffio.c.
References L_CLONE, and pixWriteTiff().
| PIX * pixReadFromMultipageTiff | ( | const char * | fname, |
| size_t * | poffset ) |
| [in] | fname | filename |
| [in,out] | poffset | set offset to 0 for first image |
Notes:
(1) This allows overhead for traversal of a multipage tiff file
to be linear in the number of images. This will also work
with a singlepage tiff file.
(2) No TIFF internal data structures are exposed to the caller
(thanks to Jeff Breidenbach).
(3) offset is the byte offset of a particular image in a multipage
tiff file. To get the first image in the file, input the
special offset value of 0.
(4) The offset is updated to point to the next image, for a
subsequent call.
(5) On the last image, the offset returned is 0. Exit the loop
when the returned offset is 0.
(6) For reading a multipage tiff from a memory buffer, see
pixReadMemFromMultipageTiff()
(7) Example usage for reading all the images in the tif file:
size_t offset = 0;
do {
Pix *pix = pixReadFromMultipageTiff(filename, &offset);
// do something with pix
} while (offset != 0);
Definition at line 1361 of file tiffio.c.
References openTiff(), and pixReadFromTiffStream().
|
static |
| [in] | tif | TIFF handle |
Notes:
(1) We can read the following images (up to 32 bits/pixel):
1 spp (grayscale): 1, 2, 4, 8, 16 bps
1 spp (colormapped): 1, 2, 4, 8 bps
2 spp (gray+alpha): 8 bps
3 spp (rgb) and 4 spp (rgba): 8 or 16 bps
Note that 16 bps rgb and rgba are converted to 8 bps in the pix.
(2) In particular, we do not support
16 bps for spp == 2
4 bps for spp == 3 or spp == 4.
(3) We only support uint image data.
(4) We do not support tiled format, old-style jpeg encoding,
or webp encoded tiff.
(5) 2 bpp gray+alpha are rasterized as 32 bit/pixel rgba, with
the gray value replicated in r, g and b.
(6) For colormapped images, we support 8 bits/color in the palette.
Tiff colormaps have 16 bits/color, and we reduce them to 8.
(7) Quoting the libtiff documentation at
http://libtiff.maptools.org/libtiff.html
"libtiff provides a high-level interface for reading image data
from a TIFF file. This interface handles the details of data
organization and format for a wide variety of TIFF files;
at least the large majority of those files that one would
normally encounter. Image data is, by default, returned as
ABGR pixels packed into 32-bit words (8 bits per sample).
Rectangular rasters can be read or data can be intercepted
at an intermediate level and packed into memory in a format
more suitable to the application. The library handles all
the details of the format of data stored on disk and,
in most cases, if any colorspace conversions are required:
bilevel to RGB, greyscale to RGB, CMYK to RGB, YCbCr to RGB,
16-bit samples to 8-bit samples, associated/unassociated alpha,
etc."
Definition at line 498 of file tiffio.c.
References COLOR_BLUE, COLOR_GREEN, COLOR_RED, getTiffCompressedFormat(), getTiffStreamResolution(), L_ALPHA_CHANNEL, REMOVE_CMAP_BASED_ON_SRC, and SET_DATA_BYTE.
Referenced by pixaReadMultipageTiff(), pixReadFromMultipageTiff(), pixReadMemFromMultipageTiff(), pixReadMemTiff(), and pixReadStreamTiff().
| PIX * pixReadMemFromMultipageTiff | ( | const l_uint8 * | cdata, |
| size_t | size, | ||
| size_t * | poffset ) |
| [in] | cdata | const; tiff-encoded |
| [in] | size | size of cdata |
| [in,out] | poffset | set offset to 0 for first image |
Notes:
(1) This is a read-from-memory version of pixReadFromMultipageTiff().
See that function for usage.
(2) If reading sequentially from the tiff data, this is more
efficient than pixReadMemTiff(), which has an overhead
proportional to the image index n.
(3) Example usage for reading all the images:
size_t offset = 0;
do {
Pix *pix = pixReadMemFromMultipageTiff(data, size, &offset);
// do something with pix
} while (offset != 0);
Definition at line 2666 of file tiffio.c.
References fopenTiffMemstream(), and pixReadFromTiffStream().
Referenced by pixaReadMemMultipageTiff().
| PIX * pixReadMemTiff | ( | const l_uint8 * | cdata, |
| size_t | size, | ||
| l_int32 | n ) |
| [in] | cdata | const; tiff-encoded |
| [in] | size | size of cdata |
| [in] | n | page image number: 0-based |
Notes:
(1) This is a version of pixReadTiff(), where the data is read
from a memory buffer and uncompressed.
(2) Use TIFFClose(); TIFFCleanup() doesn't free internal memstream.
(3) No warning messages on failure, because of how multi-page
TIFF reading works. You are supposed to keep trying until
it stops working.
(4) Tiff directory overhead is linear in the input page number.
If reading many images, use pixReadMemFromMultipageTiff().
Definition at line 2603 of file tiffio.c.
References fopenTiffMemstream(), and pixReadFromTiffStream().
| PIX * pixReadStreamTiff | ( | FILE * | fp, |
| l_int32 | n ) |
| [in] | fp | file stream |
| [in] | n | page number: 0 based |
Notes:
(1) No warning messages on failure, because of how multi-page
TIFF reading works. You are supposed to keep trying until
it stops working.
Definition at line 430 of file tiffio.c.
References fopenTiff(), and pixReadFromTiffStream().
Referenced by pixReadTiff().
| PIX * pixReadTiff | ( | const char * | filename, |
| l_int32 | n ) |
| [in] | filename | |
| [in] | n | page number 0 based |
Notes:
(1) This is a version of pixRead(), specialized for tiff
files, that allows specification of the page to be returned
(2) No warning messages on failure, because of how multi-page
TIFF reading works. You are supposed to keep trying until
it stops working.
Definition at line 394 of file tiffio.c.
References pixReadStreamTiff().
| l_ok pixWriteMemTiff | ( | l_uint8 ** | pdata, |
| size_t * | psize, | ||
| PIX * | pix, | ||
| l_int32 | comptype ) |
| [out] | pdata | data of tiff compressed image |
| [out] | psize | size of returned data |
| [in] | pix | |
| [in] | comptype | IFF_TIFF, IFF_TIFF_RLE, IFF_TIFF_PACKBITS, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_LZW, IFF_TIFF_ZIP, IFF_TIFF_JPEG |
Usage: 1) See pixWriteTiff(. This version writes to memory instead of to a file.
Definition at line 2815 of file tiffio.c.
References pixWriteMemTiffCustom().
| l_ok pixWriteMemTiffCustom | ( | l_uint8 ** | pdata, |
| size_t * | psize, | ||
| PIX * | pix, | ||
| l_int32 | comptype, | ||
| NUMA * | natags, | ||
| SARRAY * | savals, | ||
| SARRAY * | satypes, | ||
| NUMA * | nasizes ) |
| [out] | pdata | data of tiff compressed image |
| [out] | psize | size of returned data |
| [in] | pix | |
| [in] | comptype | IFF_TIFF, IFF_TIFF_RLE, IFF_TIFF_PACKBITS, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_LZW, IFF_TIFF_ZIP, IFF_TIFF_JPEG |
| [in] | natags | [optional] NUMA of custom tiff tags |
| [in] | savals | [optional] SARRAY of values |
| [in] | satypes | [optional] SARRAY of types |
| [in] | nasizes | [optional] NUMA of sizes |
Usage: 1) See pixWriteTiffCustom(. This version writes to memory instead of to a file. 2) Use TIFFClose(); TIFFCleanup( doesn't free internal memstream.
Definition at line 2846 of file tiffio.c.
References fopenTiffMemstream(), and pixWriteToTiffStream().
Referenced by pixWriteMemTiff().
| l_ok pixWriteStreamTiff | ( | FILE * | fp, |
| PIX * | pix, | ||
| l_int32 | comptype ) |
| [in] | fp | file stream |
| [in] | pix | |
| [in] | comptype | IFF_TIFF, IFF_TIFF_RLE, IFF_TIFF_PACKBITS, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_LZW, IFF_TIFF_ZIP, IFF_TIFF_JPEG |
Notes:
(1) This writes a single image to a file stream opened for writing.
(2) If the pix has a colormap, it is preserved in the output file.
(3) For images with bpp > 1, this resets the comptype, if
necessary, to write uncompressed data.
(4) G3 and G4 are only defined for 1 bpp.
(5) We only allow PACKBITS for bpp = 1, because for bpp > 1
it typically expands images that are not synthetically generated.
(6) G4 compression is typically about twice as good as G3.
G4 is excellent for binary compression of text/line-art,
but terrible for halftones and dithered patterns. (In
fact, G4 on halftones can give a file that is larger
than uncompressed!) If a binary image has dithered
regions, it is usually better to compress with png.
Definition at line 926 of file tiffio.c.
References pixWriteStreamTiffWA().
| l_ok pixWriteStreamTiffWA | ( | FILE * | fp, |
| PIX * | pix, | ||
| l_int32 | comptype, | ||
| const char * | modestr ) |
| [in] | fp | file stream opened for append or write |
| [in] | pix | |
| [in] | comptype | IFF_TIFF, IFF_TIFF_RLE, IFF_TIFF_PACKBITS, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_LZW, IFF_TIFF_ZIP, IFF_TIFF_JPEG |
| [in] | modestr | "w" or "a" |
Notes:
(1) See pixWriteStreamTiff()
Definition at line 951 of file tiffio.c.
References fopenTiff(), and pixWriteToTiffStream().
Referenced by pixaWriteMemMultipageTiff(), and pixWriteStreamTiff().
| l_ok pixWriteTiff | ( | const char * | filename, |
| PIX * | pix, | ||
| l_int32 | comptype, | ||
| const char * | modestr ) |
| [in] | filename | to write to |
| [in] | pix | any depth, colormap will be removed |
| [in] | comptype | IFF_TIFF, IFF_TIFF_RLE, IFF_TIFF_PACKBITS, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_LZW, IFF_TIFF_ZIP, IFF_TIFF_JPEG |
| [in] | modestr | "a" or "w" |
Notes:
(1) For multipage tiff, write the first pix with mode "w" and
all subsequent pix with mode "a".
(2) For multipage tiff, there is considerable overhead in the
machinery to append an image and add the directory entry,
and the time required for each image increases linearly
with the number of images in the file.
Definition at line 812 of file tiffio.c.
References pixWriteTiffCustom().
Referenced by pixaWriteMultipageTiff(), and writeMultipageTiffSA().
| l_ok pixWriteTiffCustom | ( | const char * | filename, |
| PIX * | pix, | ||
| l_int32 | comptype, | ||
| const char * | modestr, | ||
| NUMA * | natags, | ||
| SARRAY * | savals, | ||
| SARRAY * | satypes, | ||
| NUMA * | nasizes ) |
| [in] | filename | to write to |
| [in] | pix | |
| [in] | comptype | IFF_TIFF, IFF_TIFF_RLE, IFF_TIFF_PACKBITS, IFF_TIFF_G3, IFF_TIFF_G4, IFF_TIFF_LZW, IFF_TIFF_ZIP, IFF_TIFF_JPEG |
| [in] | modestr | "a" or "w" |
| [in] | natags | [optional] NUMA of custom tiff tags |
| [in] | savals | [optional] SARRAY of values |
| [in] | satypes | [optional] SARRAY of types |
| [in] | nasizes | [optional] NUMA of sizes |
Usage: 1 This writes a page image to a tiff file, with optional extra tags defined in tiff.h 2 For multipage tiff, write the first pix with mode "w" and all subsequent pix with mode "a". 3 For the custom tiff tags: a The three arrays {natags, savals, satypes} must all be either NULL or defined and of equal size. b If they are defined, the tags are an array of integers, the vals are an array of values in string format, and the types are an array of types in string format. c All valid tags are definined in tiff.h. d The types allowed are the set of strings: "char*" "l_uint8*" "l_uint16" "l_uint32" "l_int32" "l_float64" "l_uint16-l_uint16" note the dash; use it between the two l_uint16 vals in the val string Of these, "char*" and "l_uint16" are the most commonly used. e The last array, nasizes, is also optional. It is for tags that take an array of bytes for a value, a number of elements in the array, and a type that is either "char*" or "l_uint8*" probably either will work. Use NULL if there are no such tags. f VERY IMPORTANT: if there are any tags that require the extra size value, stored in nasizes, they must be written first!
Definition at line 869 of file tiffio.c.
References openTiff(), and pixWriteToTiffStream().
Referenced by pixWriteTiff().
|
static |
| [in] | tif | data structure, opened to a file |
| [in] | pix | |
| [in] | comptype | IFF_TIFF: for any image; no compression IFF_TIFF_RLE, IFF_TIFF_PACKBITS: for 1 bpp only IFF_TIFF_G4 and IFF_TIFF_G3: for 1 bpp only IFF_TIFF_LZW, IFF_TIFF_ZIP: lossless for any image IFF_TIFF_JPEG: lossy 8 bpp gray or rgb |
| [in] | natags | [optional] NUMA of custom tiff tags |
| [in] | savals | [optional] SARRAY of values |
| [in] | satypes | [optional] SARRAY of types |
| [in] | nasizes | [optional] NUMA of sizes |
Notes:
(1) This static function should only be called through higher
level functions in this file; namely, pixWriteTiffCustom(),
pixWriteTiff(), pixWriteStreamTiff(), pixWriteMemTiff()
and pixWriteMemTiffCustom().
(2) We only allow PACKBITS for bpp = 1, because for bpp > 1
it typically expands images that are not synthetically generated.
(3) See pixWriteTiffCustom() for details on how to use
the last four parameters for customized tiff tags.
(4) The only valid pixel depths in leptonica are 1, 2, 4, 8, 16
and 32. However, it is possible, and in some cases desirable,
to write out a tiff file using an rgb pix that has 24 bpp.
This can be created by appending the raster data for a 24 bpp
image (with proper scanline padding) directly to a 24 bpp
pix that was created without a data array. See note in
pixWriteStreamPng() for an example.
Definition at line 1024 of file tiffio.c.
References COLOR_BLUE, COLOR_GREEN, COLOR_RED, GET_DATA_BYTE, L_ALPHA_CHANNEL, and writeCustomTiffTags().
Referenced by pixWriteMemTiffCustom(), pixWriteStreamTiffWA(), and pixWriteTiffCustom().
| l_ok readHeaderMemTiff | ( | const l_uint8 * | cdata, |
| size_t | size, | ||
| l_int32 | n, | ||
| l_int32 * | pw, | ||
| l_int32 * | ph, | ||
| l_int32 * | pbps, | ||
| l_int32 * | pspp, | ||
| l_int32 * | pres, | ||
| l_int32 * | pcmap, | ||
| l_int32 * | pformat ) |
| [in] | cdata | const; tiff-encoded |
| [in] | size | size of data |
| [in] | n | page image number: 0-based |
| [out] | pw | [optional] width |
| [out] | ph | [optional] height |
| [out] | pbps | [optional] bits per sample – 1, 2, 4 or 8 |
| [out] | pspp | [optional] samples per pixel – 1 or 3 |
| [out] | pres | [optional] resolution in x dir; NULL to ignore |
| [out] | pcmap | [optional] colormap exists; input NULL to ignore |
| [out] | pformat | [optional] tiff format; input NULL to ignore |
Notes:
(1) Use TIFFClose(); TIFFCleanup() doesn't free internal memstream.
(2) Returns res = 0 if not set in the file.
Definition at line 1902 of file tiffio.c.
References fopenTiffMemstream(), and tiffReadHeaderTiff().
| l_ok readHeaderTiff | ( | const char * | filename, |
| l_int32 | n, | ||
| l_int32 * | pw, | ||
| l_int32 * | ph, | ||
| l_int32 * | pbps, | ||
| l_int32 * | pspp, | ||
| l_int32 * | pres, | ||
| l_int32 * | pcmap, | ||
| l_int32 * | pformat ) |
| [in] | filename | |
| [in] | n | page image number: 0-based |
| [out] | pw | [optional] width |
| [out] | ph | [optional] height |
| [out] | pbps | [optional] bits per sample – 1, 2, 4 or 8 |
| [out] | pspp | [optional] samples per pixel – 1 or 3 |
| [out] | pres | [optional] resolution in x dir; NULL to ignore |
| [out] | pcmap | [optional] colormap exists; input NULL to ignore |
| [out] | pformat | [optional] tiff format; input NULL to ignore |
Notes:
(1) If there is a colormap, cmap is returned as 1; else 0.
(2) If n is equal to or greater than the number of images, returns 1.
Definition at line 1781 of file tiffio.c.
References freadHeaderTiff().
|
static |
| l_ok tiffGetCount | ( | FILE * | fp, |
| l_int32 * | pn ) |
| [in] | fp | file stream opened for read |
| [out] | pn | number of images |
Definition at line 1637 of file tiffio.c.
References fopenTiff().
Referenced by pixaReadMultipageTiff().
|
static |
|
static |
|
static |
| [in] | tif | |
| [out] | pw | [optional] width |
| [out] | ph | [optional] height |
| [out] | pbps | [optional] bits per sample – 1, 2, 4 or 8 |
| [out] | pspp | [optional] samples per pixel – 1 or 3 |
| [out] | pres | [optional] resolution in x dir; NULL to ignore |
| [out] | pcmap | [optional] cmap exists; input NULL to ignore |
| [out] | pformat | [optional] tiff format; input NULL to ignore |
Definition at line 1961 of file tiffio.c.
References getTiffCompressedFormat(), and getTiffStreamResolution().
Referenced by freadHeaderTiff(), and readHeaderMemTiff().
|
static |
|
static |
|
static |
|
static |
| [in] | tif | |
| [in] | natags | [optional] NUMA of custom tiff tags |
| [in] | savals | [optional] SARRAY of values |
| [in] | satypes | [optional] SARRAY of types |
| [in] | nasizes | [optional] NUMA of sizes |
Notes:
(1) This static function should be called indirectly through
higher level functions, such as pixWriteTiffCustom(),
which call pixWriteToTiffStream(). See details in
pixWriteTiffCustom() for using the 4 input arrays.
(2) This is a no-op if the first 3 arrays are all NULL.
(3) Otherwise, the first 3 arrays must be defined and all
of equal size.
(4) The fourth array is always optional.
(5) The most commonly used types are "char*" and "u_int16".
See tiff.h for a full listing of the tiff tags.
Note that many of these tags, in particular the bit tags,
are intended to be private, and cannot be set by this function.
Examples are the STRIPOFFSETS and STRIPBYTECOUNTS tags,
which are bit tags that are automatically set in the header,
and can be extracted using tiffdump.
Definition at line 1235 of file tiffio.c.
References L_NOCOPY.
Referenced by pixWriteToTiffStream().
| l_ok writeMultipageTiff | ( | const char * | dirin, |
| const char * | substr, | ||
| const char * | fileout ) |
| [in] | dirin | input directory |
| [in] | substr | [optional] substring filter on filenames; can be NULL |
| [in] | fileout | output multipage tiff file |
Notes:
(1) This writes a set of image files in a directory out
as a multipage tiff file. The images can be in any
initial file format.
(2) Images with a colormap have the colormap removed before
re-encoding as tiff.
(3) All images are encoded losslessly. Those with 1 bpp are
encoded 'g4'. The rest are encoded as 'zip' (flate encoding).
Because it is lossless, this is an expensive method for
saving most rgb images.
(4) The tiff directory overhead is quadratic in the number of
images. To avoid this for very large numbers of images to be
written, apply the method used in pixaWriteMultipageTiff().
Definition at line 1521 of file tiffio.c.
References writeMultipageTiffSA().
| l_ok writeMultipageTiffSA | ( | SARRAY * | sa, |
| const char * | fileout ) |
| [in] | sa | string array of full path names |
| [in] | fileout | output ps file |
Notes:
(1) See writeMultipageTiff()
Definition at line 1555 of file tiffio.c.
References L_NOCOPY, and pixWriteTiff().
Referenced by writeMultipageTiff().
|
static |
|
static |