L_GrayScaleToDuotone

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_GrayScaleToDuotone(pBitmap, pNewColor, crColor, uFlags)

Converts the grayscale bitmap into a colored one by mixing or replacing the original values of the pixels with new colors.

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap.

LPRGBQUAD pNewColor

Pointer to an RGBQUAD structure that specifies an array of colors that will be mixed with the original gray values. If this parameter is set to NULL, the crColor parameter must contain a valid color. Pass NULL when you want the function to create the array of colors, two colors when replacing both colors in a binary image, or 256 colors when using a custom array of colors.

COLORREF crColor

An RGB color that will be used to create an array of colors internally. This parameter is used when the pNewColor structure is set to NULL. This parameter is ignored if the pNewColor value is something other than NULL.

L_UINT uFlags

Flag that indicates whether colors will be mixed or replaced. Possible values are:

Value Meaning
DT_MIX [0x0000] Mix the old colors with the new ones.
DT_REPLACE [0x0001] Replace the old colors with the new ones.

Returns

Value Meaning
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.

This function was designed for use with grayscale bitmaps. If the bitmap being used is not grayscale, this function only affects those pixels or areas of the bitmap where Red=Green=Blue.

This function transforms the 8-bit grayscale bitmaps into colored 8-bit bitmaps (Palette) meanwhile the 12-bit and 16-bit grayscale bitmaps are transformed into a 48-bit colored bitmap.

Monotone conversion is possible by setting uFlags to DT_REPLACE, which clears the palette.

This function gives you the option of having the toolkit generate the array of colors to use or creating the array of colors to use yourself.

To have the toolkit generate the array of colors:

Pass the color to use for generating the array of gradient colors in the crColor parameter.

  1. If the bitmap is binary, the L_IsGrayScaleBitmap function is called by L_GrayScaleToDuotone to determine the kind of grayscale palette being used. If L_IsGrayScaleBitmap returns GRAY_ORDEREDINVERSE or GRAY_NOTORDERED, then the color passed in the crColor parameter to L_GrayScaleToDuotone will become the first color in the array generated by the toolkit, pNewColor[0], and the toolkit will create the second color in the array pNewColor[1].

    If L_IsGrayScaleBitmap returns a value other than GRAY_ORDEREDINVERSE or GRAY_NOTORDERED, then the color passed in the crColor parameter to L_GrayScaleToDuotone will become the second color in the array generated by the toolkit, pNewColor[1], and the toolkit will create the first color in the array pNewColor[0].

  2. If the bitmap is grayscale (not binary) the L_GrayScaleToDuotone will take the color passed to it in the crColor parameter and generate a 256 color gradient in pNewColor.

  3. If the bitmap is not grayscale (it is color) then the L_GrayScaleToDuotone will use the color passed to it in the crColor parameter and generate a 256 color gradient in pNewColor. These colors will be used to change only those pixels in the color image for which Red = Green = Blue.

To use a user-defined array of colors:

  1. If the bitmap is binary, call L_GrayScaleToDuotone with the two colors you wish to use in the pNewColor parameter.

  2. If the bitmap is grayscale (not binary) call L_GrayScaleToDuotone with the 256 colors you wish to use in the pNewColor parameter.

  3. If the bitmap is not grayscale (it is color) call L_GrayScaleToDuotone with the 256 colors you wish to use in the pNewColor parameter. These colors will be used to change only those pixels in the color image for which Red = Green = Blue.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.

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

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example loads a bitmap and converts it to a Duotone.

L_INT GrayScaleToDuotoneExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;        /* Bitmap handle to hold the loaded image. */ 
   COLORREF         crColor;                  /* New Color */ 
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Beauty16.jpg")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* Change the bitmap to grayscale bitmap */ 
   nRet = L_GrayScaleBitmap (&LeadBitmap, 8); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   /* The new color is Red */ 
   crColor = RGB(255, 0, 0); 
 
   /* Apply duotone conversion*/ 
   nRet = L_GrayScaleToDuotone(&LeadBitmap, NULL, crColor,  DT_REPLACE); 
   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; 
} 

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

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