LDialogImage::DoModalHistogram

#include "ltwrappr.h"

virtual L_INT LDialogImage::DoModalHistogram(hWndOwner)

HWND hWndOwner;

/* handle of the window which owns the dialog */

Displays the Histogram dialog box.

Parameter

Description

hWndOwner

Handle of the window which owns the dialog.

Returns

SUCCESS_DLG_CLOSE

The dialog exits successfully after pressing the "Close" button.

< 1

An error occurred. Refer to Return Codes.

Comments

LDialogImage::SetHistogramParams must be called before using this function to set the initial values for the dialog. You can get the updated HISTOGRAMDLGPARAMS with the values entered by the user through the dialog by using LDialogImage::GetHistogramParams.

The Histogram dialog is shown in the following figure:

image\Histogram.gif

Required DLLs and Libraries

LTDLGIMG
LTDLGKRN
LTDLGUTL
LTDLGCTRL
LTDLGCOM
LTDIS
LTIMG

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

LBase::EnableCallBack, LDialogBase::EnablePreview, LDialogBase::EnableAutoProcess, LDialogBase::EnableToolbar, LDialogBase::Free, LDialogBase::Initialize, LDialogImage::SetHistogramParams, LDialogImage::GetHistogramParams, LBitmap::GetHistogram, Class Members

Topics:

Using Imaging Common Dialog

Example

Use this dialog to display histogram charts for a bitmap. Charts can be displayed for either the main, red, green or blue channels.

This dialog can be used in to different ways:

You may pass the bitmap, and let the dialog do the processing to calculate the histogram(s), see Example 1

You may pass the histogram table(s), which can be acquired using LBitmap::GetHistogram, see Example 2

Example 1

// example to illustrate using a bitmap to show histogram charts
void TestFunction(LBitmap * pBitmap, HWND hWnd)
{
   LDialogImage DlgImage;
   LDialogImage::Initialize(DLG_INIT_COLOR );
   DlgImage.SetBitmap(pBitmap);

   HISTOGRAMDLGPARAMS DlgParams; 

   memset ( &DlgParams, 0, sizeof ( HISTOGRAMDLGPARAMS ) ) ;

   DlgParams.uStructSize      = sizeof ( HISTOGRAMDLGPARAMS ) ;
   DlgParams.crBlueChannelPen  = RGB ( 0, 0, 255 ) ;
   DlgParams.crGreenChannelPen = RGB ( 0, 255, 0 ) ;
   DlgParams.crRedChannelPen   = RGB ( 255, 0, 0 ) ;
   DlgParams.crMasterPen       = RGB ( 0, 0, 0 ) ;
   DlgParams.uDlgFlags            = DLG_HISTOGRAM_SHOW_VIEWSTYLE | 
                                DLG_HISTOGRAM_USERPENCOLORS ;

   DlgImage.EnableCallBack(FALSE);
   DlgImage.EnablePreview(TRUE);
   DlgImage.EnableAutoProcess(TRUE);
   DlgImage.EnableToolbar(TRUE);
   DlgImage.SetHistogramParams(&DlgParams) ;
   DlgImage.DoModalHistogram(hWnd);

   // Gets the updated values for the structure
   DlgImage.GetHistogramParams(&DlgParams, sizeof(DlgParams)) ;
   LDialogImage::Free();
}

Example 2

// example to illustrate using histogram tables to show histogram charts
L_VOID GetBitmapHistogram 

   LBitmap *pBitmap, 
   L_UINT        uChannel,
   L_UINT        &uCount,
   L_UINT32**    lppHistogram
)
{
   // allocate histogram array
   if ( pBitmap->GetColorOrder() == ORDER_GRAY )
   {
      switch (pBitmap->GetBitsPerPixel() )
      {
      case 1:
      case 4:
      case 8 :
         {
            uCount = 256 ;
         }
         break ;

      case 12:
         {
            uCount = 4096 ;// maximum

            // is there any way to decrease buffer size?
            if ( !LSettings::IsSupportLocked( L_SUPPORT_MEDICAL ) )
            {
               L_INT LowBit, HighBit ;

               if ( SUCCESS == pBitmap->GetMinMaxBits(&LowBit, &HighBit ) )
               {
                  uCount = (DWORD)1 << ( HighBit - LowBit + 1 ) ;
               }
            }
            else
            {
               return ;
            }
         }

         break ;

      case 16:
         {
            uCount = 65536 ;

            // is there any way to decrease buffer size?
            if ( ! LSettings::IsSupportLocked( L_SUPPORT_MEDICAL ) )
            {
               L_INT LowBit, HighBit ;

               if ( SUCCESS == pBitmap->GetMinMaxBits( &LowBit, &HighBit ) )
               {
                  uCount = (DWORD)1 << ( HighBit - LowBit + 1 ) ;
               }
            }
            else
            {
               return ;
            }
         }
         break ;

      default:
         return ;
      }
   }
   else
   {
      switch (pBitmap->GetBitsPerPixel() )
      {
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 16:
      case 24:
      case 32:
         {
            uCount = 256 ;
         }
         break ;

      case 48:
      case 64:
         {
            uCount = 65536 ;
         }
         break ;

      default:
         return ;
      }
   }

   *lppHistogram = (L_UINT32 *)malloc ( uCount * sizeof ( L_UINT32 ) ) ;

   // read histogram
   pBitmap->GetHistogram( *lppHistogram, uCount, uChannel ) ;
}

void TestFunction(LBitmap * pBitmap, HWND hWnd)
{
   LDialogImage DlgImage;
   LDialogImage::Initialize(DLG_INIT_COLOR );
   DlgImage.SetBitmap(pBitmap);

   HISTOGRAMDLGPARAMS DlgParams; 

   memset ( &DlgParams, 0, sizeof ( HISTOGRAMDLGPARAMS ) ) ;

   DlgParams.uStructSize      = sizeof ( HISTOGRAMDLGPARAMS ) ;
   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_MASTER, 
                        DlgParams.uMasterHistogramLen,
                        &DlgParams.puMasterHistogram ) ;

   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_RED, 
                        DlgParams.uRedHistogramLen,
                        &DlgParams.puRedHistogram ) ;

   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_GREEN, 
                        DlgParams.uGreenHistogramLen,
                        &DlgParams.puGreenHistogram ) ;

   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_BLUE, 
                        DlgParams.uBlueHistogramLen,
                        &DlgParams.puBlueHistogram ) ;
   DlgParams.crBlueChannelPen  = RGB ( 0, 0, 255 ) ;
   DlgParams.crGreenChannelPen = RGB ( 0, 255, 0 ) ;
   DlgParams.crRedChannelPen   = RGB ( 255, 0, 0 ) ;
   DlgParams.crMasterPen       = RGB ( 0, 0, 0 ) ;
   DlgParams.uDlgFlags          = DLG_HISTOGRAM_SHOW_VIEWSTYLE | 
                                DLG_HISTOGRAM_USERPENCOLORS ;
   DlgImage.SetBitmap(NULL);
   DlgImage.EnableCallBack(FALSE);
   DlgImage.EnablePreview(TRUE);
   DlgImage.EnableAutoProcess(TRUE);
   DlgImage.EnableToolbar(TRUE);
   DlgImage.SetHistogramParams(&DlgParams) ;
   DlgImage.DoModalHistogram(hWnd);

   free ( DlgParams.puMasterHistogram ) ;

   free ( DlgParams.puRedHistogram ) ;

   free ( DlgParams.puGreenHistogram ) ;

   free ( DlgParams.puBlueHistogram ) ;


   // Gets the updated values for the structure
   DlgImage.GetHistogramParams(&DlgParams, sizeof(DlgParams)) ;
   LDialogImage::Free();
}