Leptonica  1.82.0
Image processing and image analysis suite
pixcomp.c File Reference
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static l_int32 pixacompExtendArray (PIXAC *pixac)
 
static l_int32 pixcompFastConvertToPdfData (PIXC *pixc, const char *title, l_uint8 **pdata, size_t *pnbytes)
 
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)
 
PIXCpixcompCopy (PIXC *pixcs)
 
l_ok pixcompGetDimensions (PIXC *pixc, l_int32 *pw, l_int32 *ph, l_int32 *pd)
 
l_ok pixcompGetParameters (PIXC *pixc, l_int32 *pxres, l_int32 *pyres, l_int32 *pcomptype, l_int32 *pcmapflag)
 
l_ok pixcompDetermineFormat (l_int32 comptype, l_int32 d, l_int32 cmapflag, l_int32 *pformat)
 
PIXpixCreateFromPixcomp (PIXC *pixc)
 
PIXACpixacompCreate (l_int32 n)
 
PIXACpixacompCreateWithInit (l_int32 n, l_int32 offset, 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_ok pixacompAddPix (PIXAC *pixac, PIX *pix, l_int32 comptype)
 
l_ok pixacompAddPixcomp (PIXAC *pixac, PIXC *pixc, l_int32 copyflag)
 
l_ok pixacompReplacePix (PIXAC *pixac, l_int32 index, PIX *pix, l_int32 comptype)
 
l_ok pixacompReplacePixcomp (PIXAC *pixac, l_int32 index, PIXC *pixc)
 
l_ok pixacompAddBox (PIXAC *pixac, BOX *box, l_int32 copyflag)
 
l_int32 pixacompGetCount (PIXAC *pixac)
 
PIXCpixacompGetPixcomp (PIXAC *pixac, l_int32 index, l_int32 copyflag)
 
PIXpixacompGetPix (PIXAC *pixac, l_int32 index)
 
l_ok 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_ok pixacompGetBoxGeometry (PIXAC *pixac, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
 
l_int32 pixacompGetOffset (PIXAC *pixac)
 
l_ok pixacompSetOffset (PIXAC *pixac, l_int32 offset)
 
PIXApixaCreateFromPixacomp (PIXAC *pixac, l_int32 accesstype)
 
l_ok pixacompJoin (PIXAC *pixacd, PIXAC *pixacs, l_int32 istart, l_int32 iend)
 
PIXACpixacompInterleave (PIXAC *pixac1, PIXAC *pixac2)
 
PIXACpixacompRead (const char *filename)
 
PIXACpixacompReadStream (FILE *fp)
 
PIXACpixacompReadMem (const l_uint8 *data, size_t size)
 
l_ok pixacompWrite (const char *filename, PIXAC *pixac)
 
l_ok pixacompWriteStream (FILE *fp, PIXAC *pixac)
 
l_ok pixacompWriteMem (l_uint8 **pdata, size_t *psize, PIXAC *pixac)
 
l_ok pixacompConvertToPdf (PIXAC *pixac, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
 
l_ok pixacompConvertToPdfData (PIXAC *pixac, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, l_uint8 **pdata, size_t *pnbytes)
 
l_ok pixacompFastConvertToPdfData (PIXAC *pixac, const char *title, l_uint8 **pdata, size_t *pnbytes)
 
l_ok pixacompWriteStreamInfo (FILE *fp, PIXAC *pixac, const char *text)
 
l_ok 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)
 
l_ok pixacompWriteFiles (PIXAC *pixac, const char *subdir)
 
l_ok pixcompWriteFile (const char *rootname, PIXC *pixc)
 

Variables

static const l_uint32 MaxPtrArraySize = 1000000
 
static const l_int32 InitialPtrArraySize = 20
 
static const size_t MaxDataSize = 1000000000
 
l_int32 NumImageFileFormatExtensions
 
const char * ImageFileFormatExtensions []
 

Detailed Description


     Pixcomp creation and destruction
          PIXC     *pixcompCreateFromPix()
          PIXC     *pixcompCreateFromString()
          PIXC     *pixcompCreateFromFile()
          void      pixcompDestroy()
          PIXC     *pixcompCopy()

     Pixcomp accessors
          l_int32   pixcompGetDimensions()
          l_int32   pixcompGetParameters()

     Pixcomp compression selection
          l_int32   pixcompDetermineFormat()

     Pixcomp conversion to Pix
          PIX      *pixCreateFromPixcomp()

     Pixacomp creation and destruction
          PIXAC    *pixacompCreate()
          PIXAC    *pixacompCreateWithInit()
          PIXAC    *pixacompCreateFromPixa()
          PIXAC    *pixacompCreateFromFiles()
          PIXAC    *pixacompCreateFromSA()
          void      pixacompDestroy()

     Pixacomp addition/replacement
          l_int32   pixacompAddPix()
          l_int32   pixacompAddPixcomp()
          static 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()
          l_int32   pixacompGetOffset()
          l_int32   pixacompSetOffset()

     Pixacomp conversion to Pixa
          PIXA     *pixaCreateFromPixacomp()

     Combining pixacomp
          l_int32   pixacompJoin()
          PIXAC    *pixacompInterleave()

     Pixacomp serialized I/O
          PIXAC    *pixacompRead()
          PIXAC    *pixacompReadStream()
          PIXAC    *pixacompReadMem()
          l_int32   pixacompWrite()
          l_int32   pixacompWriteStream()
          l_int32   pixacompWriteMem()

     Conversion to pdf
          l_int32   pixacompConvertToPdf()
          l_int32   pixacompConvertToPdfData()
          l_int32   pixacompFastConvertToPdfData()

     Output for debugging
          l_int32   pixacompWriteStreamInfo()
          l_int32   pixcompWriteStreamInfo()
          PIX      *pixacompDisplayTiledAndScaled()
          l_int32   pixacompWriteFiles()
          l_int32   pixcompWriteFile()

  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 jpeg compression quality
  can be specified using l_setJpegQuality(); otherwise the default is 75.

  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.

  There are two modes of use in accumulating images:
    (1) addition to the end of the array
    (2) random insertion (replacement) into the array

  In use, we assume that the array is fully populated up to the
  index value (n - 1), where n is the value of the pixcomp field n.
  Addition can only be made to the end of the fully populated array,
  at the index value n.  Insertion can be made randomly, but again
  only within the array of pixcomps; i.e., within the set of
  indices {0 .... n-1}.  The functions are pixacompReplacePix()
  and pixacompReplacePixcomp(), and they destroy the existing pixcomp.

  For addition to the end of the array, initialize the pixacomp with
  pixacompCreate(), which generates an empty array of pixcomps ptrs.
  For random insertion and replacement of pixcomp into a pixacomp,
  initialize a fully populated array using pixacompCreateWithInit().

  The offset field allows you to use an offset-based index to
  access the 0-based ptr array in the pixacomp.  This would typically
  be used to map the pixacomp array index to a page number, or v.v.
  By default, the offset is 0.  For example, suppose you have 50 images,
  corresponding to page numbers 10 - 59.  Then you could use
     pixac = pixacompCreateWithInit(50, 10, ...);
  This would allocate an array of 50 pixcomps, but if you asked for
  the pix at index 10, using pixacompGetPix(pixac, 10), it would
  apply the offset internally, returning the pix at index 0 in the array.

Definition in file pixcomp.c.

Function Documentation

◆ pixacompAddBox()

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

pixacompAddBox()

Parameters
[in]pixac
[in]box
[in]copyflagL_INSERT, L_COPY
Returns
0 if OK, 1 on error

Definition at line 1134 of file pixcomp.c.

References PixaComp::boxa, boxaAddBox(), L_COPY, and L_INSERT.

Referenced by pixacompInterleave().

◆ pixacompAddPix()

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

pixacompAddPix()

Parameters
[in]pixac
[in]pixto be added
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
0 if OK; 1 on error
Notes:
     (1) The array is filled up to the (n-1)-th element, and this
         converts the input pix to a pixc and adds it at
         the n-th position.
     (2) The pixc produced from the pix is owned by the pixac.
         The input pix is not affected.

Definition at line 923 of file pixcomp.c.

◆ pixacompAddPixcomp()

l_ok pixacompAddPixcomp ( PIXAC pixac,
PIXC pixc,
l_int32  copyflag 
)

pixacompAddPixcomp()

Parameters
[in]pixac
[in]pixcto be added by insertion
[in]copyflagL_INSERT, L_COPY
Returns
0 if OK; 1 on error
Notes:
     (1) Anything added to a pixac is owned by the pixac.
         So do not L_INSERT a pixc that is owned by another pixac,
         or destroy a pixc that has been L_INSERTed.

Definition at line 965 of file pixcomp.c.

References L_COPY, L_INSERT, PixaComp::n, PixaComp::nalloc, pixacompExtendArray(), PixaComp::pixc, and pixcompCopy().

Referenced by pixacompInterleave(), and pixacompJoin().

◆ pixacompConvertToPdf()

l_ok pixacompConvertToPdf ( PIXAC pixac,
l_int32  res,
l_float32  scalefactor,
l_int32  type,
l_int32  quality,
const char *  title,
const char *  fileout 
)

pixacompConvertToPdf()

Parameters
[in]pixaccontaining images all at the same resolution
[in]resoverride the resolution of each input image, in ppi; 0 to respect the resolution embedded in the input
[in]scalefactorscaling factor applied to each image; > 0.0
[in]typeencoding type (L_JPEG_ENCODE, L_G4_ENCODE, L_FLATE_ENCODE, L_JP2K_ENCODE, or L_DEFAULT_ENCODE for default)
[in]qualityused for JPEG only; 0 for default (75)
[in]title[optional] pdf title
[in]fileoutpdf file of all images
Returns
0 if OK, 1 on error
Notes:
     (1) This follows closely the function pixaConvertToPdf() in pdfio.c.
     (2) The images are encoded with G4 if 1 bpp; JPEG if 8 bpp without
         colormap and many colors, or 32 bpp; FLATE for anything else.
     (3) The scalefactor must be > 0.0; otherwise it is set to 1.0.
     (4) Specifying one of the three encoding types for type forces
         all images to be compressed with that type.  Use 0 to have
         the type determined for each image based on depth and whether
         or not it has a colormap.
     (5) If all images are jpeg compressed, don't require scaling
         and have the same resolution, it is much faster to skip
         transcoding with pixacompFastConvertToPdfData(), and then
         write the data out to file.

Definition at line 2002 of file pixcomp.c.

References l_binaryWrite(), and pixacompConvertToPdfData().

◆ pixacompConvertToPdfData()

l_ok pixacompConvertToPdfData ( PIXAC pixac,
l_int32  res,
l_float32  scalefactor,
l_int32  type,
l_int32  quality,
const char *  title,
l_uint8 **  pdata,
size_t *  pnbytes 
)

pixacompConvertToPdfData()

Parameters
[in]pixaccontaining images all at the same resolution
[in]resinput resolution of all images
[in]scalefactorscaling factor applied to each image; > 0.0
[in]typeencoding type (L_JPEG_ENCODE, L_G4_ENCODE, L_FLATE_ENCODE, L_JP2K_ENCODE, or L_DEFAULT_ENCODE for default)
[in]qualityused for JPEG only; 0 for default (75)
[in]title[optional] pdf title
[out]pdataoutput pdf data (of all images
[out]pnbytessize of output pdf data
Returns
0 if OK, 1 on error
Notes:
     (1) See pixacompConvertToPdf().

Definition at line 2055 of file pixcomp.c.

References L_DEFAULT_ENCODE, L_FLATE_ENCODE, L_G4_ENCODE, L_JP2K_ENCODE, L_JPEG_ENCODE, pixacompGetCount(), pixacompGetOffset(), pixacompGetPix(), and ptraCreate().

Referenced by pixacompConvertToPdf().

◆ pixacompCreate()

PIXAC* pixacompCreate ( l_int32  n)

pixacompCreate()

Parameters
[in]ninitial number of ptrs
Returns
pixac, or NULL on error

Definition at line 609 of file pixcomp.c.

Referenced by partifyPixac(), and pixacompInterleave().

◆ pixacompCreateFromFiles()

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

pixacompCreateFromFiles()

Parameters
[in]dirname
[in]substr[optional] substring filter on filenames; can be null
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
pixac, or NULL on error
Notes:
     (1) dirname is the full path for the directory.
     (2) substr 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 comptype == 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 797 of file pixcomp.c.

Referenced by partifyFiles().

◆ pixacompCreateFromPixa()

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

pixacompCreateFromPixa()

Parameters
[in]pixa
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
[in]accesstypeL_COPY, L_CLONE, L_COPY_CLONE
Returns
0 if OK, 1 on error
Notes:
     (1) If format == 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.
     (2) accesstype is used to extract a boxa from pixa.
     (3) To compress jpeg with a quality other than the default (75), use
            l_jpegSetQuality()

Definition at line 738 of file pixcomp.c.

◆ pixacompCreateFromSA()

PIXAC* pixacompCreateFromSA ( SARRAY sa,
l_int32  comptype 
)

pixacompCreateFromSA()

Parameters
[in]safull pathnames for all files
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
pixac, or NULL on error
Notes:
     (1) Use comptype == 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 836 of file pixcomp.c.

◆ pixacompCreateWithInit()

PIXAC* pixacompCreateWithInit ( l_int32  n,
l_int32  offset,
PIX pix,
l_int32  comptype 
)

pixacompCreateWithInit()

Parameters
[in]ninitial number of ptrs
[in]offsetdifference: accessor index - pixacomp array index
[in]pix[optional] initialize each ptr in pixacomp to this pix; can be NULL
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
pixac, or NULL on error
Notes:
     (1) Initializes a pixacomp to be fully populated with pix,
         compressed using comptype.  If pix == NULL, comptype
         is ignored.
     (2) Typically, the array is initialized with a tiny pix.
         This is most easily done by setting pix == NULL, causing
         initialization of each array element with a tiny placeholder
         pix (w = h = d = 1), using comptype = IFF_TIFF_G4 .
     (3) Example usage:
           // Generate pixacomp for pages 30 - 49.  This has an array
           // size of 20 and the page number offset is 30.
           PixaComp *pixac = pixacompCreateWithInit(20, 30, NULL,
                                                    IFF_TIFF_G4);
           // Now insert png-compressed images into the initialized array
           for (pageno = 30; pageno < 50; pageno++) {
               Pix *pixt = ...   // derived from image[pageno]
               if (pixt)
                   pixacompReplacePix(pixac, pageno, pixt, IFF_PNG);
               pixDestroy(&pixt);
           }
         The result is a pixac with 20 compressed strings, and with
         selected pixt replacing the placeholders.
         To extract the image for page 38, which is decompressed
         from element 8 in the array, use:
           pixt = pixacompGetPix(pixac, 38);

Definition at line 674 of file pixcomp.c.

◆ pixacompDestroy()

void pixacompDestroy ( PIXAC **  ppixac)

pixacompDestroy()

Parameters
[in,out]ppixacuse ptr address so it will be nulled
Returns
void
Notes:
     (1) Always nulls the input ptr.

Definition at line 878 of file pixcomp.c.

References PixaComp::boxa, boxaDestroy(), PixaComp::n, PixaComp::pixc, and pixcompDestroy().

Referenced by pixaReadBoth().

◆ pixacompDisplayTiledAndScaled()

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

pixacompDisplayTiledAndScaled()

Parameters
[in]pixac
[in]outdepthoutput depth: 1, 8 or 32 bpp
[in]tilewidtheach pix is scaled to this width
[in]ncolsnumber of tiles in each row
[in]background0 for white, 1 for black; this is the color of the spacing between the images
[in]spacingbetween images, and on outside
[in]borderwidth of additional black border on each image; use 0 for no border
Returns
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) See pixaDisplayTiledAndScaled() for details.

Definition at line 2396 of file pixcomp.c.

References L_COPY, pixaCreateFromPixacomp(), pixaDestroy(), and pixaDisplayTiledAndScaled().

◆ pixacompExtendArray()

static l_int32 pixacompExtendArray ( PIXAC pixac)
static

pixacompExtendArray()

Parameters
[in]pixac
Returns
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.
     (2) The max number of pixcomp ptrs is 1M.

Definition at line 1012 of file pixcomp.c.

References PixaComp::nalloc.

Referenced by pixacompAddPixcomp().

◆ pixacompFastConvertToPdfData()

l_ok pixacompFastConvertToPdfData ( PIXAC pixac,
const char *  title,
l_uint8 **  pdata,
size_t *  pnbytes 
)

pixacompFastConvertToPdfData()

Parameters
[in]pixaccontaining images all at the same resolution
[in]title[optional] pdf title
[out]pdataoutput pdf data (of all images
[out]pnbytessize of output pdf data
Returns
0 if OK, 1 on error
Notes:
     (1) This generates the pdf without transcoding if all the
         images in pixac are compressed with jpeg.
         Images not jpeg compressed are skipped.
     (2) It assumes all images have the same resolution, and that
         the resolution embedded in each jpeg file is correct.

Definition at line 2171 of file pixcomp.c.

References L_NOCOPY, pixacompGetCount(), pixacompGetPixcomp(), pixcompGetParameters(), and ptraCreate().

◆ pixacompGetBox()

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

pixacompGetBox()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
[in]accesstypeL_COPY or L_CLONE
Returns
box if null, not automatically an error, or NULL on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.
     (2) There is always a boxa with a pixac, and it is initialized so
         that each box ptr is NULL.
     (3) In general, we expect that there is either a box associated
         with each pixc, or no boxes at all in the boxa.
     (4) 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 1353 of file pixcomp.c.

References Boxa::box, PixaComp::boxa, boxClone(), boxCopy(), L_CLONE, L_COPY, Boxa::n, and PixaComp::offset.

Referenced by pixacompGetBoxGeometry(), and pixacompInterleave().

◆ pixacompGetBoxa()

BOXA* pixacompGetBoxa ( PIXAC pixac,
l_int32  accesstype 
)

pixacompGetBoxa()

Parameters
[in]pixac
[in]accesstypeL_COPY, L_CLONE, L_COPY_CLONE
Returns
boxa, or NULL on error

Definition at line 1294 of file pixcomp.c.

References PixaComp::boxa, boxaCopy(), L_CLONE, L_COPY, and L_COPY_CLONE.

Referenced by pixacompJoin(), and pixaCreateFromPixacomp().

◆ pixacompGetBoxaCount()

l_int32 pixacompGetBoxaCount ( PIXAC pixac)

pixacompGetBoxaCount()

Parameters
[in]pixac
Returns
count, or 0 on error

Definition at line 1318 of file pixcomp.c.

References PixaComp::boxa, and boxaGetCount().

Referenced by pixacompInterleave(), pixacompJoin(), and pixacompWriteStreamInfo().

◆ pixacompGetBoxGeometry()

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

pixacompGetBoxGeometry()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
[out]px,py,pw,ph[optional] each can be null
Returns
0 if OK, 1 on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.

Definition at line 1400 of file pixcomp.c.

References boxDestroy(), boxGetGeometry(), L_CLONE, PixaComp::n, PixaComp::offset, and pixacompGetBox().

◆ pixacompGetCount()

◆ pixacompGetOffset()

l_int32 pixacompGetOffset ( PIXAC pixac)

pixacompGetOffset()

Parameters
[in]pixac
Returns
offset, or 0 on error
Notes:
     (1) The offset is the difference between the caller's view of
         the index into the array and the actual array index.
         By default it is 0.

Definition at line 1440 of file pixcomp.c.

References PixaComp::offset.

Referenced by dewarpaCreateFromPixacomp(), pixacompConvertToPdfData(), and pixaCreateFromPixacomp().

◆ pixacompGetPix()

PIX* pixacompGetPix ( PIXAC pixac,
l_int32  index 
)

pixacompGetPix()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
Returns
pix, or NULL on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.

Definition at line 1227 of file pixcomp.c.

References L_NOCOPY, PixaComp::n, PixaComp::offset, pixacompGetPixcomp(), and pixCreateFromPixcomp().

Referenced by dewarpaCreateFromPixacomp(), partifyPixac(), pixacompConvertToPdfData(), and pixaCreateFromPixacomp().

◆ pixacompGetPixcomp()

PIXC* pixacompGetPixcomp ( PIXAC pixac,
l_int32  index,
l_int32  copyflag 
)

pixacompGetPixcomp()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
[in]copyflagL_NOCOPY, L_COPY
Returns
pixc, or NULL on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.
     (2) If copyflag == L_NOCOPY, the pixc is owned by pixac; do
         not destroy.

Definition at line 1190 of file pixcomp.c.

References L_COPY, L_NOCOPY, PixaComp::n, PixaComp::offset, PixaComp::pixc, and pixcompCopy().

Referenced by pixacompFastConvertToPdfData(), pixacompGetPix(), pixacompInterleave(), pixacompJoin(), pixacompReplacePixcomp(), pixacompWriteFiles(), pixacompWriteStream(), and pixacompWriteStreamInfo().

◆ pixacompGetPixDimensions()

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

pixacompGetPixDimensions()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
[out]pw,ph,pd[optional] each can be null
Returns
0 if OK, 1 on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.

Definition at line 1262 of file pixcomp.c.

References PixaComp::n, PixaComp::offset, PixaComp::pixc, and pixcompGetDimensions().

◆ pixacompInterleave()

PIXAC* pixacompInterleave ( PIXAC pixac1,
PIXAC pixac2 
)

pixacompInterleave()

Parameters
[in]pixac1first src pixac
[in]pixac2second src pixac
Returns
pixacd interleaved from sources, or NULL on error.
Notes:
     (1) If the two pixac have different sizes, a warning is issued,
         and the number of pairs returned is the minimum size.

Definition at line 1606 of file pixcomp.c.

References L_COPY, L_INSERT, pixacompAddBox(), pixacompAddPixcomp(), pixacompCreate(), pixacompGetBox(), pixacompGetBoxaCount(), pixacompGetCount(), and pixacompGetPixcomp().

◆ pixacompJoin()

l_ok pixacompJoin ( PIXAC pixacd,
PIXAC pixacs,
l_int32  istart,
l_int32  iend 
)

pixacompJoin()

Parameters
[in]pixacddest pixac; add to this one
[in]pixacs[optional] source pixac; add from this one
[in]istartstarting index in pixacs
[in]iendending index in pixacs; use -1 to cat all
Returns
0 if OK, 1 on error
Notes:
     (1) This appends a clone of each indicated pixc in pixcas to pixcad
     (2) istart < 0 is taken to mean 'read from the start' (istart = 0)
     (3) iend < 0 means 'read to the end'
     (4) If pixacs is NULL or contains no pixc, this is a no-op.

Definition at line 1553 of file pixcomp.c.

References boxaDestroy(), boxaJoin(), L_CLONE, L_COPY, L_NOCOPY, pixacompAddPixcomp(), pixacompGetBoxa(), pixacompGetBoxaCount(), pixacompGetCount(), and pixacompGetPixcomp().

◆ pixacompRead()

PIXAC* pixacompRead ( const char *  filename)

pixacompRead()

Parameters
[in]filename
Returns
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 1668 of file pixcomp.c.

References fopenReadStream(), and pixacompReadStream().

Referenced by pixaReadBoth().

◆ pixacompReadMem()

PIXAC* pixacompReadMem ( const l_uint8 *  data,
size_t  size 
)

pixacompReadMem()

Parameters
[in]datain pixacomp format
[in]sizeof data
Returns
pixac, or NULL on error
Notes:
     (1) Deseralizes a buffer of pixacomp data into a pixac in memory.

Definition at line 1809 of file pixcomp.c.

References fopenReadFromMemory(), and pixacompReadStream().

◆ pixacompReadStream()

PIXAC* pixacompReadStream ( FILE *  fp)

pixacompReadStream()

Parameters
[in]fpfile stream
Returns
pixac, or NULL on error
Notes:
     (1) It is OK for the pixacomp to be empty.

Definition at line 1700 of file pixcomp.c.

References PIXACOMP_VERSION_NUMBER.

Referenced by pixacompRead(), and pixacompReadMem().

◆ pixacompReplacePix()

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

pixacompReplacePix()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
[in]pixowned by the caller
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
0 if OK; 1 on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.
     (2) The input pix is converted to a pixc, which is then inserted
         into the pixac.

Definition at line 1054 of file pixcomp.c.

References PixaComp::offset, and pixacompGetCount().

◆ pixacompReplacePixcomp()

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

pixacompReplacePixcomp()

Parameters
[in]pixac
[in]indexcaller's view of index within pixac; includes offset
[in]pixcto replace existing one, which is destroyed
Returns
0 if OK; 1 on error
Notes:
     (1) The index includes the offset, which must be subtracted
         to get the actual index into the ptr array.
     (2) The inserted pixc is now owned by the pixac.  The caller
         must not destroy it.

Definition at line 1099 of file pixcomp.c.

References L_NOCOPY, PixaComp::offset, pixacompGetCount(), pixacompGetPixcomp(), PixaComp::pixc, and pixcompDestroy().

◆ pixacompSetOffset()

l_ok pixacompSetOffset ( PIXAC pixac,
l_int32  offset 
)

pixacompSetOffset()

Parameters
[in]pixac
[in]offsetnon-negative
Returns
0 if OK, 1 on error
Notes:
     (1) The offset is the difference between the caller's view of
         the index into the array and the actual array index.
         By default it is 0.

Definition at line 1465 of file pixcomp.c.

References PixaComp::offset.

Referenced by pixaCreateFromPixacomp().

◆ pixacompWrite()

l_ok pixacompWrite ( const char *  filename,
PIXAC pixac 
)

pixacompWrite()

Parameters
[in]filename
[in]pixac
Returns
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 1844 of file pixcomp.c.

References fopenWriteStream(), and pixacompWriteStream().

◆ pixacompWriteFiles()

l_ok pixacompWriteFiles ( PIXAC pixac,
const char *  subdir 
)

pixacompWriteFiles()

Parameters
[in]pixac
[in]subdirsubdirectory of /tmp
Returns
0 if OK, 1 on error

Definition at line 2430 of file pixcomp.c.

References L_NOCOPY, lept_mkdir(), pixacompGetCount(), pixacompGetPixcomp(), and pixcompWriteFile().

◆ pixacompWriteMem()

l_ok pixacompWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PIXAC pixac 
)

pixacompWriteMem()

Parameters
[out]pdataserialized data of pixac
[out]psizesize of serialized data
[in]pixac
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a pixac in memory and puts the result in a buffer.

Definition at line 1923 of file pixcomp.c.

References fopenWriteWinTempfile(), l_binaryReadStream(), and pixacompWriteStream().

◆ pixacompWriteStream()

l_ok pixacompWriteStream ( FILE *  fp,
PIXAC pixac 
)

◆ pixacompWriteStreamInfo()

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

pixacompWriteStreamInfo()

Parameters
[in]fpfile stream
[in]pixac
[in]text[optional] identifying string; can be null
Returns
0 if OK, 1 on error

Definition at line 2296 of file pixcomp.c.

References L_NOCOPY, PixaComp::nalloc, PixaComp::offset, pixacompGetBoxaCount(), pixacompGetCount(), pixacompGetPixcomp(), and pixcompWriteStreamInfo().

◆ pixaCreateFromPixacomp()

PIXA* pixaCreateFromPixacomp ( PIXAC pixac,
l_int32  accesstype 
)

pixaCreateFromPixacomp()

Parameters
[in]pixac
[in]accesstypeL_COPY, L_CLONE, L_COPY_CLONE; for boxa
Returns
pixa if OK, or NULL on error
Notes:
     (1) Because the pixa has no notion of offset, the offset must
         be set to 0 before the conversion, so that pixacompGetPix()
         fetches all the pixcomps.  It is reset at the end.

Definition at line 1495 of file pixcomp.c.

References Pixa::boxa, boxaDestroy(), L_CLONE, L_COPY, L_COPY_CLONE, L_INSERT, pixaAddPix(), pixacompGetBoxa(), pixacompGetCount(), pixacompGetOffset(), pixacompGetPix(), pixacompSetOffset(), and pixaCreate().

Referenced by pixacompDisplayTiledAndScaled(), and pixaReadBoth().

◆ pixcompCopy()

PIXC* pixcompCopy ( PIXC pixcs)

pixcompCopy()

Parameters
[in]pixcs
Returns
pixcd, or NULL on error
Notes:
     (1) Limit the size of the compressed pix to 500 MB.

Definition at line 395 of file pixcomp.c.

References PixComp::size.

Referenced by pixacompAddPixcomp(), and pixacompGetPixcomp().

◆ pixcompCreateFromFile()

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

pixcompCreateFromFile()

Parameters
[in]filename
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
pixc, or NULL on error
Notes:
     (1) Use comptype == 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 298 of file pixcomp.c.

◆ pixcompCreateFromPix()

PIXC* pixcompCreateFromPix ( PIX pix,
l_int32  comptype 
)

pixcompCreateFromPix()

Parameters
[in]pix
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
Returns
pixc, or NULL on error
Notes:
     (1) Use comptype == IFF_DEFAULT to have the compression
         type automatically determined.
     (2) To compress jpeg with a quality other than the default (75), use
            l_jpegSetQuality()

Definition at line 194 of file pixcomp.c.

◆ pixcompCreateFromString()

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

pixcompCreateFromString()

Parameters
[in]datacompressed string
[in]sizenumber of bytes
[in]copyflagL_INSERT or L_COPY
Returns
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 250 of file pixcomp.c.

References PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::data, PixComp::h, l_binaryCopy(), L_COPY, L_INSERT, pixReadHeaderMem(), PixComp::size, and PixComp::w.

◆ pixcompDestroy()

void pixcompDestroy ( PIXC **  ppixc)

pixcompDestroy()

Parameters
[in,out]ppixcuse ptr address so it will be nulled
Returns
void
Notes:
     (1) Always nulls the input ptr.

Definition at line 361 of file pixcomp.c.

References PixComp::data, and PixComp::text.

Referenced by pixacompDestroy(), and pixacompReplacePixcomp().

◆ pixcompDetermineFormat()

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

pixcompDetermineFormat()

Parameters
[in]comptypeIFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG
[in]dpix depth
[in]cmapflag1 if pix to be compressed as a colormap; 0 otherwise
[out]pformatIFF_TIFF, IFF_PNG or IFF_JFIF_JPEG
Returns
0 if OK; 1 on error
Notes:
     (1) This determines the best format for a pix, given both
         the request (comptype) and the image characteristics.
     (2) If comptype == 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 d == 8 with no colormap and:
         * you wish to compress with png, use comptype == IFF_PNG
         * you wish to compress with jpeg, use either
           comptype == IFF_JFIF_JPEG or comptype == IFF_DEFAULT.
     (4) If the pix cannot be compressed by the input value of
         comptype, this selects IFF_PNG, which can compress all pix.

Definition at line 514 of file pixcomp.c.

◆ pixcompFastConvertToPdfData()

static l_int32 pixcompFastConvertToPdfData ( PIXC pixc,
const char *  title,
l_uint8 **  pdata,
size_t *  pnbytes 
)
static

pixcompFastConvertToPdfData()

Parameters
[in]pixccontaining images all at the same resolution
[in]title[optional] pdf title
[out]pdataoutput pdf data (of all images
[out]pnbytessize of output pdf data
Returns
0 if OK, 1 on error
Notes:
     (1) This generates the pdf without transcoding.
     (2) It assumes all images are jpeg encoded, have the same
         resolution, and that the resolution embedded in each
         jpeg file is correct.  (It is transferred to the pdf
         via the cid.)

Definition at line 2256 of file pixcomp.c.

References cidConvertToPdfData(), PixComp::data, l_binaryCopy(), l_generateJpegDataMem(), and PixComp::size.

◆ pixcompGetDimensions()

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

pixcompGetDimensions()

Parameters
[in]pixc
[out]pw,ph,pd[optional]
Returns
0 if OK, 1 on error

Definition at line 444 of file pixcomp.c.

References PixComp::d, PixComp::h, and PixComp::w.

Referenced by pixacompGetPixDimensions().

◆ pixcompGetParameters()

l_ok pixcompGetParameters ( PIXC pixc,
l_int32 *  pxres,
l_int32 *  pyres,
l_int32 *  pcomptype,
l_int32 *  pcmapflag 
)

pixcompGetParameters()

Parameters
[in]pixc
[out]pxres,pyres,pcomptype,pcmapflag[optional]
Returns
0 if OK, 1 on error

Definition at line 468 of file pixcomp.c.

References PixComp::cmapflag, PixComp::comptype, PixComp::xres, and PixComp::yres.

Referenced by pixacompFastConvertToPdfData().

◆ pixcompWriteFile()

l_ok pixcompWriteFile ( const char *  rootname,
PIXC pixc 
)

pixcompWriteFile()

Parameters
[in]rootname
[in]pixc
Returns
0 if OK, 1 on error
Notes:
     (1) The compressed data is written to file, and the filename is
         generated by appending the format extension to rootname.

Definition at line 2470 of file pixcomp.c.

Referenced by pixacompWriteFiles().

◆ pixcompWriteStreamInfo()

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

pixcompWriteStreamInfo()

Parameters
[in]fpfile stream
[in]pixc
[in]text[optional] identifying string; can be null
Returns
0 if OK, 1 on error

Definition at line 2340 of file pixcomp.c.

References PixComp::cmapflag, PixComp::comptype, PixComp::d, PixComp::h, PixComp::size, PixComp::w, PixComp::xres, and PixComp::yres.

Referenced by pixacompWriteStreamInfo().

◆ pixCreateFromPixcomp()

PIX* pixCreateFromPixcomp ( PIXC pixc)

Variable Documentation

◆ InitialPtrArraySize

const l_int32 InitialPtrArraySize = 20
static

n'importe quoi

Definition at line 160 of file pixcomp.c.