Leptonica 1.68
C Image Processing Library

pixafunc2.c File Reference

Render a Pixa or Pixaa in a Pix. More...

#include <string.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

PIXpixaDisplay (PIXA *pixa, l_int32 w, l_int32 h)
PIXpixaDisplayOnColor (PIXA *pixa, l_int32 w, l_int32 h, l_uint32 bgcolor)
PIXpixaDisplayRandomCmap (PIXA *pixa, l_int32 w, l_int32 h)
PIXpixaDisplayOnLattice (PIXA *pixa, l_int32 xspace, l_int32 yspace)
PIXpixaDisplayUnsplit (PIXA *pixa, l_int32 nx, l_int32 ny, l_int32 borderwidth, l_uint32 bordercolor)
PIXpixaDisplayTiled (PIXA *pixa, l_int32 maxwidth, l_int32 background, l_int32 spacing)
PIXpixaDisplayTiledInRows (PIXA *pixa, l_int32 outdepth, l_int32 maxwidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
PIXpixaDisplayTiledAndScaled (PIXA *pixa, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
PIXpixaaDisplay (PIXAA *pixaa, l_int32 w, l_int32 h)
PIXpixaaDisplayByPixa (PIXAA *pixaa, l_int32 xspace, l_int32 yspace, l_int32 maxw)
PIXApixaaDisplayTiledAndScaled (PIXAA *pixaa, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)

Detailed Description

Render a Pixa or Pixaa in a Pix.

    Pixa Display (render into a pix)
         PIX      *pixaDisplay()
         PIX      *pixaDisplayOnColor()
         PIX      *pixaDisplayRandomCmap()
         PIX      *pixaDisplayOnLattice()
         PIX      *pixaDisplayUnsplit()
         PIX      *pixaDisplayTiled()
         PIX      *pixaDisplayTiledInRows()
         PIX      *pixaDisplayTiledAndScaled()

    Pixaa Display (render into a pix)
         PIX      *pixaaDisplay()
         PIX      *pixaaDisplayByPixa()
         PIXA     *pixaaDisplayTiledAndScaled()

We give seven methods for displaying a pixa in a pix.
Some work for 1 bpp input; others for any input depth.
Some give an output depth that depends on the input depth;
others give a different output depth or allow you to choose it.
Some use a boxes to determine where each pix goes; others tile
onto a regular lattice; yet others tile onto an irregular lattice.

Here is a brief description of what these functions do.

  pixaDisplay()
      This uses the boxes to lay out each pix.  It is typically
      used to reconstruct a pix that has been broken into components.
  pixaDisplayOnColor()
      pixaDisplay() with choice of background color
  pixaDisplayRandomCmap()
      This also uses the boxes to lay out each pix.  However, it creates
      a colormapped dest, where each 1 bpp pix is given a randomly
      generated color (up to 256 are used).
  pixaDisplayOnLattice()
      This puts each pix, sequentially, onto a regular lattice,
      omitting any pix that are too big for the lattice size.
      This is useful, for example, to store bitmapped fonts,
      where all the characters are stored in a single image.
  pixaDisplayUnsplit()
      This lays out a mosaic of tiles (the pix in the pixa) that
      are all of equal size.  (Don't use this for unequal sized pix!)
      For example, it can be used to invert the action of
      pixaSplitPix().
  pixaDisplayTiled()
      Like pixaDisplayOnLattice(), this places each pix on a regular
      lattice, but here the lattice size is determined by the
      largest component, and no components are omitted.  This is
      dangerous if there are thousands of small components and
      one or more very large one, because the size of the resulting
      pix can be huge!
  pixaDisplayTiledInRows()
      This puts each pix down in a series of rows, where the upper
      edges of each pix in a row are alined and there is a uniform
      spacing between the pix.  The height of each row is determined
      by the tallest pix that was put in the row.  This function
      is a reasonably efficient way to pack the subimages.
  pixaDisplayTiledAndScaled()
      This scales each pix to a given width and output depth,
      and then tiles them in rows with a given number placed in
      each row.  This is very useful for presenting a sequence
      of images that can be at different resolutions, but which
      are derived from the same initial image.

Definition in file pixafunc2.c.


Function Documentation

PIX* pixaDisplay ( PIXA pixa,
l_int32  w,
l_int32  h 
)

pixaDisplay()

Input: pixa w, h (if set to 0, determines the size from the b.b. of the components in pixa) Return: pix, or null on error

Notes: (1) This uses the boxes to place each pix in the rendered composite. (2) Set w = h = 0 to use the b.b. of the components to determine the size of the returned pix. (3) Uses the first pix in pixa to determine the depth. (4) The background is written "white". On 1 bpp, each successive pix is "painted" (adding foreground), whereas for grayscale or color each successive pix is blitted with just the src. (5) If the pixa is empty, returns an empty 1 bpp pix.

Definition at line 110 of file pixafunc2.c.

References boxaDestroy(), boxaGetExtent(), ERROR_PTR, L_CLONE, L_WARNING, NULL, PIX_PAINT, PIX_SRC, pixaGetBoxa(), pixaGetBoxGeometry(), pixaGetCount(), pixaGetPix(), pixCreate(), pixDestroy(), pixGetDepth(), pixRasterop(), pixSetAll(), and PROCNAME.

Referenced by DisplayPix(), DisplayResult(), main(), PixaSaveDisplay(), pixDisplayColorArray(), pixGetTextlineCenters(), pixItalicWords(), pixSelectByAreaFraction(), pixSelectByAreaPerimRatio(), pixSelectBySize(), pixSelectByWidthHeightRatio(), pixSetUnderTransparency(), PixTest1(), PixTest2(), RotateTest(), shearTest(), TestImage(), TestProjection(), and wshedRenderColors().

PIX* pixaDisplayOnColor ( PIXA pixa,
l_int32  w,
l_int32  h,
l_uint32  bgcolor 
)

pixaDisplayOnColor()

Input: pixa w, h (if set to 0, determines the size from the b.b. of the components in pixa) color (background color to use) Return: pix, or null on error

Notes: (1) This uses the boxes to place each pix in the rendered composite. (2) Set w = h = 0 to use the b.b. of the components to determine the size of the returned pix. (3) If any pix in are colormapped, or if the pix have different depths, it returns a 32 bpp pix. Otherwise, the depth of the returned pixa equals that of the pix in . (4) If the pixa is empty, return null.

Definition at line 184 of file pixafunc2.c.

References boxaDestroy(), boxaGetExtent(), ERROR_PTR, L_CLONE, L_INSERT, L_WARNING, NULL, PIX_SRC, pixaAddPix(), pixaAnyColormaps(), pixaCopy(), pixaCreate(), pixaDestroy(), pixaGetBoxa(), pixaGetBoxGeometry(), pixaGetCount(), pixaGetDepthInfo(), pixaGetPix(), pixConvertTo32(), pixCreate(), pixDestroy(), pixRasterop(), pixSetAll(), pixSetAllArbitrary(), PROCNAME, and x3.

Referenced by main().

PIX* pixaDisplayRandomCmap ( PIXA pixa,
l_int32  w,
l_int32  h 
)

pixaDisplayRandomCmap()

Input: pixa (of 1 bpp components, with boxa) w, h (if set to 0, determines the size from the b.b. of the components in pixa) Return: pix (8 bpp, cmapped, with random colors on the components), or null on error

Notes: (1) This uses the boxes to place each pix in the rendered composite. (2) By default, the background color is: black, cmap index 0. This can be changed by pixcmapResetColor()

Definition at line 271 of file pixafunc2.c.

References boxaDestroy(), boxaGetExtent(), ERROR_PTR, L_CLONE, NULL, PIX_PAINT, pixaGetBoxa(), pixaGetBoxGeometry(), pixaGetCount(), pixaGetPix(), pixcmapCreateRandom(), pixConvert1To8(), pixCreate(), pixDestroy(), pixGetDepth(), pixRasterop(), pixSetColormap(), and PROCNAME.

Referenced by main(), pixGetRegionsBinary(), and wshedRenderColors().

PIX* pixaDisplayOnLattice ( PIXA pixa,
l_int32  xspace,
l_int32  yspace 
)

pixaDisplayOnLattice()

Input: pixa xspace yspace Return: pix of composite images, or null on error

Notes: (1) This places each pix on sequentially on a regular lattice in the rendered composite. If a pix is too large to fit in the allocated lattice space, it is not rendered. (2) If any pix has a colormap, all pix are rendered in rgb. (3) This is useful when putting bitmaps of components, such as characters, into a single image.

Definition at line 342 of file pixafunc2.c.

References ERROR_PTR, L_CLONE, L_INSERT, NULL, PIX_PAINT, pixaAddPix(), pixaAnyColormaps(), pixaCopy(), pixaCreate(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixaGetPixDimensions(), pixConvertTo32(), pixCreate(), pixDestroy(), pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by jbDataSave(), and main().

PIX* pixaDisplayUnsplit ( PIXA pixa,
l_int32  nx,
l_int32  ny,
l_int32  borderwidth,
l_uint32  bordercolor 
)

pixaDisplayUnsplit()

Input: pixa nx (number of mosaic cells horizontally) ny (number of mosaic cells vertically) borderwidth (of added border on all sides) bordercolor (in our RGBA format: 0xrrggbbaa) Return: pix of tiled images, or null on error

Notes: (1) This is a logical inverse of pixaSplitPix(). It constructs a pix from a mosaic of tiles, all of equal size. (2) For added generality, a border of arbitrary color can be added to each of the tiles. (3) In use, pixa will typically have either been generated from pixaSplitPix() or will derived from a pixa that was so generated. (4) All pix in the pixa must be of equal depth, and, if colormapped, have the same colormap.

Definition at line 428 of file pixafunc2.c.

References ERROR_PTR, L_CLONE, L_MAX, NULL, nx, ny, PIX_SRC, pixaGetCount(), pixaGetPix(), pixaGetPixDimensions(), pixCopyColormap(), pixCreate(), pixDestroy(), pixRasterop(), pixSetAllArbitrary(), and PROCNAME.

Referenced by main().

PIX* pixaDisplayTiled ( PIXA pixa,
l_int32  maxwidth,
l_int32  background,
l_int32  spacing 
)

pixaDisplayTiled()

Input: pixa maxwidth (of output image) background (0 for white, 1 for black) spacing Return: pix of tiled images, or null on error

Notes: (1) This saves a pixa to a single image file of width not to exceed maxwidth, with background color either white or black, and with each subimage spaced on a regular lattice. (2) The lattice size is determined from the largest width and height, separately, of all pix in the pixa. (3) All pix in the pixa must be of equal depth. (4) If any pix has a colormap, all pix are rendered in rgb. (5) Careful: because no components are omitted, this is dangerous if there are thousands of small components and one or more very large one, because the size of the resulting pix can be huge!

Definition at line 501 of file pixafunc2.c.

References ERROR_PTR, L_CLONE, L_INSERT, L_MAX, ncols, NULL, PIX_SRC, pixaAddPix(), pixaAnyColormaps(), pixaCopy(), pixaCreate(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixConvertTo32(), pixCreate(), pixDestroy(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetWidth(), pixRasterop(), pixSetAll(), and PROCNAME.

Referenced by main(), and pixaGenerateFont().

PIX* pixaDisplayTiledInRows ( PIXA pixa,
l_int32  outdepth,
l_int32  maxwidth,
l_float32  scalefactor,
l_int32  background,
l_int32  spacing,
l_int32  border 
)

pixaDisplayTiledInRows()

Input: pixa outdepth (output depth: 1, 8 or 32 bpp) maxwidth (of output image) scalefactor (applied to every pix; use 1.0 for no scaling) 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 black border added to each image; use 0 for no border) Return: pixd (of tiled images), or null on error

Notes: (1) This saves a pixa to a single image file of width not to exceed maxwidth, with background color either white or black, and with each row tiled such that the top of each pix is aligned and separated by 'spacing' from the next one. A black border can be added to each pix. (2) All pix are converted to outdepth; existing colormaps are removed. (3) This does a reasonably spacewise-efficient job of laying out the individual pix images into a tiled composite.

Definition at line 618 of file pixafunc2.c.

References ERROR_PTR, FALSE, L_CLONE, L_INSERT, L_MAX, L_WARNING_INT, NULL, numaAddNumber(), numaCreate(), numaDestroy(), numaGetCount(), numaGetIValue(), PIX_SRC, pixaAddPix(), pixaCreate(), pixAddBorder(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixaGetPixDimensions(), pixClone(), pixConvertTo1(), pixConvertTo32(), pixConvertTo8(), pixCreate(), pixDestroy(), pixGetDimensions(), pixRasterop(), pixScale(), pixSetAll(), and PROCNAME.

Referenced by fpixaDisplayQuadtree(), GetImageMask(), main(), pixExtractBarcodes(), and selaDisplayInPix().

PIX* pixaDisplayTiledAndScaled ( PIXA pixa,
l_int32  outdepth,
l_int32  tilewidth,
l_int32  ncols,
l_int32  background,
l_int32  spacing,
l_int32  border 
)

pixaDisplayTiledAndScaled()

Input: pixa 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 can be used to tile a number of renderings of an image that are at different scales and depths. (2) 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 776 of file pixafunc2.c.

References CALLOC, ERROR_PTR, FALSE, FREE, L_CLONE, L_INSERT, L_MAX, NULL, PIX_SRC, pixaAddPix(), pixaCreate(), pixAddBorder(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixClone(), pixConvertTo1(), pixConvertTo32(), pixConvertTo8(), pixCreate(), pixDestroy(), pixGetDimensions(), pixRasterop(), pixScale(), pixScaleToGray(), pixSetAll(), and PROCNAME.

Referenced by AddTransformsRGB(), AddTransformsYUV(), DoPageSegmentation(), GeneratePattern(), main(), pixaaDisplayTiledAndScaled(), selaAddCrossJunctions(), and selaAddTJunctions().

PIX* pixaaDisplay ( PIXAA pixaa,
l_int32  w,
l_int32  h 
)

pixaaDisplay()

Input: pixaa w, h (if set to 0, determines the size from the b.b. of the components in pixaa) Return: pix, or null on error

Notes: (1) Each pix of the pixaa is displayed at the location given by its box, translated by the box of the containing pixa if it exists.

Definition at line 912 of file pixafunc2.c.

References boxaDestroy(), boxaGetBoxGeometry(), boxaGetCount(), boxaGetExtent(), ERROR_PTR, L_CLONE, L_MAX, NULL, PIX_PAINT, pixaaGetBoxa(), pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), pixaGetBoxa(), pixaGetBoxGeometry(), pixaGetCount(), pixaGetPix(), pixCreate(), pixDestroy(), pixGetDepth(), pixRasterop(), and PROCNAME.

Referenced by main().

PIX* pixaaDisplayByPixa ( PIXAA pixaa,
l_int32  xspace,
l_int32  yspace,
l_int32  maxw 
)

pixaaDisplayByPixa()

Input: pixaa xspace between pix in pixa yspace between pixa max width of output pix Return: pix, or null on error

Notes: (1) Displays each pixa on a line (or set of lines), in order from top to bottom. Within each pixa, the pix are displayed in order from left to right. (2) The size of each pix in each pixa is assumed to be approximately equal to the size of the first pix in the pixa. If this assumption is not correct, this function will not work properly. (3) This ignores the boxa of the pixaa.

Definition at line 1004 of file pixafunc2.c.

References ERROR_PTR, L_CLONE, L_MAX, NULL, PIX_PAINT, pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixCreate(), pixDestroy(), pixGetDepth(), pixGetHeight(), pixGetWidth(), pixRasterop(), and PROCNAME.

Referenced by main().

PIXA* pixaaDisplayTiledAndScaled ( PIXAA pixaa,
l_int32  outdepth,
l_int32  tilewidth,
l_int32  ncols,
l_int32  background,
l_int32  spacing,
l_int32  border 
)

pixaaDisplayTiledAndScaled()

Input: pixaa 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: pixa (of tiled images, one image for each pixa in the pixaa), or null on error

Notes: (1) For each pixa, this generates from all the pix a tiled/scaled output pix, and puts it in the output pixa. (2) See comments in pixaDisplayTiledAndScaled().

Definition at line 1100 of file pixafunc2.c.

References ERROR_PTR, L_CLONE, L_INSERT, NULL, pixaAddPix(), pixaaGetCount(), pixaaGetPixa(), pixaCreate(), pixaDestroy(), pixaDisplayTiledAndScaled(), and PROCNAME.

Referenced by main().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines