forked from dongnanzhy/Digital-Image-Processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHgdlg.cpp
executable file
·147 lines (108 loc) · 3.08 KB
/
Hgdlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Hgdlg.cpp : implementation file
//
#include "stdafx.h"
#include "DIP_Final.h"
#include "Hgdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "Dib.h"
/////////////////////////////////////////////////////////////////////////////
// CHgdlg dialog
CHgdlg::CHgdlg(CDib *m_pDib,CWnd* pParent /*=NULL*/)
: CDialog(CHgdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHgdlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
if (m_pDib!=NULL)
{
m_pData =m_pDib->GetGreyCountNumber();
m_count=m_pDib->GetPaletteEntries();
}
}
void CHgdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHgdlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHgdlg, CDialog)
//{{AFX_MSG_MAP(CHgdlg)
ON_WM_PAINT()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHgdlg message handlers
void CHgdlg::OnPaint()
{
if (m_pData == NULL)
{
return;
}
CPaintDC dc(this);
CRect rect;
CWnd *pWnd = GetDlgItem(IDC_Histogram);
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);
CDC *pDC = &dc;
// CBrush BrushBlue(RGB(0,255,0));
// CBrush *pOldBrush = pDC->SelectObject(&BrushBlue);
CPen *pPen = new CPen;
pPen->CreatePen(PS_SOLID,2,RGB(255,0,0));
CPen *pOldPen = pDC->SelectObject(pPen);
CPen *pBluePen = new CPen;
pBluePen->CreatePen(PS_SOLID,2,RGB(0,0,255));
rect.DeflateRect(20, 20);
/* pDC->Rectangle(&rect);*/
pDC->MoveTo(rect.left,rect.bottom);
pDC->LineTo(rect.left,rect.top);
pDC->LineTo(rect.left-5,rect.top + 5);
pDC->MoveTo(rect.left,rect.top);
pDC->LineTo(rect.left+5,rect.top + 5);
pDC->MoveTo(rect.left,rect.bottom);
pDC->LineTo(rect.right,rect.bottom);
pDC->LineTo(rect.right-5,rect.bottom - 5);
pDC->MoveTo(rect.right,rect.bottom);
pDC->LineTo(rect.right-5,rect.bottom + 5);
int DeltaCount = rect.Width()/m_count;
CString Str;
Str.Format("0");
pDC->TextOut(rect.left,rect.bottom+10,Str );
Str.Format("25");
pDC->TextOut(rect.left + 25 * DeltaCount,rect.bottom +10, Str);
pDC->SelectObject(pBluePen);
long GreyNumberMax = 0;
for (int i=0; i< m_count; i++)
{
if (GreyNumberMax < *(m_pData+i))
{
GreyNumberMax = *(m_pData+i);
}
}
for (i=0; i< m_count; i++)
{
if (GreyNumberMax != 0)
{
double Ratio = (( double )m_pData[i])/GreyNumberMax;
pDC->MoveTo(rect.left + i* DeltaCount+10, rect.bottom);
pDC->LineTo(rect.left + i* DeltaCount+10, rect.bottom - (int)(Ratio * rect.Height()));
}
}
pDC->SelectObject(pOldPen);
// pDC->SelectObject(pOldBrush);
delete pPen;
delete pBluePen;
// device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CHgdlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}