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

#include "stdafx.h"


HWND m_hWnd1 =NULL, m_hWnd2=NULL,  m_hWnd3 =NULL, m_hWnd4=NULL;
CCanvasWindow m_cw1, m_cw2, m_cw3, m_cw4;	

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_hWnd1 = CreateAuxilliaryWindow(hInstance, _T("Image 1" ), x / 5,y / 3,w,h);
	assert(m_hWnd1);

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

	m_hWnd3 = CreateAuxilliaryWindow(hInstance, _T("Image 3" ), (x * 2) / 5,y,w,h);
	assert(m_hWnd2);

	m_hWnd4 = CreateAuxilliaryWindow(hInstance, _T("Image 4" ), (x * 2) / 5,y + (y * 2) / 3,w,h);
	assert(m_hWnd2);

	RECT rect;

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

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

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

	::GetClientRect(m_hWnd1, &rect);
	m_cw4.Create(  m_hWnd4, _T("Cast 4" ), rect.left, rect.top, rect.right -rect.left, rect.bottom- rect.top);
}

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

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

	RvImage imSrc1 = NULL;
	RvImage imSrc2 = NULL;

	RvImage imDest1 = NULL;
	RvImage imDest2 = NULL;
	RvImage imDest3 = NULL;
	RvImage imDest4 = NULL;

	const char* filePath1 = _T("..\\samples\\waterdrop.png");
	imSrc1= rvLoadImage(filePath1);
	RV_IMAGE_TYPE it= rviGetImageType(imSrc1);

	const char* filePath2 = _T("..\\samples\\colorwave.jpg");
	imSrc2= rvLoadImage(filePath2);
	it= rviGetImageType(imSrc2);

	if(imSrc1 != NULL && imSrc2 != NULL)
	{
		imDest1 = rviDuplicate(imSrc1);
		if(imDest1 != NULL)
		{
			if(rviCvt32To24(imDest1, 0, FALSE))
			{
				m_cw1.Show(imDest1);
			}
		}

		imDest2 = rviDuplicate(imSrc2);
		if(imDest2 != NULL)
		{
			if(rviCvt24To32(imDest2, 160))
			{
				m_cw2.Show(imDest2);
			}
		}

		imDest3 = rviDuplicate(imSrc2);
		if(imDest3 != NULL)
		{
			rviCast(imDest3, RIT_RGBA);
			if(rviCvt24To32Ex( imSrc2, imDest3, 100))
			{
				m_cw3.Show(imDest3);
			}
		}

		imDest4 = rviDuplicate(imSrc1);
		if(imDest4 != NULL  )
		{
			rviCast(imDest4, RIT_RGB);
			if(rviCvt32To24Ex(imSrc1,imDest4,  RV_RGB(12,35,123), TRUE))
			{
				m_cw4.Show(imDest4);
			}
		}
		
	}

	//End

	//消息处理
	DoEvents();

	rvDestroyImage(imSrc1);
	rvDestroyImage(imSrc2);
	rvDestroyImage(imDest1);
	rvDestroyImage(imDest2);
	rvDestroyImage(imDest3);
	rvDestroyImage(imDest4);

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

	return 0;
}

