コード例 #1
0
ファイル: FloatDibWnd.cpp プロジェクト: obabywawa/UPIM
/*
*--------------------------------------------------------------------------------
*  函数名	: MergeDib
*  功能		: 将窗口内的图像与指定图像融合
*  参数		: CDib* pDib	-	画布图像,融合于此DIB之上
*  算法		: 先隐藏按钮,然后将窗口内的图像抓取下来,再将此DIB与参数DIB融合
*--------------------------------------------------------------------------------
*/
BOOL CFloatDibWnd::MergeDib(CDib * pDib)
{	
	CDib* newDib = new CDib();
	
	// 隐藏全部形变按钮
	if(g_createBtn)
    	HideAllButton();

	CRect rcSelf, rcParent;
	GetWindowRect(&rcSelf);
	::GetWindowRect(m_hParentWnd, &rcParent);

	// 抓取浮动窗口客户区图像
	newDib->Create(GetSafeHwnd(), CRect(0, 0, rcSelf.Width(), rcSelf.Height()) );

	// 计算起点座标
	int xStart, yStart;

	// 减 2 是因为边框占两个像素
	xStart = rcSelf.left - rcParent.left - 2;
	yStart = rcSelf.top - rcParent.top - 2;

	pDib->MergeDib(newDib->GetHandle(), CPoint(xStart, yStart));

	delete newDib;
	return TRUE;
}
コード例 #2
0
void CPluginTestDlg::OnAcquire() 
{
	int iListIndex = m_listPlugins.GetCurSel();
	if ( iListIndex == LB_ERR )
		return;

	// Find the plugin that matches the command ID from the plugin list
	LPADOBEPLUGIN lpPlugin = m_lpPluginList;
	while (lpPlugin)
	{
		if ( lpPlugin->iListIndex == iListIndex )
			break;
		lpPlugin = lpPlugin->lpNext;
	}

	// Get out if you can't find it
	if ( !lpPlugin )
		return;

//j	if ( lpPlugin->piType != PIT_ACQUIRE )
//j		return;

	// Load the acquisition DLL
	HMODULE hModule;
	if ( !( hModule = LoadLibrary(lpPlugin->szFileName)))
		return;

	CWnd* hFocus = GetFocus();

	bool bDone = false;
	m_bAborted = false;

	// Get the entry point into the DLL
	LPACQUIREENTRYPROC lpEntryPoint;
	if (!(lpEntryPoint = (LPACQUIREENTRYPROC)GetProcAddress( hModule,
		(lpPlugin->bOldStyle ? "ENTRYPOINT1" : "ENTRYPOINT") )))
		goto BadStart;

	// Set the FilterRecord Info
	PlatformData MyPlatformData;
	memset(&MyPlatformData, 0, sizeof(MyPlatformData));
	MyPlatformData.hwnd = (long)GetSafeHwnd();

	BufferProcs MyBufferProcs;
	memset(&MyBufferProcs, 0, sizeof(MyBufferProcs));
	MyBufferProcs.bufferProcsVersion = kCurrentBufferProcsVersion;
	MyBufferProcs.numBufferProcs = kCurrentBufferProcsCount;
	MyBufferProcs.allocateProc = MyAllocateBufferProc;
	MyBufferProcs.lockProc = MyLockBufferProc;
	MyBufferProcs.unlockProc = MyUnlockBufferProc;
	MyBufferProcs.freeProc = MyFreeBufferProc;
	MyBufferProcs.spaceProc = MyBufferSpaceProc;

	AcquireRecord Record;
	memset(&Record, 0, sizeof(Record));
	Record.abortProc       = MyAbortProc;
	Record.progressProc    = MyProgressProc;
	Record.maxData         = MyBufferSpaceProc();
	Record.planeMap[0]     = 0;
	Record.planeMap[1]     = 1;
	Record.planeMap[2]     = 2;
	Record.planeMap[3]     = 3;
	Record.platformData    = &MyPlatformData;
	Record.canTranspose    = false;
	Record.needTranspose   = false;
	Record.canReadBack     = false;
	Record.canFinalize	   = true;
	Record.diskSpace       = -1;
	Record.spaceProc       = NULL;
	Record.bufferProcs     = NULL; //j &MyBufferProcs;
	Record.resourceProcs   = NULL;
	Record.processEvent    = NULL;
	Record.displayPixels   = MyDisplayPixelsProc;
	Record.handleProcs     = NULL;
	Record.hostProc	       = NULL;	// Host specific callback procedure
	Record.hostModes	   = (1<<plugInModeRGBColor);

	Record.hostSig         =
		( long )'M' << 24 | ( long )'C' << 16 | ( long )'O' << 8 | ( long )'S';

//j	Record.monitor.gamma   = 65536L;
//j	Record.monitor.redX    = 40960L;
//j	Record.monitor.redY    = 22282L;
//j	Record.monitor.greenX  = 18350L;
//j	Record.monitor.greenY  = 38993L;
//j	Record.monitor.blueX   = 10158L;
//j	Record.monitor.blueY   = 4587L;
//j	Record.monitor.whiteX  = 20493L;
//j	Record.monitor.whiteY  = 21561L;
//j	Record.monitor.ambient = 32768L;

	LPLONG lpData;
	lpData = &lpPlugin->lData;
	short sErrCode;
	sErrCode = true;

	// The acquireSelectorPrepare function sets up the acquire operation.
	try
	{
		(*lpEntryPoint)( (short)acquireSelectorPrepare, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
	}
	catch(...)
	{
		sErrCode = true;
	}

	if ( sErrCode )
	{
		m_bAborted = true;
		goto BadStart;
	}

	// The acquireSelectorStart function informs the host of the image type, 
	// mode, and resolution. Plugin dialogs are displayed during this call. 
	try
	{
		(*lpEntryPoint)( (short)acquireSelectorStart, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
	}
	catch(...)
	{
		sErrCode = true;
	}

	if ( sErrCode )
	{
		m_bAborted = true;
	}

	bool bRGBColor;
	bRGBColor = (Record.depth == 8 && Record.planes == 3);
	if ( !bRGBColor || Record.imageMode != plugInModeRGBColor )
	{
		m_bAborted = true;
	}

	// Only support chunky data
	if ( Record.planeBytes != 1 || Record.colBytes != Record.planes )
	{
		m_bAborted = true;
	}

	// Create a DIB to catch the image data
	CDib* pDib;
	if (pDib = new CDib())
	{
		pDib->Create(8 * Record.planes, Record.imageSize.h, Record.imageSize.v);
	}
	else
	{
		m_bAborted = true;
	}

	// Create a progress dialog
	if (CPluginTestDlg::pProgressDlg = new CProgressDlg)
	{
		CPluginTestDlg::pProgressDlg->Create(this);
		CPluginTestDlg::pProgressDlg->SetStatus((const char*)Record.filename);
		CPluginTestDlg::pProgressDlg->SetStep(1);
	}

	// start the processing of the data
	while ( !bDone && !m_bAborted )
	{
		// The acquireSelectorContinue function returns an area of the image to the host.
		try
		{
			(*lpEntryPoint)( (short)acquireSelectorContinue, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
		}
		catch(...)
		{
			sErrCode = true;
		}

		if ( sErrCode )
		{
			m_bAborted = true;
			break;
		}

		if ( !Record.data )  // no more data
		{
			bDone = true;
			break;
		}

		if (pDib)
		{
			long lRowBytes;
			if ( Record.rowBytes < 1 )
				lRowBytes = ( Record.theRect.right - Record.theRect.left ) * Record.planes; 
			else
				lRowBytes = Record.rowBytes;

			// Write the data into the DIB
			HPTR pData;
			pData = (HPTR)Record.data;
			for (int y=Record.theRect.top; y<Record.theRect.bottom; y++)
			{ 
					HPTR pRow = pDib->GetXY(Record.theRect.left, y);
					if (pRow)
						memcpy(pRow, pData, lRowBytes);
					pData += lRowBytes;
			} //j watch: Record.theRect, Record.loPlane, Record.hiPlane
		}
	}

	if (CPluginTestDlg::pProgressDlg)
		delete pProgressDlg;

	if (pDib)
	{
		pDib->WriteFile("c:\\windows\\desktop\\test.dib");
		delete pDib;
	}

	// The acquireSelectorFinish function must be called when exiting at any 
	// point after acquireSelectorStart is called without error.
	try
	{
		(*lpEntryPoint)( (short)acquireSelectorFinish, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
	}
	catch(...)
	{
		sErrCode = true;
	}

	if ( sErrCode )
		m_bAborted = true;

	// The acquireSelectorFinalize function must be called if asked for
	if (Record.wantFinalize)
	{
		try
		{
			(*lpEntryPoint)( (short)acquireSelectorFinalize, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
		}
		catch(...)
		{
			sErrCode = true;
		}
	
		if ( sErrCode )
			m_bAborted = true;
	}

	BadStart:

	if ( hModule )
		FreeLibrary( hModule );

	if ( hFocus )
		hFocus->SetFocus();
}