Image-Leptonica
view release on metacpan or search on metacpan
lib/Image/Leptonica/Func/bmpio.pm view on Meta::CPAN
Write bmp to file
l_int32 pixWriteStreamBmp()
Read/write to memory
PIX *pixReadMemBmp()
l_int32 pixWriteMemBmp()
On systems like windows without fmemopen() and open_memstream(),
we write data to a temp file and read it back for operations
between pix and compressed-data, such as pixReadMemPng() and
pixWriteMemPng().
=head1 FUNCTIONS
=head2 pixReadMemBmp
PIX * pixReadMemBmp ( const l_uint8 *cdata, size_t size )
pixReadMemBmp()
Input: cdata (const; bmp-encoded)
lib/Image/Leptonica/Func/jpegio.pm view on Meta::CPAN
line buffer, and compress as three 8 bpp images.
* 8 bpp colormapped image: convert each line to three
8 bpp line images in the color line buffer, and
compress as three 8 bpp images.
(5) The only valid pixel depths in leptonica are 1, 2, 4, 8, 16
and 32 bpp. However, it is possible, and in some cases desirable,
to write out a jpeg 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.
=head2 readHeaderJpeg
l_int32 readHeaderJpeg ( const char *filename, l_int32 *pw, l_int32 *ph, l_int32 *pspp, l_int32 *pycck, l_int32 *pcmyk )
readHeaderJpeg()
Input: filename
&w (<optional return>)
&h (<optional return>)
lib/Image/Leptonica/Func/pngio.pm view on Meta::CPAN
=head1 VERSION
version 0.04
=head1 C<pngio.c>
pngio.c
Read png from file
PIX *pixReadStreamPng()
l_int32 readHeaderPng()
l_int32 freadHeaderPng()
l_int32 sreadHeaderPng()
l_int32 fgetPngResolution()
Write png to file
l_int32 pixWritePng() [ special top level ]
l_int32 pixWriteStreamPng()
l_int32 pixSetZlibCompression()
Setting flag for special read mode
void l_pngSetReadStrip16To8()
Read/write to memory
PIX *pixReadMemPng()
l_int32 pixWriteMemPng()
Documentation: libpng.txt and example.c
On input (decompression from file), palette color images
are read into an 8 bpp Pix with a colormap, and 24 bpp
3 component color images are read into a 32 bpp Pix with
rgb samples. On output (compression to file), palette color
images are written as 8 bpp with the colormap, and 32 bpp
full color images are written compressed as a 24 bpp,
3 component color image.
lib/Image/Leptonica/Func/pngio.pm view on Meta::CPAN
sample down to 8 bps:
- For 16 bps rgb (16 bps, 3 spp) --> 32 bpp rgb Pix
- For 16 bps gray (16 bps, 1 spp) --> 8 bpp grayscale Pix
If the variable is set to FALSE, the 16 bit gray samples
are saved when read; the 16 bit rgb samples return an error.
Note: results can be non-deterministic if used with
multi-threaded applications.
On systems like windows without fmemopen() and open_memstream(),
we write data to a temp file and read it back for operations
between pix and compressed-data, such as pixReadMemPng() and
pixWriteMemPng().
=head1 FUNCTIONS
=head2 fgetPngResolution
l_int32 fgetPngResolution ( FILE *fp, l_int32 *pxres, l_int32 *pyres )
fgetPngResolution()
Input: stream (opened for read)
&xres, &yres (<return> resolution in ppi)
Return: 0 if OK; 0 on error
Notes:
(1) If neither resolution field is set, this is not an error;
the returned resolution values are 0 (designating 'unknown').
(2) Side-effect: this rewinds the stream.
=head2 freadHeaderPng
l_int32 freadHeaderPng ( FILE *fp, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap )
freadHeaderPng()
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().
=head2 l_pngSetReadStrip16To8
void l_pngSetReadStrip16To8 ( l_int32 flag )
l_pngSetReadStrip16To8()
Input: flag (1 for stripping 16 bpp to 8 bpp on reading;
0 for leaving 16 bpp)
Return: void
=head2 pixReadMemPng
PIX * pixReadMemPng ( const l_uint8 *cdata, size_t size )
pixReadMemPng()
Input: cdata (const; png-encoded)
size (of data)
Return: pix, or null on error
Notes:
(1) The @size byte of @data must be a null character.
=head2 pixReadStreamPng
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()
(3) Grayscale-with-alpha pngs (spp = 2) are converted to RGBA
on read; the returned pix has spp = 4 and equal red, green and
blue channels.
(4) spp = 1 with alpha (palette) is converted to RGBA with spp = 4.
(5) 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 OK for single images,
but I could not get it to work properly for the successive
lib/Image/Leptonica/Func/pngio.pm view on Meta::CPAN
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.
=head2 pixWriteMemPng
l_int32 pixWriteMemPng ( l_uint8 **pdata, size_t *psize, PIX *pix, l_float32 gamma )
pixWriteMemPng()
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.
=head2 pixWritePng
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.
=head2 pixWriteStreamPng
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
lib/Image/Leptonica/Func/pngio.pm view on Meta::CPAN
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.
=head2 readHeaderPng
l_int32 readHeaderPng ( const char *filename, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap )
readHeaderPng()
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.
=head2 sreadHeaderPng
l_int32 sreadHeaderPng ( const l_uint8 *data, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap )
sreadHeaderPng()
Input: data
&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.
lib/Image/Leptonica/leptonica.h view on Meta::CPAN
extern PIX * pixConnCompTransform ( PIX *pixs, l_int32 connect, l_int32 depth );
extern PIX * pixConnCompAreaTransform ( PIX *pixs, l_int32 connect );
extern PIX * pixLocToColorTransform ( PIX *pixs );
extern PIXTILING * pixTilingCreate ( PIX *pixs, l_int32 nx, l_int32 ny, l_int32 w, l_int32 h, l_int32 xoverlap, l_int32 yoverlap );
extern void pixTilingDestroy ( PIXTILING **ppt );
extern l_int32 pixTilingGetCount ( PIXTILING *pt, l_int32 *pnx, l_int32 *pny );
extern l_int32 pixTilingGetSize ( PIXTILING *pt, l_int32 *pw, l_int32 *ph );
extern PIX * pixTilingGetTile ( PIXTILING *pt, l_int32 i, l_int32 j );
extern l_int32 pixTilingNoStripOnPaint ( PIXTILING *pt );
extern l_int32 pixTilingPaintTile ( PIX *pixd, l_int32 i, l_int32 j, PIX *pixs, PIXTILING *pt );
extern PIX * pixReadStreamPng ( FILE *fp );
extern l_int32 readHeaderPng ( const char *filename, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap );
extern l_int32 freadHeaderPng ( FILE *fp, l_int32 *pw, l_int32 *ph, l_int32 *pbps, l_int32 *pspp, l_int32 *piscmap );
extern 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 );
extern l_int32 fgetPngResolution ( FILE *fp, l_int32 *pxres, l_int32 *pyres );
extern l_int32 isPngInterlaced ( const char *filename, l_int32 *pinterlaced );
extern l_int32 pixWritePng ( const char *filename, PIX *pix, l_float32 gamma );
extern l_int32 pixWriteStreamPng ( FILE *fp, PIX *pix, l_float32 gamma );
extern l_int32 pixSetZlibCompression ( PIX *pix, l_int32 compval );
extern void l_pngSetReadStrip16To8 ( l_int32 flag );
extern PIX * pixReadMemPng ( const l_uint8 *cdata, size_t size );
extern l_int32 pixWriteMemPng ( l_uint8 **pdata, size_t *psize, PIX *pix, l_float32 gamma );
extern PIX * pixReadStreamPnm ( FILE *fp );
extern l_int32 readHeaderPnm ( const char *filename, l_int32 *pw, l_int32 *ph, l_int32 *pd, l_int32 *ptype, l_int32 *pbps, l_int32 *pspp );
extern l_int32 freadHeaderPnm ( FILE *fp, l_int32 *pw, l_int32 *ph, l_int32 *pd, l_int32 *ptype, l_int32 *pbps, l_int32 *pspp );
extern l_int32 pixWriteStreamPnm ( FILE *fp, PIX *pix );
extern l_int32 pixWriteStreamAsciiPnm ( FILE *fp, PIX *pix );
extern PIX * pixReadMemPnm ( const l_uint8 *cdata, size_t size );
extern l_int32 readHeaderMemPnm ( const l_uint8 *cdata, size_t size, l_int32 *pw, l_int32 *ph, l_int32 *pd, l_int32 *ptype, l_int32 *pbps, l_int32 *pspp );
extern l_int32 pixWriteMemPnm ( l_uint8 **pdata, size_t *psize, PIX *pix );
extern PIX * pixProjectiveSampledPta ( PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor );
extern PIX * pixProjectiveSampled ( PIX *pixs, l_float32 *vc, l_int32 incolor );
( run in 0.738 second using v1.01-cache-2.11-cpan-0a6323c29d9 )