WindowLevelFillLUT example for Delphi

var
   uHigh: Cardinal; 
   uLow: Cardinal; 
   uSigned: Cardinal; 
begin
   LEADImage1.GetMinMaxBits();
   LEADImage1.GetMinMaxVal();

   LEADImage1.LevelLowBit:= 0; 
   LEADImage1.LevelHighBit:= LEADImage1.BitmapBits - 1; 

   uLow:= LEADImage1.MinBit; 
   uHigh:= Trunc(Power(2, LEADImage1.MaxBit - LEADImage1.MinBit + 1) ); 

   //allocate the LUT
   LEADImage1.LevelLUT[uHigh - 1]:= 0; 

   //set the FILLLUT_SIGNED flag for signed images
   uSigned:= FILLLUT_UNSIGNED; 
   if(LEADImage1.IsSigned)then
      uSigned:= FILLLUT_SIGNED; 

   //fill the entire LUT with gradient from RED to BLUE
   LEADImage1.WindowLevelFillLUT(RGB(255, 0, 0), 
      RGB(0, 0, 255), 
      uLow, 
      uHigh, 
      LEADImage1.MinBit, 
      LEADImage1.MaxBit, 
      LEADImage1.MinVal, 
      LEADImage1.MaxVal, 
      0, 
      FILLLUT_INSIDE Or FILLLUT_LINEAR Or uSigned); 

   //now use it
   LEADImage1.WindowLevelBitmap:= True; 
   LEADImage1.WindowLevel();
end;