// ConertImageType3.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

HWND m_hWnd =NULL,  m_hWnd1 =NULL, m_hWnd2=NULL;
CCanvasWindow m_cw, m_cw1, m_cw2;	

void InitAuxWnd()
{
	HINSTANCE hInstance = InitInstance(NULL, FALSE);

	int  cx   =   GetSystemMetrics(  SM_CXFULLSCREEN ); 
	int  cy   =   GetSystemMetrics(  SM_CYFULLSCREEN );

	int w = 600;
	int h = 500;
	int  x = (cx - w)/2;
	int  y = (cy - h)/2;

	// 执行应用程序初始化: 
	m_hWnd = CreateAuxilliaryWindow(hInstance, _T("Image" ), x,y,w,h);
	assert(m_hWnd);

	m_hWnd1 = CreateAuxilliaryWindow(hInstance, _T("Image" ), x / 3,y / 3,w,h);
	assert(m_hWnd1);

	m_hWnd2 = CreateAuxilliaryWindow(hInstance, _T("Image" ), x + x / 3,y + y / 3,w,h);
	assert(m_hWnd2);

	RECT rect;

	::GetClientRect(m_hWnd, &rect);
	m_cw.Create(  m_hWnd, _T("FVI canvas window" ), rect.left, rect.top, rect.right -rect.left, rect.bottom- rect.top);

	::GetClientRect(m_hWnd1, &rect);
	m_cw1.Create(  m_hWnd1, _T("Cast" ), rect.left, rect.top, rect.right -rect.left, rect.bottom- rect.top);

	::GetClientRect(m_hWnd2, &rect);
	m_cw2.Create(  m_hWnd2, _T("Cast" ), rect.left, rect.top, rect.right -rect.left, rect.bottom- rect.top);
}

void ReleaseAuxWnd()
{
	//释放窗口对象
	m_cw.Destroy();
	m_cw1.Destroy();
	m_cw2.Destroy();
};

int _tmain(int argc, _TCHAR* argv[])
{
	//初始化应用窗口;
	InitAuxWnd();

	RvImage imSrc = NULL;
	RvImage imDest1 = NULL;
	RvImage imDest2 = NULL;
	RvImage imDest3 = NULL;

	const char* filePath = _T("..\\samples\\colorwave.jpg");
	imSrc= rvLoadImage(filePath);

	if(imSrc != NULL)
	{
		imDest1 = rviDuplicate(imSrc);
		if(imDest1 != NULL)
		{
			if(rviCvt24To8(imDest1, RV_CVT_24_8_HSV))
			{
				m_cw1.Show(imDest1);
			}
		}

		imDest2 = rviDuplicate(imSrc);
		if(imDest2 != NULL)
		{
			imDest3 = rvCreateImage(RIT_GRAY, rviGetWidth(imDest2), rviGetHeight(imDest2));
			if(imDest3 != NULL)
			{
				if(rviCvt24To8Ex(imDest2, imDest3, RV_CVT_24_8_DIRECT))
				{
					m_cw2.Show(imDest3);
				}
			}
		}

		m_cw.Show(imSrc);
	}
 

	//消息处理
	DoEvents();
	 

	rvDestroyImage(imSrc);
	rvDestroyImage(imDest1);
	rvDestroyImage(imDest2);
	rvDestroyImage(imDest3);

	//释放窗口对象
	ReleaseAuxWnd();

	return 0;
}

