Leptonica
1.54
|
l_int32 pixcmapAddBlackOrWhite | ( | PIXCMAP * | cmap, |
l_int32 | color, | ||
l_int32 * | pindex | ||
) |
Input: cmap color (0 for black, 1 for white) &index (<optional return>=""> index of color; can be null) Return: 0 if OK, 1 on error
Notes: (1) This only adds color if not already there. (2) This sets index to the requested color. (3) If there is no room in the colormap, returns the index of the closest color.
Input: cmap rval, gval, bval (colormap entry to be added; each number is in range [0, ... 255]) Return: 0 if OK, 1 on error
Note: always adds the color if there is room.
l_int32 pixcmapAddNearestColor | ( | PIXCMAP * | cmap, |
l_int32 | rval, | ||
l_int32 | gval, | ||
l_int32 | bval, | ||
l_int32 * | pindex | ||
) |
Input: cmap rval, gval, bval (colormap entry to be added; each number is in range [0, ... 255]) &index (<return> index of color) Return: 0 if OK, 1 on error
Notes: (1) This only adds color if not already there. (2) If it's not in the colormap and there is no room to add another color, this returns the index of the nearest color.
l_int32 pixcmapAddNewColor | ( | PIXCMAP * | cmap, |
l_int32 | rval, | ||
l_int32 | gval, | ||
l_int32 | bval, | ||
l_int32 * | pindex | ||
) |
Input: cmap rval, gval, bval (colormap entry to be added; each number is in range [0, ... 255]) &index (<return> index of color) Return: 0 if OK, 1 on error; 2 if unable to add color
Notes: (1) This only adds color if not already there. (2) This returns the index of the new (or existing) color. (3) Returns 2 with a warning if unable to add this color; the caller should check the return value.
l_int32 pixcmapClear | ( | PIXCMAP * | cmap | ) |
Input: cmap Return: 0 if OK, 1 on error
Note: this removes the colors by setting the count to 0.
Input: cmap rwt, gwt, bwt (non-negative; these should add to 1.0) Return: cmap (gray), or null on error
Notes: (1) This creates a gray colormap from an arbitrary colormap. (2) In use, attach the output gray colormap to the pix (or a copy of it) that provided the input colormap.
l_int32 pixcmapContrastTRC | ( | PIXCMAP * | cmap, |
l_float32 | factor | ||
) |
Input: colormap factor (generally between 0.0 (no enhancement) and 1.0, but can be larger than 1.0) Return: 0 if OK; 1 on error
Notes: (1) This is an in-place transform (2) See pixContrastTRC() and numaContrastTRC() in enhance.c for description and use of transform
char* pixcmapConvertToHex | ( | l_uint8 * | data, |
l_int32 | nbytes, | ||
l_int32 | ncolors | ||
) |
Input: data (binary serialized data) nbytes (size of data) ncolors (in colormap) Return: hexdata (bracketed, space-separated ascii hex string), or null on error.
Notes: (1) If rgb, there are 3 colors/component; if rgba, there are 4. (2) Output is in form: < r0g0b0 r1g1b1 ... rngnbn > where r0, g0, b0, ... are each 2 bytes of hex ascii (3) This is used in pdf files to express the colormap as an array in ascii (human-readable) format.
PIXCMAP* pixcmapCopy | ( | PIXCMAP * | cmaps | ) |
Input: cmaps Return: cmapd, or null on error
l_int32 pixcmapCountGrayColors | ( | PIXCMAP * | cmap, |
l_int32 * | pngray | ||
) |
Input: cmap &ngray (<return> number of gray colors) Return: 0 if OK, 1 on error
Notes: (1) This counts the unique gray colors, including black and white.
PIXCMAP* pixcmapCreate | ( | l_int32 | depth | ) |
Input: depth (bpp, of pix) Return: cmap, or null on error
PIXCMAP* pixcmapCreateLinear | ( | l_int32 | d, |
l_int32 | nlevels | ||
) |
Input: d (depth of pix for this colormap; 1, 2, 4 or 8) nlevels (valid in range [2, 2^d]) Return: cmap, or null on error
Notes: (1) Colormap has equally spaced gray color values from black (0, 0, 0) to white (255, 255, 255).
PIXCMAP* pixcmapCreateRandom | ( | l_int32 | depth, |
l_int32 | hasblack, | ||
l_int32 | haswhite | ||
) |
Input: depth (bpp, of pix; 2, 4 or 8) hasblack (1 if the first color is black; 0 if no black) haswhite (1 if the last color is white; 0 if no white) Return: cmap, or null on error
Notes: (1) This sets up a colormap with random colors, where the first color is optionally black, the last color is optionally white, and the remaining colors are chosen randomly. (2) The number of randomly chosen colors is: 2^(depth) - haswhite - hasblack (3) Because rand() is seeded, it might disrupt otherwise deterministic results if also used elsewhere in a program. (4) rand() is not threadsafe, and will generate garbage if run on multiple threads at once -- though garbage is generally what you want from a random number generator! (5) Modern rand()s have equal randomness in low and high order bits, but older ones don't. Here, we're just using rand() to choose colors for output.
PIXCMAP* pixcmapDeserializeFromMemory | ( | l_uint8 * | data, |
l_int32 | ncolors, | ||
l_int32 | nbytes | ||
) |
pixcmapDeserializeFromMemory()
Input: data (binary string, 3 or 4 bytes per color) ncolors nbytes (size of returned data) Return: cmap, or null on error
void pixcmapDestroy | ( | PIXCMAP ** | pcmap | ) |
Input: &cmap (<set to="" null>="">) Return: void
Input: colormap gamma (gamma correction; must be > 0.0) minval (input value that gives 0 for output; can be < 0) maxval (input value that gives 255 for output; can be > 255) Return: 0 if OK; 1 on error
Notes: (1) This is an in-place transform (2) See pixGammaTRC() and numaGammaTRC() in enhance.c for description and use of transform
l_int32 pixcmapGetColor | ( | PIXCMAP * | cmap, |
l_int32 | index, | ||
l_int32 * | prval, | ||
l_int32 * | pgval, | ||
l_int32 * | pbval | ||
) |
Input: cmap index &rval, &gval, &bval (<return> each color value in l_int32) Return: 0 if OK, 1 if not accessable (caller should check)
l_int32 pixcmapGetColor32 | ( | PIXCMAP * | cmap, |
l_int32 | index, | ||
l_uint32 * | pval32 | ||
) |
Input: cmap index &val32 (<return> 32-bit rgba color value) Return: 0 if OK, 1 if not accessable (caller should check)
Notes: (1) The returned alpha channel value is zero, because it is not used in leptonica colormaps.
l_int32 pixcmapGetComponentRange | ( | PIXCMAP * | cmap, |
l_int32 | color, | ||
l_int32 * | pminval, | ||
l_int32 * | pmaxval | ||
) |
Input: cmap color (L_SELECT_RED, L_SELECT_GREEN or L_SELECT_BLUE) &minval (<optional return>=""> minimum value of component) &maxval (<optional return>=""> minimum value of component) Return: 0 if OK, 1 on error
Notes: (1) Returns for selected components the extreme value (either min or max) of the color component that is found in the colormap.
l_int32 pixcmapGetCount | ( | PIXCMAP * | cmap | ) |
Input: cmap Return: count, or 0 on error
l_int32 pixcmapGetDepth | ( | PIXCMAP * | cmap | ) |
Input: cmap Return: depth, or 0 on error
l_int32 pixcmapGetExtremeValue | ( | PIXCMAP * | cmap, |
l_int32 | type, | ||
l_int32 * | prval, | ||
l_int32 * | pgval, | ||
l_int32 * | pbval | ||
) |
Input: cmap type (L_SELECT_MIN or L_SELECT_MAX) &rval (<optional return>=""> red component) &gval (<optional return>=""> green component) &bval (<optional return>=""> blue component) Return: 0 if OK, 1 on error
Notes: (1) Returns for selected components the extreme value (either min or max) of the color component that is found in the colormap.
l_int32 pixcmapGetFreeCount | ( | PIXCMAP * | cmap | ) |
Input: cmap Return: free entries, or 0 on error
l_int32 pixcmapGetIndex | ( | PIXCMAP * | cmap, |
l_int32 | rval, | ||
l_int32 | gval, | ||
l_int32 | bval, | ||
l_int32 * | pindex | ||
) |
Input: cmap rval, gval, bval (colormap colors to search for; each number is in range [0, ... 255]) &index (<return>) Return: 0 if found, 1 if not found (caller must check)
l_int32 pixcmapGetMinDepth | ( | PIXCMAP * | cmap, |
l_int32 * | pmindepth | ||
) |
Input: cmap &mindepth (<return> minimum depth to support the colormap) Return: 0 if OK, 1 on error
Notes: (1) On error, &mindepth is returned as 0.
l_int32 pixcmapGetNearestGrayIndex | ( | PIXCMAP * | cmap, |
l_int32 | val, | ||
l_int32 * | pindex | ||
) |
Input: cmap val (gray value to search for; in range [0, ... 255]) &index (<return> the index of the nearest color) Return: 0 if OK, 1 on error (caller must check)
Notes: (1) This should be used on gray colormaps. It uses only the green value of the colormap. (2) Returns the index of the exact color if possible, otherwise the index of the color closest to the target color.
l_int32 pixcmapGetNearestIndex | ( | PIXCMAP * | cmap, |
l_int32 | rval, | ||
l_int32 | gval, | ||
l_int32 | bval, | ||
l_int32 * | pindex | ||
) |
Input: cmap rval, gval, bval (colormap colors to search for; each number is in range [0, ... 255]) &index (<return> the index of the nearest color) Return: 0 if OK, 1 on error (caller must check)
Notes: (1) Returns the index of the exact color if possible, otherwise the index of the color closest to the target color. (2) Nearest color is that which is the least sum-of-squares distance from the target color.
l_int32 pixcmapGetRankIntensity | ( | PIXCMAP * | cmap, |
l_float32 | rankval, | ||
l_int32 * | pindex | ||
) |
Input: cmap rankval (0.0 for darkest, 1.0 for lightest color) &index (<return> the index into the colormap that corresponds to the rank intensity color) Return: 0 if OK, 1 on error
PIXCMAP* pixcmapGrayToColor | ( | l_uint32 | color | ) |
Input: color Return: cmap, or null on error
Notes: (1) This creates a colormap that maps from gray to a specific color. In the mapping, each component is faded to white, depending on the gray value. (2) In use, this is simply attached to a grayscale pix to give it the input color.
l_int32 pixcmapHasColor | ( | PIXCMAP * | cmap, |
l_int32 * | pcolor | ||
) |
Input: cmap &color (<return> TRUE if cmap has color; FALSE otherwise) Return: 0 if OK, 1 on error
PIXCMAP* pixcmapReadStream | ( | FILE * | fp | ) |
Input: stream Return: cmap, or null on error
l_int32 pixcmapResetColor | ( | PIXCMAP * | cmap, |
l_int32 | index, | ||
l_int32 | rval, | ||
l_int32 | gval, | ||
l_int32 | bval | ||
) |
Input: cmap index rval, gval, bval (colormap entry to be reset; each number is in range [0, ... 255]) Return: 0 if OK, 1 if not accessable (caller should check)
Notes: (1) This resets sets the color of an entry that has already been set and included in the count of colors.
l_int32 pixcmapSerializeToMemory | ( | PIXCMAP * | cmap, |
l_int32 | cpc, | ||
l_int32 * | pncolors, | ||
l_uint8 ** | pdata, | ||
l_int32 * | pnbytes | ||
) |
Input: colormap cpc (components/color: 3 for rgb, 4 for rgba) &ncolors (<return> number of colors in table) &data (<return> binary string, 3 or 4 bytes per color) &nbytes (<return> size of data) Return: 0 if OK; 1 on error
Notes: (1) If == 4, we leave room for the alpha channel value in each color entry, but it is set to 0.
l_int32 pixcmapSetBlackAndWhite | ( | PIXCMAP * | cmap, |
l_int32 | setblack, | ||
l_int32 | setwhite | ||
) |
Input: cmap setblack (0 for no operation; 1 to set darkest color to black) setwhite (0 for no operation; 1 to set lightest color to white) Return: 0 if OK, 1 on error
l_int32 pixcmapShiftByComponent | ( | PIXCMAP * | cmap, |
l_uint32 | srcval, | ||
l_uint32 | dstval | ||
) |
Input: colormap srcval (source color: 0xrrggbb00) dstval (target color: 0xrrggbb00) Return: 0 if OK; 1 on error
Notes: (1) This is an in-place transform (2) It implements pixelShiftByComponent() for each color. The mapping is specified by srcval and dstval. (3) If a component decreases, the component in the colormap decreases by the same ratio. Likewise for increasing, except all ratios are taken with respect to the distance from 255.
l_int32 pixcmapShiftIntensity | ( | PIXCMAP * | cmap, |
l_float32 | fraction | ||
) |
Input: colormap fraction (between -1.0 and +1.0) Return: 0 if OK; 1 on error
Notes: (1) This is an in-place transform (2) It does a proportional shift of the intensity for each color. (3) If fraction < 0.0, it moves all colors towards (0,0,0). This darkens the image. If fraction > 0.0, it moves all colors towards (255,255,255) This fades the image. (4) The equivalent transform can be accomplished with pixcmapGammaTRC(), but it is considerably more difficult (see numaGammaTRC()).
Input: colormap &rmap, &gmap, &bmap (<return> colormap arrays) Return: 0 if OK; 1 on error
l_int32 pixcmapToRGBTable | ( | PIXCMAP * | cmap, |
l_uint32 ** | ptab, | ||
l_int32 * | pncolors | ||
) |
Input: colormap &tab (<return> table of rgba values for the colormap) &ncolors (<optional return>=""> size of table) Return: 0 if OK; 1 on error
l_int32 pixcmapUsableColor | ( | PIXCMAP * | cmap, |
l_int32 | rval, | ||
l_int32 | gval, | ||
l_int32 | bval, | ||
l_int32 * | pusable | ||
) |
Input: cmap rval, gval, bval (colormap entry to be added; each number is in range [0, ... 255]) usable (<return> 1 if usable; 0 if not) Return: 0 if OK, 1 on error
Notes: (1) This checks if the color already exists or if there is room to add it. It makes no change in the colormap.
l_int32 pixcmapWriteStream | ( | FILE * | fp, |
PIXCMAP * | cmap | ||
) |
Input: stream, cmap Return: 0 if OK, 1 on error