L_BalanceColors

Summary

Redistributes the RGB values of the specified bitmap, using the values stored in the specified structures.

Syntax

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_BalanceColors(pBitmap, pRedFact, pGreenFact, pBlueFact, uFlags)

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle that references the bitmap in which to balance the colors.

BALANCING *pRedFact

Pointer to a BALANCING structure that contains the values to use for redistributing the bitmap's red values.

BALANCING *pGreenFact

Pointer to a BALANCING structure that contains the values to use for redistributing the bitmap's green values.

BALANCING *pBlueFact

Pointer to a BALANCING structure that contains the values to use for redistributing the bitmap's blue values.

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.

For each pixel in the bitmap, the red value is modified using the values pointed to by pRedFact. This generates an intermediate red value, an intermediate green value and an intermediate blue value.

For each pixel in the bitmap the green value is modified using the values pointed to by pGreenFact. This generates an intermediate red value, an intermediate green value and an intermediate blue value.

For each pixel in the bitmap the blue value is modified using the values pointed to by pBlueFact. This generates an intermediate red value, an intermediate green value and an intermediate blue value.

The intermediate red values are added to generate the new red value for the pixel. The intermediate green values are added to generate the new green value for the pixel and the intermediate blue values are added to generate the new blue value for the pixel. This triplet forms the new RGB value for the pixel.

The Balancing structure has three components of type double: toRed, toGreen and toBlue. The possible values of each member must be within the range: 0.0 1.0.

This function supports 48 and 64-bit colored images.

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.

Balance Colors Function - Before

Balance Colors Function - Before

Balance Colors Function - After

Balance Colors Function - After

View additional platform support for this Balance Colors function.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example assumes there is a bitmap loaded into Bitmap, which is of type BITMAPHANDLE.

L_INT BalanceColorsExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE Bitmap; 
   BALANCING RedFact, GreenFact, BlueFact; 
 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("Image2.jpg")), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   RedFact.uStructSize = sizeof(BALANCING); 
   RedFact.toRed = 0.25; 
   RedFact.toGreen = 0.50; 
   RedFact.toBlue = 0.25; 
   GreenFact.uStructSize = sizeof(BALANCING); 
   GreenFact.toRed = 0.30; 
   GreenFact.toGreen = 0.40; 
   GreenFact.toBlue = 0.30; 
   BlueFact.uStructSize = sizeof(BALANCING); 
   BlueFact.toRed = 0.10; 
   BlueFact.toGreen = 0.60; 
   BlueFact.toBlue = 0.30; 
 
   nRet = L_BalanceColors(&Bitmap, &RedFact, &GreenFact, &BlueFact, 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 22.0.2023.7.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 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.