L_SelectBitmapData

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_SelectBitmapData (pDstBitmap, pSrcBitmap, crColor, uSrcLowBit, uSrcHighBit, uThreshold, bCombine)

pBITMAPHANDLE pDstBitmap;

/* pointer to the destination bitmap handle */

pBITMAPHANDLE pSrcBitmap;

/* pointer to the source bitmap handle */

COLORREF crColor;

/* color value that will be used for coloration */

L_UINT uSrcLowBit;

/* position of the starting bit of the mask */

L_UINT uSrcHighBit;

/* position of the ending bit of the mask */

L_UINT uThreshold;

/* threshold value */

L_BOOL bCombine;

/* flag */

Selects a specified number of bits of an 8, 12 or 16-bit grayscale bitmap and puts them into a mask, then colors the bitmap depending on the mask. This can show bitmap variances depending on user-defined conditions. This function is available in the Medical toolkits.

Parameter

Description

pDstBitmap

Pointer to the destination bitmap that will contain the result of the function. This bitmap will be updated as a 24-bit RGB. The bitmap is assumed to be uninitialized, so you should free the bitmap before passing it to the function.

pSrcBitmap

Pointer to the bitmap handle referencing the 8, 12 or 16-bit grayscale bitmap. pSrcBitmap will not be affected.

crColor

Color that will be used for showing the variances in the bitmap.

uSrcLowBit

Position of the start bit that will construct the mask. The position is a zero based number.

uSrcHighBit

Position of the end bit that will construct the mask. This is inclusive (it is part of the mask). The value should not be less than uSrcLowBit. You can also pass –1, which is interpreted as "highest bit" (pSrcBitmap->BitsPerPixel – 1).

uThreshold

Value that indicates the threshold for showing the bitmap variances. If the mask value is greater or equal to the threshold value then the pixel will be colored using crColor. See bCombine for more details.

bCombine

A flag which tells how to color the output pixels:

 

- Pixels with values greater than or equal to the threshold value are:

 

set to crColor (if bCombine is set to FALSE) or

 

AND-ed with crColor (if bCombine is TRUE). In this case, the source pixel is first converted to grayscale 24-bit and then AND-ed with crColor.

 

- Pixels with values less than the threshold value are:

 

set to black (if bCombine is set to FALSE) or

 

The RGB pixel value will be the same as the high byte source pixel value (if bCombine is TRUE). That is R = G = B = High byte values of the source pixel.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is used as a visualization aid. You can select certain bits of the supported type bitmap and show the variances of that bitmap under conditions that you define.

The pDstBitmap should not be allocated when calling this function. That is, you should free the allocated bitmap before calling this function. When the function returns successfully the pDstBitmap will be a 24-bit RGB bitmap.

For 8, 12 and 16-bit grayscale bitmap, the uSrcLowBit can range from 0 to 7, 11, and 15 respectively. However if this value exceeded the range then the function will not return an error, and the pDstBitmap will be a pure black bitmap.

For 8, 12 and 16-bit grayscale bitmap, the uSrcHighBit can range from uSrcLowBit to 7, 11, and 15 respectively. No error will be returned if uSrcHighBit is greater than 7, 11 or 15. The function will return an invalid parameter error if uSrcHighBit < uSrcLowBit.

The function will first construct a mask from bits uSrcLowBit through uSrcHighBit. For each pixel, the pixel value will be combined with the mask using a bitwise ‘and’ operation. The result will be shifted to the right by uSrcLowBit. This result will be compared with the threshold: if the value is greater than or equal to the threshold, the output pixel’s color is changed using crColor. If the result is less than the threshold, the output is set to 0.

The following example shows you how to treat a 16-bit grayscale bitmap:

In a16-bit grayscale bitmap, the bits are ordered as b15 b14 b13 ... b2 b1 b0.

For uSrcLowBit = 3, uSrcHighBit = 8, uThreshold = 16 and crColor = RGB(0, 255, 0):

In Source bitmap (pSrcBitmap)

------------------- 

b15 b14 b13 b12 b11 b10 b9 |b8 b7 b6 b5 b4 b3| b2 b1 b0

-------------------  

0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 1 

In our case, the mask is 010011 in base 2 (19 in decimal). Since 19 >= 16, the destination pixel will be colored using rcColor. The output pixel will be:

if bCombine = FALSE: crColor = RGB(0,255,0)

if bCombine = TRUE: we take the high byte of the source pixel, which is 01101110 in base 2 (0x6E), and then the value is AND-ed with each component of the crColor. So the output pixel will be RGB(0x00 & 0x6E, 0xFF & 0x6E, 0x00 & 0x6E) which is RGB(0x00, 0x6E, 0x00).

Let us consider another case: the source pixel is 0110111000011101 the mask value is 000011 in base 2(3 in decimal). Since 3 < 16, the destination pixel will be:

if bCombine = FALSE: RGB(0,0,0)

if bCombine = TRUE: The high byte of source pixel will bet set for the RGB, that is RGB(0x6E, 0x6E, 0x6E).

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function supports 8, 12 and 16-bit grayscale bitmaps only. Support for 12 and 16-bit grayscale images are available only in the Document/Medical toolkits. It also can process the whole image or a region of the image. If a bitmap has a region, the effect is applied only to the region.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

Required DLLs and Libraries

LTIMG

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP.

See Also

Functions:

L_WindowLevel, L_WindowLevelBitmap, L_GrayScaleToDuotone, L_GrayScaleToMultitone, L_ShiftBitmapData, L_ColorizeGrayBitmap, L_SelectiveColorBitmap, L_AdjustBitmapTint, L_ColorHalfToneBitmap

Topics:

Raster Image Functions: Modifying Intensity Values

 

Grayscale Images

 

Using Color Values in LEADTOOLS

 

Color Halftone and Halftone Images

 

Raster Image Functions: Correcting Colors

Example

/* This example loads a bitmap and applies Selecting. */
 BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */
 BITMAPHANDLE DstBitmap;     /* Bitmap handle to hold the result. */

/* Load the bitmap, keeping the bits per pixel of the file */
L_LoadBitmap
 (TEXT("IMAGE1.CMP"), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); 

// Call the function
L_SelectBitmapData
 (&DstBitmap, 
                                    &LeadBitmap,
                                    RGB(233, 10, 77), 
                                    2 /* uSrcLowBit */,
                                    6 /* uSrcHighBit */,
                                    25 /* uThreshold */,
                                    TRUE); 

L_FreeBitmap
 (&LeadBitmap); 

// Now we have the resulted image in DstBitmap