Leptonica 1.68
C Image Processing Library

colormap.c File Reference

Implements PixColormap; colormap conversions, serialization, transforms. More...

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

Go to the source code of this file.

Functions

PIXCMAPpixcmapCreate (l_int32 depth)
PIXCMAPpixcmapCreateRandom (l_int32 depth, l_int32 hasblack, l_int32 haswhite)
PIXCMAPpixcmapCreateLinear (l_int32 d, l_int32 nlevels)
PIXCMAPpixcmapCopy (PIXCMAP *cmaps)
void pixcmapDestroy (PIXCMAP **pcmap)
l_int32 pixcmapAddColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
l_int32 pixcmapAddNewColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
l_int32 pixcmapAddNearestColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
l_int32 pixcmapUsableColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pusable)
l_int32 pixcmapAddBlackOrWhite (PIXCMAP *cmap, l_int32 color, l_int32 *pindex)
l_int32 pixcmapSetBlackAndWhite (PIXCMAP *cmap, l_int32 setblack, l_int32 setwhite)
l_int32 pixcmapGetCount (PIXCMAP *cmap)
l_int32 pixcmapGetFreeCount (PIXCMAP *cmap)
l_int32 pixcmapGetDepth (PIXCMAP *cmap)
l_int32 pixcmapGetMinDepth (PIXCMAP *cmap, l_int32 *pmindepth)
l_int32 pixcmapClear (PIXCMAP *cmap)
l_int32 pixcmapGetColor (PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
l_int32 pixcmapGetColor32 (PIXCMAP *cmap, l_int32 index, l_uint32 *pval32)
l_int32 pixcmapResetColor (PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval)
l_int32 pixcmapGetIndex (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
l_int32 pixcmapHasColor (PIXCMAP *cmap, l_int32 *pcolor)
l_int32 pixcmapCountGrayColors (PIXCMAP *cmap, l_int32 *pngray)
l_int32 pixcmapGetRankIntensity (PIXCMAP *cmap, l_float32 rankval, l_int32 *pindex)
l_int32 pixcmapGetNearestIndex (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
l_int32 pixcmapGetNearestGrayIndex (PIXCMAP *cmap, l_int32 val, l_int32 *pindex)
l_int32 pixcmapGetComponentRange (PIXCMAP *cmap, l_int32 color, l_int32 *pminval, l_int32 *pmaxval)
l_int32 pixcmapGetExtremeValue (PIXCMAP *cmap, l_int32 type, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
PIXCMAPpixcmapGrayToColor (l_uint32 color)
PIXCMAPpixcmapColorToGray (PIXCMAP *cmaps, l_float32 rwt, l_float32 gwt, l_float32 bwt)
PIXCMAPpixcmapReadStream (FILE *fp)
l_int32 pixcmapWriteStream (FILE *fp, PIXCMAP *cmap)
l_int32 pixcmapToArrays (PIXCMAP *cmap, l_int32 **prmap, l_int32 **pgmap, l_int32 **pbmap)
l_int32 pixcmapToRGBTable (PIXCMAP *cmap, l_uint32 **ptab, l_int32 *pncolors)
l_int32 pixcmapSerializeToMemory (PIXCMAP *cmap, l_int32 cpc, l_int32 *pncolors, l_uint8 **pdata, l_int32 *pnbytes)
PIXCMAPpixcmapDeserializeFromMemory (l_uint8 *data, l_int32 ncolors, l_int32 nbytes)
char * pixcmapConvertToHex (l_uint8 *data, l_int32 nbytes, l_int32 ncolors)
l_int32 pixcmapGammaTRC (PIXCMAP *cmap, l_float32 gamma, l_int32 minval, l_int32 maxval)
l_int32 pixcmapContrastTRC (PIXCMAP *cmap, l_float32 factor)
l_int32 pixcmapShiftIntensity (PIXCMAP *cmap, l_float32 fraction)

Detailed Description


Function Documentation

PIXCMAP* pixcmapCreateRandom ( l_int32  depth,
l_int32  hasblack,
l_int32  haswhite 
)

pixcmapCreateRandom()

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.

Definition at line 133 of file colormap.c.

References ERROR_PTR, NULL, pixcmapAddColor(), pixcmapCreate(), and PROCNAME.

Referenced by main(), pixaDisplayRandomCmap(), pixBlendBoxaRandom(), pixDrawBoxaRandom(), pixPaintBoxaRandom(), and pixRenderRandomCmapPtaa().

PIXCMAP* pixcmapCreateLinear ( l_int32  d,
l_int32  nlevels 
)

pixcmapCreateLinear()

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

Definition at line 177 of file colormap.c.

References ERROR_PTR, nlevels, NULL, pixcmapAddColor(), pixcmapCreate(), and PROCNAME.

Referenced by pixAddGrayColormap8(), pixConvertGrayToColormap(), pixDitherTo2bppSpec(), pixThreshold8(), pixThresholdOn8bpp(), pixThresholdTo2bpp(), and pixThresholdTo4bpp().

void pixcmapDestroy ( PIXCMAP **  pcmap)
l_int32 pixcmapAddColor ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval 
)

pixcmapAddColor()

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.

Definition at line 271 of file colormap.c.

References PixColormap::array, RGBA_Quad::blue, ERROR_INT, RGBA_Quad::green, PixColormap::n, PixColormap::nalloc, PROCNAME, and RGBA_Quad::red.

Referenced by boxaaDisplay(), jbDataRender(), makeGrayQuantColormapArb(), makeGrayQuantTableArb(), numaFillCmapFromHisto(), octreeGenerateAndPrune(), pixAddMinimalGrayColormap8(), pixBlendCmap(), pixcmapAddNearestColor(), pixcmapAddNewColor(), pixcmapCreateLinear(), pixcmapCreateRandom(), pixcmapDeserializeFromMemory(), pixcmapGenerateFromHisto(), pixcmapGenerateFromMedianCuts(), pixcmapGrayToColor(), pixcmapReadStream(), pixConvert1To2Cmap(), pixConvert1To4Cmap(), pixConvert2To8(), pixConvert4To8(), pixConvertGrayToColormap8(), pixConvertGrayToFalseColor(), pixConvertTo8(), pixDisplayDiffBinary(), pixDisplayHitMissSel(), pixDisplayMatchedPattern(), pixFewColorsOctcubeQuant1(), pixFewColorsOctcubeQuant2(), pixFewColorsOctcubeQuantMixed(), pixFixedOctcubeQuant256(), pixGetEdgeProfile(), pixMedianCutQuantMixed(), pixOctcubeQuantMixedWithGray(), pixOctreeQuantByPopulation(), pixOctreeQuantNumColors(), pixReadFromTiffStream(), pixReadStreamGif(), pixReadStreamJpeg(), pixReadStreamPng(), pixRemoveUnusedColors(), pixSetMaskedCmap(), pixSetSelectCmap(), pixSetSelectMaskedCmap(), pixSnapColorCmap(), and pixWriteStreamGif().

l_int32 pixcmapAddNewColor ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32 pindex 
)

pixcmapAddNewColor()

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.

Definition at line 311 of file colormap.c.

References ERROR_INT, L_WARNING, PixColormap::n, PixColormap::nalloc, pixcmapAddColor(), pixcmapGetCount(), pixcmapGetIndex(), and PROCNAME.

Referenced by addColorizedGrayToCmap(), pixcmapAddBlackOrWhite(), pixColorSegmentTryCluster(), pixDrawBoxa(), pixPaintBoxa(), and pixRenderPtaArb().

l_int32 pixcmapAddNearestColor ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32 pindex 
)

pixcmapAddNearestColor()

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.

Definition at line 357 of file colormap.c.

References ERROR_INT, PixColormap::n, PixColormap::nalloc, pixcmapAddColor(), pixcmapGetCount(), pixcmapGetIndex(), pixcmapGetNearestIndex(), and PROCNAME.

Referenced by pixAddSingleTextblock(), and pixSetTextline().

l_int32 pixcmapUsableColor ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32 pusable 
)

pixcmapUsableColor()

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.

Definition at line 402 of file colormap.c.

References ERROR_INT, PixColormap::n, PixColormap::nalloc, pixcmapGetIndex(), and PROCNAME.

l_int32 pixcmapAddBlackOrWhite ( PIXCMAP cmap,
l_int32  color,
l_int32 pindex 
)

pixcmapAddBlackOrWhite()

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.

Definition at line 446 of file colormap.c.

References ERROR_INT, pixcmapAddNewColor(), pixcmapGetFreeCount(), pixcmapGetRankIntensity(), and PROCNAME.

Referenced by pixAffineSampled(), pixBilinearSampled(), pixProjectiveSampled(), pixRotate(), pixSetBlackOrWhite(), and pixSetBlackOrWhiteBoxa().

l_int32 pixcmapSetBlackAndWhite ( PIXCMAP cmap,
l_int32  setblack,
l_int32  setwhite 
)

pixcmapSetBlackAndWhite()

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

Definition at line 486 of file colormap.c.

References ERROR_INT, pixcmapGetRankIntensity(), pixcmapResetColor(), and PROCNAME.

Referenced by pixThresholdGrayArb().

l_int32 pixcmapGetCount ( PIXCMAP cmap)

pixcmapGetCount()

Input: cmap Return: count, or 0 on error

Definition at line 517 of file colormap.c.

References ERROR_INT, PixColormap::n, and PROCNAME.

Referenced by addColorizedGrayToCmap(), main(), numaFillCmapFromHisto(), pixAddMinimalGrayColormap8(), pixBlendCmap(), pixcmapAddNearestColor(), pixcmapAddNewColor(), pixcmapColorToGray(), pixcmapContrastTRC(), pixcmapConvertHSVToRGB(), pixcmapConvertRGBToHSV(), pixcmapConvertRGBToYUV(), pixcmapConvertYUVToRGB(), pixcmapCountGrayColors(), pixcmapGammaTRC(), pixcmapGetExtremeValue(), pixcmapGetIndex(), pixcmapGetMinDepth(), pixcmapGetNearestGrayIndex(), pixcmapGetNearestIndex(), pixcmapGetRankIntensity(), pixcmapHasColor(), pixcmapSerializeToMemory(), pixcmapShiftIntensity(), pixcmapToArrays(), pixcmapToOctcubeLUT(), pixcmapToRGBTable(), pixColorSegmentClean(), pixColorSegmentCluster(), pixColorSegmentRemoveColors(), pixColorSegmentTryCluster(), pixColorsForQuantization(), pixConvert2To8(), pixConvert4To8(), pixDrawBoxa(), pixEqualWithCmap(), pixFewColorsOctcubeQuantMixed(), pixGetEdgeProfile(), pixGlobalNormRGB(), pixGrayQuantFromHisto(), pixMedianCutQuantGeneral(), pixMedianCutQuantMixed(), pixMultConstantColor(), pixMultMatrixColor(), pixNumColors(), pixOctreeQuantNumColors(), pixPaintBoxa(), pixRemoveColormap(), pixRemoveUnusedColors(), pixSetAll(), pixSetAllArbitrary(), pixSetInRect(), pixSetInRectArbitrary(), pixSetMaskedCmap(), pixSetSelectCmap(), pixSetSelectMaskedCmap(), pixSnapColorCmap(), pixUsesCmapColor(), pixWriteStreamBmp(), pixWriteStreamGif(), pixWriteStreamPng(), and pixWriteToTiffStream().

l_int32 pixcmapGetFreeCount ( PIXCMAP cmap)

pixcmapGetFreeCount()

Input: cmap Return: free entries, or 0 on error

Definition at line 535 of file colormap.c.

References ERROR_INT, PixColormap::n, PixColormap::nalloc, and PROCNAME.

Referenced by pixcmapAddBlackOrWhite(), and pixSnapColorCmap().

l_int32 pixcmapGetDepth ( PIXCMAP cmap)

pixcmapGetDepth()

Input: cmap Return: depth, or 0 on error

Definition at line 553 of file colormap.c.

References PixColormap::depth, ERROR_INT, and PROCNAME.

l_int32 pixcmapGetMinDepth ( PIXCMAP cmap,
l_int32 pmindepth 
)

pixcmapGetMinDepth()

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.

Definition at line 575 of file colormap.c.

References ERROR_INT, pixcmapGetCount(), and PROCNAME.

Referenced by pixGrayQuantFromCmap(), and pixOctcubeQuantFromCmapLUT().

l_int32 pixcmapClear ( PIXCMAP cmap)

pixcmapClear()

Input: cmap Return: 0 if OK, 1 on error

Note: this removes the colors by setting the count to 0.

Definition at line 609 of file colormap.c.

References ERROR_INT, PixColormap::n, and PROCNAME.

Referenced by pixColorSegmentTryCluster().

l_int32 pixcmapGetColor ( PIXCMAP cmap,
l_int32  index,
l_int32 prval,
l_int32 pgval,
l_int32 pbval 
)
l_int32 pixcmapGetColor32 ( PIXCMAP cmap,
l_int32  index,
l_uint32 pval32 
)

pixcmapGetColor32()

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.

Definition at line 672 of file colormap.c.

References composeRGBPixel(), ERROR_INT, pixcmapGetColor(), and PROCNAME.

Referenced by pixColorSegmentClean(), and pixColorSegmentRemoveColors().

l_int32 pixcmapResetColor ( PIXCMAP cmap,
l_int32  index,
l_int32  rval,
l_int32  gval,
l_int32  bval 
)

pixcmapResetColor()

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.

Definition at line 705 of file colormap.c.

References PixColormap::array, RGBA_Quad::blue, ERROR_INT, RGBA_Quad::green, PixColormap::n, PROCNAME, and RGBA_Quad::red.

Referenced by DoPageSegmentation(), main(), pixcmapColorToGray(), pixcmapContrastTRC(), pixcmapConvertHSVToRGB(), pixcmapConvertRGBToHSV(), pixcmapConvertRGBToYUV(), pixcmapConvertYUVToRGB(), pixcmapGammaTRC(), pixcmapSetBlackAndWhite(), pixcmapShiftIntensity(), pixColorSegmentTryCluster(), pixGetRegionsBinary(), pixGlobalNormRGB(), pixMedianCutQuantGeneral(), pixMultConstantColor(), pixMultMatrixColor(), pixOctcubeQuantMixedWithGray(), pixOctreeColorQuantGeneral(), and pixSnapColorCmap().

l_int32 pixcmapGetIndex ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32 pindex 
)

pixcmapGetIndex()

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)

Definition at line 739 of file colormap.c.

References PixColormap::array, ERROR_INT, CCBorda::n, pixcmapGetCount(), and PROCNAME.

Referenced by main(), pixBlendCmap(), pixcmapAddNearestColor(), pixcmapAddNewColor(), pixcmapUsableColor(), pixSetMaskedCmap(), pixSetSelectCmap(), and pixSetSelectMaskedCmap().

l_int32 pixcmapHasColor ( PIXCMAP cmap,
l_int32 pcolor 
)

pixcmapHasColor()

Input: cmap &color (<return> TRUE if cmap has color; FALSE otherwise) Return: 0 if OK, 1 on error

Definition at line 777 of file colormap.c.

References ERROR_INT, FALSE, FREE, CCBorda::n, pixcmapGetCount(), pixcmapToArrays(), PROCNAME, and TRUE.

Referenced by main(), pixColorsForQuantization(), pixGrayQuantFromCmap(), pixRemoveColormap(), pixUsesCmapColor(), and selCreateFromColorPix().

l_int32 pixcmapCountGrayColors ( PIXCMAP cmap,
l_int32 pngray 
)

pixcmapCountGrayColors()

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.

Definition at line 819 of file colormap.c.

References CALLOC, ERROR_INT, FREE, CCBorda::n, pixcmapGetColor(), pixcmapGetCount(), and PROCNAME.

l_int32 pixcmapGetRankIntensity ( PIXCMAP cmap,
l_float32  rankval,
l_int32 pindex 
)

pixcmapGetRankIntensity()

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

Definition at line 860 of file colormap.c.

References ERROR_INT, L_SORT_INCREASING, CCBorda::n, numaAddNumber(), numaCreate(), numaDestroy(), numaGetIValue(), numaGetSortIndex(), pixcmapGetColor(), pixcmapGetCount(), and PROCNAME.

Referenced by pixAddBlackBorder(), pixcmapAddBlackOrWhite(), pixcmapSetBlackAndWhite(), pixMedianCutQuantGeneral(), pixOctreeColorQuantGeneral(), pixRasteropHip(), and pixRasteropVip().

l_int32 pixcmapGetNearestIndex ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32 pindex 
)

pixcmapGetNearestIndex()

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.

Definition at line 909 of file colormap.c.

References PixColormap::array, RGBA_Quad::blue, ERROR_INT, RGBA_Quad::green, CCBorda::n, NULL, pixcmapGetCount(), PROCNAME, RGBA_Quad::red, and UNDEF.

Referenced by octreeGenerateAndPrune(), pixClipMasked(), pixcmapAddNearestColor(), and pixcmapToOctcubeLUT().

l_int32 pixcmapGetNearestGrayIndex ( PIXCMAP cmap,
l_int32  val,
l_int32 pindex 
)

pixcmapGetNearestGrayIndex()

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.

Definition at line 965 of file colormap.c.

References PixColormap::array, ERROR_INT, RGBA_Quad::green, L_ABS, CCBorda::n, NULL, pixcmapGetCount(), and PROCNAME.

Referenced by pixGrayQuantFromCmap().

l_int32 pixcmapGetComponentRange ( PIXCMAP cmap,
l_int32  color,
l_int32 pminval,
l_int32 pmaxval 
)

pixcmapGetComponentRange()

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.

Definition at line 1017 of file colormap.c.

References ERROR_INT, L_SELECT_BLUE, L_SELECT_GREEN, L_SELECT_MAX, L_SELECT_MIN, L_SELECT_RED, NULL, pixcmapGetExtremeValue(), and PROCNAME.

Referenced by pixGetComponentRange().

l_int32 pixcmapGetExtremeValue ( PIXCMAP cmap,
l_int32  type,
l_int32 prval,
l_int32 pgval,
l_int32 pbval 
)

pixcmapGetExtremeValue()

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.

Definition at line 1064 of file colormap.c.

References ERROR_INT, L_SELECT_MAX, L_SELECT_MIN, CCBorda::n, pixcmapGetColor(), pixcmapGetCount(), and PROCNAME.

Referenced by pixcmapGetComponentRange(), and pixGetExtremeValue().

PIXCMAP* pixcmapGrayToColor ( l_uint32  color)

pixcmapGrayToColor()

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.

Definition at line 1132 of file colormap.c.

References extractRGBValues(), pixcmapAddColor(), and pixcmapCreate().

Referenced by main(), and pixColorizeGray().

PIXCMAP* pixcmapColorToGray ( PIXCMAP cmaps,
l_float32  rwt,
l_float32  gwt,
l_float32  bwt 
)

pixcmapColorToGray()

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.

Definition at line 1162 of file colormap.c.

References ERROR_PTR, L_ABS, L_WARNING, CCBorda::n, NULL, pixcmapCopy(), pixcmapGetColor(), pixcmapGetCount(), pixcmapResetColor(), and PROCNAME.

Referenced by main(), and pixGrayQuantFromCmap().

PIXCMAP* pixcmapReadStream ( FILE *  fp)

pixcmapReadStream()

Input: stream Return: cmap, or null on error

Definition at line 1215 of file colormap.c.

References ERROR_PTR, NULL, pixcmapAddColor(), pixcmapCreate(), and PROCNAME.

Referenced by main().

l_int32 pixcmapWriteStream ( FILE *  fp,
PIXCMAP cmap 
)

pixcmapWriteStream()

Input: stream, cmap Return: 0 if OK, 1 on error

Definition at line 1255 of file colormap.c.

References PixColormap::depth, ERROR_INT, FREE, PixColormap::n, pixcmapToArrays(), and PROCNAME.

Referenced by main(), and pixPrintStreamInfo().

l_int32 pixcmapToArrays ( PIXCMAP cmap,
l_int32 **  prmap,
l_int32 **  pgmap,
l_int32 **  pbmap 
)

pixcmapToArrays()

Input: colormap &rmap, &gmap, &bmap (<return> colormap arrays) Return: 0 if OK; 1 on error

Definition at line 1297 of file colormap.c.

References PixColormap::array, RGBA_Quad::blue, CALLOC, ERROR_INT, RGBA_Quad::green, NULL, pixcmapGetCount(), PROCNAME, and RGBA_Quad::red.

Referenced by pixcmapHasColor(), pixcmapToOctcubeLUT(), pixcmapWriteStream(), pixRemoveColormap(), pixWriteStreamJpeg(), pixWriteStreamPng(), and pixWriteToTiffStream().

l_int32 pixcmapToRGBTable ( PIXCMAP cmap,
l_uint32 **  ptab,
l_int32 pncolors 
)

pixcmapToRGBTable()

Input: colormap &tab (<return> table of rgba values for the colormap) &ncolors (<optional return>=""> size of table) Return: 0 if OK; 1 on error

Definition at line 1343 of file colormap.c.

References CALLOC, composeRGBPixel(), ERROR_INT, NULL, pixcmapGetColor(), pixcmapGetCount(), and PROCNAME.

Referenced by pixColorizeGray().

l_int32 pixcmapSerializeToMemory ( PIXCMAP cmap,
l_int32  cpc,
l_int32 pncolors,
l_uint8 **  pdata,
l_int32 pnbytes 
)

pixcmapSerializeToMemory()

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.

Definition at line 1392 of file colormap.c.

References CALLOC, ERROR_INT, NULL, pixcmapGetColor(), pixcmapGetCount(), and PROCNAME.

Referenced by pixGenerateFlateData(), and pixSerializeToMemory().

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

Definition at line 1440 of file colormap.c.

References ERROR_PTR, NULL, pixcmapAddColor(), pixcmapCreate(), and PROCNAME.

Referenced by pixDeserializeFromMemory().

char* pixcmapConvertToHex ( l_uint8 data,
l_int32  nbytes,
l_int32  ncolors 
)

pixcmapConvertToHex()

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.

Definition at line 1500 of file colormap.c.

References buf, CALLOC, ERROR_PTR, NULL, and PROCNAME.

Referenced by pixGenerateFlateData().

l_int32 pixcmapGammaTRC ( PIXCMAP cmap,
l_float32  gamma,
l_int32  minval,
l_int32  maxval 
)

pixcmapGammaTRC()

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:

Definition at line 1562 of file colormap.c.

References ERROR_INT, L_WARNING, NULL, numaDestroy(), numaGammaTRC(), numaGetIValue(), pixcmapGetColor(), pixcmapGetCount(), pixcmapResetColor(), and PROCNAME.

Referenced by pixGammaTRC().

l_int32 pixcmapContrastTRC ( PIXCMAP cmap,
l_float32  factor 
)

pixcmapContrastTRC()

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:

Definition at line 1615 of file colormap.c.

References ERROR_INT, L_WARNING, NULL, numaContrastTRC(), numaDestroy(), numaGetIValue(), pixcmapGetColor(), pixcmapGetCount(), pixcmapResetColor(), and PROCNAME.

Referenced by pixContrastTRC().

l_int32 pixcmapShiftIntensity ( PIXCMAP cmap,
l_float32  fraction 
)

pixcmapShiftIntensity()

Input: colormap fraction (between -1.0 and +1.0) Return: 0 if OK; 1 on error

Notes:

  • in-place transform
  • This does a proportional shift of the intensity for each color.
  • 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.
  • The equivalent transform can be accomplished with pixcmapGammaTRC(), but it is considerably more difficult (see numaGammaTRC()).

Definition at line 1665 of file colormap.c.

References ERROR_INT, pixcmapGetColor(), pixcmapGetCount(), pixcmapResetColor(), and PROCNAME.

Referenced by main().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines