Leptonica 1.54
Файл src/pixcomp.c
#include <string.h>
#include "allheaders.h"

Функции

PIXCpixcompCreateFromPix (PIX *pix, l_int32 comptype)
PIXCpixcompCreateFromString (l_uint8 *data, size_t size, l_int32 copyflag)
PIXCpixcompCreateFromFile (const char *filename, l_int32 comptype)
void pixcompDestroy (PIXC **ppixc)
l_int32 pixcompGetDimensions (PIXC *pixc, l_int32 *pw, l_int32 *ph, l_int32 *pd)
l_int32 pixcompDetermineFormat (l_int32 comptype, l_int32 d, l_int32 cmapflag, l_int32 *pformat)
PIXpixCreateFromPixcomp (PIXC *pixc)
PIXACpixacompCreate (l_int32 n)
PIXACpixacompCreateInitialized (l_int32 n, PIX *pix, l_int32 comptype)
PIXACpixacompCreateFromPixa (PIXA *pixa, l_int32 comptype, l_int32 accesstype)
PIXACpixacompCreateFromFiles (const char *dirname, const char *substr, l_int32 comptype)
PIXACpixacompCreateFromSA (SARRAY *sa, l_int32 comptype)
void pixacompDestroy (PIXAC **ppixac)
l_int32 pixacompAddPix (PIXAC *pixac, PIX *pix, l_int32 comptype)
l_int32 pixacompAddPixcomp (PIXAC *pixac, PIXC *pixc)
l_int32 pixacompExtendArray (PIXAC *pixac)
l_int32 pixacompReplacePix (PIXAC *pixac, l_int32 index, PIX *pix, l_int32 comptype)
l_int32 pixacompReplacePixcomp (PIXAC *pixac, l_int32 index, PIXC *pixc)
l_int32 pixacompAddBox (PIXAC *pixac, BOX *box, l_int32 copyflag)
l_int32 pixacompGetCount (PIXAC *pixac)
PIXCpixacompGetPixcomp (PIXAC *pixac, l_int32 index)
PIXpixacompGetPix (PIXAC *pixac, l_int32 index)
l_int32 pixacompGetPixDimensions (PIXAC *pixac, l_int32 index, l_int32 *pw, l_int32 *ph, l_int32 *pd)
BOXApixacompGetBoxa (PIXAC *pixac, l_int32 accesstype)
l_int32 pixacompGetBoxaCount (PIXAC *pixac)
BOXpixacompGetBox (PIXAC *pixac, l_int32 index, l_int32 accesstype)
l_int32 pixacompGetBoxGeometry (PIXAC *pixac, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
PIXApixaCreateFromPixacomp (PIXAC *pixac, l_int32 accesstype)
PIXACpixacompRead (const char *filename)
PIXACpixacompReadStream (FILE *fp)
l_int32 pixacompWrite (const char *filename, PIXAC *pixac)
l_int32 pixacompWriteStream (FILE *fp, PIXAC *pixac)
l_int32 pixacompWriteStreamInfo (FILE *fp, PIXAC *pixac, const char *text)
l_int32 pixcompWriteStreamInfo (FILE *fp, PIXC *pixc, const char *text)
PIXpixacompDisplayTiledAndScaled (PIXAC *pixac, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)

Переменные

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20
l_int32 NumImageFileFormatExtensions
const char * ImageFileFormatExtensions []

Функции

l_int32 pixacompAddBox ( PIXAC pixac,
BOX box,
l_int32  copyflag 
)

pixacompAddBox()

Input: pixac box copyflag (L_INSERT, L_COPY) Return: 0 if OK, 1 on error

l_int32 pixacompAddPix ( PIXAC pixac,
PIX pix,
l_int32  comptype 
)

pixacompAddPix()

Input: pixac pix (to be added) comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: 0 if OK; 1 on error

l_int32 pixacompAddPixcomp ( PIXAC pixac,
PIXC pixc 
)

pixacompAddPixcomp()

Input: pixac pixc (to be added by insertion) Return: 0 if OK; 1 on error

PIXAC* pixacompCreate ( l_int32  n)

pixacompCreate()

Input: n (initial number of ptrs) Return: pixac, or null on error

PIXAC* pixacompCreateFromFiles ( const char *  dirname,
const char *  substr,
l_int32  comptype 
)

pixacompCreateFromFiles()

Input: dirname substr (<optional> substring filter on filenames; can be null) comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: pixac, or null on error

Notes: (1) is the full path for the directory. (2) is the part of the file name (excluding the directory) that is to be matched. All matching filenames are read into the Pixa. If substr is NULL, all filenames are read into the Pixa. (3) Use == IFF_DEFAULT to have the compression type automatically determined for each file. (4) If the comptype is invalid for a file, the default will be substituted.

PIXAC* pixacompCreateFromPixa ( PIXA pixa,
l_int32  comptype,
l_int32  accesstype 
)

pixacompCreateFromPixa()

Input: pixa comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) accesstype (L_COPY, L_CLONE, L_COPY_CLONE; for boxa) Return: 0 if OK, 1 on error

Notes: (1) If == IFF_DEFAULT, the conversion format for each image is chosen automatically. Otherwise, we use the specified format unless it can't be done (e.g., jpeg for a 1, 2 or 4 bpp pix, or a pix with a colormap), in which case we use the default (assumed best) compression.

PIXAC* pixacompCreateFromSA ( SARRAY sa,
l_int32  comptype 
)

pixacompCreateFromSA()

Input: sarray (full pathnames for all files) comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: pixac, or null on error

Notes: (1) Use == IFF_DEFAULT to have the compression type automatically determined for each file. (2) If the comptype is invalid for a file, the default will be substituted.

PIXAC* pixacompCreateInitialized ( l_int32  n,
PIX pix,
l_int32  comptype 
)

pixacompCreateInitialized()

Input: n (initial number of ptrs) pix (initialize each ptr in pixacomp to this pix) comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: pixac, or null on error

Notes: (1) Initializes a pixacomp to be fully populated with . (2) Typically use a very small (w = h = 1) with == IFF_TIFF_G4 for the initialization. (3) Example usage: Pix *pix = pixCreate(1, 1, 1); Pixacomp *pixac = pixacompCreateInitialized(50, pix, IFF_TIFF_G4); for (i = 0; i < 50; i++) { Pix *pixt = ... if (pixt) pixacompReplacePix(pixac, i, pixt, IFF_TIFF_G4); pixDestroy(&pixt); } The result is a fully populated pixac with selected pixt replacing the placeholders.

void pixacompDestroy ( PIXAC **  ppixac)

pixacompDestroy()

Input: &pixac (<to be="" nulled>="">) Return: void

Notes: (1) Always nulls the input ptr.

PIX* pixacompDisplayTiledAndScaled ( PIXAC pixac,
l_int32  outdepth,
l_int32  tilewidth,
l_int32  ncols,
l_int32  background,
l_int32  spacing,
l_int32  border 
)

pixacompDisplayTiledAndScaled()

Input: pixac outdepth (output depth: 1, 8 or 32 bpp) tilewidth (each pix is scaled to this width) ncols (number of tiles in each row) background (0 for white, 1 for black; this is the color of the spacing between the images) spacing (between images, and on outside) border (width of additional black border on each image; use 0 for no border) Return: pix of tiled images, or null on error

Notes: (1) This is the same function as pixaDisplayTiledAndScaled(), except it works on a Pixacomp instead of a Pix. It is particularly useful for showing the images in a Pixacomp at reduced resolution. (2) This can be used to tile a number of renderings of an image that are at different scales and depths. (3) Each image, after scaling and optionally adding the black border, has width 'tilewidth'. Thus, the border does not affect the spacing between the image tiles. The maximum allowed border width is tilewidth / 5.

l_int32 pixacompExtendArray ( PIXAC pixac)

pixacompExtendArray()

Input: pixac Return: 0 if OK; 1 on error

Notes: (1) We extend the boxa array simultaneously. This is necessary in case we are NOT adding boxes simultaneously with adding pixc. We always want the sizes of the pixac and boxa ptr arrays to be equal.

BOX* pixacompGetBox ( PIXAC pixac,
l_int32  index,
l_int32  accesstype 
)

pixacompGetBox()

Input: pixac index (to the index-th pix) accesstype (L_COPY or L_CLONE) Return: box (if null, not automatically an error), or null on error

Notes: (1) There is always a boxa with a pixac, and it is initialized so that each box ptr is NULL. (2) In general, we expect that there is either a box associated with each pixc, or no boxes at all in the boxa. (3) Having no boxes is thus not an automatic error. Whether it is an actual error is determined by the calling program. If the caller expects to get a box, it is an error; see, e.g., pixacGetBoxGeometry().

BOXA* pixacompGetBoxa ( PIXAC pixac,
l_int32  accesstype 
)

pixacompGetBoxa()

Input: pixac accesstype (L_COPY, L_CLONE, L_COPY_CLONE) Return: boxa, or null on error

l_int32 pixacompGetBoxaCount ( PIXAC pixac)

pixacompGetBoxaCount()

Input: pixac Return: count, or 0 on error

l_int32 pixacompGetBoxGeometry ( PIXAC pixac,
l_int32  index,
l_int32 px,
l_int32 py,
l_int32 pw,
l_int32 ph 
)

pixacompGetBoxGeometry()

Input: pixac index (to the index-th box) &x, &y, &w, &h (<optional return>="">; each can be null) Return: 0 if OK, 1 on error

l_int32 pixacompGetCount ( PIXAC pixac)

pixacompGetCount()

Input: pixac Return: count, or 0 if no pixa

PIX* pixacompGetPix ( PIXAC pixac,
l_int32  index 
)

pixacompGetPix()

Input: pixac index (to the index-th pix) Return: pix, or null on error

PIXC* pixacompGetPixcomp ( PIXAC pixac,
l_int32  index 
)

pixacompGetPixcomp()

Input: pixac index (to the index-th pix) Return: pixc, or null on error

Notes: (1) Important: this is just a ptr to the pixc owned by the pixac. Do not destroy unless you are replacing the pixc.

l_int32 pixacompGetPixDimensions ( PIXAC pixac,
l_int32  index,
l_int32 pw,
l_int32 ph,
l_int32 pd 
)

pixacompGetPixDimensions()

Input: pixa index (to the index-th box) &w, &h, &d (<optional return>="">; each can be null) Return: 0 if OK, 1 on error

PIXAC* pixacompRead ( const char *  filename)

pixacompRead()

Input: filename Return: pixac, or null on error

Notes: (1) Unlike the situation with serialized Pixa, where the image data is stored in png format, the Pixacomp image data can be stored in tiffg4, png and jpg formats.

PIXAC* pixacompReadStream ( FILE *  fp)

pixacompReadStream()

Input: stream Return: pixac, or null on error

l_int32 pixacompReplacePix ( PIXAC pixac,
l_int32  index,
PIX pix,
l_int32  comptype 
)

pixacompReplacePix()

Input: pixac index (of pixc within pixac to be replaced) pix (owned by the caller) comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: 0 if OK; 1 on error

Notes: (1) The input is converted to a pixc, which is then inserted into the pixac.

l_int32 pixacompReplacePixcomp ( PIXAC pixac,
l_int32  index,
PIXC pixc 
)

pixacompReplacePixcomp()

Input: pixac index (of pixc within pixac to be replaced) pixc (to replace existing one, which is destroyed) Return: 0 if OK; 1 on error

Notes: (1) The inserted is now owned by the pixac. The caller must not destroy it.

l_int32 pixacompWrite ( const char *  filename,
PIXAC pixac 
)

pixacompWrite()

Input: filename pixac Return: 0 if OK, 1 on error

Notes: (1) Unlike the situation with serialized Pixa, where the image data is stored in png format, the Pixacomp image data can be stored in tiffg4, png and jpg formats.

l_int32 pixacompWriteStream ( FILE *  fp,
PIXAC pixac 
)

pixacompWriteStream()

Input: stream pixac Return: 0 if OK, 1 on error

l_int32 pixacompWriteStreamInfo ( FILE *  fp,
PIXAC pixac,
const char *  text 
)

pixacompWriteStreamInfo()

Input: fp (file stream) pixac text (<optional> identifying string; can be null) Return: 0 if OK, 1 on error

PIXA* pixaCreateFromPixacomp ( PIXAC pixac,
l_int32  accesstype 
)

pixaCreateFromPixacomp()

Input: pixac accesstype (L_COPY, L_CLONE, L_COPY_CLONE; for boxa) Return: pixa if OK, or null on error

PIXC* pixcompCreateFromFile ( const char *  filename,
l_int32  comptype 
)

pixcompCreateFromFile()

Input: filename comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: pixc, or null on error

Notes: (1) Use == IFF_DEFAULT to have the compression type automatically determined. (2) If the comptype is invalid for this file, the default will be substituted.

PIXC* pixcompCreateFromPix ( PIX pix,
l_int32  comptype 
)

pixcompCreateFromPix()

Input: pix comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: pixc, or null on error

Notes: (1) Use == IFF_DEFAULT to have the compression type automatically determined.

PIXC* pixcompCreateFromString ( l_uint8 data,
size_t  size,
l_int32  copyflag 
)

pixcompCreateFromString()

Input: data (compressed string) size (number of bytes) copyflag (L_INSERT or L_COPY) Return: pixc, or null on error

Notes: (1) This works when the compressed string is png, jpeg or tiffg4. (2) The copyflag determines if the data in the new Pixcomp is a copy of the input data.

void pixcompDestroy ( PIXC **  ppixc)

pixcompDestroy()

Input: &pixc <will be="" nulled>=""> Return: void

Notes: (1) Always nulls the input ptr.

l_int32 pixcompDetermineFormat ( l_int32  comptype,
l_int32  d,
l_int32  cmapflag,
l_int32 pformat 
)

pixcompDetermineFormat()

Input: comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) d (pix depth) cmapflag (1 if pix to be compressed as a colormap; 0 otherwise) &format (return IFF_TIFF, IFF_PNG or IFF_JFIF_JPEG) Return: 0 if OK; 1 on error

Notes: (1) This determines the best format for a pix, given both the request () and the image characteristics. (2) If == IFF_DEFAULT, this does not necessarily result in png encoding. Instead, it returns one of the three formats that is both valid and most likely to give best compression. (3) If the pix cannot be compressed by the input value of , this selects IFF_PNG, which can compress all pix.

l_int32 pixcompGetDimensions ( PIXC pixc,
l_int32 pw,
l_int32 ph,
l_int32 pd 
)

pixcompGetDimensions()

Input: pixc &w, &h, &d (<optional return>="">) Return: 0 if OK, 1 on error

l_int32 pixcompWriteStreamInfo ( FILE *  fp,
PIXC pixc,
const char *  text 
)

pixcompWriteStreamInfo()

Input: fp (file stream) pixc text (<optional> identifying string; can be null) Return: 0 if OK, 1 on error

PIX* pixCreateFromPixcomp ( PIXC pixc)

pixCreateFromPixcomp()

Input: pixc Return: pix, or null on error


Переменные

const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static]