L_ConvertToColoredGray

Summary

Converts a bitmap to a grayscale bitmap, then enhances the color components based on the specified parameters.

Syntax

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_ConvertToColoredGray(pBitmap, RedFact, GreenFact, BlueFact, RedGrayFact, GreenGrayFact, BlueGrayFact, uFlags)

Parameters

pBITMAPHANDLE pBitmap

Pointer to a bitmap handle that references the bitmap to convert.

L_INT RedFact

Value that represents the percentage or weight given to the red value of each pixel in the bitmap. Possible values are 0 to 1000.

L_INT GreenFact

Value that represents the percentage or weight given to the green value of each pixel in the bitmap. Possible values are 0 to 1000.

L_INT BlueFact

Value that represents the percentage or weight given to the blue value of each pixel in the bitmap. Possible values are 0 to 1000.

L_INT RedGrayFact

Additional weighting factor (percentage) used to modify the red component in the output pixel. This value can be negative. Possible values are -1000 to 1000.

L_INT GreenGrayFact

Additional weighting factor (percentage) used to modify the green component in the output pixel. This value can be negative. Possible values are -1000 to 1000.

L_INT BlueGrayFact

Additional weighting factor (percentage) used to modify the blue component in the output pixel. This value can be negative. Possible values are -1000 to 1000.

L_UINT32 uFlags

Reserved for future use. Must be 0.

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 is more general than the L_GrayScaleBitmapExt function. L_ConvertToColoredGray can be used to give images an "sepia" look by adding a blue or brown color.

RedFact + GreenFact + BlueFact must equal 1000. (Internally the values are divided by 1000).

For each pixel in the bitmap the red, green and blue values are modified by the RedFact, GreenFact and BlueFact parameters, respectively. This allows the user to give more weight to one color, essentially enhancing that color, before the pixel is converted to grayscale.

For example, if this function is called with the RedFact set to 500, the GreenFact set to 250 and the BlueFact set to 250, the red value of each pixel will get 50% of the weight when determining the grayscale value. The green value will get 25% of the weight and the blue value will get 25% of the weight when determining the grayscale value. This highlights or enhances the red in the bitmap, prior to conversion to grayscale. Upon conversion to grayscale, the red, green and blue components of the output pixel are the same. Call this value G. Therefore, the RGB values for the pixel would be (G, G, G).

Once the grayscale value for the pixel has been obtained, the red component of the output pixel can be further modified using the RedGrayFact value. The equation for this can be seen below:

Goutput-red = G + G * RedGrayFact / 1000

The green and blue components are found similarly, using the GreenGrayFact and the BlueGrayFact values, respectively.

Please note that the RedGrayFact, GreenGrayFact and BlueGrayFact values can be negative. A negative value results in a decrease in pixel intensity. A positive value results in an increase in pixel intensity.

If RedGrayFact = GreenGrayFact = BlueGrayFact = 0, then the output is the same as the output from the L_GrayScaleBitmapExt function.

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.

Convert to Colored Gray Function - Before

Convert to Colored Gray Function - Before

Convert to Colored Gray Function - After

Convert to Colored Gray Function - After

View additional platform support for this Convert to Colored Gray function.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

L_INT ConvertToColoredGrayExample(L_VOID) 
{ 
   L_INT nRet; 
   L_INT nRedFact, nGreenFact, nBlueFact, nRedGrayFact, nGreenGrayFact, nBlueGrayFact; 
   BITMAPHANDLE Bitmap;   /* Bitmap handle for the image */ 
 
   /* Load a bitmap at its own bits per pixel  */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP")), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   nRedFact = 300; 
   nGreenFact = 590; 
   nBlueFact = 110; 
   nRedGrayFact = 500; 
   nGreenGrayFact = 300; 
   nBlueGrayFact = 200; 
 
   // These arguments will transform the image into a grayscale image 
   nRet = L_ConvertToColoredGray(&Bitmap, nRedFact, nGreenFact, nBlueFact, nRedGrayFact, nGreenGrayFact, nBlueGrayFact, 0); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &Bitmap, FILE_BMP, 24, 0, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   //free bitmap 
   if (Bitmap.Flags.Allocated) 
      L_FreeBitmap(&Bitmap); 
 
   return SUCCESS; 
} 
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 API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.