Leptonica  1.77.0
Image processing and image analysis suite
colormap.c File Reference
#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_ok pixcmapIsValid (PIXCMAP *cmap, l_int32 *pvalid)
 
l_ok pixcmapAddColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
 
l_ok pixcmapAddRGBA (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval)
 
l_ok pixcmapAddNewColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
 
l_ok pixcmapAddNearestColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
 
l_ok pixcmapUsableColor (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pusable)
 
l_ok pixcmapAddBlackOrWhite (PIXCMAP *cmap, l_int32 color, l_int32 *pindex)
 
l_ok 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_ok pixcmapGetMinDepth (PIXCMAP *cmap, l_int32 *pmindepth)
 
l_ok pixcmapClear (PIXCMAP *cmap)
 
l_ok pixcmapGetColor (PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
 
l_ok pixcmapGetColor32 (PIXCMAP *cmap, l_int32 index, l_uint32 *pval32)
 
l_ok pixcmapGetRGBA (PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval, l_int32 *paval)
 
l_ok pixcmapGetRGBA32 (PIXCMAP *cmap, l_int32 index, l_uint32 *pval32)
 
l_ok pixcmapResetColor (PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval)
 
l_ok pixcmapSetAlpha (PIXCMAP *cmap, l_int32 index, l_int32 aval)
 
l_int32 pixcmapGetIndex (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
 
l_ok pixcmapHasColor (PIXCMAP *cmap, l_int32 *pcolor)
 
l_ok pixcmapIsOpaque (PIXCMAP *cmap, l_int32 *popaque)
 
l_ok pixcmapIsBlackAndWhite (PIXCMAP *cmap, l_int32 *pblackwhite)
 
l_ok pixcmapCountGrayColors (PIXCMAP *cmap, l_int32 *pngray)
 
l_ok pixcmapGetRankIntensity (PIXCMAP *cmap, l_float32 rankval, l_int32 *pindex)
 
l_ok pixcmapGetNearestIndex (PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
 
l_ok pixcmapGetNearestGrayIndex (PIXCMAP *cmap, l_int32 val, l_int32 *pindex)
 
l_ok pixcmapGetDistanceToColor (PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pdist)
 
l_ok pixcmapGetRangeValues (PIXCMAP *cmap, l_int32 select, l_int32 *pminval, l_int32 *pmaxval, l_int32 *pminindex, l_int32 *pmaxindex)
 
PIXCMAPpixcmapGrayToColor (l_uint32 color)
 
PIXCMAPpixcmapColorToGray (PIXCMAP *cmaps, l_float32 rwt, l_float32 gwt, l_float32 bwt)
 
PIXCMAPpixcmapConvertTo4 (PIXCMAP *cmaps)
 
PIXCMAPpixcmapConvertTo8 (PIXCMAP *cmaps)
 
PIXCMAPpixcmapRead (const char *filename)
 
PIXCMAPpixcmapReadStream (FILE *fp)
 
PIXCMAPpixcmapReadMem (const l_uint8 *data, size_t size)
 
l_ok pixcmapWrite (const char *filename, PIXCMAP *cmap)
 
l_ok pixcmapWriteStream (FILE *fp, PIXCMAP *cmap)
 
l_ok pixcmapWriteMem (l_uint8 **pdata, size_t *psize, PIXCMAP *cmap)
 
l_ok pixcmapToArrays (PIXCMAP *cmap, l_int32 **prmap, l_int32 **pgmap, l_int32 **pbmap, l_int32 **pamap)
 
l_ok pixcmapToRGBTable (PIXCMAP *cmap, l_uint32 **ptab, l_int32 *pncolors)
 
l_ok pixcmapSerializeToMemory (PIXCMAP *cmap, l_int32 cpc, l_int32 *pncolors, l_uint8 **pdata)
 
PIXCMAPpixcmapDeserializeFromMemory (l_uint8 *data, l_int32 cpc, l_int32 ncolors)
 
char * pixcmapConvertToHex (l_uint8 *data, l_int32 ncolors)
 
l_ok pixcmapGammaTRC (PIXCMAP *cmap, l_float32 gamma, l_int32 minval, l_int32 maxval)
 
l_ok pixcmapContrastTRC (PIXCMAP *cmap, l_float32 factor)
 
l_ok pixcmapShiftIntensity (PIXCMAP *cmap, l_float32 fraction)
 
l_ok pixcmapShiftByComponent (PIXCMAP *cmap, l_uint32 srcval, l_uint32 dstval)
 

Detailed Description

 Colormap creation, copy, destruction, addition
      PIXCMAP    *pixcmapCreate()
      PIXCMAP    *pixcmapCreateRandom()
      PIXCMAP    *pixcmapCreateLinear()
      PIXCMAP    *pixcmapCopy()
      void        pixcmapDestroy()
      l_int32     pixcmapIsValid()
      l_int32     pixcmapAddColor()
      l_int32     pixcmapAddRGBA()
      l_int32     pixcmapAddNewColor()
      l_int32     pixcmapAddNearestColor()
      l_int32     pixcmapUsableColor()
      l_int32     pixcmapAddBlackOrWhite()
      l_int32     pixcmapSetBlackAndWhite()
      l_int32     pixcmapGetCount()
      l_int32     pixcmapGetDepth()
      l_int32     pixcmapGetMinDepth()
      l_int32     pixcmapGetFreeCount()
      l_int32     pixcmapClear()

 Colormap random access and test
      l_int32     pixcmapGetColor()
      l_int32     pixcmapGetColor32()
      l_int32     pixcmapGetRGBA()
      l_int32     pixcmapGetRGBA32()
      l_int32     pixcmapResetColor()
      l_int32     pixcmapSetAlpha()
      l_int32     pixcmapGetIndex()
      l_int32     pixcmapHasColor()
      l_int32     pixcmapIsOpaque()
      l_int32     pixcmapIsBlackAndWhite()
      l_int32     pixcmapCountGrayColors()
      l_int32     pixcmapGetRankIntensity()
      l_int32     pixcmapGetNearestIndex()
      l_int32     pixcmapGetNearestGrayIndex()
      l_int32     pixcmapGetDistanceToColor()
      l_int32     pixcmapGetRangeValues()

 Colormap conversion
      PIXCMAP    *pixcmapGrayToColor()
      PIXCMAP    *pixcmapColorToGray()
      PIXCMAP    *pixcmapConvertTo4()
      PIXCMAP    *pixcmapConvertTo8()

 Colormap I/O
      l_int32     pixcmapRead()
      l_int32     pixcmapReadStream()
      l_int32     pixcmapReadMem()
      l_int32     pixcmapWrite()
      l_int32     pixcmapWriteStream()
      l_int32     pixcmapWriteMem()

 Extract colormap arrays and serialization
      l_int32     pixcmapToArrays()
      l_int32     pixcmapToRGBTable()
      l_int32     pixcmapSerializeToMemory()
      PIXCMAP    *pixcmapDeserializeFromMemory()
      char       *pixcmapConvertToHex()

 Colormap transforms
      l_int32     pixcmapGammaTRC()
      l_int32     pixcmapContrastTRC()
      l_int32     pixcmapShiftIntensity()
      l_int32     pixcmapShiftByComponent()

Definition in file colormap.c.

Function Documentation

◆ pixcmapAddBlackOrWhite()

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

pixcmapAddBlackOrWhite()

Parameters
[in]cmap
[in]color0 for black, 1 for white
[out]pindex[optional] index of color; can be null
Returns
0 if OK, 1 on error
Notes:
     (1) This only adds color if not already there.
     (2) The alpha component is 255 (opaque)
     (3) This sets index to the requested color.
     (4) If there is no room in the colormap, returns the index
         of the closest color.

Definition at line 566 of file colormap.c.

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

◆ pixcmapAddColor()

l_ok pixcmapAddColor ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval 
)

pixcmapAddColor()

Parameters
[in]cmap
[in]rval,gval,bvalcolormap entry to be added; each number is in range [0, ... 255]
Returns
0 if OK, 1 on error
Notes:
     (1) This always adds the color if there is room.
     (2) The alpha component is 255 (opaque)

Definition at line 341 of file colormap.c.

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

Referenced by fpixRenderContours(), makeGrayQuantTableArb(), numaFillCmapFromHisto(), pixcmapAddNearestColor(), pixcmapAddNewColor(), pixcmapConvertTo4(), pixcmapConvertTo8(), pixcmapCreateLinear(), pixcmapCreateRandom(), pixcmapGenerateFromMedianCuts(), pixcmapGrayToColor(), and pixDisplayDiffBinary().

◆ pixcmapAddNearestColor()

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

pixcmapAddNearestColor()

Parameters
[in]cmap
[in]rval,gval,bvalcolormap entry to be added; each number is in range [0, ... 255]
[out]pindexindex of color
Returns
0 if OK, 1 on error
Notes:
     (1) This only adds color if not already there.
     (2) The alpha component is 255 (opaque)
     (3) 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 472 of file colormap.c.

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

◆ pixcmapAddNewColor()

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

pixcmapAddNewColor()

Parameters
[in]cmap
[in]rval,gval,bvalcolormap entry to be added; each number is in range [0, ... 255]
[out]pindexindex of color
Returns
0 if OK, 1 on error; 2 if unable to add color
Notes:
     (1) This only adds color if not already there.
     (2) The alpha component is 255 (opaque)
     (3) This returns the index of the new (or existing) color.
     (4) Returns 2 with a warning if unable to add this color;
         the caller should check the return value.

Definition at line 423 of file colormap.c.

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

Referenced by addColorizedGrayToCmap(), and pixcmapAddBlackOrWhite().

◆ pixcmapAddRGBA()

l_ok pixcmapAddRGBA ( PIXCMAP cmap,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32  aval 
)

pixcmapAddRGBA()

Parameters
[in]cmap
[in]rval,gval,bval,avalcolormap entry to be added; each number is in range [0, ... 255]
Returns
0 if OK, 1 on error
Notes:
     (1) This always adds the color if there is room.

Definition at line 379 of file colormap.c.

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

Referenced by pixcmapDeserializeFromMemory(), and pixcmapReadStream().

◆ pixcmapClear()

l_ok pixcmapClear ( PIXCMAP cmap)

pixcmapClear()

Parameters
[in]cmap
Returns
0 if OK, 1 on error
Notes:
     (1) This removes the colors by setting the count to 0.

Definition at line 728 of file colormap.c.

References PixColormap::n.

◆ pixcmapColorToGray()

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

pixcmapColorToGray()

Parameters
[in]cmaps
[in]rwt,gwt,bwtnon-negative; these should add to 1.0
Returns
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 1504 of file colormap.c.

References CCBorda::n, pixcmapCopy(), pixcmapGetColor(), pixcmapGetCount(), and pixcmapResetColor().

◆ pixcmapContrastTRC()

l_ok pixcmapContrastTRC ( PIXCMAP cmap,
l_float32  factor 
)

pixcmapContrastTRC()

Parameters
[in]cmapcolormap
[in]factorgenerally between 0.0 [no enhancement] and 1.0, but can be larger than 1.0
Returns
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

Definition at line 2178 of file colormap.c.

References numaContrastTRC(), numaDestroy(), numaGetIValue(), pixcmapGetColor(), pixcmapGetCount(), and pixcmapResetColor().

◆ pixcmapConvertTo4()

PIXCMAP* pixcmapConvertTo4 ( PIXCMAP cmaps)

pixcmapConvertTo4()

Parameters
[in]cmapscolormap for 2 bpp pix
Returns
cmapd (4 bpp)
Notes:
     (1) This converts a 2 bpp colormap to 4 bpp.  The colors
         are the same; the output colormap entry array has size 16.

Definition at line 1561 of file colormap.c.

References CCBorda::n, pixcmapAddColor(), pixcmapCreate(), pixcmapGetColor(), pixcmapGetCount(), and pixcmapGetDepth().

◆ pixcmapConvertTo8()

PIXCMAP* pixcmapConvertTo8 ( PIXCMAP cmaps)

pixcmapConvertTo8()

Parameters
[in]cmapscolormap for 2 bpp or 4 bpp pix
Returns
cmapd (8 bpp)
Notes:
     (1) This converts a 2 bpp or 4 bpp colormap to 8 bpp.  The colors
         are the same; the output colormap entry array has size 256.

Definition at line 1596 of file colormap.c.

References CCBorda::n, pixcmapAddColor(), pixcmapCopy(), pixcmapCreate(), pixcmapGetColor(), pixcmapGetCount(), and pixcmapGetDepth().

◆ pixcmapConvertToHex()

char* pixcmapConvertToHex ( l_uint8 *  data,
l_int32  ncolors 
)

pixcmapConvertToHex()

Parameters
[in]databinary serialized data
[in]ncolorsin colormap
Returns
hexdata bracketed, space-separated ascii hex string, or NULL on error.
Notes:
     (1) The number of bytes in data is 3 * ncolors.
     (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 2065 of file colormap.c.

◆ pixcmapCopy()

PIXCMAP* pixcmapCopy ( PIXCMAP cmaps)

pixcmapCopy()

Parameters
[in]cmaps
Returns
cmapd, or NULL on error

Definition at line 234 of file colormap.c.

References PixColormap::nalloc, and pixcmapIsValid().

Referenced by pixcmapColorToGray(), and pixcmapConvertTo8().

◆ pixcmapCountGrayColors()

l_ok pixcmapCountGrayColors ( PIXCMAP cmap,
l_int32 *  pngray 
)

pixcmapCountGrayColors()

Parameters
[in]cmap
[out]pngraynumber of gray colors
Returns
0 if OK, 1 on error
Notes:
     (1) This counts the unique gray colors, including black and white.

Definition at line 1117 of file colormap.c.

References CCBorda::n, pixcmapGetColor(), and pixcmapGetCount().

◆ pixcmapCreate()

◆ pixcmapCreateLinear()

PIXCMAP* pixcmapCreateLinear ( l_int32  d,
l_int32  nlevels 
)

pixcmapCreateLinear()

Parameters
[in]ddepth of pix for this colormap; 1, 2, 4 or 8
[in]nlevelsvalid in range [2, 2^d]
Returns
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 204 of file colormap.c.

References pixcmapAddColor(), and pixcmapCreate().

◆ pixcmapCreateRandom()

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

pixcmapCreateRandom()

Parameters
[in]depthbpp, of pix; 2, 4 or 8
[in]hasblack1 if the first color is black; 0 if no black
[in]haswhite1 if the last color is white; 0 if no white
Returns
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 158 of file colormap.c.

References pixcmapAddColor(), and pixcmapCreate().

Referenced by pixaDisplayRandomCmap(), pixBlendBoxaRandom(), and pixRenderRandomCmapPtaa().

◆ pixcmapDeserializeFromMemory()

PIXCMAP* pixcmapDeserializeFromMemory ( l_uint8 *  data,
l_int32  cpc,
l_int32  ncolors 
)

pixcmapDeserializeFromMemory()

Parameters
[in]databinary string, 3 or 4 bytes per color
[in]cpccomponents/color: 3 for rgb, 4 for rgba
[in]ncolors
Returns
cmap, or NULL on error

Definition at line 2004 of file colormap.c.

References pixcmapAddRGBA(), and pixcmapCreate().

◆ pixcmapDestroy()

void pixcmapDestroy ( PIXCMAP **  pcmap)

pixcmapDestroy()

Parameters
[in,out]pcmapset to null
Returns
void

Definition at line 265 of file colormap.c.

References PixColormap::array.

Referenced by pixBlendBoxaRandom(), pixcmapReadStream(), pixDestroyColormap(), and pixThresholdGrayArb().

◆ pixcmapGammaTRC()

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

pixcmapGammaTRC()

Parameters
[in]cmapcolormap
[in]gammagamma correction; must be > 0.0
[in]minvalinput value that gives 0 for output; can be < 0
[in]maxvalinput value that gives 255 for output; can be > 255
Returns
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

Definition at line 2123 of file colormap.c.

References numaDestroy(), numaGammaTRC(), numaGetIValue(), pixcmapGetColor(), pixcmapGetCount(), and pixcmapResetColor().

◆ pixcmapGetColor()

◆ pixcmapGetColor32()

l_ok pixcmapGetColor32 ( PIXCMAP cmap,
l_int32  index,
l_uint32 *  pval32 
)

pixcmapGetColor32()

Parameters
[in]cmap
[in]index
[out]pval3232-bit rgb color value
Returns
0 if OK, 1 if not accessible caller should check
Notes:
     (1) The returned alpha channel value is 255.

Definition at line 791 of file colormap.c.

References composeRGBAPixel(), and pixcmapGetColor().

◆ pixcmapGetCount()

◆ pixcmapGetDepth()

l_int32 pixcmapGetDepth ( PIXCMAP cmap)

pixcmapGetDepth()

Parameters
[in]cmap
Returns
depth, or 0 on error

Definition at line 669 of file colormap.c.

References PixColormap::depth.

Referenced by pixcmapConvertTo4(), and pixcmapConvertTo8().

◆ pixcmapGetDistanceToColor()

l_ok pixcmapGetDistanceToColor ( PIXCMAP cmap,
l_int32  index,
l_int32  rval,
l_int32  gval,
l_int32  bval,
l_int32 *  pdist 
)

pixcmapGetDistanceToColor()

Parameters
[in]cmap
[in]index
[in]rval,gval,bvaltarget color
[out]pdistthe distance from the cmap entry to target
Returns
0 if OK, 1 on error
Notes:
     (1) Returns the L2 distance (squared) between the color at index i
         and the target color.

Definition at line 1320 of file colormap.c.

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

◆ pixcmapGetFreeCount()

l_int32 pixcmapGetFreeCount ( PIXCMAP cmap)

pixcmapGetFreeCount()

Parameters
[in]cmap
Returns
free entries, or 0 on error

Definition at line 652 of file colormap.c.

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

Referenced by pixcmapAddBlackOrWhite().

◆ pixcmapGetIndex()

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

pixcmapGetIndex()

Parameters
[in]cmap
[in]rval,gval,bvalcolormap colors to search for; each number is in range [0, ... 255]
[out]pindexfound index
Returns
0 if found, 1 if not found caller must check

Definition at line 963 of file colormap.c.

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

Referenced by pixcmapAddNearestColor(), pixcmapAddNewColor(), and pixcmapUsableColor().

◆ pixcmapGetMinDepth()

l_ok pixcmapGetMinDepth ( PIXCMAP cmap,
l_int32 *  pmindepth 
)

pixcmapGetMinDepth()

Parameters
[in]cmap
[out]pmindepthminimum depth to support the colormap
Returns
0 if OK, 1 on error
Notes:
     (1) On error, &mindepth is returned as 0.

Definition at line 692 of file colormap.c.

References pixcmapGetCount().

◆ pixcmapGetNearestGrayIndex()

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

pixcmapGetNearestGrayIndex()

Parameters
[in]cmap
[in]valgray value to search for; in range [0, ... 255]
[out]pindexthe index of the nearest color
Returns
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 1267 of file colormap.c.

References PixColormap::array, RGBA_Quad::green, CCBorda::n, and pixcmapGetCount().

◆ pixcmapGetNearestIndex()

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

pixcmapGetNearestIndex()

Parameters
[in]cmap
[in]rval,gval,bvalcolormap colors to search for; each number is in range [0, ... 255]
[out]pindexthe index of the nearest color
Returns
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 1209 of file colormap.c.

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

Referenced by pixcmapAddNearestColor(), and pixcmapToOctcubeLUT().

◆ pixcmapGetRangeValues()

l_ok pixcmapGetRangeValues ( PIXCMAP cmap,
l_int32  select,
l_int32 *  pminval,
l_int32 *  pmaxval,
l_int32 *  pminindex,
l_int32 *  pmaxindex 
)

pixcmapGetRangeValues()

Parameters
[in]cmap
[in]selectL_SELECT_RED, L_SELECT_GREEN, L_SELECT_BLUE or L_SELECT_AVERAGE
[out]pminval[optional] minimum value of component
[out]pmaxval[optional] maximum value of component
[out]pminindex[optional] index of minimum value
[out]pmaxindex[optional] index of maximum value
Returns
0 if OK, 1 on error
Notes:
     (1) Returns, for selected components (or the average), the
         the extreme values (min and/or max) and their indices
         that are found in the cmap.

Definition at line 1376 of file colormap.c.

References L_SELECT_AVERAGE, L_SELECT_BLUE, L_SELECT_GREEN, L_SELECT_RED, CCBorda::n, pixcmapGetColor(), and pixcmapGetCount().

◆ pixcmapGetRankIntensity()

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

pixcmapGetRankIntensity()

Parameters
[in]cmap
[in]rankval0.0 for darkest, 1.0 for lightest color
[out]pindexthe index into the colormap that corresponds to the rank intensity color
Returns
0 if OK, 1 on error

Definition at line 1158 of file colormap.c.

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

Referenced by pixcmapAddBlackOrWhite(), and pixcmapSetBlackAndWhite().

◆ pixcmapGetRGBA()

l_ok pixcmapGetRGBA ( PIXCMAP cmap,
l_int32  index,
l_int32 *  prval,
l_int32 *  pgval,
l_int32 *  pbval,
l_int32 *  paval 
)

pixcmapGetRGBA()

Parameters
[in]cmap
[in]index
[out]prval,pgval,pbval,pavaleach color value
Returns
0 if OK, 1 if not accessible caller should check

Definition at line 819 of file colormap.c.

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

Referenced by cmapEqual(), pixcmapGetRGBA32(), pixcmapSerializeToMemory(), and pixcmapToRGBTable().

◆ pixcmapGetRGBA32()

l_ok pixcmapGetRGBA32 ( PIXCMAP cmap,
l_int32  index,
l_uint32 *  pval32 
)

pixcmapGetRGBA32()

Parameters
[in]cmap
[in]index
[out]pval3232-bit rgba color value
Returns
0 if OK, 1 if not accessible caller should check

Definition at line 857 of file colormap.c.

References composeRGBAPixel(), and pixcmapGetRGBA().

◆ pixcmapGrayToColor()

PIXCMAP* pixcmapGrayToColor ( l_uint32  color)

pixcmapGrayToColor()

Parameters
[in]color
Returns
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 1472 of file colormap.c.

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

◆ pixcmapHasColor()

l_ok pixcmapHasColor ( PIXCMAP cmap,
l_int32 *  pcolor 
)

pixcmapHasColor()

Parameters
[in]cmap
[out]pcolorTRUE if cmap has color; FALSE otherwise
Returns
0 if OK, 1 on error

Definition at line 1002 of file colormap.c.

References CCBorda::n, pixcmapGetCount(), and pixcmapToArrays().

Referenced by pixcmapIsBlackAndWhite().

◆ pixcmapIsBlackAndWhite()

l_ok pixcmapIsBlackAndWhite ( PIXCMAP cmap,
l_int32 *  pblackwhite 
)

pixcmapIsBlackAndWhite()

Parameters
[in]cmap
[out]pblackwhiteTRUE if the cmap has only two colors: black (0,0,0) and white (255,255,255)
Returns
0 if OK, 1 on error

Definition at line 1076 of file colormap.c.

References PixColormap::array, pixcmapGetCount(), pixcmapHasColor(), and RGBA_Quad::red.

◆ pixcmapIsOpaque()

l_ok pixcmapIsOpaque ( PIXCMAP cmap,
l_int32 *  popaque 
)

pixcmapIsOpaque()

Parameters
[in]cmap
[out]popaqueTRUE if fully opaque: all entries are 255
Returns
0 if OK, 1 on error

Definition at line 1041 of file colormap.c.

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

◆ pixcmapIsValid()

l_ok pixcmapIsValid ( PIXCMAP cmap,
l_int32 *  pvalid 
)

pixcmapIsValid()

Parameters
[in]cmap
[out]pvalidreturn 1 if valid; 0 if not
Returns
0 if OK, 1 on error or if cmap is not valid

Definition at line 293 of file colormap.c.

References PixColormap::array, PixColormap::depth, PixColormap::n, and PixColormap::nalloc.

Referenced by pixcmapCopy().

◆ pixcmapRead()

PIXCMAP* pixcmapRead ( const char *  filename)

pixcmapRead()

Parameters
[in]filename
Returns
cmap, or NULL on error

Definition at line 1630 of file colormap.c.

References fopenReadStream(), and pixcmapReadStream().

◆ pixcmapReadMem()

PIXCMAP* pixcmapReadMem ( const l_uint8 *  data,
size_t  size 
)

pixcmapReadMem()

Parameters
[in]dataserialization of pixcmap; in ascii
[in]sizeof data in bytes; can use strlen to get it
Returns
cmap, or NULL on error

Definition at line 1698 of file colormap.c.

References fopenReadFromMemory(), and pixcmapReadStream().

◆ pixcmapReadStream()

PIXCMAP* pixcmapReadStream ( FILE *  fp)

pixcmapReadStream()

Parameters
[in]fpfile stream
Returns
cmap, or NULL on error

Definition at line 1657 of file colormap.c.

References pixcmapAddRGBA(), pixcmapCreate(), and pixcmapDestroy().

Referenced by pixcmapRead(), and pixcmapReadMem().

◆ pixcmapResetColor()

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

pixcmapResetColor()

Parameters
[in]cmap
[in]index
[in]rval,gval,bvalcolormap entry to be reset; each number is in range [0, ... 255]
Returns
0 if OK, 1 if not accessible 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.
     (2) The alpha component is 255 (opaque)

Definition at line 893 of file colormap.c.

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

Referenced by pixcmapColorToGray(), pixcmapContrastTRC(), pixcmapConvertHSVToRGB(), pixcmapConvertRGBToHSV(), pixcmapConvertRGBToYUV(), pixcmapConvertYUVToRGB(), pixcmapGammaTRC(), pixcmapSetBlackAndWhite(), pixcmapShiftByComponent(), and pixcmapShiftIntensity().

◆ pixcmapSerializeToMemory()

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

pixcmapSerializeToMemory()

Parameters
[in]cmapcolormap
[in]cpccomponents/color: 3 for rgb, 4 for rgba
[out]pncolorsnumber of colors in table
[out]pdatabinary string, cpc bytes per color
Returns
0 if OK; 1 on error
Notes:
     (1) When serializing to store in a pdf, use cpc = 3.

Definition at line 1955 of file colormap.c.

References pixcmapGetCount(), and pixcmapGetRGBA().

◆ pixcmapSetAlpha()

l_ok pixcmapSetAlpha ( PIXCMAP cmap,
l_int32  index,
l_int32  aval 
)

pixcmapSetAlpha()

Parameters
[in]cmap
[in]index
[in]avalin range [0, ... 255]
Returns
0 if OK, 1 on error
Notes:
     (1) This modifies the transparency of one entry in a colormap.
         The alpha component by default is 255 (opaque).
         This is used when extracting the colormap from a PNG file
         without decoding the image.

Definition at line 934 of file colormap.c.

References RGBA_Quad::alpha, PixColormap::array, and PixColormap::n.

◆ pixcmapSetBlackAndWhite()

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

pixcmapSetBlackAndWhite()

Parameters
[in]cmap
[in]setblack0 for no operation; 1 to set darkest color to black
[in]setwhite0 for no operation; 1 to set lightest color to white
Returns
0 if OK, 1 on error

Definition at line 605 of file colormap.c.

References pixcmapGetRankIntensity(), and pixcmapResetColor().

Referenced by pixThresholdGrayArb().

◆ pixcmapShiftByComponent()

l_ok pixcmapShiftByComponent ( PIXCMAP cmap,
l_uint32  srcval,
l_uint32  dstval 
)

pixcmapShiftByComponent()

Parameters
[in]cmapcolormap
[in]srcvalsource color: 0xrrggbb00
[in]dstvaltarget color: 0xrrggbb00
Returns
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.

Definition at line 2280 of file colormap.c.

References extractRGBValues(), pixcmapGetColor(), pixcmapGetCount(), pixcmapResetColor(), and pixelShiftByComponent().

◆ pixcmapShiftIntensity()

l_ok pixcmapShiftIntensity ( PIXCMAP cmap,
l_float32  fraction 
)

pixcmapShiftIntensity()

Parameters
[in]cmapcolormap
[in]fractionbetween -1.0 and +1.0
Returns
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()).

Definition at line 2230 of file colormap.c.

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

◆ pixcmapToArrays()

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

pixcmapToArrays()

Parameters
[in]cmapcolormap
[out]prmap,pgmap,pbmapcolormap arrays
[out]pamap[optional] alpha array
Returns
0 if OK; 1 on error

Definition at line 1856 of file colormap.c.

References RGBA_Quad::alpha, PixColormap::array, RGBA_Quad::blue, RGBA_Quad::green, pixcmapGetCount(), and RGBA_Quad::red.

Referenced by pixcmapHasColor(), pixcmapToOctcubeLUT(), and pixcmapWriteStream().

◆ pixcmapToRGBTable()

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

pixcmapToRGBTable()

Parameters
[in]cmapcolormap
[out]ptabtable of rgba values for the colormap
[out]pncolors[optional] size of table
Returns
0 if OK; 1 on error

Definition at line 1910 of file colormap.c.

References composeRGBAPixel(), pixcmapGetCount(), and pixcmapGetRGBA().

◆ pixcmapUsableColor()

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

pixcmapUsableColor()

Parameters
[in]cmap
[in]rval,gval,bvalcolormap entry to be added; each number is in range [0, ... 255]
[out]pusable1 if usable; 0 if not
Returns
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 519 of file colormap.c.

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

◆ pixcmapWrite()

l_ok pixcmapWrite ( const char *  filename,
PIXCMAP cmap 
)

pixcmapWrite()

Parameters
[in]filename
[in]cmap
Returns
0 if OK, 1 on error

Definition at line 1726 of file colormap.c.

References fopenWriteStream(), and pixcmapWriteStream().

◆ pixcmapWriteMem()

l_ok pixcmapWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PIXCMAP cmap 
)

pixcmapWriteMem()

Parameters
[out]pdatadata of serialized pixcmap; ascii
[out]psizesize of returned data
[in]cmap
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a pixcmap in memory and puts the result in a buffer.

Definition at line 1804 of file colormap.c.

References fopenWriteWinTempfile(), l_binaryReadStream(), and pixcmapWriteStream().

◆ pixcmapWriteStream()

l_ok pixcmapWriteStream ( FILE *  fp,
PIXCMAP cmap 
)

pixcmapWriteStream()

Parameters
[in]fpfile stream
[in]cmap
Returns
0 if OK, 1 on error

Definition at line 1758 of file colormap.c.

References PixColormap::depth, PixColormap::n, and pixcmapToArrays().

Referenced by pixcmapWrite(), and pixcmapWriteMem().