Leptonica 1.68
C Image Processing Library
|
Handles compressed pix arrays in memory. More...
Go to the source code of this file.
Handles compressed pix arrays in memory.
Pixcomp creation and destruction PIXC *pixcompCreateFromPix() PIXC *pixcompCreateFromString() PIXC *pixcompCreateFromFile() void pixcompDestroy() Pixcomp accessors l_int32 pixcompGetDimensions() l_int32 pixcompDetermineFormat() Pixcomp conversion to Pix PIX *pixCreateFromPixcomp() Pixacomp creation and destruction PIXAC *pixacompCreate() PIXAC *pixacompCreateInitialized() PIXAC *pixacompCreateFromPixa() PIXAC *pixacompCreateFromFiles() PIXAC *pixacompCreateFromSA() void pixacompDestroy() Pixacomp addition/replacement l_int32 pixacompAddPix() l_int32 pixacompAddPixcomp() l_int32 pixacompExtendArray() l_int32 pixacompReplacePix() l_int32 pixacompReplacePixcomp() l_int32 pixacompAddBox() Pixacomp accessors l_int32 pixacompGetCount() PIXC *pixacompGetPixcomp() PIX *pixacompGetPix() l_int32 pixacompGetPixDimensions() BOXA *pixacompGetBoxa() l_int32 pixacompGetBoxaCount() BOX *pixacompGetBox() l_int32 pixacompGetBoxGeometry() Pixacomp conversion to Pixa PIXA *pixaCreateFromPixacomp() Pixacomp serialized I/O PIXAC *pixacompRead() PIXAC *pixacompReadStream() l_int32 pixacompWrite() l_int32 pixacompWriteStream() Output for debugging l_int32 pixacompWriteStreamInfo() l_int32 pixcompWriteStreamInfo() PIX *pixacompDisplayTiledAndScaled() The Pixacomp is an array of Pixcomp, where each Pixcomp is a compressed string of the image. We don't use reference counting here. The basic application is to allow a large array of highly compressible images to reside in memory. We purposely don't reuse the Pixa for this, to avoid confusion and programming errors. Three compression formats are used: g4, png and jpeg. The compression type can be either specified or defaulted. If specified and it is not possible to compress (for example, you specify a jpeg on a 1 bpp image or one with a colormap), the compression type defaults to png. The serialized version of the Pixacomp is similar to that for a Pixa, except that each Pixcomp can be compressed by one of tiffg4, png, or jpeg. Unlike serialization of the Pixa, serialization of the Pixacomp does not require any imaging libraries because it simply reads and writes the compressed data. For random insertion and replacement of pixcomp into a pixcomp, initialize a fully populated array using pixacompCreateInitialized(). Then use pixacompReplacePix() or pixacompReplacePixcomp() for the random insertion.
Definition in file pixcomp.c.
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.
Definition at line 121 of file pixcomp.c.
References CALLOC, PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::data, ERROR_PTR, PixComp::h, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, L_ERROR, NULL, pixcompDestroy(), pixcompDetermineFormat(), pixGetColormap(), pixGetDimensions(), pixGetResolution(), pixGetText(), pixWriteMem(), PROCNAME, PixComp::size, size, stringNew(), PixComp::text, PixComp::w, PixComp::xres, and PixComp::yres.
Referenced by main(), pixacompAddPix(), pixacompCreateInitialized(), pixacompReplacePix(), and pixcompCreateFromFile().
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.
Definition at line 176 of file pixcomp.c.
References CALLOC, PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::data, ERROR_PTR, PixComp::h, l_binaryCopy(), L_COPY, L_INSERT, NULL, pixReadHeaderMem(), PROCNAME, size, PixComp::size, and PixComp::w.
Referenced by 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.
Definition at line 223 of file pixcomp.c.
References ERROR_PTR, findFileFormat(), FREE, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, IFF_UNKNOWN, l_binaryRead(), L_INSERT, PixMemoryStore::nbytes, NULL, pixcompCreateFromPix(), pixcompCreateFromString(), pixDestroy(), pixRead(), and PROCNAME.
Referenced by pixacompCreateFromSA().
void pixcompDestroy | ( | PIXC ** | ppixc | ) |
Input: &pixc <will be="" nulled>=""> Return: void
Notes: (1) Always nulls the input ptr.
Definition at line 282 of file pixcomp.c.
References PixComp::data, FREE, L_WARNING, NULL, PROCNAME, and PixComp::text.
Referenced by main(), pixacompDestroy(), pixacompReplacePixcomp(), and pixcompCreateFromPix().
Input: pixc &w, &h, &d (<optional return>="">) Return: 0 if OK, 1 on error
Definition at line 316 of file pixcomp.c.
References PixComp::d, ERROR_INT, PixComp::h, PROCNAME, and PixComp::w.
Referenced by pixacompGetPixDimensions().
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.
Definition at line 351 of file pixcomp.c.
References ERROR_INT, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, and PROCNAME.
Referenced by pixacompAddPix(), and pixcompCreateFromPix().
Input: pixc Return: pix, or null on error
Definition at line 393 of file pixcomp.c.
References PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::data, ERROR_PTR, PixComp::h, L_ERROR, L_ERROR_INT, L_INFO_INT2, L_WARNING_INT, NULL, pixGetColormap(), pixGetDimensions(), pixGetInputFormat(), pixReadMem(), pixSetResolution(), pixSetText(), PROCNAME, PixComp::size, PixComp::text, PixComp::w, PixComp::xres, and PixComp::yres.
Referenced by main(), and pixacompGetPix().
Input: n (initial number of ptrs) Return: pixac, or null on error
Definition at line 447 of file pixcomp.c.
References PixaComp::boxa, boxaCreate(), CALLOC, ERROR_PTR, INITIAL_PTR_ARRAYSIZE, PixaComp::n, PixaComp::nalloc, NULL, PixaComp::pixc, and PROCNAME.
Referenced by main(), pixacompCreateFromPixa(), pixacompCreateFromSA(), pixacompCreateInitialized(), and pixacompReadStream().
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.
Definition at line 495 of file pixcomp.c.
References ERROR_PTR, NULL, pixacompAddPixcomp(), pixacompCreate(), pixcompCreateFromPix(), and PROCNAME.
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.
Definition at line 537 of file pixcomp.c.
References PixaComp::boxa, boxaDestroy(), ERROR_PTR, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, L_CLONE, L_COPY, L_COPY_CLONE, NULL, pixacompAddPix(), pixacompCreate(), pixaGetBoxa(), pixaGetCount(), pixaGetPix(), pixDestroy(), and PROCNAME.
Referenced by main().
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.
Definition at line 596 of file pixcomp.c.
References ERROR_PTR, getSortedPathnamesInDirectory(), IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, NULL, pixacompCreateFromSA(), PROCNAME, and sarrayDestroy().
Referenced by main().
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.
Definition at line 633 of file pixcomp.c.
References ERROR_PTR, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, L_NOCOPY, L_WARNING_STRING, NULL, pixacompAddPixcomp(), pixacompCreate(), pixcompCreateFromFile(), PROCNAME, sarrayGetCount(), and sarrayGetString().
Referenced by pixacompCreateFromFiles().
void pixacompDestroy | ( | PIXAC ** | ppixac | ) |
Input: &pixac (<to be="" nulled>="">) Return: void
Notes: (1) Always nulls the input ptr.
Definition at line 673 of file pixcomp.c.
References PixaComp::boxa, boxaDestroy(), FREE, L_WARNING, PixaComp::n, NULL, PixaComp::pixc, pixcompDestroy(), and PROCNAME.
Referenced by main().
Input: pixac pix (to be added) comptype (IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG) Return: 0 if OK; 1 on error
Definition at line 711 of file pixcomp.c.
References ERROR_INT, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, NULL, pixacompAddPixcomp(), pixcompCreateFromPix(), pixcompDetermineFormat(), pixGetColormap(), pixGetDepth(), and PROCNAME.
Referenced by main(), and pixacompCreateFromPixa().
Input: pixac pixc (to be added by insertion) Return: 0 if OK; 1 on error
Definition at line 745 of file pixcomp.c.
References ERROR_INT, PixaComp::n, PixaComp::nalloc, pixacompExtendArray(), PixaComp::pixc, and PROCNAME.
Referenced by pixacompAddPix(), pixacompCreateFromSA(), pixacompCreateInitialized(), and pixacompReadStream().
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.
Definition at line 780 of file pixcomp.c.
References PixaComp::boxa, boxaExtendArray(), ERROR_INT, PixaComp::nalloc, NULL, PixaComp::pixc, PROCNAME, and reallocNew().
Referenced by pixacompAddPixcomp().
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.
Definition at line 811 of file pixcomp.c.
References ERROR_INT, IFF_DEFAULT, IFF_JFIF_JPEG, IFF_PNG, IFF_TIFF_G4, pixacompGetCount(), pixacompReplacePixcomp(), pixcompCreateFromPix(), and PROCNAME.
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.
Definition at line 851 of file pixcomp.c.
References ERROR_INT, pixacompGetCount(), pixacompGetPixcomp(), PixaComp::pixc, pixcompDestroy(), and PROCNAME.
Referenced by pixacompReplacePix().
Input: pixac box copyflag (L_INSERT, L_COPY) Return: 0 if OK, 1 on error
Definition at line 885 of file pixcomp.c.
References PixaComp::boxa, boxaAddBox(), ERROR_INT, L_COPY, L_INSERT, and PROCNAME.
Input: pixac Return: count, or 0 if no pixa
Definition at line 913 of file pixcomp.c.
References ERROR_INT, PixaComp::n, and PROCNAME.
Referenced by main(), pixacompDisplayTiledAndScaled(), pixacompReplacePix(), pixacompReplacePixcomp(), pixacompWriteStream(), pixacompWriteStreamInfo(), and pixaCreateFromPixacomp().
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.
Definition at line 936 of file pixcomp.c.
References ERROR_PTR, PixaComp::n, NULL, PixaComp::pixc, and PROCNAME.
Referenced by main(), pixacompGetPix(), pixacompReplacePixcomp(), pixacompWriteStream(), and pixacompWriteStreamInfo().
Input: pixac index (to the index-th pix) Return: pix, or null on error
Definition at line 958 of file pixcomp.c.
References ERROR_PTR, PixaComp::n, NULL, pixacompGetPixcomp(), pixCreateFromPixcomp(), and PROCNAME.
Referenced by main(), pixacompDisplayTiledAndScaled(), and pixaCreateFromPixacomp().
l_int32 pixacompGetPixDimensions | ( | PIXAC * | pixac, |
l_int32 | index, | ||
l_int32 * | pw, | ||
l_int32 * | ph, | ||
l_int32 * | pd | ||
) |
Input: pixa index (to the index-th box) &w, &h, &d (<optional return>="">; each can be null) Return: 0 if OK, 1 on error
Definition at line 984 of file pixcomp.c.
References ERROR_INT, PixaComp::n, NULL, PixaComp::pixc, pixcompGetDimensions(), and PROCNAME.
Input: pixac accesstype (L_COPY, L_CLONE, L_COPY_CLONE) Return: boxa, or null on error
Definition at line 1014 of file pixcomp.c.
References PixaComp::boxa, boxaCopy(), ERROR_PTR, L_CLONE, L_COPY, L_COPY_CLONE, NULL, and PROCNAME.
Referenced by pixaCreateFromPixacomp().
Input: pixac Return: count, or 0 on error
Definition at line 1038 of file pixcomp.c.
References PixaComp::boxa, boxaGetCount(), ERROR_INT, and PROCNAME.
Referenced by pixacompWriteStreamInfo().
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().
Definition at line 1068 of file pixcomp.c.
References Boxa::box, PixaComp::boxa, boxClone(), boxCopy(), ERROR_PTR, L_CLONE, L_COPY, Boxa::n, NULL, and PROCNAME.
Referenced by pixacompGetBoxGeometry().
l_int32 pixacompGetBoxGeometry | ( | PIXAC * | pixac, |
l_int32 | index, | ||
l_int32 * | px, | ||
l_int32 * | py, | ||
l_int32 * | pw, | ||
l_int32 * | ph | ||
) |
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
Definition at line 1106 of file pixcomp.c.
References boxDestroy(), boxGetGeometry(), ERROR_INT, L_CLONE, PixaComp::n, NULL, pixacompGetBox(), and PROCNAME.
Input: pixac accesstype (L_COPY, L_CLONE, L_COPY_CLONE; for boxa) Return: pixa if OK, or null on error
Definition at line 1141 of file pixcomp.c.
References Pixa::boxa, boxaDestroy(), ERROR_PTR, L_CLONE, L_COPY, L_COPY_CLONE, L_INSERT, L_WARNING_INT, NULL, pixaAddPix(), pixacompGetBoxa(), pixacompGetCount(), pixacompGetPix(), pixaCreate(), and PROCNAME.
Referenced by main().
PIXAC* pixacompRead | ( | const char * | filename | ) |
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.
Definition at line 1190 of file pixcomp.c.
References ERROR_PTR, fopenReadStream(), NULL, pixacompReadStream(), and PROCNAME.
Referenced by main().
PIXAC* pixacompReadStream | ( | FILE * | fp | ) |
Input: stream Return: pixac, or null on error
Definition at line 1219 of file pixcomp.c.
References PixaComp::boxa, boxaDestroy(), boxaReadStream(), CALLOC, PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::data, ERROR_PTR, PixComp::h, NULL, PIXACOMP_VERSION_NUMBER, pixacompAddPixcomp(), pixacompCreate(), PROCNAME, PixComp::size, size, version, PixComp::w, PixComp::xres, and PixComp::yres.
Referenced by pixacompRead().
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.
Definition at line 1290 of file pixcomp.c.
References ERROR_INT, fopenWriteStream(), NULL, pixacompWriteStream(), and PROCNAME.
Referenced by main().
Input: stream pixac Return: 0 if OK, 1 on error
Definition at line 1319 of file pixcomp.c.
References PixaComp::boxa, boxaWriteStream(), PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::data, ERROR_INT, PixComp::h, NULL, PIXACOMP_VERSION_NUMBER, pixacompGetCount(), pixacompGetPixcomp(), PROCNAME, PixComp::size, PixComp::w, PixComp::xres, and PixComp::yres.
Referenced by pixacompWrite().
Input: fp (file stream) pixac text (<optional> identifying string; can be null) Return: 0 if OK, 1 on error
Definition at line 1362 of file pixcomp.c.
References ERROR_INT, PixaComp::nalloc, NULL, pixacompGetBoxaCount(), pixacompGetCount(), pixacompGetPixcomp(), pixcompWriteStreamInfo(), and PROCNAME.
Referenced by main().
Input: fp (file stream) pixc text (<optional> identifying string; can be null) Return: 0 if OK, 1 on error
Definition at line 1405 of file pixcomp.c.
References PixComp::cmapflag, PixComp::comptype, PixComp::d, ERROR_INT, PixComp::h, ImageFileFormatExtensions, NumImageFileFormatExtensions, PROCNAME, PixComp::size, PixComp::w, PixComp::xres, and PixComp::yres.
Referenced by main(), and pixacompWriteStreamInfo().
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.
Definition at line 1463 of file pixcomp.c.
References CALLOC, ERROR_PTR, FALSE, FREE, L_CLONE, L_INSERT, L_MAX, L_WARNING_INT, NULL, PIX_SRC, pixaAddPix(), pixacompGetCount(), pixacompGetPix(), pixaCreate(), pixAddBorder(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixClone(), pixConvertTo1(), pixConvertTo32(), pixConvertTo8(), pixCreate(), pixDestroy(), pixGetDimensions(), pixRasterop(), pixScale(), pixScaleToGray(), pixSetAll(), and PROCNAME.
Referenced by main().
const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static] |
Definition at line 99 of file pixcomp.c.
Referenced by pixacompCreate().
Definition at line 79 of file writefile.c.
Referenced by getFormatExtension(), pixaWriteFiles(), pixcompWriteStreamInfo(), and regTestWritePixAndCheck().
const char* ImageFileFormatExtensions[] |
Definition at line 80 of file writefile.c.