L_DlgHistogram

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_DlgHistogram(hWndOwner, pDlgParams)

HWND hWndOwner;

/* owner of dialog */

LPHISTOGRAMDLGPARAMS pDlgParams;

/* pointer to a HISTOGRAMDLGPARAMS structure */

Displays the Histogram dialog box.

Parameter

Description

hWndOwner

Handle of the window which owns the dialog.

pDlgParams

Pointer to a HISTOGRAMDLGPARAMS structure to be updated with the values entered by the user, through the dialog. Set members of this structure, before calling this function, to set the dialog’s initial values.

Returns

SUCCESS_DLG_CLOSE

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

< 1

An error occurred. Refer to Return Codes.

Comments

The Histogram dialog can be seen below:

image\Histogram.gif

Required DLLs and Libraries

LTDLGIMG
LTDLGKRN
LTDLGUTL
LTDLGCTRL
LTDLGCOM
LTDIS
LTIMG
LTKRN

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:

L_DlgInit, L_GetBitmapHistogram

Topics:

Dialogs: Color Manipulation

 

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 L_GetBitmapHistogram, see Example 2

Example 1

// Example to illustrate using a bitmap to show histogram charts
L_VOID ShowDialog ( HWND hWnd, pBITMAPHANDLE pBitmap )
{
   HISTOGRAMDLGPARAMS DlgParam ;
   
   memset ( &DlgParam, 0, sizeof ( HISTOGRAMDLGPARAMS ) ) ; 

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

   L_DlgHistogram ( hWnd, &DlgParam ) ;

   L_DlgFree () ;
}
 

Example 2

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

   pBITMAPHANDLE pBitmap, 
   L_UINT        uChannel,
   L_UINT        uCount,
   L_UINT32**    lppHistogram
)
{
   // allocate histogram array
   if ( ISGRAY( pBitmap ) )
   {
      switch ( pBitmap->BitsPerPixel )
      {
      case 1:
      case 4:
      case 8 :
         {
            uCount = 256 ;
         }
         break ;

      case 12:
         {
            uCount = 4096 ;// maximum

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

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

         break ;

      case 16:
         {
            uCount = 65536 ;

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

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

      default:
         return ;
      }
   }
   else
   {
      switch ( pBitmap->BitsPerPixel )
      {
      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
   L_GetBitmapHistogram( pBitmap, *lppHistogram, uCount, uChannel ) ;
}

L_VOID ShowDialog ( HWND hWnd, pBITMAPHANDLE pBitmap )
{
   HISTOGRAMDLGPARAMS DlgParam ;
   
   memset ( &DlgParam, 0, sizeof ( HISTOGRAMDLGPARAMS ) ) ; 

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

   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_RED, 
                        DlgParam.uRedHistogramLen,
                        &DlgParam.puRedHistogram ) ;
   
   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_GREEN, 
                        DlgParam.uGreenHistogramLen,
                        &DlgParam.puGreenHistogram ) ;

   GetBitmapHistogram ( pBitmap, 
                        CHANNEL_BLUE, 
                        DlgParam.uBlueHistogramLen,
                        &DlgParam.puBlueHistogram ) ;

   DlgParam.pBitmap           = NULL ;
   DlgParam.crBlueChannelPen  = RGB ( 0, 0, 255 ) ;
   DlgParam.crGreenChannelPen = RGB ( 0, 255, 0 ) ;
   DlgParam.crRedChannelPen   = RGB ( 255, 0, 0 ) ;
   DlgParam.crMasterPen       = RGB ( 0, 0, 0 ) ;
   DlgParam.uDlgFlags            = DLG_HISTOGRAM_SHOW_VIEWSTYLE | 
                                DLG_HISTOGRAM_USERPENCOLORS ;

   L_DlgInit ( 0 ) ;

   L_DlgHistogram ( hWnd, &DlgParam ) ;

   L_DlgFree ();

   free ( DlgParam.puMasterHistogram ) ;

   free ( DlgParam.puRedHistogram ) ;

   free ( DlgParam.puGreenHistogram ) ;
   
   free ( DlgParam.puBlueHistogram ) ;
}