Файл src/pngio.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"
#include "png.h"

Макросы

#define DEBUG   0

Функции

PIXpixReadStreamPng (FILE *fp)
l_int32 readHeaderPng (const char *filename, l_int32 *pwidth, l_int32 *pheight, l_int32 *pbpc, l_int32 *pcpp, l_int32 *piscmap)
l_int32 freadHeaderPng (FILE *fp, l_int32 *pwidth, l_int32 *pheight, l_int32 *pbpc, l_int32 *pcpp, l_int32 *piscmap)
l_int32 sreadHeaderPng (const l_uint8 *data, l_int32 *pwidth, l_int32 *pheight, l_int32 *pbpc, l_int32 *pcpp, l_int32 *piscmap)
l_int32 pixWritePng (const char *filename, PIX *pix, l_float32 gamma)
l_int32 pixWriteStreamPng (FILE *fp, PIX *pix, l_float32 gamma)
void l_pngSetStrip16To8 (l_int32 flag)
void l_pngSetStripAlpha (l_int32 flag)
void l_pngSetZlibCompression (l_int32 val)
PIXpixReadMemPng (const l_uint8 *cdata, size_t size)
l_int32 pixWriteMemPng (l_uint8 **pdata, size_t *psize, PIX *pix, l_float32 gamma)

Переменные

static l_int32 L_PNG_STRIP_16_TO_8 = 1
static l_int32 L_PNG_STRIP_ALPHA = 1
static l_int32 L_ZLIB_COMPRESSION = Z_DEFAULT_COMPRESSION

Макросы

#define DEBUG   0


Функции

l_int32 freadHeaderPng ( FILE *  fp,
l_int32 pwidth,
l_int32 pheight,
l_int32 pbpc,
l_int32 pcpp,
l_int32 piscmap 
)

freadHeaderPng()

Input: stream &width (<return>) &height (<return>) &bpc (<return>, bits/component) &cpp (<return>, components/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  ) 

l_pngSetStrip16To8()

Input: flag (1 for stripping 16 bpp to 8 bpp; 0 for leaving 16 bpp) Return: void

void l_pngSetStripAlpha ( l_int32  flag  ) 

l_pngSetStripAlpha()

Input: flag (1 for stripping alpha channel on read; 0 for leaving it) Return: void

void l_pngSetZlibCompression ( l_int32  val  ) 

l_pngSetZlibCompression()

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* pixReadStreamPng ( FILE *  fp  ) 

pixReadStreamPng()

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 
)

pixWritePng()

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 
)

pixWriteStreamPng()

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. To write these directly to file in leptonica, 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); pixSetPadBits(pix, 0); Consequently, we enable writing 24 bpp pix.

l_int32 readHeaderPng ( const char *  filename,
l_int32 pwidth,
l_int32 pheight,
l_int32 pbpc,
l_int32 pcpp,
l_int32 piscmap 
)

readHeaderPng()

Input: filename &width (<return>) &height (<return>) &bpc (<return>, bits/component) &cpp (<return>, components/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 pbpc,
l_int32 pcpp,
l_int32 piscmap 
)

sreadHeaderPng()

Input: data &width (<return>) &height (<return>) &bpc (<return>, bits/component) &cpp (<return>, components/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 L_PNG_STRIP_ALPHA = 1 [static]

l_int32 L_ZLIB_COMPRESSION = Z_DEFAULT_COMPRESSION [static]


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9