?? histogramdlg.cpp
字號:
// HistogramDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CarLP.h"
#include "HistogramDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHistogramDlg dialog
CHistogramDlg::CHistogramDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHistogramDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHistogramDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
lpSource=0;
lpDest=0;
}
void CHistogramDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHistogramDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHistogramDlg, CDialog)
//{{AFX_MSG_MAP(CHistogramDlg)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHistogramDlg message handlers
BOOL CHistogramDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHistogramDlg::GetHistogram(int *ret,BYTE *lpPoints,int width,int height)
{
int nByteWidth=width*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
int x,y,p;
for(y=0;y<256;y++)
{
ret[y]=0;
}
BYTE Bright;
double b;
for(y=0;y<height;y++)
{
for(x=0;x<width;x++)
{
p=x*3+y*nByteWidth;
// b=0.2125*(double)lpPoints[p+2]+0.7154*(double)lpPoints[p+1]+0.0721*(double)lpPoints[p];
b=0.299*(double)lpPoints[p+2]+0.587*(double)lpPoints[p+1]+0.114*(double)lpPoints[p];
b+=0.1;
if (b>=256) b=255;
Bright=(BYTE)b;
ret[Bright]++;
}
}
int max=0;
for(y=0;y<256;y++)
{
if (ret[y]>max) max=ret[y];
}
for(y=0;y<256;y++)
{
if (ret[y])
{
ret[y]*=99;
ret[y]/=max;
ret[y]+=1;
}
}
}
void CHistogramDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
HPEN pen=(HPEN)GetStockObject(BLACK_PEN);
dc.SelectObject(pen);
int i;
if (lpSource)
{
GetHistogram(sourceh,lpSource,nWidth,nHeight);
dc.Draw3dRect(11,29,258,101,0,0);
dc.Draw3dRect(11,134,258,12,0,0);
for(i=0;i<256;i++)
{
dc.FillSolidRect(12+i,135,1,10,RGB(i,i,i));
if (sourceh[i]>0)
{
dc.FillSolidRect(12+i,130-sourceh[i],1,sourceh[i],0);
}
}
}
if (lpDest)
{
GetHistogram(desth,lpDest,nDestWidth,nDestHeight);
dc.Draw3dRect(11,179,258,101,0,0);
dc.Draw3dRect(11,284,258,12,0,0);
for(i=0;i<256;i++)
{
dc.FillSolidRect(12+i,285,1,10,RGB(i,i,i));
if (desth[i]>0)
{
dc.FillSolidRect(12+i,280-desth[i],1,desth[i],0);
}
}
}
// Do not call CDialog::OnPaint() for painting messages
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -