Leptonica
1.54
|
Макросы | |
#define | DEBUG_READ 0 |
#define | DEBUG_WRITE 0 |
Функции | |
PIX * | pixReadStreamPng (FILE *fp) |
l_int32 | readHeaderPng (const char *filename, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap) |
l_int32 | freadHeaderPng (FILE *fp, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap) |
l_int32 | readHeaderMemPng (const l_uint8 *data, size_t size, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap) |
l_int32 | fgetPngResolution (FILE *fp, l_int32 *pxres, l_int32 *pyres) |
l_int32 | isPngInterlaced (const char *filename, l_int32 *pinterlaced) |
l_int32 | fgetPngColormapInfo (FILE *fp, PIXCMAP **pcmap, l_int32 *ptransparency) |
l_int32 | pixWritePng (const char *filename, PIX *pix, l_float32 gamma) |
l_int32 | pixWriteStreamPng (FILE *fp, PIX *pix, l_float32 gamma) |
l_int32 | pixSetZlibCompression (PIX *pix, l_int32 compval) |
void | l_pngSetReadStrip16To8 (l_int32 flag) |
FILE * | open_memstream (char **data, size_t *size) |
FILE * | fmemopen (void *data, size_t size, const char *mode) |
PIX * | pixReadMemPng (const l_uint8 *cdata, size_t size) |
l_int32 | pixWriteMemPng (l_uint8 **pdata, size_t *psize, PIX *pix, l_float32 gamma) |
Переменные | |
static l_int32 | var_PNG_STRIP_16_TO_8 = 1 |
#define DEBUG_READ 0 |
#define DEBUG_WRITE 0 |
l_int32 fgetPngColormapInfo | ( | FILE * | fp, |
PIXCMAP ** | pcmap, | ||
l_int32 * | ptransparency | ||
) |
l_int32 fgetPngResolution | ( | FILE * | fp, |
l_int32 * | pxres, | ||
l_int32 * | pyres | ||
) |
FILE* fmemopen | ( | void * | data, |
size_t | size, | ||
const char * | mode | ||
) |
l_int32 freadHeaderPng | ( | FILE * | fp, |
l_int32 * | pw, | ||
l_int32 * | ph, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp, | ||
l_int32 * | piscmap | ||
) |
Input: stream &w (<optional return>="">) &h (<optional return>="">) &bps (<optional return>="">, bits/sample) &spp (<optional return>="">, samples/pixel) &iscmap (<optional return>="">) Return: 0 if OK, 1 on error
Notes: (1) See readHeaderPng(). We only need the first 40 bytes in the file.
l_int32 isPngInterlaced | ( | const char * | filename, |
l_int32 * | pinterlaced | ||
) |
Input: filename &interlaced (<return> 1 if interlaced png; 0 otherwise) Return: 0 if OK, 1 on error
void l_pngSetReadStrip16To8 | ( | l_int32 | flag | ) |
Input: flag (1 for stripping 16 bpp to 8 bpp on reading; 0 for leaving 16 bpp) Return: void
FILE* open_memstream | ( | char ** | data, |
size_t * | size | ||
) |
PIX* pixReadMemPng | ( | const l_uint8 * | cdata, |
size_t | size | ||
) |
Input: cdata (const; png-encoded) size (of data) Return: pix, or null on error
Notes: (1) The byte of must be a null character.
PIX* pixReadStreamPng | ( | FILE * | fp | ) |
Input: stream Return: pix, or null on error
Notes: (1) If called from pixReadStream(), the stream is positioned at the beginning of the file. (2) To do sequential reads of png format images from a stream, use pixReadStreamPng() (3) Any image with alpha is converted to RGBA (spp = 4, with equal red, green and blue channels) on reading. There are three important cases with alpha: (a) grayscale-with-alpha (spp = 2), where bpp = 8, and each pixel has an associated alpha (transparency) value in the second component of the image data. (b) spp = 1, d = 1 with colormap and alpha in the trans array. Transparency is usually associated with the white background. (c) spp = 1, d = 8 with colormap and alpha in the trans array. Each color in the colormap has a separate transparency value. (4) We use the high level png interface, where the transforms are set up in advance and the header and image are read with a single call. The more complicated interface, where the header is read first and the buffers for the raster image are user- allocated before reading the image, works for single images, but I could not get it to work properly for the successive png reads that are required by pixaReadStream().
l_int32 pixSetZlibCompression | ( | PIX * | pix, |
l_int32 | compval | ||
) |
Input: pix compval (zlib compression value) Return: 0 if OK, 1 on error
Notes: (1) Valid zlib compression values are in the interval [0 ... 9], where, as defined in zlib.h: 0 Z_NO_COMPRESSION 1 Z_BEST_SPEED (poorest compression) 9 Z_BEST_COMPRESSION For the default value, use either of these: 6 Z_DEFAULT_COMPRESSION -1 (resolves to Z_DEFAULT_COMPRESSION) (2) If you use the defined constants in zlib.h instead of the compression integers given above, you must include zlib.h.
l_int32 pixWriteMemPng | ( | l_uint8 ** | pdata, |
size_t * | psize, | ||
PIX * | pix, | ||
l_float32 | gamma | ||
) |
Input: &data (<return> data of tiff compressed image) &size (<return> size of returned data) pix gamma (use 0.0 if gamma is not defined) Return: 0 if OK, 1 on error
Notes: (1) See pixWriteStreamPng() for usage. This version writes to memory instead of to a file stream.
l_int32 pixWritePng | ( | const char * | filename, |
PIX * | pix, | ||
l_float32 | gamma | ||
) |
Input: filename pix gamma Return: 0 if OK; 1 on error
Notes: (1) Special version for writing png with a specified gamma. When using pixWrite(), no field is given for gamma.
l_int32 pixWriteStreamPng | ( | FILE * | fp, |
PIX * | pix, | ||
l_float32 | gamma | ||
) |
Input: stream pix gamma (use 0.0 if gamma is not defined) Return: 0 if OK; 1 on error
Notes: (1) If called from pixWriteStream(), the stream is positioned at the beginning of the file. (2) To do sequential writes of png format images to a stream, use pixWriteStreamPng() directly. (3) gamma is an optional png chunk. If no gamma value is to be placed into the file, use gamma = 0.0. Otherwise, if gamma > 0.0, its value is written into the header. (4) The use of gamma in png is highly problematic. For an illuminating discussion, see: http://hsivonen.iki.fi/png-gamma/ (5) What is the effect/meaning of gamma in the png file? This gamma, which we can call the 'source' gamma, is the inverse of the gamma that was used in enhance.c to brighten or darken images. The 'source' gamma is supposed to indicate the intensity mapping that was done at the time the image was captured. Display programs typically apply a 'display' gamma of 2.2 to the output, which is intended to linearize the intensity based on the response of thermionic tubes (CRTs). Flat panel LCDs have typically been designed to give a similar response as CRTs (call it "backward compatibility"). The 'display' gamma is in some sense the inverse of the 'source' gamma. jpeg encoders attached to scanners and cameras will lighten the pixels, applying a gamma corresponding to approximately a square-root relation of output vs input: output = input^(gamma) where gamma is often set near 0.4545 (1/gamma is 2.2). This is stored in the image file. Then if the display program reads the gamma, it will apply a display gamma, typically about 2.2; the product is 1.0, and the display program produces a linear output. This works because the dark colors were appropriately boosted by the scanner, as described by the 'source' gamma, so they should not be further boosted by the display program. (6) As an example, with xv and display, if no gamma is stored, the program acts as if gamma were 0.4545, multiplies this by 2.2, and does a linear rendering. Taking this as a baseline brightness, if the stored gamma is: > 0.4545, the image is rendered lighter than baseline < 0.4545, the image is rendered darker than baseline In contrast, gqview seems to ignore the gamma chunk in png. (7) 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 png file using an rgb pix that has 24 bpp. For example, the open source xpdf SplashBitmap class generates 24 bpp rgb images. Consequently, we enable writing 24 bpp pix. To generate such a pix, you can make a 24 bpp pix without data and assign the data array to the pix; e.g., pix = pixCreateHeader(w, h, 24); pixSetData(pix, rgbdata); See pixConvert32To24() for an example, where we get rgbdata from the 32 bpp pix. Caution: do not call pixSetPadBits(), because the alignment is wrong and you may erase part of the last pixel on each line. (8) If the pix has a colormap, it is written to file. In most situations, the alpha component is 255 for each colormap entry, which is opaque and indicates that it should be ignored. However, if any alpha component is not 255, it is assumed that the alpha values are valid, and they are written to the png file in a tRNS segment. On readback, the tRNS segment is identified, and the colormapped image with alpha is converted to a 4 spp rgba image.
l_int32 readHeaderMemPng | ( | const l_uint8 * | data, |
size_t | size, | ||
l_int32 * | pw, | ||
l_int32 * | ph, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp, | ||
l_int32 * | piscmap | ||
) |
Input: data size (40 bytes is sufficient) &w (<optional return>="">) &h (<optional return>="">) &bps (<optional return>="">, bits/sample) &spp (<optional return>="">, samples/pixel) &iscmap (<optional return>="">; input NULL to ignore) Return: 0 if OK, 1 on error
Notes: (1) See readHeaderPng(). (2) png colortypes (see png.h: PNG_COLOR_TYPE_*): 0: gray; fully transparent (with tRNS) (1 spp) 2: RGB (3 spp) 3: colormap; colormap+alpha (with tRNS) (1 spp) 4: gray + alpha (2 spp) 6: RGBA (4 spp) Note: 0 and 3 have the alpha information in a tRNS chunk 4 and 6 have separate alpha samples with each pixel.
l_int32 readHeaderPng | ( | const char * | filename, |
l_int32 * | pw, | ||
l_int32 * | ph, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp, | ||
l_int32 * | piscmap | ||
) |
Input: filename &w (<optional return>="">) &h (<optional return>="">) &bps (<optional return>="">, bits/sample) &spp (<optional return>="">, samples/pixel) &iscmap (<optional return>="">) Return: 0 if OK, 1 on error
Notes: (1) If there is a colormap, iscmap is returned as 1; else 0. (2) For gray+alpha, although the png records bps = 16, we consider this as two 8 bpp samples (gray and alpha). When a gray+alpha is read, it is converted to 32 bpp RGBA.
l_int32 var_PNG_STRIP_16_TO_8 = 1 [static] |