L_SelectiveColorBitmap

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_SelectiveColorBitmap(pBitmap, pSelClr, uFlags)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

pSELCLR pSelClr;

/* pointer to a SELCLR structure that contains the selected colors definition */

L_UINT32 uFlags;

/* flags */

Changes the color of a bitmap by altering the definitions of one or more colors used by the bitmap.

Parameter

Description

pBitmap

Pointer to the bitmap handle.

pSelClr

Pointer to a SELCLR structure that contains the selected colors along with the CMYK values for each.

uFlags

Reserved for future use. Must be 0.

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.

Before you call the L_SelectiveColorBitmap function, you need to initialize the size and all remaining fields of the SELCLR structure.

Selected colors are the additive colors (Red, Green and Blue), the subtractive colors (Cyan, Magenta and Yellow), the highlights (White), the midtones (Neutral) and the shadows (Black). Each of those"Selected Colors" has information about the percentages of cyan, magenta, yellow and black that constructs that selective color. Each unique pixels color can be defined as using some certain percentage of CMYK values. By changing the percentage of CMYK values for a "selected color", all colors related to that "selected color" would change also. For example, you can decrease the Magenta percentage from the "Blue selected color" to change a blue color to a color that is more similar to Cyan. Also you can increase the Yellow percentage from the "Magenta selected color" to change magenta color to a color that is more similar to Red.

You control the percentage of CMYK for each of the selected colors using the selClrs member of the SELCLR structure. The SELCLRINF structure used in selClrs has four members, cCyan, cMagenta, cYellow and cBlack. Each takes a value from -100 to 100. Negative values for any of these members decreases the percentage of that color, whereas positive values increases the percentage of that color. If cCyan = -100 it means no cyan will be used, whereas if cCyan = 100 it means the full percentage of cyan will be used. If a value is out of range, a negative value goes to -100 and a positive value goes to 100.

Pixel colors are changed based on HSV color space. For example, if you alter the values for selClrs[SELCLR_RED], then if a pixel value is within the RED range of the Hue scale, it is considered red and is changed using the settings in selClrs[SELCLR_RED].

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

This function supports 48- and 64-bit color images. It does not support grayscale images. Support for 48- and 64-bit color images is available in the Document and Medical Imaging toolkits.

If the bitmap has a region, the effect will be applied on the region only.

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

LTIMGCLR

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.

See Also

Functions:

L_SharpenBitmap, L_PosterizeBitmap, L_MosaicBitmap, L_EmbossBitmap, L_MedianFilterBitmap, L_AddBitmapNoise, L_IntensityDetectBitmap, L_SpatialFilterBitmap, L_BinaryFilterBitmap, L_MaxFilterBitmap, L_MinFilterBitmap, L_OilifyBitmap, L_SolarizeBitmap, L_DlgColor, L_WindowLevel, L_ColorLevelBitmap, L_AutoColorLevelBitmap, L_AdjustBitmapTint, L_ColorHalfToneBitmap

Topics:

Raster Image Functions: Modifying Intensity Values

 

Correcting Colors

 

Color Halftone and Halftone Images

 

Raster Image Functions: Correcting Colors

Example

This example loads a bitmap and applies selective color to the image.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


#if defined (LEADTOOLS_V16_OR_LATER)
 L_INT SelectiveColorBitmapExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */
   SELCLR selClr;                              /* Variable to be used in the function */

   /* 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;

   // Initialize selClr to zeros.
   memset (&selClr, 0, sizeof(SELCLR));

   /* Manipulate values */
   selClr.uStructSize = sizeof (SELCLR);
   selClr.selClrs[SELCLR_RED].cCyan  = -100; // Change the "Red selected color"
   selClr.selClrs[SELCLR_YELLOW].cCyan  =  34;  // Change the "Yellow selected color"
   selClr.selClrs[SELCLR_YELLOW].cMagenta = 100;
   selClr.selClrs[SELCLR_YELLOW].cYellow  =  40;
   selClr.selClrs[SELCLR_GREEN].cBlack = 100; // Change the "Green selected color"
   selClr.selClrs[SELCLR_NEUTRAL].cCyan = -65;  // Change the "neutral selected color"
   selClr.selClrs[SELCLR_NEUTRAL].cMagenta = -39;
   selClr.selClrs[SELCLR_NEUTRAL].cYellow  =  63;

   // Call the function
   nRet = L_SelectiveColorBitmap (&LeadBitmap, &selClr, 0);
   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;
}
#else
 L_INT SelectiveColorBitmapExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */
   SELCLR selClr;                              /* Variable to be used in the function */

   /* 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;

   // Initialize selClr to zeros.
   memset (&selClr, 0, sizeof(SELCLR));

   /* Manipulate values */
   selClr.uStructSize = sizeof (SELCLR);
   selClr.selClrs[SELCLR_RED].cCyan  = -100; // Change the "Red selected color"
   selClr.selClrs[SELCLR_YELLOW].cCyan  =  34;  // Change the "Yellow selected color"
   selClr.selClrs[SELCLR_YELLOW].cMagenta = 100;
   selClr.selClrs[SELCLR_YELLOW].cYellow  =  40;
   selClr.selClrs[SELCLR_GREEN].cBlack = 100; // Change the "Green selected color"
   selClr.selClrs[SELCLR_NEUTRAL].cCyan = -65;  // Change the "neutral selected color"
   selClr.selClrs[SELCLR_NEUTRAL].cMagenta = -39;
   selClr.selClrs[SELCLR_NEUTRAL].cYellow  =  63;

   // Call the function
   nRet = L_SelectiveColorBitmap (&LeadBitmap, &selClr);
   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;
}
#endif // LEADTOOLS_V16_OR_LATER