L_GrayScaleBitmapExt

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_GrayScaleBitmapExt(pBitmap, RedFact, GreenFact, BlueFact)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_INT RedFact;

/* the red factor */

L_INT GreenFact;

/* the green factor */

L_INT BlueFact;

/* the blue factor */

Converts any Bitmap to a gray scale bitmap without changing its resolution.

Parameter

Description

pBitmap

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

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.

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.

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.

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.

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.

This function supports 48 and 64-bit color images.

This function does not support grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 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

Windows 2000 / XP/Vista.

See Also

Functions:

L_GrayScaleBitmap, L_IsGrayScaleBitmap, L_ConvertToColoredGray, L_BalanceColors, L_SwapColors

Topics:

Raster Image Functions: Doing Color Expansion or Reduction

 

Grayscale Images

 

Color Halftone and Halftone Images

Example

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

 L_INT GrayScaleBitmapExtExample(L_VOID)
{
   L_INT nRet;
   L_INT RedFact , GreenFact , BlueFact;
   BITMAPHANDLE Bitmap;
  /* Load a bitmap at its own bits per pixel  */
   nRet = L_LoadBitmap(TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\IMAGE3.CMP"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   RedFact    = 300;
   GreenFact = 590;
   BlueFact   = 110;
   nRet = L_GrayScaleBitmapExt(&Bitmap,RedFact,GreenFact,BlueFact);
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_SaveBitmap(TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\Result.BMP"), &Bitmap, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(Bitmap.Flags.Allocated)  
      L_FreeBitmap(&Bitmap);  
   return SUCCESS;
}