www.pudn.com > MyImageDB(imageobject).rar > ColorPalette.cpp


 
#include "stdafx.h" 
#include "colorpalette.h" 
#include "myimagedb.h" 
#include "mycolorspace.h" 
#include "include\imageobject.h" 
#include "include\imageload.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
CColorPalette::CColorPalette() 
{                     
	m_ForeColor = RGB(0, 0, 0); 
	m_BackColor = RGB(255, 255, 255); 
	 
} 
 
CColorPalette::~CColorPalette() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CColorPalette, CDialogBar) 
//{{AFX_MSG_MAP(CColorPalette) 
ON_WM_PAINT() 
//}}AFX_MSG_MAP 
//ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdate) 
END_MESSAGE_MAP() 
 
void CColorPalette::UpdateNeiData(BYTE* curnei, INT radius, FLOAT d 
		, FLOAT e, FLOAT d0, FLOAT e0 
		, FLOAT d1, FLOAT e1, FLOAT d2 
		, FLOAT e2, FLOAT d3, FLOAT e3) 
{ 
	if (curnei==NULL) 
	{ 
		return; 
	} 
	CWnd* myMatrix = GetDlgItem(IDC_MATRIX); 
	CRect matrixrect; 
	myMatrix->GetClientRect(matrixrect); 
	myMatrix->ClientToScreen(matrixrect); 
	ScreenToClient(matrixrect); 
	//建立一个临时图像;(输入数据为neiHeigth*neiWidth*3) 
	INT neiHeigth, neiWidth; 
	neiHeigth = neiWidth = 2*radius + 1; 
	 
	CImageObject tempimage; 
	tempimage.CreateDIBFromBits(neiWidth, neiHeigth, curnei); 
	 
	CClientDC dc(this); 
	 
	tempimage.DrawToHdc( dc.GetSafeHdc(), matrixrect.left 
		, matrixrect.top, matrixrect.right-matrixrect.left 
		, matrixrect.bottom-matrixrect.top); 
 
	//以下刷新邻域信息; 
	CWnd* wd = GetDlgItem(IDC_D); 
	CWnd* we = GetDlgItem(IDC_E); 
	CWnd* wd0 = GetDlgItem(IDC_D0); 
	CWnd* we0 = GetDlgItem(IDC_E0); 
	CWnd* wd1 = GetDlgItem(IDC_D1); 
	CWnd* we1 = GetDlgItem(IDC_E1); 
	CWnd* wd2 = GetDlgItem(IDC_D2); 
	CWnd* we2 = GetDlgItem(IDC_E2); 
	CWnd* wd3 = GetDlgItem(IDC_D3); 
	CWnd* we3 = GetDlgItem(IDC_E3); 
 
	CString sd( _T("0") ); 
	CString se( _T("0") ); 
	CString sd1( _T("0") ); 
	CString se1( _T("0") ); 
	CString sd2( _T("0") ); 
	CString se2( _T("0") ); 
	CString sd3( _T("0") ); 
	CString se3( _T("0") ); 
	CString sd0( _T("0") ); 
	CString se0( _T("0") ); 
 
	sd.Format("%1.3f", d); 
	se.Format("%2.2f", e); 
	sd0.Format("%1.3f", d0); 
	se0.Format("%2.2f", e0); 
	sd1.Format("%1.3f", d1); 
	se1.Format("%2.2f", e1); 
	sd2.Format("%1.3f", d2); 
	se2.Format("%2.2f", e2); 
	sd3.Format("%1.3f", d3); 
	se3.Format("%2.2f", e3); 
 
	wd->SetWindowText(sd); 
	we->SetWindowText(se); 
	wd0->SetWindowText(sd0); 
	we0->SetWindowText(se0); 
	wd1->SetWindowText(sd1); 
	we1->SetWindowText(se1); 
	wd2->SetWindowText(sd2); 
	we2->SetWindowText(se2); 
	wd3->SetWindowText(sd3); 
	we3->SetWindowText(se3); 
} 
 
void CColorPalette::OnUpdateColor(RGBQUAD color, int inx 
	, int iny, MyLUV luv) 
{ 
	CWnd* colorframe = GetDlgItem(IDC_COLOR_FRAME); 
	CWnd* red = GetDlgItem(IDC_RED); 
	CWnd* green = GetDlgItem(IDC_GREEN); 
	CWnd* blue = GetDlgItem(IDC_BLUE); 
	CWnd* intensity = GetDlgItem(IDC_INTENSITY); 
	CWnd* wx = GetDlgItem(IDC_X);//窗口标签caption; 
	CWnd* wy = GetDlgItem(IDC_Y); 
	CWnd* wl = GetDlgItem(IDC_L); 
	CWnd* wu = GetDlgItem(IDC_U); 
	CWnd* wv = GetDlgItem(IDC_V); 
 
	ASSERT(colorframe); 
	ASSERT(red); 
	ASSERT(green); 
	ASSERT(blue); 
	ASSERT(intensity); 
 
	CRect rect; 
	colorframe->GetClientRect(rect); 
	colorframe->ClientToScreen(rect); 
	ScreenToClient(rect); 
	rect.DeflateRect(2, 2); 
 
	CString sred( _T("0") ); 
	CString sgreen( _T("0") ); 
	CString sblue( _T("0") ); 
	CString sintensity( _T("0") ); 
	CString sx( _T("0") ); 
	CString sy( _T("0") ); 
	CString sl( _T("0") ); 
	CString su( _T("0") ); 
	CString sv( _T("0") ); 
 
	CBrush brush; 
	 
	COLORREF c; 
	c = RGB(color.rgbRed, color.rgbGreen, color.rgbBlue); 
	brush.CreateSolidBrush(c); 
	sred.Format(_T("%d"), GetRValue(c)); 
	sgreen.Format(_T("%d"), GetGValue(c)); 
	sblue.Format(_T("%d"), GetBValue(c)); 
	sintensity.Format(_T("%d"), (GetRValue(c) + GetGValue(c) + GetBValue(c))/3); 
	sx.Format(_T("%d"), inx); 
	sy.Format(_T("%d"), iny); 
	sl.Format(_T("%3.1f"), luv.l); 
	su.Format(_T("%3.1f"), luv.u); 
	sv.Format(_T("%3.1f"), luv.v); 
 
	CClientDC dc(this); 
	dc.FillRect(rect, &brush); 
	 
	red->SetWindowText(sred); 
	green->SetWindowText(sgreen); 
	blue->SetWindowText(sblue); 
	intensity->SetWindowText(sintensity); 
	wx->SetWindowText(sx); 
	wy->SetWindowText(sy); 
	wl->SetWindowText(sl); 
	wu->SetWindowText(su); 
	wv->SetWindowText(sv);	 
	return; 
} 
 
void CColorPalette::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
}