Leptonica 1.68
C Image Processing Library

blend.c File Reference

Blend (optionally with a mask) and re-coloring images. More...

#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static l_int32 blendComponents (l_int32 a, l_int32 b, l_float32 fract)
static l_int32 blendHardLightComponents (l_int32 a, l_int32 b, l_float32 fract)
PIXpixBlend (PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract)
PIXpixBlendMask (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 type)
PIXpixBlendGray (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 type, l_int32 transparent, l_uint32 transpix)
PIXpixBlendColor (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 transparent, l_uint32 transpix)
PIXpixBlendColorByChannel (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 rfract, l_float32 gfract, l_float32 bfract, l_int32 transparent, l_uint32 transpix)
PIXpixBlendGrayAdapt (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 shift)
PIXpixFadeWithGray (PIX *pixs, PIX *pixb, l_float32 factor, l_int32 type)
PIXpixBlendHardLight (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract)
l_int32 pixBlendCmap (PIX *pixs, PIX *pixb, l_int32 x, l_int32 y, l_int32 sindex)
PIXpixBlendWithGrayMask (PIX *pixs1, PIX *pixs2, PIX *pixg, l_int32 x, l_int32 y)
l_int32 pixColorGray (PIX *pixs, BOX *box, l_int32 type, l_int32 thresh, l_int32 rval, l_int32 gval, l_int32 bval)
PIXpixSnapColor (PIX *pixd, PIX *pixs, l_uint32 srcval, l_uint32 dstval, l_int32 diff)
PIXpixSnapColorCmap (PIX *pixd, PIX *pixs, l_uint32 srcval, l_uint32 dstval, l_int32 diff)
PIXpixLinearMapToTargetColor (PIX *pixd, PIX *pixs, l_uint32 srcval, l_uint32 dstval)
l_int32 pixelLinearMapToTargetColor (l_uint32 scolor, l_uint32 srcmap, l_uint32 dstmap, l_uint32 *pdcolor)
l_int32 pixelFractionalShift (l_int32 rval, l_int32 gval, l_int32 bval, l_float32 fraction, l_uint32 *ppixel)

Detailed Description

Blend (optionally with a mask) and re-coloring images.

    Blending two images that are not colormapped
         PIX             *pixBlend()
         PIX             *pixBlendMask()
         PIX             *pixBlendGray()
         PIX             *pixBlendColor()
         PIX             *pixBlendColorByChannel()
         PIX             *pixBlendGrayAdapt()
         static l_int32   blendComponents()
         PIX             *pixFadeWithGray()
         PIX             *pixBlendHardLight()
         static l_int32   blendHardLightComponents()

    Blending two colormapped images
         l_int32          pixBlendCmap()

    Blending two images using a third (alpha mask)
         PIX             *pixBlendWithGrayMask()

    Coloring "gray" pixels
         l_int32          pixColorGray()

    Adjusting one or more colors to a target color
         PIX             *pixSnapColor()
         PIX             *pixSnapColorCmap()

    Mapping colors based on a source/target pair
         PIX             *pixLinearMapToTargetColor()
         l_uint32         pixelLinearMapToTargetColor()

    Fractional shift of RGB towards black or white
         l_uint32         pixelFractionalShift()

In blending operations a new pix is produced where typically
a subset of pixels in src1 are changed by the set of pixels
in src2, when src2 is located in a given position relative
to src1.  This is similar to rasterop, except that the
blending operations we allow are more complex, and typically
result in dest pixels that are a linear combination of two
pixels, such as src1 and its inverse.  I find it convenient
to think of src2 as the "blender" (the one that takes the action)
and src1 as the "blendee" (the one that changes).

Blending works best when src1 is 8 or 32 bpp.  We also allow
src1 to be colormapped, but the colormap is removed before blending,
so if src1 is colormapped, we can't allow in-place blending.

Because src2 is typically smaller than src1, we can implement by
clipping src2 to src1 and then transforming some of the dest
pixels that are under the support of src2.  In practice, we
do the clipping in the inner pixel loop.  For grayscale and
color src2, we also allow a simple form of transparency, where
pixels of a particular value in src2 are transparent; for those pixels,
no blending is done.

The blending functions are categorized by the depth of src2,
the blender, and not that of src1, the blendee.

 - If src2 is 1 bpp, we can do one of three things:
   (1) L_BLEND_WITH_INVERSE: Blend a given fraction of src1 with its
       inverse color for those pixels in src2 that are fg (ON),
       and leave the dest pixels unchanged for pixels in src2 that
       are bg (OFF).
   (2) L_BLEND_TO_WHITE: Fade the src1 pixels toward white by a
       given fraction for those pixels in src2 that are fg (ON),
       and leave the dest pixels unchanged for pixels in src2 that
       are bg (OFF).
   (3) L_BLEND_TO_BLACK: Fade the src1 pixels toward black by a
       given fraction for those pixels in src2 that are fg (ON),
       and leave the dest pixels unchanged for pixels in src2 that
       are bg (OFF).
   The blending function is pixBlendMask().

 - If src2 is 8 bpp grayscale, we can do one of two things
   (but see pixFadeWithGray() below):
   (1) L_BLEND_GRAY: If src1 is 8 bpp, mix the two values, using
       a fraction of src2 and (1 - fraction) of src1.
       If src1 is 32 bpp (rgb), mix the fraction of src2 with
       each of the color components in src1.
   (2) L_BLEND_GRAY_WITH_INVERSE: Use the grayscale value in src2
       to determine how much of the inverse of a src1 pixel is
       to be combined with the pixel value.  The input fraction
       further acts to scale the change in the src1 pixel.
   The blending function is pixBlendGray().

 - If src2 is color, we blend a given fraction of src2 with
   src1.  If src1 is 8 bpp, the resulting image is 32 bpp.
   The blending function is pixBlendColor().

 - For all three blending functions -- pixBlendMask(), pixBlendGray()
   and pixBlendColor() -- you can apply the blender to the blendee
   either in-place or generating a new pix.  For the in-place
   operation, this requires that the depth of the resulting pix
   must equal that of the input pixs1.

 - We remove colormaps from src1 and src2 before blending.
   Any quantization would have to be done after blending.

We include another function, pixFadeWithGray(), that blends
a gray or color src1 with a gray src2.  It does one of these things:
   (1) L_BLEND_TO_WHITE: Fade the src1 pixels toward white by
       a number times the value in src2.
   (2) L_BLEND_TO_BLACK: Fade the src1 pixels toward black by
       a number times the value in src2.

Also included is a generalization of the so-called "hard light"
blending: pixBlendHardLight().  We generalize by allowing a fraction < 1.0
of the blender to be admixed with the blendee.  The standard function
does full mixing.

Definition in file blend.c.


Function Documentation

static l_int32 blendComponents ( l_int32  a,
l_int32  b,
l_float32  fract 
) [static]

Definition at line 845 of file blend.c.

Referenced by pixBlendColorByChannel().

static l_int32 blendHardLightComponents ( l_int32  a,
l_int32  b,
l_float32  fract 
) [static]

Definition at line 1318 of file blend.c.

Referenced by pixBlendHardLight().

PIX* pixBlend ( PIX pixs1,
PIX pixs2,
l_int32  x,
l_int32  y,
l_float32  fract 
)

pixBlend()

Input: pixs1 (blendee) pixs2 (blender; typ. smaller) x,y (origin (UL corner) of pixs2 relative to the origin of pixs1; can be < 0) fract (blending fraction) Return: pixd (blended image), or null on error

Notes: (1) This is a simple top-level interface. For more flexibility, call directly into pixBlendMask(), etc.

Definition at line 157 of file blend.c.

References boxCreate(), boxDestroy(), ERROR_PTR, L_BLEND_GRAY, L_BLEND_WITH_INVERSE, L_MAX, L_WARNING, NULL, pixBlendColor(), pixBlendGray(), pixBlendMask(), pixClipRectangle(), pixDestroy(), pixGetDepth(), pixGetDimensions(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.

Referenced by main().

PIX* pixBlendMask ( PIX pixd,
PIX pixs1,
PIX pixs2,
l_int32  x,
l_int32  y,
l_float32  fract,
l_int32  type 
)

pixBlendMask()

Input: pixd (<optional>; either NULL or equal to pixs1 for in-place) pixs1 (blendee; depth > 1) pixs2 (blender; typ. smaller in size than pixs1) x,y (origin (UL corner) of pixs2 relative to the origin of pixs1; can be < 0) fract (blending fraction) type (L_BLEND_WITH_INVERSE, L_BLEND_TO_WHITE, L_BLEND_TO_BLACK) Return: pixd if OK; pixs1 on error

Notes: (1) pixs2 must be 1 bpp (2) Clipping of pixs2 to pixs1 is done in the inner pixel loop. (3) If pixs1 has a colormap, it is removed. (4) For inplace operation, call it this way: pixBlendMask(pixs1, pixs1, pixs2, ...) (5) For generating a new pixd: pixd = pixBlendMask(NULL, pixs1, pixs2, ...) (6) Only call in-place if pixs1 does not have a colormap.

Definition at line 240 of file blend.c.

References composeRGBPixel(), ERROR_PTR, extractRGBValues(), FALSE, GET_DATA_BIT, L_BLEND_TO_BLACK, L_BLEND_TO_WHITE, L_BLEND_WITH_INVERSE, L_WARNING, NULL, pixClone(), pixConvertTo8(), pixCopy(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetPixel(), pixGetWidth(), pixGetWpl(), pixRemoveColormap(), pixSetPixel(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.

Referenced by pixBlend().

PIX* pixBlendGray ( PIX pixd,
PIX pixs1,
PIX pixs2,
l_int32  x,
l_int32  y,
l_float32  fract,
l_int32  type,
l_int32  transparent,
l_uint32  transpix 
)

pixBlendGray()

Input: pixd (<optional>; either NULL or equal to pixs1 for in-place) pixs1 (blendee; depth > 1) pixs2 (blender, 8 bpp; typ. smaller in size than pixs1) x,y (origin (UL corner) of pixs2 relative to the origin of pixs1; can be < 0) fract (blending fraction) type (L_BLEND_GRAY, L_BLEND_GRAY_WITH_INVERSE) transparent (1 to use transparency; 0 otherwise) transpix (pixel grayval in pixs2 that is to be transparent) Return: pixd if OK; pixs1 on error

Notes: (1) pixs2 must be 8 bpp, and have no colormap. (2) Clipping of pixs2 to pixs1 is done in the inner pixel loop. (3) If pixs1 has a colormap, it is removed. (4) If pixs1 has depth < 8, it is unpacked to generate a 8 bpp pix. (5) For inplace operation, call it this way: pixBlendGray(pixs1, pixs1, pixs2, ...) (6) For generating a new pixd: pixd = pixBlendGray(NULL, pixs1, pixs2, ...) (7) Only call in-place if pixs1 does not have a colormap; otherwise it is an error. (8) If transparent = 0, the blending fraction (fract) is applied equally to all pixels. (9) If transparent = 1, all pixels of value transpix (typically either 0 or 0xff) in pixs2 are transparent in the blend. (10) After processing pixs1, it is either 8 bpp or 32 bpp:

  • if 8 bpp, the fraction of pixs2 is mixed with pixs1.
  • if 32 bpp, each component of pixs1 is mixed with the same fraction of pixs2. (11) For L_BLEND_GRAY_WITH_INVERSE, the white values of the blendee (cval == 255 in the code below) result in a delta of 0. Thus, these pixels are intrinsically transparent! The "pivot" value of the src, at which no blending occurs, is 128. Compare with the adaptive pivot in pixBlendGrayAdapt().

Definition at line 456 of file blend.c.

References composeRGBPixel(), ERROR_PTR, extractRGBValues(), FALSE, GET_DATA_BYTE, L_BLEND_GRAY, L_BLEND_GRAY_WITH_INVERSE, L_WARNING, NULL, pixClone(), pixConvertTo8(), pixCopy(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and SET_DATA_BYTE.

Referenced by GrayBlend(), main(), and pixBlend().

PIX* pixBlendColor ( PIX pixd,
PIX pixs1,
PIX pixs2,
l_int32  x,
l_int32  y,
l_float32  fract,
l_int32  transparent,
l_uint32  transpix 
)

pixBlendColor()

Input: pixd (<optional>; either NULL or equal to pixs1 for in-place) pixs1 (blendee; depth > 1) pixs2 (blender, 32 bpp; typ. smaller in size than pixs1) x,y (origin (UL corner) of pixs2 relative to the origin of pixs1) fract (blending fraction) transparent (1 to use transparency; 0 otherwise) transpix (pixel color in pixs2 that is to be transparent) Return: pixd if OK; pixs1 on error

Notes: (1) pixs2 must be 32 bpp, and have no colormap. (2) Clipping of pixs2 to pixs1 is done in the inner pixel loop. (3) If pixs1 has a colormap, it is removed to generate a 32 bpp pix. (4) If pixs1 has depth < 32, it is unpacked to generate a 32 bpp pix. (5) For inplace operation, call it this way: pixBlendColor(pixs1, pixs1, pixs2, ...) (6) For generating a new pixd: pixd = pixBlendColor(NULL, pixs1, pixs2, ...) (7) Only call in-place if pixs1 is 32 bpp; otherwise it is an error. (8) If transparent = 0, the blending fraction (fract) is applied equally to all pixels. (9) If transparent = 1, all pixels of value transpix (typically either 0 or 0xffffff00) in pixs2 are transparent in the blend.

Definition at line 652 of file blend.c.

References composeRGBPixel(), ERROR_PTR, extractRGBValues(), L_WARNING, NULL, pixClone(), pixConvertTo32(), pixCopy(), pixDestroy(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_TO_FULL_COLOR.

Referenced by ColorBlend(), main(), and pixBlend().

PIX* pixBlendColorByChannel ( PIX pixd,
PIX pixs1,
PIX pixs2,
l_int32  x,
l_int32  y,
l_float32  rfract,
l_float32  gfract,
l_float32  bfract,
l_int32  transparent,
l_uint32  transpix 
)
PIX* pixBlendGrayAdapt ( PIX pixd,
PIX pixs1,
PIX pixs2,
l_int32  x,
l_int32  y,
l_float32  fract,
l_int32  shift 
)

pixBlendGrayAdapt()

Input: pixd (<optional>; either NULL or equal to pixs1 for in-place) pixs1 (blendee; depth > 1) pixs2 (blender, 8 bpp; typ. smaller in size than pixs1) x,y (origin (UL corner) of pixs2 relative to the origin of pixs1; can be < 0) fract (blending fraction) shift (>= 0 but <= 128: shift of zero blend value from median source; use -1 for default value; ) Return: pixd if OK; pixs1 on error

Notes: (1) pixs2 must be 8 bpp, and have no colormap. (2) Clipping of pixs2 to pixs1 is done in the inner pixel loop. (3) If pixs1 has a colormap, it is removed. (4) If pixs1 has depth < 8, it is unpacked to generate a 8 bpp pix. (5) For inplace operation, call it this way: pixBlendGray(pixs1, pixs1, pixs2, ...) For generating a new pixd: pixd = pixBlendGray(NULL, pixs1, pixs2, ...) Only call in-place if pixs1 does not have a colormap; otherwise it is an error. (6) This does a blend with inverse. Whereas in pixGlendGray(), the zero blend point is where the blendee pixel is 128, here the zero blend point is found adaptively, with respect to the median of the blendee region. If the median is < 128, the zero blend point is found from median + shift. Otherwise, if the median >= 128, the zero blend point is median - shift. The purpose of shifting the zero blend point away from the median is to prevent a situation in pixBlendGray() where the median is 128 and the blender is not visible. The default value of shift is 64. (7) After processing pixs1, it is either 8 bpp or 32 bpp:

  • if 8 bpp, the fraction of pixs2 is mixed with pixs1.
  • if 32 bpp, each component of pixs1 is mixed with the same fraction of pixs2. (8) The darker the blender, the more it mixes with the blendee. A blender value of 0 has maximum mixing; a value of 255 has no mixing and hence is transparent.

Definition at line 902 of file blend.c.

References boxCreate(), boxDestroy(), boxIntersects(), composeRGBPixel(), ERROR_PTR, extractRGBValues(), FALSE, GET_DATA_BYTE, L_MAX, L_WARNING, NULL, pixClipRectangle(), pixClone(), pixConvertTo8(), pixCopy(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetRankValueMasked(), pixGetWpl(), pixRemoveColormap(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and SET_DATA_BYTE.

Referenced by AdaptiveGrayBlend().

PIX* pixFadeWithGray ( PIX pixs,
PIX pixb,
l_float32  factor,
l_int32  type 
)

pixFadeWithGray()

Input: pixs (colormapped or 8 bpp or 32 bpp) pixb (8 bpp blender) factor (multiplicative factor to apply to blender value) type (L_BLEND_TO_WHITE, L_BLEND_TO_BLACK) Return: pixd, or null on error

Notes: (1) This function combines two pix aligned to the UL corner; they need not be the same size. (2) Each pixel in pixb is multiplied by 'factor' divided by 255, and clipped to the range [0 ... 1]. This gives the fade fraction to be appied to pixs. Fade either to white (L_BLEND_TO_WHITE) or to black (L_BLEND_TO_BLACK).

Definition at line 1079 of file blend.c.

References composeRGBPixel(), ERROR_PTR, extractRGBValues(), GET_DATA_BYTE, L_BLEND_TO_BLACK, L_BLEND_TO_WHITE, L_MIN, NULL, pixCopy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and SET_DATA_BYTE.

l_int32 pixBlendCmap ( PIX pixs,
PIX pixb,
l_int32  x,
l_int32  y,
l_int32  sindex 
)

pixBlendCmap()

Input: pixs (2, 4 or 8 bpp, with colormap) pixb (colormapped blender) x, y (UL corner of blender relative to pixs) sindex (colormap index of pixels in pixs to be changed) Return: 0 if OK, 1 on error

Note: (1) This function combines two colormaps, and replaces the pixels in pixs that have a specified color value with those in pixb. (2) sindex must be in the existing colormap; otherwise an error is returned. In use, sindex will typically be the index for white (255, 255, 255). (3) Blender colors that already exist in the colormap are used; others are added. If any blender colors cannot be stored in the colormap, an error is returned. (4) In the implementation, a mapping is generated from each original blender colormap index to the corresponding index in the expanded colormap for pixs. Then for each pixel in pixs with value sindex, and which is covered by a blender pixel, the new index corresponding to the blender pixel is substituted for sindex.

Definition at line 1361 of file blend.c.

References ERROR_INT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, NULL, pixcmapAddColor(), pixcmapCopy(), pixcmapDestroy(), pixcmapGetColor(), pixcmapGetCount(), pixcmapGetIndex(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetPixel(), pixGetWpl(), pixSetColormap(), PROCNAME, SET_DATA_BYTE, SET_DATA_DIBIT, and SET_DATA_QBIT.

Referenced by main().

PIX* pixBlendWithGrayMask ( PIX pixs1,
PIX pixs2,
PIX pixg,
l_int32  x,
l_int32  y 
)

pixBlendWithGrayMask()

Input: pixs1 (8 bpp gray, rgb or colormapped) pixs2 (8 bpp gray, rgb or colormapped) pixg (8 bpp gray, for transparency of pixs2; can be null) x, y (UL corner of pixg with respect to pixs1) Return: pixd (blended image), or null on error

Notes: (1) The result is 8 bpp grayscale if both pixs1 and pixs2 are 8 bpp gray. Otherwise, the result is 32 bpp rgb. (2) pixg is an 8 bpp transparency image, where 0 is transparent and 255 is opaque. It determines the transparency of pixs2 when applied over pixs1. It can be null if pixs2 is rgb, in which case we use the alpha component of pixs2. (3) If pixg exists, both it and pixs2 must be the same size, and they are applied with both their UL corners at the location (x, y) in pixs1. (4) The pixels in pixd are a combination of those in pixs1 and pixs2, where the amount from pixs2 is proportional to the value of the pixel (p) in pixg, and the amount from pixs1 is proportional to (255 - p). Thus pixg is a transparency image (usually called an alpha blender) where each pixel can be associated with a pixel in pixs2, and determines the amount of the pixs2 pixel in the final result. For example, if pixg is all 0, pixs2 is transparent and the result in pixd is simply pixs1. (5) A typical use is for the pixs2/pixg combination to be a small watermark that is applied to pixs1.

Definition at line 1495 of file blend.c.

References composeRGBPixel(), ERROR_PTR, extractRGBValues(), FALSE, GET_DATA_BYTE, L_ALPHA_CHANNEL, L_MIN, NULL, pixClone(), pixConvertTo32(), pixConvertTo8(), pixCopy(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetRGBComponent(), pixGetWpl(), pixRemoveColormap(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and SET_DATA_BYTE.

Referenced by main().

l_int32 pixColorGray ( PIX pixs,
BOX box,
l_int32  type,
l_int32  thresh,
l_int32  rval,
l_int32  gval,
l_int32  bval 
)

pixColorGray()

Input: pixs (8 bpp gray, rgb or colormapped image) box (<optional> region in which to apply color; can be NULL) type (L_PAINT_LIGHT, L_PAINT_DARK) thresh (average value below/above which pixel is unchanged) rval, gval, bval (new color to paint) Return: 0 if OK; 1 on error

Notes: (1) This is an in-place operation; pixs is modified. If pixs is colormapped, the operation will add colors to the colormap. Otherwise, pixs will be converted to 32 bpp rgb if it is initially 8 bpp gray. (2) If type == L_PAINT_LIGHT, it colorizes non-black pixels, preserving antialiasing. If type == L_PAINT_DARK, it colorizes non-white pixels, preserving antialiasing. (3) If box is NULL, applies function to the entire image; otherwise, clips the operation to the intersection of the box and pix. (4) If colormapped, calls pixColorGrayCmap(), which applies the coloring algorithm only to pixels that are strictly gray. (5) For RGB, determines a "gray" value by averaging; then uses this value, plus the input rgb target, to generate the output pixel values. (6) thresh is only used for rgb; it is ignored for colormapped pix. If type == L_PAINT_LIGHT, use thresh = 0 if all pixels are to be colored (black pixels will be unaltered). In situations where there are a lot of black pixels, setting thresh > 0 will make the function considerably more efficient without affecting the final result. If type == L_PAINT_DARK, use thresh = 255 if all pixels are to be colored (white pixels will be unaltered). In situations where there are a lot of white pixels, setting thresh < 255 will make the function considerably more efficient without affecting the final result.

Definition at line 1678 of file blend.c.

References boxGetGeometry(), composeRGBPixel(), ERROR_INT, L_PAINT_DARK, L_PAINT_LIGHT, L_WARNING, pixColorGrayCmap(), pixConvertTo32(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), pixTransferAllData(), PROCNAME, x1, x2, y1, and y2.

Referenced by main().

PIX* pixSnapColor ( PIX pixd,
PIX pixs,
l_uint32  srcval,
l_uint32  dstval,
l_int32  diff 
)

pixSnapColor()

Input: pixd (<optional>; either NULL or equal to pixs for in-place) pixs (colormapped or 8 bpp gray or 32 bpp rgb) srcval (color center to be selected for change: 0xrrggbb00) dstval (target color for pixels: 0xrrggbb00) diff (max absolute difference, applied to all components) Return: pixd (with all pixels within diff of pixval set to pixval), or pixd on error

Notes: (1) For inplace operation, call it this way: pixSnapColor(pixs, pixs, ... ) (2) For generating a new pixd: pixd = pixSnapColor(NULL, pixs, ...) (3) If pixs has a colormap, it is handled by pixSnapColorCmap(). (4) All pixels within 'diff' of 'srcval', componentwise, will be changed to 'dstval'.

Definition at line 1801 of file blend.c.

References ERROR_PTR, extractRGBValues(), GET_DATA_BYTE, L_ABS, NULL, pixCopy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixSnapColorCmap(), PROCNAME, and SET_DATA_BYTE.

Referenced by main().

PIX* pixSnapColorCmap ( PIX pixd,
PIX pixs,
l_uint32  srcval,
l_uint32  dstval,
l_int32  diff 
)

pixSnapColorCmap()

Input: pixd (<optional>; either NULL or equal to pixs for in-place) pixs (colormapped) srcval (color center to be selected for change: 0xrrggbb00) dstval (target color for pixels: 0xrrggbb00) diff (max absolute difference, applied to all components) Return: pixd (with all pixels within diff of srcval set to dstval), or pixd on error

Notes: (1) For inplace operation, call it this way: pixSnapCcmap(pixs, pixs, ... ) (2) For generating a new pixd: pixd = pixSnapCmap(NULL, pixs, ...) (3) pixs must have a colormap. (4) All colors within 'diff' of 'srcval', componentwise, will be changed to 'dstval'.

Definition at line 1887 of file blend.c.

References CALLOC, ERROR_PTR, extractRGBValues(), FALSE, FREE, L_ABS, L_INFO, NULL, pixcmapAddColor(), pixcmapGetColor(), pixcmapGetCount(), pixcmapGetFreeCount(), pixcmapResetColor(), pixCopy(), pixDestroy(), pixGetColormap(), pixMakeMaskFromLUT(), pixRemoveUnusedColors(), pixSetMasked(), PROCNAME, and TRUE.

Referenced by pixSnapColor().

PIX* pixLinearMapToTargetColor ( PIX pixd,
PIX pixs,
l_uint32  srcval,
l_uint32  dstval 
)

pixLinearMapToTargetColor()

Input: pixd (<optional>; either NULL or equal to pixs for in-place) pixs (32 bpp rgb) srcval (source color: 0xrrggbb00) dstval (target color: 0xrrggbb00) Return: pixd (with all pixels mapped based on the srcval/destval mapping), or pixd on error

Notes: (1) For each component (r, b, g) separately, this does a piecewise linear mapping of the colors in pixs to colors in pixd. If rs and rd are the red src and dest components in and , then the range [0 ... rs] in pixs is mapped to [0 ... rd] in pixd. Likewise, the range [rs ... 255] in pixs is mapped to [rd ... 255] in pixd. And similarly for green and blue. (2) The mapping will in general change the hue of the pixels. However, if the src and dst targets are related by a transformation given by pixelFractionalShift(), the hue is invariant. (3) For inplace operation, call it this way: pixLinearMapToTargetColor(pixs, pixs, ... ) (4) For generating a new pixd: pixd = pixLinearMapToTargetColor(NULL, pixs, ...)

Definition at line 2002 of file blend.c.

References CALLOC, composeRGBPixel(), ERROR_PTR, extractRGBValues(), FREE, L_MAX, L_MIN, NULL, pixCopy(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by main().

l_int32 pixelLinearMapToTargetColor ( l_uint32  scolor,
l_uint32  srcmap,
l_uint32  dstmap,
l_uint32 pdcolor 
)

pixelLinearMapToTargetColor()

Input: scolor (rgb source color: 0xrrggbb00) srcmap (source mapping color: 0xrrggbb00) dstmap (target mapping color: 0xrrggbb00) &pdcolor (<return> rgb dest color: 0xrrggbb00) Return: 0 if OK, 1 on error

Notes: (1) This does this does a piecewise linear mapping of each component of to , based on the relation between the components of and . It is the same transformation, performed on a single color, as mapped on every pixel in a pix by pixLinearMapToTargetColor(). (2) For each component, if the sval is larger than the smap, the dval will be pushed up from dmap towards white. Otherwise, dval will be pushed down from dmap towards black. This is because you can visualize the transformation as a linear stretching where smap moves to dmap, and everything else follows linearly with 0 and 255 fixed. (3) The mapping will in general change the hue of . However, if the and targets are related by a transformation given by pixelFractionalShift(), the hue will be invariant.

Definition at line 2095 of file blend.c.

References composeRGBPixel(), ERROR_INT, extractRGBValues(), L_MAX, L_MIN, and PROCNAME.

Referenced by main().

l_int32 pixelFractionalShift ( l_int32  rval,
l_int32  gval,
l_int32  bval,
l_float32  fraction,
l_uint32 ppixel 
)

pixelFractionalShift()

Input: rval, gval, bval fraction (negative toward black; positive toward white) &ppixel (<return> rgb value) Return: 0 if OK, 1 on error

Notes: (1) This transformation leaves the hue invariant, while changing the saturation and intensity. It can be used for that purpose in pixLinearMapToTargetColor(). (2) is in the range [-1 .... +1]. If < 0, saturation is increased and brightness is reduced. The opposite results if > 0. If == -1, the resulting pixel is black; == 1 results in white.

Definition at line 2155 of file blend.c.

References composeRGBPixel(), ERROR_INT, and PROCNAME.

Referenced by main().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines