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.

Required DLLs and Libraries

LTDLGIMG
LTDLGKRN
LTDLGUTL
LTDLGCTRL
LTDLGCOM
LTDIS
LTIMGUTL
LTIMGCLR

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 LBitmap::GetHistogram, see Example 2

Example 1

// Exmaple 1
// example to illustrate using a bitmap to show histogram charts
L_INT LDialogImage_DoModalHistogramExample_1(LBitmap * pBitmap, HWND hWnd)
{
   L_INT nRet;
   LDialogImage DlgImage;
   nRet = LDialogImage::Initialize(DLG_INIT_COLOR );
   if(nRet != SUCCESS)
      return nRet;
   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);
   nRet = DlgImage.SetHistogramParams(&DlgParams) ;
   if(nRet != SUCCESS)
      return nRet;
   nRet = DlgImage.DoModalHistogram(hWnd);
   if(nRet < 1)
      return nRet;
   // Gets the updated values for the structure
   nRet = DlgImage.GetHistogramParams(&DlgParams, sizeof(DlgParams)) ;
   if(nRet != SUCCESS)
      return nRet;
   nRet = LDialogImage::Free();
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}
// Example 2
// example to illustrate using histogram tables to show histogram charts
L_INT GetBitmapHistogram ( LBitmap *pBitmap, L_UINT uChannel, L_UINT &uCount, L_UINT64** lppHistogram)
{
   L_INT nRet;
   // 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 ;
               nRet = pBitmap->GetMinMaxBits (&LowBit, &HighBit );
               if ( SUCCESS == nRet )
               {
                  uCount = (DWORD)1 << ( HighBit - LowBit + 1 ) ;
               }
               else
               {
                  return nRet;
               }
            }
            else
            {
               return FAILURE;
            }
         }
         break ;
      case 16:
         {
            uCount = 65536 ;
            // is there any way to decrease buffer size?
            if ( ! LSettings::IsSupportLocked ( L_SUPPORT_MEDICAL ) )
            {
               L_INT LowBit, HighBit ;
               nRet = pBitmap->GetMinMaxBits ( &LowBit, &HighBit );
               if ( SUCCESS == nRet )
               {
                  uCount = (DWORD)1 << ( HighBit - LowBit + 1 ) ;
               }
            }
            else
            {
               return FAILURE;
            }
         }
         break ;
      default:
         return FAILURE;
      }
   }
   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 FAILURE;
      }
   }
   *lppHistogram = (L_UINT64 *)malloc ( uCount * sizeof ( L_UINT64 ) ) ;
   // read histogram
   nRet = pBitmap->GetHistogram ( *lppHistogram, uCount, uChannel ) ;
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}
L_INT LDialogImage_DoModalHistogramExample_2(LBitmap * pBitmap, HWND hWnd)
{
   L_INT nRet;
   LDialogImage DlgImage;
   nRet = LDialogImage::Initialize(DLG_INIT_COLOR );
   if(nRet != SUCCESS)
      return nRet;
   DlgImage.SetBitmap(pBitmap);
   HISTOGRAMDLGPARAMS DlgParams; 
   memset ( &DlgParams, 0, sizeof ( HISTOGRAMDLGPARAMS ) ) ;
   DlgParams.uStructSize      = sizeof ( HISTOGRAMDLGPARAMS ) ;
   L_UINT64 * puMasterHistogram = DlgParams.puMasterHistogram;
   L_UINT &uMasterHistogramLen = DlgParams.uMasterHistogramLen;
   nRet = GetBitmapHistogram ( pBitmap, 
                              CHANNEL_MASTER, 
                              uMasterHistogramLen,
                              &puMasterHistogram) ;
   if(nRet != SUCCESS)
      return nRet;
   L_UINT64 *puRedHistogram  = DlgParams.puRedHistogram ;
   L_UINT &uRedHistogramLen = DlgParams.uRedHistogramLen;
   nRet = GetBitmapHistogram (pBitmap, 
                              CHANNEL_RED, 
                              uRedHistogramLen,
                              &puRedHistogram) ;
   if(nRet != SUCCESS)
      return nRet;
   L_UINT64 * puGreenHistogram = DlgParams.puGreenHistogram;
   L_UINT &uGreenHistogramLen =DlgParams.uGreenHistogramLen;
   nRet = GetBitmapHistogram (pBitmap, 
                              CHANNEL_GREEN, 
                              uGreenHistogramLen,
                              &puGreenHistogram) ;
   if(nRet != SUCCESS)
      return nRet;
   L_UINT64 *puBlueHistogram = DlgParams.puBlueHistogram;
   L_UINT &uBlueHistogramLen= DlgParams.uBlueHistogramLen;
   nRet = GetBitmapHistogram (pBitmap, 
                              CHANNEL_BLUE,
                              uBlueHistogramLen,
                             &puBlueHistogram ) ;
   if(nRet != SUCCESS)
      return nRet;
   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);
   nRet = DlgImage.SetHistogramParams(&DlgParams) ;
   if(nRet != SUCCESS)
      return nRet;
   nRet = DlgImage.DoModalHistogram(hWnd);
   if(nRet < 1)
      return nRet;
   free ( DlgParams.puMasterHistogram ) ;
   free ( DlgParams.puRedHistogram ) ;
   free ( DlgParams.puGreenHistogram ) ;
   free ( DlgParams.puBlueHistogram ) ;
   // Gets the updated values for the structure
   nRet = DlgImage.GetHistogramParams(&DlgParams, sizeof(DlgParams)) ;
   if(nRet != SUCCESS)
      return nRet;
   nRet = LDialogImage::Free();
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}