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

#include "stdafx.h"


/*
内容:
	复制图像对象;
相关函数:
	rviCloneE1
		说明:
			该函数可以拷贝虚拟函数，可以将虚拟图像转成常规图像;
		参数:
			src					-	图像对象
			bForceToNormal		-	布尔值, FALSE拷贝虚拟函数, TRUE虚拟图像转成常规图像;
			dest				-	拷贝目标图像对象, 默认为NULL
	
	rviClone
		说明:
			支持虚拟图象拷贝，dest图象在clone以后，与原图象是完全一致的
		参数:
			src					-	图像对象
			dest				-	拷贝至目标图像对象

	rviDuplicate
		说明:
			拷贝图象,不管dest是否为虚拟图象,dest最终将转换为常规图象,即有自己的数据图象区并将src里面的图象数据拷贝到自己的数据缓冲区
		参数:
			src					-	图像对象常量
			dest				-	拷贝至目标图像对象
*/

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("Clone" ), x,y,w,h);
	assert(m_hWnd);

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

	m_hWnd2 = CreateAuxilliaryWindow(hInstance, _T("CloneE1" ), 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[])
{
	//Demo programs
	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)
	{
		int nSrcW = rviGetWidth(imSrc);
		int nSrcH = rviGetHeight(imSrc);
		RV_IMAGE_TYPE tySrcType = rviGetImageType(imSrc);

		imDest1 = rviClone(imSrc);
		if(imDest1 != NULL)
		{
			m_cw.Show(imDest1);
		}
		
		imDest2 = rviDuplicate(imSrc);
		if(imDest2 != NULL)
		{
			m_cw1.Show(imDest2);
		}
		
		imDest3 = rviCloneE1(imSrc, FALSE);
		if(imDest3 != NULL)
		{
			m_cw2.Show(imDest3);
		}
	}
	//End

	//消息处理
	DoEvents();

	//销毁图像对象;
	rvDestroyImage(imSrc);
	rvDestroyImage(imDest1);
	rvDestroyImage(imDest2);
	rvDestroyImage(imDest3);

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

	return 0;
}

