LBitmap::RemapHue

#include "ltwrappr.h"

virtual L_INT LBitmap::RemapHue(pMask, pHTable, pSTable, pVTable, uLUTLen, uFlags = 0)

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. Support for 48 and 64-bit images is available only in the Document/Medical toolkits.

Parameters

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 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 LBase::EnableStatusCallback.

This function supports 48 and 64-bit color images. Support for 48 and 64-bit color images is available only in the Document/Medical toolkits.

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

See Also

Functions

Topics

Example

// 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 LBitmap__RemapHueExample(LBitmap * pBitmap, COLORREF crNewColor)  
{ 
   UNREFERENCED_PARAMETER(crNewColor); 
 
   L_UINT   * uMaskTable;  
   L_UINT   * uHueTable;  
   L_UINT uHueGreen, uHueChange;  
   L_INT   iHueChange;  
   L_INT   i, iCount, nRet, uLUTLen;  
    
   if(pBitmap->GetBitsPerPixel() >= 48)  
      uLUTLen = 0x10000;  
   else if(pBitmap->IsGrayScale()) 
      uLUTLen = 256;  
   else if((pBitmap->GetHandle())->pLUT && (pBitmap->GetHandle())->Flags.UseLUT)  
      uLUTLen = 256;  
   else 
      uLUTLen = (1 << pBitmap->GetBitsPerPixel ()); 
 
   //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 
   uHueGreen = RGB(0,255,0);  
 
   //Obtain new hue 
   iHueChange = (L_INT)RGB(0,255,0) - (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 = pBitmap->RemapHue(uMaskTable, uHueTable, NULL, NULL, uLUTLen);  
    
   if(uMaskTable)  
      free(uMaskTable);  
   if(uHueTable)  
      free (uHueTable);  
 
   return nRet;  
} 
Help Version 21.0.2021.4.8
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help