#include "l_bitmap.h"
L_LTDLG_API L_INT L_DlgHistogram(hWndOwner, pDlgParams)
Displays the Histogram dialog box.
Handle of the window which owns the dialog.
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 dialogs initial values.
Value | Meaning |
---|---|
SUCCESS_DLG_CLOSE | The dialog exits successfully after pressing the "Close" button. |
< 1 | An error occurred. Refer to Return Codes. |
The Histogram dialog.
Required DLLs and Libraries
// Example 1
// Example to illustrate using a bitmap to show histogram charts
L_INT DlgHistogramFirstExample(HWND hWnd,pBITMAPHANDLE pBitmap)
{
L_INT nRet;
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 ;
nRet = L_DlgInit ( DLG_INIT_COLOR ) ;
if(nRet != SUCCESS && nRet != ERROR_DLG_ALREADYINITIATED)
return nRet;
nRet = L_DlgHistogram ( hWnd, &DlgParam ) ;
if(nRet < 1)
return nRet;
nRet = L_DlgFree () ;
if(nRet != SUCCESS)
return nRet;
return SUCCESS;
}
// Example 2
// Example to illustrate using histogram tables to show histogram charts
L_VOID GetBitmapHistogram(pBITMAPHANDLE pBitmap,
L_UINT uChannel,
L_UINT uCount,
L_UINT64** 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, 0 ) )
{
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, 0 ) )
{
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_UINT64 *)malloc ( uCount * sizeof ( L_UINT64 ) ) ;
// read histogram
L_GetBitmapHistogram( pBitmap, *lppHistogram, uCount, uChannel ) ;
}
L_INT DlgHistogramSecondExample(HWND hWnd, pBITMAPHANDLE pBitmap)
{
L_INT nRet;
HISTOGRAMDLGPARAMS DlgParam ;
L_UINT64* pTempPtr = NULL;
memset ( &DlgParam, 0, sizeof ( HISTOGRAMDLGPARAMS ) ) ;
DlgParam.uStructSize = sizeof ( HISTOGRAMDLGPARAMS ) ;
pTempPtr = DlgParam.puMasterHistogram;
GetBitmapHistogram(pBitmap,
CHANNEL_MASTER,
DlgParam.uMasterHistogramLen,
&pTempPtr) ;
pTempPtr = DlgParam.puRedHistogram ;
GetBitmapHistogram(pBitmap,
CHANNEL_RED,
DlgParam.uRedHistogramLen,
&pTempPtr) ;
pTempPtr = DlgParam.puGreenHistogram;
GetBitmapHistogram(pBitmap,
CHANNEL_GREEN,
DlgParam.uGreenHistogramLen,
&pTempPtr) ;
pTempPtr = DlgParam.puBlueHistogram;
GetBitmapHistogram(pBitmap,
CHANNEL_BLUE,
DlgParam.uBlueHistogramLen,
&pTempPtr) ;
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 ;
nRet = L_DlgInit ( DLG_INIT_COLOR ) ;
if(nRet != SUCCESS && nRet != ERROR_DLG_ALREADYINITIATED)
return nRet;
nRet = L_DlgHistogram ( hWnd, &DlgParam ) ;
if(nRet < 1)
return nRet;
nRet = L_DlgFree () ;
if(nRet != SUCCESS)
return nRet;
free ( DlgParam.puMasterHistogram ) ;
free ( DlgParam.puRedHistogram ) ;
free ( DlgParam.puGreenHistogram ) ;
free ( DlgParam.puBlueHistogram ) ;
return SUCCESS;
}