Leptonica 1.68
C Image Processing Library
|
Read/write pnm format from/to file and memory. More...
Go to the source code of this file.
Functions | |
static l_int32 | pnmReadNextAsciiValue (FILE *fp, l_int32 *pval) |
static l_int32 | pnmSkipCommentLines (FILE *fp) |
PIX * | pixReadStreamPnm (FILE *fp) |
l_int32 | readHeaderPnm (const char *filename, PIX **ppix, l_int32 *pwidth, l_int32 *pheight, l_int32 *pdepth, l_int32 *ptype, l_int32 *pbps, l_int32 *pspp) |
l_int32 | freadHeaderPnm (FILE *fp, PIX **ppix, l_int32 *pwidth, l_int32 *pheight, l_int32 *pdepth, l_int32 *ptype, l_int32 *pbps, l_int32 *pspp) |
l_int32 | pixWriteStreamPnm (FILE *fp, PIX *pix) |
l_int32 | pixWriteStreamAsciiPnm (FILE *fp, PIX *pix) |
PIX * | pixReadMemPnm (const l_uint8 *cdata, size_t size) |
l_int32 | sreadHeaderPnm (const l_uint8 *cdata, size_t size, l_int32 *pwidth, l_int32 *pheight, l_int32 *pdepth, l_int32 *ptype, l_int32 *pbps, l_int32 *pspp) |
l_int32 | pixWriteMemPnm (l_uint8 **pdata, size_t *psize, PIX *pix) |
Variables | |
static const l_int32 | MAX_PNM_WIDTH = 100000 |
static const l_int32 | MAX_PNM_HEIGHT = 100000 |
Read/write pnm format from/to file and memory.
Stream interface PIX *pixReadStreamPnm() l_int32 readHeaderPnm() l_int32 freadHeaderPnm() l_int32 pixWriteStreamPnm() l_int32 pixWriteStreamAsciiPnm() Read/write to memory [not on windows] PIX *pixReadMemPnm() l_int32 sreadHeaderPnm() l_int32 pixWriteMemPnm() Local helpers static l_int32 pnmReadNextAsciiValue(); static l_int32 pnmSkipCommentLines(); These are here by popular demand, with the help of Mattias Kregert (mattias@kregert.se), who provided the first implementation. The pnm formats are exceedingly simple, because they have no compression and no colormaps. They support images that are 1 bpp; 2, 4, 8 and 16 bpp grayscale; and rgb. The original pnm formats ("ascii") are included for completeness, but their use is deprecated for all but tiny iconic images. They are extremely wasteful of memory; for example, the P1 binary ascii format is 16 times as big as the packed uncompressed format, because 2 characters are used to represent every bit (pixel) in the image. Reading is slow because we check for extra white space and EOL at every sample value. The packed pnm formats ("raw") give file sizes similar to bmp files, which are uncompressed packed. However, bmp are more flexible, because they can support colormaps. We don't differentiate between the different types ("pbm", "pgm", "ppm") at the interface level, because this is really a "distinction without a difference." You read a file, you get the appropriate Pix. You write a file from a Pix, you get the appropriate type of file. If there is a colormap on the Pix, and the Pix is more than 1 bpp, you get either an 8 bpp pgm or a 24 bpp RGB pnm, depending on whether the colormap colors are gray or rgb, respectively. This follows the general policy that the I/O routines don't make decisions about the content of the image -- you do that with image processing before you write it out to file. The I/O routines just try to make the closest connection possible between the file and the Pix in memory.
Definition in file pnmio.c.
Return: 0 if OK, 1 on error or EOF.
Notes: (1) This reads the next sample value in ascii from the the file.
Definition at line 751 of file pnmio.c.
References ERROR_INT, and PROCNAME.
Referenced by pixReadStreamPnm().
static l_int32 pnmSkipCommentLines | ( | FILE * | fp | ) | [static] |
Return: 0 if OK, 1 on error or EOF
Notes: (1) Comment lines begin with '#' (2) Usage: caller should check return value for EOF
Definition at line 784 of file pnmio.c.
References ERROR_INT, and PROCNAME.
Referenced by freadHeaderPnm().
PIX* pixReadStreamPnm | ( | FILE * | fp | ) |
Input: stream opened for read Return: pix, or null on error
Definition at line 96 of file pnmio.c.
References composeRGBPixel(), ERROR_PTR, freadHeaderPnm(), NULL, pixGetData(), pixGetWpl(), pixSetPixel(), pnmReadNextAsciiValue(), PROCNAME, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_QBIT, and SET_DATA_TWO_BYTES.
Referenced by pixReadStream().
l_int32 readHeaderPnm | ( | const char * | filename, |
PIX ** | ppix, | ||
l_int32 * | pwidth, | ||
l_int32 * | pheight, | ||
l_int32 * | pdepth, | ||
l_int32 * | ptype, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp | ||
) |
Input: filename &pix (<optional return>=""> use null to return only header data) &width (<return>) &height (<return>) &depth (<return>) &type (<return> pnm type) &bps (<optional return>="">, bits/sample) &spp (<optional return>="">, samples/pixel) Return: 0 if OK, 1 on error
Definition at line 214 of file pnmio.c.
References ERROR_INT, fopenReadStream(), freadHeaderPnm(), NULL, and PROCNAME.
Referenced by pixReadHeader().
l_int32 freadHeaderPnm | ( | FILE * | fp, |
PIX ** | ppix, | ||
l_int32 * | pwidth, | ||
l_int32 * | pheight, | ||
l_int32 * | pdepth, | ||
l_int32 * | ptype, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp | ||
) |
Input: stream opened for read &pix (<optional return>=""> use null to return only header data) &width (<return>) &height (<return>) &depth (<return>) &type (<return> pnm type) &bps (<optional return>="">, bits/sample) &spp (<optional return>="">, samples/pixel) Return: 0 if OK, 1 on error
Definition at line 254 of file pnmio.c.
References ERROR_INT, L_WARNING_INT, MAX_PNM_HEIGHT, MAX_PNM_WIDTH, NULL, pixCreate(), pnmSkipCommentLines(), and PROCNAME.
Referenced by pixReadStreamPnm(), and readHeaderPnm().
Input: stream opened for write pix Return: 0 if OK; 1 on error
Notes: (1) This writes "raw" packed format only: 1 bpp --> pbm (P4) 2, 4, 8, 16 bpp, no colormap or grayscale colormap --> pgm (P5) 2, 4, 8 bpp with color-valued colormap, or rgb --> rgb ppm (P6) (2) 24 bpp rgb are not supported in leptonica, but this will write them out as a packed array of bytes (3 to a pixel).
Definition at line 344 of file pnmio.c.
References ERROR_INT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, GET_DATA_TWO_BYTES, NULL, pixClone(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.
Referenced by pixWriteStream().
Input: stream opened for write pix Return: 0 if OK; 1 on error
Writes "ascii" format only: 1 bpp --> pbm (P1) 2, 4, 8, 16 bpp, no colormap or grayscale colormap --> pgm (P2) 2, 4, 8 bpp with color-valued colormap, or rgb --> rgb ppm (P3)
Definition at line 464 of file pnmio.c.
References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_INT, GET_DATA_BYTE, NULL, pixClone(), pixDestroy(), pixGetColormap(), pixGetDepth(), pixGetDimensions(), pixGetPixel(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.
const l_int32 MAX_PNM_WIDTH = 100000 [static] |
Definition at line 82 of file pnmio.c.
Referenced by freadHeaderPnm().
const l_int32 MAX_PNM_HEIGHT = 100000 [static] |
Definition at line 83 of file pnmio.c.
Referenced by freadHeaderPnm().