Leptonica
1.54
|
#define DEBUG 0 |
l_int32 fgetPngResolution | ( | FILE * | fp, |
l_int32 * | pxres, | ||
l_int32 * | pyres | ||
) |
l_int32 freadHeaderPng | ( | FILE * | fp, |
l_int32 * | pwidth, | ||
l_int32 * | pheight, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp, | ||
l_int32 * | piscmap | ||
) |
Input: stream &width (<return>) &height (<return>) &bps (<return>, bits/sample) &spp (<return>, samples/pixel) &iscmap (<optional return>="">; input NULL to ignore) Return: 0 if OK, 1 on error
Notes: (1) If there is a colormap, iscmap is returned as 1; else 0.
void l_pngSetStrip16To8 | ( | l_int32 | flag | ) |
Input: flag (1 for stripping 16 bpp to 8 bpp; 0 for leaving 16 bpp) Return: void
void l_pngSetStripAlpha | ( | l_int32 | flag | ) |
Input: flag (1 for stripping alpha channel on read; 0 for leaving it) Return: void
void l_pngSetWriteAlpha | ( | l_int32 | flag | ) |
Input: flag (1 for writing alpha channel; 0 for just writing rgb) Return: void
void l_pngSetZlibCompression | ( | l_int32 | val | ) |
Input: val (zlib compression value) Return: void
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.
PIX* pixReadMemPng | ( | const l_uint8 * | cdata, |
size_t | size | ||
) |
PIX* pixReadRGBAPng | ( | const char * | filename | ) |
Input: filename (of png file) Return: pix, or null on error
Notes: (1) Wrapper to keep the alpha channel of a png, if it exists. (2) The default behavior of pix read functions is to ignore the alpha channel. (3) This always leaves alpha stripping in the same mode as when this function begins. So if alpha stripping is in default mode, this disables it, reads the file (including the alpha channel), and resets back to stripping. Otherwise, it leaves stripping disabled.
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()
l_int32 pixWriteMemPng | ( | l_uint8 ** | pdata, |
size_t * | psize, | ||
PIX * | pix, | ||
l_float32 | gamma | ||
) |
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 pixWriteRGBAPng | ( | const char * | filename, |
PIX * | pix | ||
) |
Input: filename pix (rgba) Return: 0 if OK, 1 on error
Notes: (1) Wrapper to write the alpha sample of a 32 bpp pix to a png file in rgba format. (2) The default behavior of pix write to png is to ignore the alpha sample. (3) This always leaves alpha writing in the same mode as when this function begins. So if alpha writing is in default mode, this enables it, writes out a rgba png file that includes the alpha channel, and resets to default. Otherwise, it leaves alpha writing enabled.
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 anble 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.
l_int32 readHeaderPng | ( | const char * | filename, |
l_int32 * | pwidth, | ||
l_int32 * | pheight, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp, | ||
l_int32 * | piscmap | ||
) |
Input: filename &width (<return>) &height (<return>) &bps (<return>, bits/sample) &spp (<return>, samples/pixel) &iscmap (<optional return>="">; input NULL to ignore) Return: 0 if OK, 1 on error
Notes: (1) If there is a colormap, iscmap is returned as 1; else 0.
l_int32 sreadHeaderPng | ( | const l_uint8 * | data, |
l_int32 * | pwidth, | ||
l_int32 * | pheight, | ||
l_int32 * | pbps, | ||
l_int32 * | pspp, | ||
l_int32 * | piscmap | ||
) |
Input: data &width (<return>) &height (<return>) &bps (<return>, bits/sample) &spp (<return>, samples/pixel) &iscmap (<optional return>="">; input NULL to ignore) Return: 0 if OK, 1 on error
Notes: (1) If there is a colormap, iscmap is returned as 1; else 0.
const char* ImageFileFormatExtensions[] |
l_int32 var_PNG_STRIP_16_TO_8 = 1 [static] |
l_int32 var_PNG_STRIP_ALPHA = 1 [static] |
l_int32 var_PNG_WRITE_ALPHA = 0 [static] |
l_int32 var_ZLIB_COMPRESSION = Z_DEFAULT_COMPRESSION [static] |