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

Функции

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)
PIXpixaDisplayLinearly (PIXA *pixas, l_int32 direction, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border, BOXA **pboxa)
PIXpixaDisplayOnLattice (PIXA *pixa, l_int32 cellw, l_int32 cellh, l_int32 *pncols, BOXA **pboxa)
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)
PIXpixaDisplayTiledWithText (PIXA *pixa, l_int32 maxwidth, l_float32 scalefactor, l_int32 spacing, l_int32 border, l_int32 fontsize, l_uint32 textcolor)
PIXpixaDisplayTiledByIndex (PIXA *pixa, NUMA *na, l_int32 width, l_int32 spacing, l_int32 border, l_int32 fontsize, l_uint32 textcolor)
PIXpixaaDisplay (PIXAA *paa, l_int32 w, l_int32 h)
PIXpixaaDisplayByPixa (PIXAA *paa, l_int32 xspace, l_int32 yspace, l_int32 maxw)
PIXApixaaDisplayTiledAndScaled (PIXAA *paa, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
PIXApixaConvertTo1 (PIXA *pixas, l_int32 thresh)
PIXApixaConvertTo8 (PIXA *pixas, l_int32 cmapflag)
PIXApixaConvertTo8Color (PIXA *pixas, l_int32 dither)
PIXApixaConvertTo32 (PIXA *pixas)
l_int32 convertToNUpFiles (const char *dir, const char *substr, l_int32 nx, l_int32 ny, l_int32 tw, l_int32 spacing, l_int32 border, l_int32 fontsize, const char *outdir)
PIXAconvertToNUpPixa (const char *dir, const char *substr, l_int32 nx, l_int32 ny, l_int32 tw, l_int32 spacing, l_int32 border, l_int32 fontsize)

Функции

l_int32 convertToNUpFiles ( const char *  dir,
const char *  substr,
l_int32  nx,
l_int32  ny,
l_int32  tw,
l_int32  spacing,
l_int32  border,
l_int32  fontsize,
const char *  outdir 
)

convertToNUpFiles()

Input: indir (full path to directory of images) substr (<optional> can be null) nx, ny (in [1, ... 50], tiling factors in each direction) tw (target width, in pixels; must be >= 20) spacing (between images, and on outside) border (width of additional black border on each image; use 0 for no border) fontsize (to print tail of filename with image. Valid set is {4,6,8,10,12,14,16,18,20}. Use 0 to disable.) outdir (subdirectory of /tmp to put N-up tiled images) Return: 0 if OK, 1 on error

Notes: (1) Each set of nx*ny images is scaled and tiled into a single image, that is written out to . (2) All images in each nx*ny set are scaled to the same width. This is typically used when all images are roughly the same size. (3) Typical values for nx and ny are in [2 ... 5]. (4) All images are scaled to a width . They are not rescaled when placed in the (nx,ny) mosaic.

PIXA* convertToNUpPixa ( const char *  dir,
const char *  substr,
l_int32  nx,
l_int32  ny,
l_int32  tw,
l_int32  spacing,
l_int32  border,
l_int32  fontsize 
)

convertToNUpPixa()

Input: dir (full path to directory of images) substr (<optional> can be null) nx, ny (in [1, ... 50], tiling factors in each direction) tw (target width, in pixels; must be >= 20) spacing (between images, and on outside) border (width of additional black border on each image; use 0 for no border) fontsize (to print tail of filename with image. Valid set is {4,6,8,10,12,14,16,18,20}. Use 0 to disable.) Return: pixad, or null on error

Notes: (1) See notes for convertToNUpFiles()

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

pixaaDisplay()

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

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

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

pixaaDisplayByPixa()

Input: paa (with pix that may have different depths) xspace between pix in pixa yspace between pixa max width of output pix Return: pixd, 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 sizes and depths of each pix can differ. The output pix has a depth equal to the max depth of all the pix. (3) This ignores the boxa of the paa.

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

pixaaDisplayTiledAndScaled()

Input: paa 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 paa), 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().

PIXA* pixaConvertTo1 ( PIXA pixas,
l_int32  thresh 
)

pixaConvertTo1()

Input: pixas thresh (threshold for final binarization from 8 bpp gray) Return: pixad, or null on error

PIXA* pixaConvertTo32 ( PIXA pixas)

pixaConvertTo32()

Input: pixas Return: pixad (32 bpp rgb), or null on error

Notes: (1) See notes for pixConvertTo32(), applied to each pix in pixas.

PIXA* pixaConvertTo8 ( PIXA pixas,
l_int32  cmapflag 
)

pixaConvertTo8()

Input: pixas cmapflag (1 to give pixd a colormap; 0 otherwise) Return: pixad (each pix is 8 bpp), or null on error

Notes: (1) See notes for pixConvertTo8(), applied to each pix in pixas.

PIXA* pixaConvertTo8Color ( PIXA pixas,
l_int32  dither 
)

pixaConvertTo8Color()

Input: pixas ditherflag (1 to dither if necessary; 0 otherwise) Return: pixad (each pix is 8 bpp), or null on error

Notes: (1) See notes for pixConvertTo8Color(), applied to each pix in pixas.

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.

PIX* pixaDisplayLinearly ( PIXA pixas,
l_int32  direction,
l_float32  scalefactor,
l_int32  background,
l_int32  spacing,
l_int32  border,
BOXA **  pboxa 
)

pixaDisplayLinearly()

Input: pixa direction (L_HORIZ or L_VERT) 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) &boxa (<optional return>=""> location of images in output pix Return: pix of composite images, or null on error

Notes: (1) This puts each pix, sequentially, in a line, either horizontally or vertically. (2) If any pix has a colormap, all pix are rendered in rgb. (3) The boxa gives the location of each image.

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.

PIX* pixaDisplayOnLattice ( PIXA pixa,
l_int32  cellw,
l_int32  cellh,
l_int32 pncols,
BOXA **  pboxa 
)

pixaDisplayOnLattice()

Input: pixa cellw (lattice cell width) cellh (lattice cell height) &ncols (<optional return>=""> number of columns in output lattice) &boxa (<optional return>=""> location of images in lattice) 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. (4) The boxa gives the location of each image. The UL corner of each image is on a lattice cell corner. Omitted images (due to size) are assigned an invalid width and height of 0.

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()

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 renders a pixa to a single image 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!

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.

PIX* pixaDisplayTiledByIndex ( PIXA pixa,
NUMA na,
l_int32  width,
l_int32  spacing,
l_int32  border,
l_int32  fontsize,
l_uint32  textcolor 
)

pixaDisplayTiledByIndex()

Input: pixa numa (with indices corresponding to the pix in pixa) width (each pix is scaled to this width) spacing (between images, and on outside) border (width of black border added to each image; use 0 for no border) fontsize (4, 6, ... 20) textcolor (0xrrggbb00) Return: pixd (of tiled images), or null on error

Notes: (1) This renders a pixa to a single image with white background color, where the pix are placed in columns given by the index value in the numa. Each pix is separated by from the adjacent ones, and an optional border is placed around them. (2) Up to 127 chars of text in the pix text field are rendered below each pix. Use newlines in the text field to write the text in multiple lines that fit within the pix width. (3) To avoid having empty columns, if there are N different index values, they should be in [0 ... N-1]. (4) All pix are converted to 32 bpp.

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 renders a pixa to a single image 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. (4) A serialized boxa giving the location in pixd of each input pix (without added border) is stored in the text string of pixd. This allows, e.g., regeneration of a pixa from pixd, using pixaCreateFromBoxa(). If there is no scaling and the depth of each input pix in the pixa is the same, this tiling operation can be inverted using the boxa (except for loss of text in each of the input pix): pix1 = pixaDisplayTiledInRows(pixa1, 1, 1500, 1.0, 0, 30, 0); char *boxatxt = pixGetText(pix1); boxa1 = boxaReadMem((l_uint8 *)boxatxt, strlen(boxatxt)); pixa2 = pixaCreateFromBoxa(pix1, boxa1, NULL);

PIX* pixaDisplayTiledWithText ( PIXA pixa,
l_int32  maxwidth,
l_float32  scalefactor,
l_int32  spacing,
l_int32  border,
l_int32  fontsize,
l_uint32  textcolor 
)

pixaDisplayTiledWithText()

Input: pixa maxwidth (of output image) scalefactor (applied to every pix; use 1.0 for no scaling) spacing (between images, and on outside) border (width of black border added to each image; use 0 for no border) fontsize (4, 6, ... 20) textcolor (0xrrggbb00) Return: pixd (of tiled images), or null on error

Notes: (1) This is a version of pixaDisplayTiledInRows() that prints, below each pix, the text in the pix text field. Up to 127 chars of text in the pix text field are rendered below each pix. (2) It renders a pixa to a single image of width not to exceed , with white background color, with each row tiled such that the top of each pix is aligned and separated by from the next one. (3) All pix are converted to 32 bpp. (4) This does a reasonably spacewise-efficient job of laying out the individual pix images into a tiled composite.

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.