L_WindowLevelBitmap

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_WindowLevelBitmap (pBitmap, nLowBit, nHighBit, pLUT, uLUTLength, nOrderDst, uFlags)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_INT nLowBit;

/* low bit to use */

L_INT nHighBit;

/* high bit to use */

RGBQUAD *pLUT;

/* lookup table */

L_UINT uLUTLength;

/* number of entries */

L_INT nOrderDst;

/* destination color order */

L_UINT32 uFlags;

/* flags */

Converts a 12 or 16-bit grayscale image to an 8-bit grayscale or a 24-bit RGB bitmap.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap to be leveled.

nLowBit

Value indicating the low bit used for leveling. 0 <= nLowBit <= nHighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).

nHighBit

Value indicating the high bit used for leveling. 0 <= nLowBit <= nHighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).

pLUT

Optional lookup table that can be used to implement a user defined conversion. For every intensity value between 0 and 2 raised to the power of (nHighBit - nLowBit + 1) - 1 there should be a corresponding entry in the lookup table that contains an RGB quad. If pLUT is NULL, the conversion is a normal shift (right or left) and the output bitmap is 8-bit grayscale. If pLUT is not NULL, the output bitmap is a 24-bit bitmap.

uLUTLength

Value indicating the number of entries pointed to by pLUT.

nOrderDst

Value indicating the color order if the output bitmap will be 24-bit. If pLUT is NULL, this parameter is ignored. Possible values are:

 

Value

Meaning

 

ORDER_RGB

[0] The input colors are in red-green-blue order.

 

ORDER_BGR

[1] The input colors are in blue-green-red order.

uFlags

Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function will convert the bitmap to a window leveled bitmap. To implement window leveling without affecting the image, use L_WindowLevel.

The bitmap data is changed by this function.

This function supports 12 and 16-bit grayscale. Support for 12 and 16-bit grayscale images is available in the Document and Medical Imaging toolkits.

This function is similar to L_WindowLevelBitmapExt, except that it uses 8-bit per component LUT instead of 16-bit per component LUT. If more precision is desired, you can use L_WindowLevelBitmapExt instead of L_WindowLevelBitmap.

For information on saving bitmaps that have been window leveled, refer to Saving Window-Leveled Bitmaps.

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

LTIMGCOR

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

Win32, x64.

See Also

Functions:

L_WindowLevelBitmapExt, L_WindowLevel, L_WindowLevelFillLUT, L_ChangeHueSatIntBitmap, L_ColorReplaceBitmap, L_ColorThresholdBitmap, L_AdaptiveContrastBitmap, L_ApplyMathLogicBitmap, L_ColorIntensityBalance, L_ColorizeGrayBitmap, L_ContBrightIntBitmap, L_DigitalSubtractBitmap, L_DynamicBinaryBitmap, L_EdgeDetectEffectBitmap, L_FunctionalLightBitmap, L_MultiScaleEnhancementBitmap, L_SelectBitmapData, L_ShiftBitmapData, L_WindowLevelExt, L_WindowLevelFillLUTExt

Topics:

Raster Image Functions: Palettes

 

Color Halftone and Halftone Images

 

Grayscale Images

 

Saving Window-Leveled Bitmaps

 

Raster Image Functions: Processing an Image

Example

This example window levels the bitmap with a custom palette. The image data is changed in this example.

#if defined (LEADTOOLS_V16_OR_LATER)
L_INT WindowLevelBitmapExample(pBITMAPHANDLE pBitmap)
{
   L_INT nRet;
   L_UINT32 x;
   RGBQUAD * ptmp;
   RGBQUAD * pLUT;
   L_INT nLowBit;
   L_INT nHighBit;
   L_INT nLow;
   L_INT nHigh;
   L_UINT32 nSize;

   /* Change the bitmap to 16-bit grayscale */
   nRet = L_GrayScaleBitmap(pBitmap, 16 );
   if(nRet !=SUCCESS)
      return nRet;

   nRet = L_GetMinMaxBits(pBitmap, &nLowBit, &nHighBit, 0);
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_GetMinMaxVal(pBitmap, &nLow, &nHigh, 0);
   if(nRet !=SUCCESS)
      return nRet;

   nSize = (L_UINT32)(1L<<(pBitmap->HighBit - pBitmap->LowBit + 1));
   pLUT = (RGBQUAD *)GlobalAllocPtr(GHND, nSize * sizeof(RGBQUAD));    

   ptmp = pLUT;
   /* fill the first half of the LUT with RED */
   for(x=0;x<nSize/2;x++)
   {
      ptmp->rgbRed       = 255;
      ptmp->rgbGreen     = 0;
      ptmp->rgbBlue      = 0;
      ptmp->rgbReserved  = 0;
      ptmp++;
   }
   /* fill the rest with gray values */
   for(x=nSize/2;x<nSize;x++)
   {
      ptmp->rgbRed       = (( L_UCHAR) ((L_UINT32) (x - nLow) * 255 / (nHigh - nLow)));
      ptmp->rgbGreen     = ptmp->rgbRed;
      ptmp->rgbBlue      = ptmp->rgbGreen;
      ptmp->rgbReserved  = 0;
      ptmp++;
   }

   nRet = L_WindowLevelBitmap ( pBitmap, nLowBit, nHighBit,(RGBQUAD *)pLUT, nSize, ORDER_BGR, 0);
   if(nRet !=SUCCESS)
      return nRet;

   GlobalFreePtr(pLUT);
   return SUCCESS;
}
#else
L_INT WindowLevelBitmapExample(pBITMAPHANDLE pBitmap)
{
   L_INT nRet;
   L_UINT32 x;
   RGBQUAD * ptmp;
   RGBQUAD * pLUT;
   L_INT nLowBit;
   L_INT nHighBit;
   L_INT nLow;
   L_INT nHigh;
   L_UINT32 nSize;

   /* Change the bitmap to 16-bit grayscale */
   nRet = L_GrayScaleBitmap(pBitmap, 16 );
   if(nRet !=SUCCESS)
      return nRet;

   nRet = L_GetMinMaxBits(pBitmap, &nLowBit, &nHighBit);
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_GetMinMaxVal(pBitmap, &nLow, &nHigh);
   if(nRet !=SUCCESS)
      return nRet;

   nSize = (L_UINT32)(1L<<(pBitmap->HighBit - pBitmap->LowBit + 1));
   pLUT = (RGBQUAD *)GlobalAllocPtr(GHND, nSize * sizeof(RGBQUAD));    

   ptmp = pLUT;
   /* fill the first half of the LUT with RED */
   for(x=0;x<nSize/2;x++)
   {
      ptmp->rgbRed       = 255;
      ptmp->rgbGreen     = 0;
      ptmp->rgbBlue      = 0;
      ptmp->rgbReserved  = 0;
      ptmp++;
   }
   /* fill the rest with gray values */
   for(x=nSize/2;x<nSize;x++)
   {
      ptmp->rgbRed       = (( L_UCHAR) ((L_UINT32) (x - nLow) * 255 / (nHigh - nLow)));
      ptmp->rgbGreen     = ptmp->rgbRed;
      ptmp->rgbBlue      = ptmp->rgbGreen;
      ptmp->rgbReserved  = 0;
      ptmp++;
   }

   nRet = L_WindowLevelBitmap ( pBitmap, nLowBit, nHighBit,(RGBQUAD *)pLUT, nSize, ORDER_BGR);
   if(nRet !=SUCCESS)
      return nRet;

   GlobalFreePtr(pLUT);
   return SUCCESS;
}
#endif // LEADTOOLS_V16_OR_LATER