Leptonica 1.54
|
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.
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.
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:
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.
Input: cmaps Return: cmapd, or null on error
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.
Input: depth (bpp, of pix) Return: cmap, or null on error
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).
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.
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:
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)
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.
Input: cmap Return: count, or 0 on error
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.
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)
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.
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.
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
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.
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.
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
Input: colormap fraction (between -1.0 and +1.0) Return: 0 if OK; 1 on error
Notes:
Input: colormap &rmap, &gmap, &bmap (<return> colormap arrays) Return: 0 if OK; 1 on error
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.
Input: stream, cmap Return: 0 if OK, 1 on error