LEADTOOLS Raster Imaging C DLL Help > Function References > L_SampleTargetBitmap |
#include "l_bitmap.h"
L_LTIMGCLR_API L_INT L_SampleTargetBitmap(pBitmap, crSample, crTarget, uFlags)
pBITMAPHANDLE pBitmap; |
/* pointer to the bitmap handle */ |
COLORREF crSample; |
/* sample color */ |
COLORREF crTarget; |
/* target color */ |
L_UINT uFlags; |
/* flags */ |
Corrects color values by shifting the sample colors to the target colors.
Parameter |
Description |
|
pBitmap |
Pointer to the bitmap handle referencing the bitmap to be changed. |
|
crSample |
The COLORREF value that specifies the Sample color. The red value for red channel, green value for green channel, blue value for blue channel. |
|
crTarget |
The COLORREF value that specifies the Target color. The red value for red channel, green value for green channel, blue value for blue channel. |
|
uFlags |
Flags that indicates the channel for which to shift the color and how to remap the other values for that channel. You can use a bit wise OR (|) to specify one flag from each group. |
|
|
The following are the flags that indicate the channel: |
|
|
Value |
Meaning |
|
SAMP_RED |
[0x0001] Shift the color in the red channel. |
|
SAMP_GREEN |
[0x0002] Shift the color in the green channel. |
|
SAMP_BLUE |
[0x0003] Shift the color in the blue channel. |
|
SAMP_RGB |
[0x0004] Shift the color in the red, green, and blue channels. |
|
The following are the flags that indicate how other pixel values in the set channel will be affected: |
|
|
Value |
Meaning |
|
SAMP_LOW |
[0x0010] Remap the shadow values for the channel set in uFlags. |
|
SAMP_MID |
[0x0020] Remap the midtone values for the channel set in uFlags. |
|
SAMP_HIGH |
[0x0030] Remap the highlight values for the channel set in uFlags. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
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.
For example, suppose you are working with a color image. In crSample you set the red value portion of the COLORREF structure to 125, the green portion to 165 and the blue portion to 100. In crTarget you set the red value portion to 170, the green to 120 and the blue to 200. If you set SAMP_BLUE in uFlags, then for every pixel in the bitmap that has a blue value of 100, that blue value will be changed to 200, thus shifting the colors in the bitmap. Depending on whether you set SAMP_LOW, SAMP_MID, or SAMP_HIGH, either the shadow values in the blue channel will be remapped, or the midtone values in the blue channel will be remapped, or the highlight values in the blue channel will be remapped.
This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Supportfor 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.
For gray scale bitmaps the gray value of the crSample and crTarget are used, and the different channel flags have the same effect since it works on the same channel (gray channel).
To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
Required DLLs and Libraries
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
Win32, x64, Linux.
See Also
Example
The following example loads bitmap, and applies the sample target function:
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName L_INT SampleTargetBitmapExample(L_VOID) { L_INT nRet; BITMAPHANDLE LeadBitmap; /* Load the bitmap, keeping the bits per pixel of the file */ nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); if(nRet !=SUCCESS) return nRet; /*Apply the filter*/ nRet = L_SampleTargetBitmap(&LeadBitmap, RGB(50, 100, 150), RGB(60, 90 , 150), SAMP_RED| SAMP_MID); if(nRet !=SUCCESS) return nRet; nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL); if(nRet !=SUCCESS) return nRet; //free bitmap if(LeadBitmap.Flags.Allocated) L_FreeBitmap(&LeadBitmap); return SUCCESS; }