L_RemapBitmapHue

#include "l_bitmap.h"

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

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.

Parameters

pBITMAPHANDLE pBitmap

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

L_UINT * 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.

L_UINT * 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.

L_UINT * 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.

L_UINT * 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.

L_UINT uLUTLen

Length of the lookup table. Possible values are:

Value Meaning
65536 16-bit image
4096 12-bit image
256 8-bit image

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 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 to 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

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

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) 
{ 
	/* Load an pass a 24-bit image */ 
 
   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, 0); 
   if(nRet !=SUCCESS) 
      return nRet; 
   if(uMaskTable) 
      free(uMaskTable); 
   if(uHueTable) 
      free (uHueTable); 
   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.