Flags for the LBitmap::ApplyMathLogic Function

The following flags indicate the channel that will be used:

Value Meaning
CHANNEL_MASTER * [0x00000000] All channels.
CHANNEL_RED [0x00000001] Red channel only.
CHANNEL_GREEN [0x00000002] Green channel only.
CHANNEL_BLUE [0x00000003] Blue channel only.

Calculating Master Channel Values

In order to speed up widely used image processing filters in LEADTOOLS, the grayscale value (master channel) of a colored image is calculated using the following formulas:

#define CalcGrayValue(r, g, b) ((L_UCHAR)(((L_UCHAR) (((2 * (L_UINT) (r)) + (5 * (L_UINT) (g)) + (L_UINT) (b) + 4) / 8)))) 
#define CalcGrayValue16(r, g, b) ((L_UINT16) (((2 * (L_UINT32) (r)) + (5 * (L_UINT32) (g)) + (L_UINT32) (b) + 4) / 8)) 
#define CalcGrayValue32(r, g, b) ((L_UINT32) (((2 * (L_UINT32) (r)) + (5 * (L_UINT32) (g)) + (L_UINT32) (b) + 4) / 8)) 

The following flags indicate how to treat the color value:

Value Meaning
AML_VALUE_NOP [0x00000000] No change.
AML_VALUE_NOT [0x00000010] Invert the color, resulting in its complement.
AML_VALUE_0 [0x00000020] Change all bits to 0.
AML_VALUE_1 [0x00000030] Change all bits to 1.

The following flags indicate the mathematical operation to use. The operations are performed between each component (R, G and B) and nFactor:

Value Meaning
AML_OP_AND [0x00000000] Combine each pixel component value and nFactor using a bitwise AND (&).
(pixel = pixel & nFactor)
AML_OP_OR [0x00000100] Combine each pixel component value and nFactor using a bitwise OR ( ).
(pixel = pixel | nFactor)
AML_OP_XOR [0x00000200] Combine each pixel component value and nFactor using a bitwise XOR (^).
(pixel = pixel ^ nFactor)
AML_OP_ADD [0x00000300] Add pixel component value to the nFactor clamping the result to the maximum allowed pixel value.
(pixel = min(pixel + nFactor, MAX_PIXEL_VALUE) )
AML_OP_SUBFACT [0x00000400] Subtract each pixel component value from the nFactor, clamping the result to the allowed pixel range.
(pixel = min(max(nFactor - pixel, MIN_PIXEL_VALUE), MAX_PIXEL_VALUE) )
AML_OP_SUBVALUE [0x00000500] Subtract nFactor from each pixel component value, clamping the result to the allowed pixel range.
(pixel = min(max(pixel nFactor), MIN_PIXEL_VALUE, MAX_PIXEL_VALUE) )
AML_OP_ABSDIF [0x00000600] Calculate the absolute difference between nFactor and each pixel component value.
(pixel = abs(pixel nFactor))
AML_OP_MUL [0x00000700] Multiply each pixel component value by nFactor/100.
(pixel = pixel * nFactor / 100)
AML_OP_DIVFACT [0x00000800] Divide each pixel component value by nFactor/100. An error will be returned if nFactor = 0.
(pixel = pixel * 100 / nFactor)
AML_OP_DIVVALUE [0x00000900] Divide nFactor by each pixel values. If the pixel values are 0, the result set to maximum allowed pixel value.
(pixel = pixel ? min(nFactor / pixel, MAX_PIXEL_VALUE) : MAX_PIXEL_VALUE)
AML_OP_AVG [0x00000A00] Use the average of the each pixel component value and nFactor.
(pixel = (pixel+nFactor) / 2).
AML_OP_MIN [0x00000B00] Use the lesser of the pixel component values and nFactor:
(pixel = min(pixel, nFactor) )
AML_OP_MAX [0x00000C00] Use the greater of the pixel component values and nFactor:
(pixel = max(pixel, nFactor) )

The way MIN_PIXEL_VALUE and MAX_PIXEL_VALUE are calculated depends on the bits per pixel and whether the bitmap is signed or unsigned:

If the bitmap is unsigned (most common):

If the bitmap is signed (rare case):

The following flags indicate how to treat the output value:

Value Meaning
AML_RES_NOP [0x00000000] No change.
AML_RES_NOT [0x00001000] Invert the color, resulting in its complement.
AML_RES_0 [0x00002000] Change all bits to 0.
AML_RES_1 [0x00003000] Change all bits to 1.

For uFlags equal to AML_OP_AND, AML_OP_OR, AML_OP_XOR, AML_OP_ADD, AML_OP_MIN, AML_OP_MUL, AML_OP_MAX, AML_OP_DIVVALUE , or AML_OP_SUBVALUE, the valid range for nFactor is from MIN_PIXEL_VALUE to MAX_PIXEL_VALUE.

For uFlags equal to AML_OP_SUBFACT, AML_OP_DIF, AML_OP_AVG, the valid range for nFactor is from (2 * MIN_PIXEL_VALUE) to (2 * MAX_PIXEL_VALUE).

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.