![]() |
Leptonica
1.82.0
Image processing and image analysis suite
|
#include <string.h>
#include "allheaders.h"
Go to the source code of this file.
Functions | |
static l_int32 | stringAllWhitespace (char *textstr, l_int32 *pval) |
static l_int32 | stringLeadingWhitespace (char *textstr, l_int32 *pval) |
PIX * | pixAddSingleTextblock (PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow) |
PIX * | pixAddTextlines (PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location) |
l_ok | pixSetTextblock (PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 x0, l_int32 y0, l_int32 wtext, l_int32 firstindent, l_int32 *poverflow) |
l_ok | pixSetTextline (PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 x0, l_int32 y0, l_int32 *pwidth, l_int32 *poverflow) |
PIXA * | pixaAddTextNumber (PIXA *pixas, L_BMF *bmf, NUMA *na, l_uint32 val, l_int32 location) |
PIXA * | pixaAddTextlines (PIXA *pixas, L_BMF *bmf, SARRAY *sa, l_uint32 val, l_int32 location) |
l_ok | pixaAddPixWithText (PIXA *pixa, PIX *pixs, l_int32 reduction, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location) |
SARRAY * | bmfGetLineStrings (L_BMF *bmf, const char *textstr, l_int32 maxw, l_int32 firstindent, l_int32 *ph) |
NUMA * | bmfGetWordWidths (L_BMF *bmf, const char *textstr, SARRAY *sa) |
l_ok | bmfGetStringWidth (L_BMF *bmf, const char *textstr, l_int32 *pw) |
SARRAY * | splitStringToParagraphs (char *textstr, l_int32 splitflag) |
Font layout PIX *pixAddSingleTextblock() PIX *pixAddTextlines() l_int32 pixSetTextblock() l_int32 pixSetTextline() PIXA *pixaAddTextNumber() PIXA *pixaAddTextlines() l_int32 pixaAddPixWithText() Text size estimation and partitioning SARRAY *bmfGetLineStrings() NUMA *bmfGetWordWidths() l_int32 bmfGetStringWidth() Text splitting SARRAY *splitStringToParagraphs() static l_int32 stringAllWhitespace() static l_int32 stringLeadingWhitespace() This is a simple utility to put text on images. One font and style is provided, with a variety of pt sizes. For example, to put a line of green 10 pt text on an image, with the beginning baseline at (50, 50): L_Bmf *bmf = bmfCreate(NULL, 10); const char *textstr = "This is a funny cat"; pixSetTextline(pixs, bmf, textstr, 0x00ff0000, 50, 50, NULL, NULL); The simplest interfaces for adding text to an image are pixAddTextlines() and pixAddSingleTextblock(). For example, to add the same text in red, centered, below the image: Pix *pixd = pixAddTextlines(pixs, bmf, textstr, 0xff000000, L_ADD_BELOW); // red text To add text to all pix in a pixa, generating a new pixa, use either an sarray to hold the strings for each pix, or use the strings in the text field of each pix; e.g., Pixa *pixa2 = pixaAddTextlines(pixa1, bmf, sa, 0x0000ff00, L_ADD_LEFT); // blue text Pixa *pixa2 = pixaAddTextlines(pixa1, bmf, NULL, 0x00ff0000, L_ADD_RIGHT); // green text
Definition in file textops.c.
SARRAY* bmfGetLineStrings | ( | L_BMF * | bmf, |
const char * | textstr, | ||
l_int32 | maxw, | ||
l_int32 | firstindent, | ||
l_int32 * | ph | ||
) |
[in] | bmf | |
[in] | textstr | |
[in] | maxw | max width of a text line in pixels |
[in] | firstindent | indentation of first line, in x-widths |
[out] | ph | height required to hold text bitmap |
Notes: (1) Divides the input text string into an array of text strings, each of which will fit within maxw bits of width.
Definition at line 871 of file textops.c.
References bmfGetWidth(), bmfGetWordWidths(), L_INSERT, L_Bmf::lineheight, numaDestroy(), numaGetCount(), numaGetIValue(), sarrayAddString(), sarrayCreate(), sarrayCreateWordsFromString(), sarrayDestroy(), sarrayGetCount(), sarrayToStringRange(), L_Bmf::spacewidth, and L_Bmf::vertlinesep.
l_ok bmfGetStringWidth | ( | L_BMF * | bmf, |
const char * | textstr, | ||
l_int32 * | pw | ||
) |
[in] | bmf | |
[in] | textstr | |
[out] | pw | width of text string, in pixels for the font represented by the bmf |
Definition at line 988 of file textops.c.
References bmfGetWidth(), and L_Bmf::kernwidth.
Referenced by bmfGetWordWidths().
[in] | bmf | |
[in] | textstr | |
[in] | sa | of individual words |
Definition at line 947 of file textops.c.
References bmfGetStringWidth(), L_NOCOPY, numaAddNumber(), numaCreate(), sarrayGetCount(), and sarrayGetString().
Referenced by bmfGetLineStrings().
l_ok pixaAddPixWithText | ( | PIXA * | pixa, |
PIX * | pixs, | ||
l_int32 | reduction, | ||
L_BMF * | bmf, | ||
const char * | textstr, | ||
l_uint32 | val, | ||
l_int32 | location | ||
) |
[in] | pixa | |
[in] | pixs | any depth, colormap ok |
[in] | reduction | integer subsampling factor |
[in] | bmf | [optional] bitmap font data |
[in] | textstr | [optional] text string to be added |
[in] | val | color to set the text |
[in] | location | L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT |
Notes: (1) This function generates a new pix with added text, and adds it by insertion into the pixa. (2) If the input pixs is not cmapped and not 32 bpp, it is converted to 32 bpp rgb. val is a standard 32 bpp pixel, expressed as 0xrrggbb00. If there is a colormap, this does the best it can to use the requested color, or something close. (3) if bmf == NULL, generate an 8 pt font; this takes about 5 msec. (4) If textstr == NULL, use the text field in the pix. (5) In general, the text string can be written in multiple lines; use newlines as the separators. (6) Typical usage is for debugging, where the pixa of labeled images is used to generate a pdf. Suggest using 1.0 for scalefactor.
Definition at line 789 of file textops.c.
References bmfCreate(), L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT, L_COPY, pixaAddPix(), pixClone(), pixGetText(), and pixScaleByIntSampling().
[in] | pixas | input pixa; colormap ok |
[in] | bmf | bitmap font data |
[in] | sa | [optional] sarray; use text embedded in each pix if null |
[in] | val | color to set the text |
[in] | location | L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT |
Notes: (1) This function adds one or more lines of text externally to each pix, in a position given by location. In all cases, the pix is expanded as necessary to accommodate the text. (2) val is the pixel value to be painted through the font mask. It should be chosen to agree with the depth of pixs. If it is out of bounds, an intermediate value is chosen. For RGB, use hex notation: 0xRRGGBB00, where RR is the hex representation of the red intensity, etc. (3) If sa == NULL, use the text embedded in each pix. In all cases, newlines in the text string are used to separate the lines of text that are added to the pix. (4) If sa has a smaller count than pixa, issue a warning and do not use any embedded text. (5) If there is a colormap, this does the best it can to use the requested color, or something similar to it.
Definition at line 719 of file textops.c.
References L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT, L_CLONE, L_INSERT, L_NOCOPY, pixaAddPix(), pixaCreate(), pixAddTextlines(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixGetText(), sarrayGetCount(), and sarrayGetString().
[in] | pixas | input pixa; colormap ok |
[in] | bmf | bitmap font data |
[in] | na | [optional] number array; use 1 ... n if null |
[in] | val | color to set the text |
[in] | location | L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT |
Notes: (1) Typical usage is for labelling each pix in a pixa with a number. (2) This function paints numbers external to each pix, in a position given by location. In all cases, the pix is expanded on on side and the number is painted over white in the added region. (3) val is the pixel value to be painted through the font mask. It should be chosen to agree with the depth of pixs. If it is out of bounds, an intermediate value is chosen. For RGB, use hex notation: 0xRRGGBB00, where RR is the hex representation of the red intensity, etc. (4) If na == NULL, number each pix sequentially, starting with 1. (5) If there is a colormap, this does the best it can to use the requested color, or something similar to it.
Definition at line 649 of file textops.c.
References L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT, L_CLONE, L_INSERT, numaGetIValue(), pixaAddPix(), pixaCreate(), pixAddTextlines(), pixaGetCount(), pixaGetPix(), and pixDestroy().
Referenced by pixaSelectToPdf().
PIX* pixAddSingleTextblock | ( | PIX * | pixs, |
L_BMF * | bmf, | ||
const char * | textstr, | ||
l_uint32 | val, | ||
l_int32 | location, | ||
l_int32 * | poverflow | ||
) |
[in] | pixs | input pix; colormap ok |
[in] | bmf | bitmap font data |
[in] | textstr | [optional] text string to be added |
[in] | val | color to set the text |
[in] | location | L_ADD_ABOVE, L_ADD_AT_TOP, L_ADD_AT_BOT, L_ADD_BELOW |
[out] | poverflow | [optional] 1 if text overflows allocated region and is clipped; 0 otherwise |
Notes: (1) This function paints a set of lines of text over an image. If location is L_ADD_ABOVE or L_ADD_BELOW, the pix size is expanded with a border and rendered over the border. (2) val is the pixel value to be painted through the font mask. It should be chosen to agree with the depth of pixs. If it is out of bounds, an intermediate value is chosen. For RGB, use hex notation: 0xRRGGBB00, where RR is the hex representation of the red intensity, etc. (3) If textstr == NULL, use the text field in the pix. (4) If there is a colormap, this does the best it can to use the requested color, or something similar to it. (5) Typical usage is for labelling a pix with some text data.
Definition at line 120 of file textops.c.
References L_ADD_ABOVE, L_ADD_AT_BOT, L_ADD_AT_TOP, L_ADD_BELOW, pixCopy(), pixGetDimensions(), and pixGetText().
Referenced by boxaDisplayTiled(), dewarpaShowArrays(), fpixaDisplayQuadtree(), pixaDisplayTiledWithText(), pixDisplayColorArray(), recogDisplayOutlier(), and recogShowMatch().
PIX* pixAddTextlines | ( | PIX * | pixs, |
L_BMF * | bmf, | ||
const char * | textstr, | ||
l_uint32 | val, | ||
l_int32 | location | ||
) |
[in] | pixs | input pix; colormap ok |
[in] | bmf | bitmap font data |
[in] | textstr | [optional] text string to be added |
[in] | val | color to set the text |
[in] | location | L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT |
Notes: (1) This function expands an image as required to paint one or more lines of text adjacent to the image. If bmf == NULL, this returns a copy. If above or below, the lines are centered with respect to the image; if left or right, they are left justified. (2) val is the pixel value to be painted through the font mask. It should be chosen to agree with the depth of pixs. If it is out of bounds, an intermediate value is chosen. For RGB, use hex notation: 0xRRGGBB00, where RR is the hex representation of the red intensity, etc. (3) If textstr == NULL, use the text field in the pix. The text field contains one or most "lines" of text, where newlines are used as line separators. (4) If there is a colormap, this does the best it can to use the requested color, or something similar to it. (5) Typical usage is for labelling a pix with some text data.
Definition at line 276 of file textops.c.
References L_ADD_ABOVE, L_ADD_BELOW, L_ADD_LEFT, L_ADD_RIGHT, pixCopy(), pixGetDimensions(), and pixGetText().
Referenced by pixaAddTextlines(), pixaAddTextNumber(), pixaConvertToNUpPixa(), pixaDisplayTiledByIndex(), recogShowPath(), and showExtractNumbers().
l_ok pixSetTextblock | ( | PIX * | pixs, |
L_BMF * | bmf, | ||
const char * | textstr, | ||
l_uint32 | val, | ||
l_int32 | x0, | ||
l_int32 | y0, | ||
l_int32 | wtext, | ||
l_int32 | firstindent, | ||
l_int32 * | poverflow | ||
) |
[in] | pixs | input image |
[in] | bmf | bitmap font data |
[in] | textstr | block text string to be set |
[in] | val | color to set the text |
[in] | x0 | left edge for each line of text |
[in] | y0 | baseline location for the first text line |
[in] | wtext | max width of each line of generated text |
[in] | firstindent | indentation of first line, in x-widths |
[out] | poverflow | [optional] 0 if text is contained in input pix; 1 if it is clipped |
Notes: (1) This function paints a set of lines of text over an image. (2) val is the pixel value to be painted through the font mask. It should be chosen to agree with the depth of pixs. If it is out of bounds, an intermediate value is chosen. For RGB, use hex notation: 0xRRGGBB00, where RR is the hex representation of the red intensity, etc. The last two hex digits are 00 (byte value 0), assigned to the A component. Note that, as usual, RGBA proceeds from left to right in the order from MSB to LSB (see pix.h for details). (3) If there is a colormap, this does the best it can to use the requested color, or something similar to it.
Definition at line 439 of file textops.c.
References pixGetDimensions().
l_ok pixSetTextline | ( | PIX * | pixs, |
L_BMF * | bmf, | ||
const char * | textstr, | ||
l_uint32 | val, | ||
l_int32 | x0, | ||
l_int32 | y0, | ||
l_int32 * | pwidth, | ||
l_int32 * | poverflow | ||
) |
[in] | pixs | input image |
[in] | bmf | bitmap font data |
[in] | textstr | text string to be set on the line |
[in] | val | color to set the text |
[in] | x0 | left edge for first char |
[in] | y0 | baseline location for all text on line |
[out] | pwidth | [optional] width of generated text |
[out] | poverflow | [optional] 0 if text is contained in input pix; 1 if it is clipped |
Notes: (1) This function paints a line of text over an image. (2) val is the pixel value to be painted through the font mask. It should be chosen to agree with the depth of pixs. If it is out of bounds, an intermediate value is chosen. For RGB, use hex notation: 0xRRGGBB00, where RR is the hex representation of the red intensity, etc. The last two hex digits are 00 (byte value 0), assigned to the A component. Note that, as usual, RGBA proceeds from left to right in the order from MSB to LSB (see pix.h for details). (3) If there is a colormap, this does the best it can to use the requested color, or something similar to it.
SARRAY* splitStringToParagraphs | ( | char * | textstr, |
l_int32 | splitflag | ||
) |
[in] | textstr | text string |
[in] | splitflag | see enum in bmf.h; valid values in {1,2,3} |
Definition at line 1032 of file textops.c.
References L_COPY, L_INSERT, L_NOCOPY, sarrayAddString(), sarrayCreate(), sarrayCreateLinesFromString(), sarrayDestroy(), sarrayGetCount(), sarrayGetString(), sarrayToString(), SPLIT_ON_BLANK_LINE, SPLIT_ON_BOTH, SPLIT_ON_LEADING_WHITE, stringAllWhitespace(), and stringLeadingWhitespace().
|
static |
[in] | textstr | text string |
[out] | pval | 1 if all whitespace; 0 otherwise |
Definition at line 1082 of file textops.c.
Referenced by splitStringToParagraphs().
|
static |
[in] | textstr | text string |
[out] | pval | 1 if leading char is [space] or [tab]; 0 otherwise |
Definition at line 1114 of file textops.c.
Referenced by splitStringToParagraphs().