L_RemapBitmapHue

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_RemapBitmapHue(pBitmap, pMask, pHTable, pSTable, pVTable, uLUTLen)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_UINT * pMask;

/* table of 256 bytes identifying valid values in hue table */

L_UINT * pHTable;

/* table of 256 bytes representing the hue lookup table */

L_UINT * pSTable;

/* table of 256 bytes representing the saturation lookup table */

L_UINT * pVTable;

/* table of 256 bytes representing the value lookup table */

L_UINT uLUTLen;

/* length of the lookup table */

Uses a lookup table to change a bitmap's hue values. The saturation and value tables change S and V values only if a particular hue value is marked as non-zero in the pMask table. It is used for all resolutions, including 48 and 64-bit images.

Parameter

Description

pBitmap

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

pMask

Lookup table that identifies which values in the pHTable, pSTable and pVTable are valid. If pMask[i] is non-zero, then pHTable, pSTable and pVTable are to be used. If pMask[i] is 0 then pHTable, pSTable and pVTable are ignored. If pMask is NULL, all entries in the pHTable, pSTable and pVTable are used.

pHTable

Hue look up table. If the pMask table value for a particular pixel hue is non-zero, then the hue is changed to the corresponding entry in pHTable. For example, if a pixel value has a hue of 85 and pMask[85] is non-zero, the hue is changed to pHTable[85]. If pHTable is NULL, the hue of each pixel is unchanged.

pSTable

Saturation look up table. If the pMask table value for a particular pixel hue is non-zero, then the saturation is changed to the corresponding entry in pSTable. For example, if a pixel value has a hue of 85 and pMask[85] is non-zero, the saturation is changed to pSTable[85]. If pHTable is NULL, the saturation is changed to pSTable[85]. If pSTable is NULL, the saturation of each pixel is unchanged.

pVTable

Value look up table. If the pMask table value for a particular pixel hue is non-zero, then the value is changed to the corresponding entry in pVTable. For example, if a pixel value has a hue of 85 and pMask[85] is non-zero, the value is changed to pVTable[85]. If pHTable is NULL, the value is changed to pVTable[85]. If pVTable is NULL, the value of each pixel is unchanged.

uLUTLen

Length of the lookup table. Possible values are:

 

Value

Meaning

 

65536

16-bit image

 

4096

12-bit image

 

256

8-bit image

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.

This function can be used to change a range of colors to another range of colors. For example, it could be used to change all red pixels to any color, where a red pixel can have any brightness (V) and any amount of white (saturation). A red pixel in this case would be

RGB(x,y,y) where

0<=x<(uLUTLen  1) and 

0<=y<x

or in the HSV color space

HSV(0,x,x) where 

0<=x<=(uLUTLen  1)

The pMask lookup table identifies which values in the pHTable are valid. If a pMask value is 0, then the corresponding value in the pHTable is ignored. If a pMask value is non-zero, then the corresponding value in the pHTable is used. For example, if a pixel has a hue value of 240 and pMask[240] is nonzero, then the hue value of 240 is replaced with pHTable[240]. Traditionally, hue ranges from 0 to 359. For the lookup table, the range of 0 to 359 is remapped to a range of 0.. uLUTLen 1. For example, if uLUTLen = 256

Color

Hue(0..359)

Hue(0..255)

Red

0

0

Green

120

85

Blue

240

170

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

Use L_RGBtoHSV() and L_HSVtoRGB to convert between RGB and HSV colorspace.

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.

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_SetBitmapRgnColorHSVRange, L_SetBitmapRgnColorRGBRange, L_RGBtoHSV, L_HSVtoRGB, L_ChangeBitmapIntensity, L_GammaCorrectBitmap, L_ChangeBitmapContrast, L_HistoContrastBitmap, L_StretchBitmapIntensity, L_InvertBitmap, L_ChangeBitmapHue, L_ChangeBitmapSaturation, L_HistoEqualizeBitmap, L_FillBitmap, L_GetPixelColor, L_PutPixelColor, L_GetBitmapHistogram, L_WindowLevel

Topics:

Raster Image Functions: Modifying Intensity Values

 

Changing Brightness and Contrast

 

Raster Image Functions: Changing Brightness and Contrast

 

Using Color Values in LEADTOOLS

Example

This example changes all green hues (and hues near green) to the hue of crNewColor. The example uses the following macros.

#define INCREMENT(x, uLUTLen) ((x+1)% uLUTLen)
#define DECREMENT(x, uLUTLen) ((x+ (uLUTLen - 1))% uLUTLen)
#define ADD(x,y, uLUTLen)     ((x+y)% uLUTLen)
L_INT RemapBitmapHueExample(pBITMAPHANDLE pBitmap, COLORREF crNewColor)
{
   L_UINT  * uMaskTable;
   L_UINT  * uHueTable;
   HSVREF  hsvRef;
   L_UINT uHueGreen, uHueChange;
   L_INT   iHueChange;
   L_INT   i, iCount, nRet, uLUTLen;
   if(pBitmap->BitsPerPixel >= 48)
      uLUTLen = 0x10000;
   else if(!ISGRAY(pBitmap))
      uLUTLen = 256;
   else if(pBitmap->pLUT && pBitmap->Flags.UseLUT)
      uLUTLen = 256;
   else
      uLUTLen = (1 << pBitmap->BitsPerPixel);
   //Allocate tables
   uMaskTable = (L_UINT *)  malloc (uLUTLen * sizeof(L_UINT));
   uHueTable  =(L_UINT *) malloc (uLUTLen * sizeof(L_UINT));
   //Initialize tables
   for (i=0; i<uLUTLen; i++)
   {
      uMaskTable[i] = 0;
      uHueTable[i] = i;
   }
   //Get the hue for green
   hsvRef = L_RGBtoHSV(RGB(0,255,0));
   uHueGreen = hsvRef.uH;
   //Obtain new hue
   hsvRef = L_RGBtoHSV(crNewColor);
   iHueChange = (L_INT)hsvRef.uH - (L_INT)uHueGreen;
   uHueChange = (iHueChange>0) ? (L_UINT)iHueChange : (L_UINT)(iHueChange + (uLUTLen - 1));
   uHueGreen   *= (uLUTLen - 1)/255;
   uHueChange *= (uLUTLen - 1)/255;
   //Set values in uHueTable, uMaskTable 
   uHueTable[uHueGreen] = (uHueTable[uHueGreen] + uHueChange);
   uMaskTable[uHueGreen] = 1;
   
   //set the hues near green (+/- 15)
   iCount = (15 * (uLUTLen - 1))/255;
   for (i=INCREMENT(uHueGreen,uLUTLen); iCount > 0; i = INCREMENT(i, uLUTLen), iCount--)
   {
      uHueTable[i] = ADD(uHueTable[i], uHueChange, uLUTLen);
      uMaskTable[i] = 1;
   }
   iCount = (15 * (uLUTLen - 1))/255;
   for (i=DECREMENT(uHueGreen, uLUTLen); iCount > 0; i =DECREMENT(i, uLUTLen), iCount--)
   {
      uHueTable[i] = ADD(uHueTable[i],uHueChange, uLUTLen);
      uMaskTable[i] = 1;
   }
   nRet = L_RemapBitmapHue(pBitmap, uMaskTable, uHueTable, NULL, NULL, uLUTLen);
   if(nRet !=SUCCESS)
      return nRet;
   if(uMaskTable)
      free(uMaskTable);
   if(uHueTable)
      free (uHueTable);
   return SUCCESS;
}