📄 histrogram.cpp
字号:
// Histrogram.cpp : implementation file
//
#include "stdafx.h"
#include "RSImageStar.h"
#include "RSImageStarDoc.h"
#include "RSImageStarView.h"
#include "Histrogram.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHistrogram dialog
extern CRSImageStarView *m_pView;
CHistrogram::CHistrogram(CWnd* pParent /*=NULL*/)
: CDialog(CHistrogram::IDD, pParent)
{
//{{AFX_DATA_INIT(CHistrogram)
m_count1 = 0;
m_count2 = 0;
m_count3 = 0;
m_count6 = 0.0f;
m_count5 = 0;
m_count4 = _T("");
//}}AFX_DATA_INIT
nCount=0;
m_InRect= false;
mStart = false;
nRedraw =true;
}
void CHistrogram::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHistrogram)
DDX_Control(pDX, IDC_BUTTON1, m_Bitmap);
DDX_Control(pDX, IDC_COMBO1, m_ComboBox);
DDX_Control(pDX, IDC_STATIC7, Histrog);
DDX_Text(pDX, IDC_EDIT1, m_count1);
DDX_Text(pDX, IDC_EDIT2, m_count2);
DDX_Text(pDX, IDC_EDIT3, m_count3);
DDX_Text(pDX, IDC_EDIT6, m_count6);
DDX_Text(pDX, IDC_EDIT5, m_count5);
DDX_Text(pDX, IDC_EDIT4, m_count4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHistrogram, CDialog)
//{{AFX_MSG_MAP(CHistrogram)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHistrogram message handlers
BOOL CHistrogram::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
Histrog.GetWindowRect(rect);
ScreenToClient(&rect);
m_Bitmap.GetWindowRect(RectMap);
ScreenToClient(&RectMap);
if((m_pView->m_pDoc->curptr->dib->filetype==6)||(m_pView->m_pDoc->curptr->dib->filetype==5))
{
m_ComboBox.SetWindowText("红色");
m_ComboBox.AddString("红色");
m_ComboBox.AddString("绿色");
m_ComboBox.AddString("蓝色");
}
else
{
m_ComboBox.SetWindowText("亮度");
m_ComboBox.AddString("亮度");
}
m_Cross = AfxGetApp()->LoadCursor(IDC_CURSORCROSS);
m_count1=m_pView->m_pDoc->curptr->dib->MeanRed;
m_count2=m_pView->m_pDoc->curptr->dib->DevRed;
m_count3=m_pView->m_pDoc->size.cx*m_pView->m_pDoc->size.cy;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHistrogram::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if((rect.PtInRect(point))&&(!m_InRect))
{
SetCursor( m_Cross);
SetCapture();
CClientDC dc(this);
int nOldRop = dc.SetROP2(R2_NOT);
dc.MoveTo(point.x,rect.top);
dc.LineTo(point.x,rect.bottom);
dc.SetROP2(nOldRop);
m_InRect=true;
startpoint=point;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CHistrogram::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if((m_InRect))//&&(rect.PtInRect(point)))
{
CClientDC dc(this);
int nOldRop = dc.SetROP2(R2_NOT);
if(mStart)
dc.Rectangle(rect1);
mStart=true;
if(startpoint.x<point.x)
{
rect1.left = startpoint.x;
rect1.right= point.x;
}
else
{
rect1.left = point.x;
rect1.right= startpoint.x;
}
rect1.top=rect.top;
rect1.bottom=rect.bottom;
int m=int((rect1.left-rect.left)*256.0/rect.Width()+0.5);
if(m<0)
{
m=0;
rect1.left=rect.left;
}
int n=int((rect1.right-rect.left)*256.0/rect.Width()+0.5);
if(n>255)
{
n=255;
rect1.right=rect.right;
}
dc.Rectangle(rect1);
dc.SetROP2(nOldRop);
m_count5=0;
int i;
switch(nCount)
{
case 0:
for(i=m;i<=n;i++)
m_count5+=m_pView->m_pDoc->curptr->dib->nRedChannel[i];
break;
case 1:
for(i=m;i<=n;i++)
m_count5+=m_pView->m_pDoc->curptr->dib->nGreenChannel[i];
break;
case 2:
for(i=m;i<=n;i++)
m_count5+=m_pView->m_pDoc->curptr->dib->nBlueChannel[i];
break;
default:
break;
}
m_count4.Format("%d.%d",m,n);
m_count6=float(m_count5)/m_count3;
UpdateData(FALSE);
}
else if(rect.PtInRect(point))
{
SetCursor( m_Cross);
int m=int((point.x-rect.left)*256.0/rect.Width()+0.5);
m_count5=0;
switch(nCount)
{
case 0:
m_count5=m_pView->m_pDoc->curptr->dib->nRedChannel[m];
break;
case 1:
m_count5=m_pView->m_pDoc->curptr->dib->nGreenChannel[m];
break;
case 2:
m_count5=m_pView->m_pDoc->curptr->dib->nBlueChannel[m];
break;
default:
break;
}
m_count4.Format("%d",m);
m_count6=float(m_count5)/m_count3;
UpdateData(FALSE);
}
CDialog::OnMouseMove(nFlags, point);
}
void CHistrogram::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_InRect=false;
mStart=false;
if(rect.PtInRect(point))
SetCursor(m_Cross);
// InvalidateRect(rect,true);
m_count4.Empty();
m_count5=0;
m_count6=0;
UpdateData(FALSE);
ReleaseCapture();
CDialog::OnLButtonUp(nFlags, point);
}
void CHistrogram::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
nCount=m_ComboBox.GetCurSel();
Histrog.nChannel=nCount;
switch(nCount)
{
case 0:
m_count1=m_pView->m_pDoc->curptr->dib->MeanRed;
m_count2=m_pView->m_pDoc->curptr->dib->DevRed;
break;
case 1:
m_count1=m_pView->m_pDoc->curptr->dib->MeanGreen;
m_count2=m_pView->m_pDoc->curptr->dib->DevGreen;
break;
case 2:
m_count1=m_pView->m_pDoc->curptr->dib->MeanBlue;
m_count2=m_pView->m_pDoc->curptr->dib->DevBlue;
break;
default:
break;
}
nRedraw=true;
UpdateData(FALSE);
Invalidate();
}
void CHistrogram::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if(nRedraw)
{
CPen pen(PS_SOLID, 1, RGB(0,0,0));
CPen *pOldpen;
pOldpen=dc.SelectObject(&pen);
int i;
float scale,color;
scale=float(2.0*256/RectMap.Width());
color=0;
if((m_pView->m_pDoc->curptr->dib->filetype==6)||(m_pView->m_pDoc->curptr->dib->filetype==5))
switch(nCount)
{
case 0:
for(i=RectMap.left;i<RectMap.right;i+=2)
{
CPen pen1(PS_SOLID, 1, RGB(int(color+0.5),0,0));
dc.SelectObject(&pen1);
dc.Rectangle(i,RectMap.top,i+2,RectMap.bottom);
color+=scale;
}
break;
case 1:
for(i=RectMap.left;i<RectMap.right;i+=2)
{
CPen pen1(PS_SOLID, 1, RGB(0,int(color+0.5),0));
dc.SelectObject(&pen1);
dc.Rectangle(i,RectMap.top,i+2,RectMap.bottom);
color+=scale;
}
break;
case 2:
for(i=RectMap.left;i<RectMap.right;i+=2)
{
CPen pen1(PS_SOLID, 1, RGB(0,0,int(color+0.5)));
dc.SelectObject(&pen1);
dc.Rectangle(i,RectMap.top,i+2,RectMap.bottom);
color+=scale;
}
break;
default:
break;
}
else
{
for(i=RectMap.left;i<RectMap.right;i+=2)
{
CPen pen1(PS_SOLID, 1, RGB(int(color+0.5),int(color+0.5),int(color+0.5)));
dc.SelectObject(&pen1);
dc.Rectangle(i,RectMap.top,i+2,RectMap.bottom);
color+=scale;
}
}
dc.SelectObject(pOldpen);
nRedraw=false;
}
// Do not call CDialog::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -