|
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) |
|
PIX * | pixBlend (PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract) |
|
PIX * | pixBlendMask (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 type) |
|
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) |
|
PIX * | pixBlendGrayInverse (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract) |
|
PIX * | pixBlendColor (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 transparent, l_uint32 transpix) |
|
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) |
|
PIX * | pixFadeWithGray (PIX *pixs, PIX *pixb, l_float32 factor, l_int32 type) |
|
PIX * | pixBlendHardLight (PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract) |
|
l_ok | pixBlendCmap (PIX *pixs, PIX *pixb, l_int32 x, l_int32 y, l_int32 sindex) |
|
PIX * | pixBlendWithGrayMask (PIX *pixs1, PIX *pixs2, PIX *pixg, l_int32 x, l_int32 y) |
|
PIX * | pixBlendBackgroundToColor (PIX *pixd, PIX *pixs, BOX *box, l_uint32 color, l_float32 gamma, l_int32 minval, l_int32 maxval) |
|
PIX * | pixMultiplyByColor (PIX *pixd, PIX *pixs, BOX *box, l_uint32 color) |
|
PIX * | pixAlphaBlendUniform (PIX *pixs, l_uint32 color) |
|
PIX * | pixAddAlphaToBlend (PIX *pixs, l_float32 fract, l_int32 invert) |
|
PIX * | pixSetAlphaOverWhite (PIX *pixs) |
|
l_ok | pixLinearEdgeFade (PIX *pixs, l_int32 dir, l_int32 fadeto, l_float32 distfract, l_float32 maxfade) |
|
Blending two images that are not colormapped
PIX *pixBlend()
PIX *pixBlendMask()
PIX *pixBlendGray()
PIX *pixBlendGrayInverse()
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()
Blending background to a specific color
PIX *pixBlendBackgroundToColor()
Multiplying by a specific color
PIX *pixMultiplyByColor()
Rendering with alpha blending over a uniform background
PIX *pixAlphaBlendUniform()
Adding an alpha layer for blending
PIX *pixAddAlphaToBlend()
Setting a transparent alpha component over a white background
PIX *pixSetAlphaOverWhite()
Fading from the edge
l_int32 pixLinearEdgeFade()
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.
PIX* pixBlendBackgroundToColor |
( |
PIX * |
pixd, |
|
|
PIX * |
pixs, |
|
|
BOX * |
box, |
|
|
l_uint32 |
color, |
|
|
l_float32 |
gamma, |
|
|
l_int32 |
minval, |
|
|
l_int32 |
maxval |
|
) |
| |
pixBlendBackgroundToColor()
- Parameters
-
[in] | pixd | can be NULL or pixs |
[in] | pixs | 32 bpp rgb |
[in] | box | region for blending; can be NULL) |
[in] | color | 32 bit color in 0xrrggbb00 format |
[in] | gamma,minval,maxval | args for grayscale TRC mapping |
- Returns
- pixd always
Notes:
(1) This in effect replaces light background pixels in pixs
by the input color. It does it by alpha blending so that
there are no visible artifacts from hard cutoffs.
(2) If pixd == pixs, this is done in-place.
(3) If box == NULL, this is performed on all of pixs.
(4) The alpha component for blending is derived from pixs,
by converting to grayscale and enhancing with a TRC.
(5) The last three arguments specify the TRC operation.
Suggested values are: gamma = 0.3, minval = 50, maxval = 200.
To skip the TRC, use gamma == 1, minval = 0, maxval = 255.
See pixGammaTRC() for details.
Definition at line 1844 of file blend.c.
PIX* pixBlendColor |
( |
PIX * |
pixd, |
|
|
PIX * |
pixs1, |
|
|
PIX * |
pixs2, |
|
|
l_int32 |
x, |
|
|
l_int32 |
y, |
|
|
l_float32 |
fract, |
|
|
l_int32 |
transparent, |
|
|
l_uint32 |
transpix |
|
) |
| |
pixBlendColor()
- Parameters
-
[in] | pixd | [optional] either equal to pixs1 for in-place, or NULL |
[in] | pixs1 | blendee; depth > 1 |
[in] | pixs2 | blender, any depth; typically, the area of pixs2 is smaller than pixs1 |
[in] | x,y | origin [UL corner] of pixs2 relative to the origin of pixs1 |
[in] | fract | blending fraction |
[in] | transparent | 1 to use transparency; 0 otherwise |
[in] | transpix | pixel color in pixs2 that is to be transparent |
- Returns
- pixd, or null on error
Notes:
(1) For inplace operation (pixs1 must be 32 bpp), call it this way:
pixBlendColor(pixs1, pixs1, pixs2, ...)
(2) For generating a new pixd:
pixd = pixBlendColor(NULL, pixs1, pixs2, ...)
(3) If pixs2 is not 32 bpp rgb, it is converted.
(4) Clipping of pixs2 to pixs1 is done in the inner pixel loop.
(5) If pixs1 has a colormap, it is removed to generate a 32 bpp pix.
(6) If pixs1 has depth < 32, it is unpacked to generate a 32 bpp pix.
(7) If transparent = 0, the blending fraction (fract) is
applied equally to all pixels.
(8) If transparent = 1, all pixels of value transpix (typically
either 0 or 0xffffff00) in pixs2 are transparent in the blend.
Definition at line 820 of file blend.c.
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()
- Parameters
-
[in] | pixd | [optional] either equal to pixs1 for in-place, or NULL |
[in] | pixs1 | blendee, depth > 1 |
[in] | pixs2 | blender, any depth; typically, the area of pixs2 is smaller than pixs1 |
[in] | x,y | origin [UL corner] of pixs2 relative to the origin of pixs1; can be < 0 |
[in] | fract | blending fraction |
[in] | type | L_BLEND_GRAY, L_BLEND_GRAY_WITH_INVERSE |
[in] | transparent | 1 to use transparency; 0 otherwise |
[in] | transpix | pixel grayval in pixs2 that is to be transparent |
- Returns
- pixd if OK; pixs1 on error
Notes:
(1) For inplace operation (pixs1 not cmapped), call it this way:
pixBlendGray(pixs1, pixs1, pixs2, ...)
(2) For generating a new pixd:
pixd = pixBlendGray(NULL, pixs1, pixs2, ...)
(3) Clipping of pixs2 to pixs1 is done in the inner pixel loop.
(4) If pixs1 has a colormap, it is removed; otherwise, if pixs1
has depth < 8, it is unpacked to generate a 8 bpp pix.
(5) If transparent = 0, the blending fraction (fract) is
applied equally to all pixels.
(6) If transparent = 1, all pixels of value transpix (typically
either 0 or 0xff) in pixs2 are transparent in the blend.
(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) 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().
(9) Invalid fract defaults to 0.5 with a warning.
Invalid type defaults to L_BLEND_GRAY with a warning.
Definition at line 490 of file blend.c.
PIX* pixBlendGrayAdapt |
( |
PIX * |
pixd, |
|
|
PIX * |
pixs1, |
|
|
PIX * |
pixs2, |
|
|
l_int32 |
x, |
|
|
l_int32 |
y, |
|
|
l_float32 |
fract, |
|
|
l_int32 |
shift |
|
) |
| |
pixBlendGrayAdapt()
- Parameters
-
[in] | pixd | [optional] either equal to pixs1 for in-place, or NULL |
[in] | pixs1 | blendee; depth > 1 |
[in] | pixs2 | blender, any depth; typically, the area of pixs2 is smaller than pixs1 |
[in] | x,y | origin [UL corner] of pixs2 relative to the origin of pixs1; can be < 0 |
[in] | fract | blending fraction |
[in] | shift | >= 0 but <= 128: shift of zero blend value from median source; use -1 for default value; |
- Returns
- pixd if OK; pixs1 on error
Notes:
(1) For inplace operation (pixs1 not cmapped), call it this way:
pixBlendGrayAdapt(pixs1, pixs1, pixs2, ...)
For generating a new pixd:
pixd = pixBlendGrayAdapt(NULL, pixs1, pixs2, ...)
(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) 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.
(6) 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.
(7) 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 1064 of file blend.c.
PIX* pixBlendGrayInverse |
( |
PIX * |
pixd, |
|
|
PIX * |
pixs1, |
|
|
PIX * |
pixs2, |
|
|
l_int32 |
x, |
|
|
l_int32 |
y, |
|
|
l_float32 |
fract |
|
) |
| |
pixBlendGrayInverse()
- Parameters
-
[in] | pixd | [optional] either equal to pixs1 for in-place, or NULL |
[in] | pixd | [optional] either NULL or equal to pixs1 for in-place |
[in] | pixs1 | blendee, depth > 1 |
[in] | pixs2 | blender, any depth; typ. smaller in size than pixs1 |
[in] | x,y | origin [UL corner] of pixs2 relative to the origin of pixs1; can be < 0 |
[in] | fract | blending fraction |
- Returns
- pixd if OK; pixs1 on error
Notes:
(1) For inplace operation (pixs1 not cmapped), call it this way:
pixBlendGrayInverse(pixs1, pixs1, pixs2, ...)
(2) For generating a new pixd:
pixd = pixBlendGrayInverse(NULL, pixs1, pixs2, ...)
(3) Clipping of pixs2 to pixs1 is done in the inner pixel loop.
(4) If pixs1 has a colormap, it is removed; otherwise if pixs1
has depth < 8, it is unpacked to generate a 8 bpp pix.
(5) This is a no-nonsense blender. It changes the src1 pixel except
when the src1 pixel is midlevel gray. Use fract == 1 for the most
aggressive blending, where, if the gray pixel in pixs2 is 0,
we get a complete inversion of the color of the src pixel in pixs1.
(6) The basic logic is that each component transforms by:
d --> c * d + (1 - c ) * (f * (1 - d) + d * (1 - f))
where c is the blender pixel from pixs2,
f is fract,
c and d are normalized to [0...1]
This has the property that for f == 0 (no blend) or c == 1 (white):
d --> d
For c == 0 (black) we get maximum inversion:
d --> f * (1 - d) + d * (1 - f) [inversion by fraction f]
Definition at line 688 of file blend.c.
PIX* pixBlendWithGrayMask |
( |
PIX * |
pixs1, |
|
|
PIX * |
pixs2, |
|
|
PIX * |
pixg, |
|
|
l_int32 |
x, |
|
|
l_int32 |
y |
|
) |
| |
pixBlendWithGrayMask()
- Parameters
-
[in] | pixs1 | 8 bpp gray, rgb, rgba or colormapped |
[in] | pixs2 | 8 bpp gray, rgb, rgba or colormapped |
[in] | pixg | [optional] 8 bpp gray, for transparency of pixs2; can be null |
[in] | x,y | UL corner of pixs2 and pixg with respect to pixs1 |
- Returns
- 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 rgba,
in which case we use the alpha component of pixs2.
(3) If pixg exists, it need not be the same size as pixs2.
However, we assume their UL corners are aligned with each other,
and placed 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 1692 of file blend.c.
References pixGetDimensions().