void Iwa_GradientWarpFx::doCompute(TTile &tile,
								   double frame,
								   const TRenderSettings &settings)
{
	/*- ソース画像が刺さっていなければreturn -*/
	if (!m_source.isConnected()) {
		tile.getRaster()->clear();
		return;
	}
	/*- 参照画像が刺さっていなければ、ソース画像をそのまま返す -*/
	if (!m_warper.isConnected()) {
		m_source->compute(tile, frame, settings);
		return;
	}

	/*-  計算パラメータを得る -*/
	/*- 移動距離のピクセルサイズ -*/
	/*--- 拡大縮小(移動回転しないで)のGeometryを反映させる ---*/
	double k = sqrt(fabs(settings.m_affine.det()));
	double hLength = m_h_maxlen->getValue(frame) * k;
	double vLength = m_v_maxlen->getValue(frame) * k;

	double scale = m_scale->getValue(frame);

	/*- ワープ距離が0なら、ソース画像をそのまま返す -*/
	if (hLength == 0.0 && vLength == 0.0) {
		m_source->compute(tile, frame, settings);
		return;
	}

	int margin = static_cast<int>(ceil((abs(hLength) < abs(vLength)) ? abs(vLength) : abs(hLength)));

	/*- 素材計算範囲を計算 -*/
	/*- 出力範囲 -*/
	TRectD rectOut(tile.m_pos, TDimensionD(
								   tile.getRaster()->getLx(), tile.getRaster()->getLy()));
	TRectD enlargedRect = rectOut.enlarge((double)margin);
	TDimensionI enlargedDim((int)enlargedRect.getLx(), (int)enlargedRect.getLy());

	/*- ソース画像を正規化して格納 -*/
	float4 *source_host;
	TRasterGR8P source_host_ras(enlargedDim.lx * sizeof(float4), enlargedDim.ly);
	source_host_ras->lock();
	source_host = (float4 *)source_host_ras->getRawData();
	{
		/*- タイルはこのフォーカス内だけ使用。正規化してsource_hostに取り込んだらもう使わない。 -*/
		TTile sourceTile;
		m_source->allocateAndCompute(
			sourceTile, enlargedRect.getP00(),
			enlargedDim,
			tile.getRaster(), frame, settings);
		/*- タイルの画像を0〜1に正規化してホストメモリに読み込む -*/
		TRaster32P ras32 = (TRaster32P)sourceTile.getRaster();
		TRaster64P ras64 = (TRaster64P)sourceTile.getRaster();
		if (ras32)
			setSourceRaster<TRaster32P, TPixel32>(ras32, source_host, enlargedDim);
		else if (ras64)
			setSourceRaster<TRaster64P, TPixel64>(ras64, source_host, enlargedDim);
	}

	/*- 参照画像を正規化して格納 -*/
	float *warper_host;
	TRasterGR8P warper_host_ras(enlargedDim.lx * sizeof(float), enlargedDim.ly);
	warper_host_ras->lock();
	warper_host = (float *)warper_host_ras->getRawData();
	{
		/*- タイルはこのフォーカス内だけ使用。正規化してwarper_hostに取り込んだらもう使わない -*/
		TTile warperTile;
		m_warper->allocateAndCompute(
			warperTile, enlargedRect.getP00(),
			enlargedDim,
			tile.getRaster(), frame, settings);
		/*- タイルの画像の輝度値を0〜1に正規化してホストメモリに読み込む -*/
		TRaster32P ras32 = (TRaster32P)warperTile.getRaster();
		TRaster64P ras64 = (TRaster64P)warperTile.getRaster();
		if (ras32)
			setWarperRaster<TRaster32P, TPixel32>(ras32, warper_host, enlargedDim);
		else if (ras64)
			setWarperRaster<TRaster64P, TPixel64>(ras64, warper_host, enlargedDim);
	}

	/*- 変位値をScale倍して増やす -*/
	hLength *= scale;
	vLength *= scale;

	TRasterGR8P result_host_ras;

	result_host_ras = TRasterGR8P(enlargedDim.lx * sizeof(float4), enlargedDim.ly);
	/*- 結果を収めるメモリ -*/
	float4 *result_host;
	result_host_ras->lock();
	result_host = (float4 *)result_host_ras->getRawData();
	doCompute_CPU(tile, frame, settings,
				  hLength, vLength,
				  margin,
				  enlargedDim,
				  source_host,
				  warper_host,
				  result_host);
	/*- ポインタ入れ替え -*/
	source_host = result_host;

	int2 yohaku = {(enlargedDim.lx - tile.getRaster()->getSize().lx) / 2,
				   (enlargedDim.ly - tile.getRaster()->getSize().ly) / 2};
	/*- ラスタのクリア -*/
	tile.getRaster()->clear();
	TRaster32P outRas32 = (TRaster32P)tile.getRaster();
	TRaster64P outRas64 = (TRaster64P)tile.getRaster();
	if (outRas32)
		setOutputRaster<TRaster32P, TPixel32>(source_host, outRas32, enlargedDim, yohaku);
	else if (outRas64)
		setOutputRaster<TRaster64P, TPixel64>(source_host, outRas64, enlargedDim, yohaku);

	/*- ソース画像のメモリ解放 -*/
	source_host_ras->unlock();
	/*- 参照画像のメモリ解放 -*/
	warper_host_ras->unlock();
	result_host_ras->unlock();
}
Beispiel #2
0
void CSpiroView::OnDraw(CDC* pDC)
{
	ENSURE(pDC != NULL);
	
	CPaintDC*	pDCPaint;
	int			nWidthClip(0);  // Initialize to avoid compiler warnings.
	int			nHeightClip(0);  // Initialize to avoid compiler warnings.
	CRect		rectClip;
	CSpiroRect	rectLogClip;
	
	if (!pDC->IsPrinting())
	{
		ASSERT(pDC->IsKindOf(RUNTIME_CLASS(CPaintDC)));
		pDCPaint = (CPaintDC*)pDC;
		rectClip = pDCPaint->m_ps.rcPaint;
		rectLogClip = rectClip;
		pDC->DPtoLP(&rectLogClip);   // this will be the clip rectangle which includes the zoom factor in it
		nWidthClip = rectLogClip.Width();
		nHeightClip = rectLogClip.Height();
		// Prepare a memory DC to draw on
		if (nWidthClip <= 0 || nHeightClip >= 0)  // the clipping region is empty
			return;  // nothing to draw in this case
	}

	g_pView = this;
	CSpiroDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CDC* pDCUse = pDC;
	int nSavedDC(0);  // Initialized to avoid compiler warnings.

	CRgn*	prgnWheel = NULL;

	if (!pDC->IsPrinting())
	{
		if (m_pDCMem == NULL)
		{
			m_pDCMem = new CDC();
			ASSERT(m_pDCMem != NULL);
			VERIFY(m_pDCMem->CreateCompatibleDC(pDC));
			m_pDCMem->SetMapMode(MM_SPIRO);
		}

		int cxClip = rectClip.Width();
		int cyClip = rectClip.Height();
		ASSERT(cxClip > 0 && cyClip >0);

		if (m_pBitmap == NULL)
			m_pBitmap = new CBitmap();

		if (cxClip > m_sizeBitmap.cx || cyClip > m_sizeBitmap.cy)
		{
			if (m_pbitmapOld != NULL)
			{
				m_pDCMem->SelectObject(m_pbitmapOld);
				m_pBitmap->DeleteObject();
			}

			VERIFY(m_pBitmap->CreateCompatibleBitmap(pDC, cxClip, cyClip));
			m_pbitmapOld  = m_pDCMem->SelectObject(m_pBitmap);
			m_sizeBitmap.cx = cxClip;
			m_sizeBitmap.cy = cyClip;
		}

		CPoint ptViewportOrg = pDC->GetViewportOrg();
		ptViewportOrg.x -= rectClip.left;
		ptViewportOrg.y -= rectClip.top;
		m_pDCMem->SetViewportOrg(ptViewportOrg);
		m_pDCMem->SetWindowOrg(pDC->GetWindowOrg());

		CSpiroRect  rectDoc(rectLogClip);
		CSpiroRect	rectOut(rectDoc);  // strip to the right of the doc (vertical strip)

		int cx = pDoc->m_sizeExtent.cx * m_nZoomNumer / m_nZoomDenom;
		CBrush	br(GetSysColor(COLOR_3DLIGHT));

		if (rectDoc.right > cx)  // paint vertical strip
		{
			rectOut.left = cx;
			rectDoc.right = cx;
			m_pDCMem->FillRect(&rectOut, &br);
		}

		if (rectDoc.bottom < 0)
		{
			rectOut.SetRect(rectDoc.left, 0, cx, rectDoc.bottom);
			m_pDCMem->FillRect(&rectOut, &br);
			rectDoc.bottom = 0;
		}

		CBrush brush(GetSysColor(COLOR_WINDOW));
		m_pDCMem->FillRect(&rectDoc, &brush);

		pDCUse = m_pDCMem;
		nSavedDC = pDCUse->SaveDC();
		pDCUse->IntersectClipRect(0, pDoc->m_sizeExtent.cy * m_nZoomNumer / m_nZoomDenom, cx, 0);

		if (m_pWheel != NULL)
		{
			prgnWheel = new CRgn();
			m_pWheel->GetLogPieceRgn(prgnWheel, m_nZoomNumer, m_nZoomDenom);
		}
	}


	// draw the current figure
	pDoc->m_pFigureCurrent->Draw(pDCUse, m_nZoomNumer, m_nZoomDenom
												, prgnWheel, &rectLogClip);

	// draw all the other figures
	INT_PTR nLast = pDoc->m_arrPFigures.GetUpperBound();
	CFigure* pFig;
	for (int i = 0; i <= nLast; i++)
	{
		pFig = (CFigure*)pDoc->m_arrPFigures.GetAt(i);
		pFig->Draw(pDCUse, m_nZoomNumer, m_nZoomDenom, prgnWheel, &rectLogClip);
	}

	delete prgnWheel;

	if (!pDC->IsPrinting())
	{

		pDCUse->RestoreDC(nSavedDC);

		if (m_pAnchor != NULL) 
			m_pAnchor->Draw(m_pDCMem, m_nZoomNumer, m_nZoomDenom);

		if (m_pWheel != NULL)
			m_pWheel->Draw(m_pDCMem, m_nZoomNumer, m_nZoomDenom);

		// now transfer the information in the memory DC to the device DC
		VERIFY(pDC->BitBlt(rectLogClip.left, rectLogClip.top, nWidthClip, nHeightClip, 
													pDCUse, rectLogClip.left, rectLogClip.top, SRCCOPY));

	}
}
Beispiel #3
0
//***********************************************************************************************************
BOOL CBCGPBaseVisualCtrl::DoPrint(CDC* pDCIn, CPrintInfo* pInfo)
{
	CObject* pBaseVisual = GetVisualBaseObject();
	if (pBaseVisual == NULL)
	{
		return FALSE;
	}

	CBCGPBaseVisualObject* pVisualObject = DYNAMIC_DOWNCAST(CBCGPBaseVisualObject, pBaseVisual);
	CBCGPVisualContainer* pVisualContainer = DYNAMIC_DOWNCAST(CBCGPVisualContainer, pBaseVisual);

	if (pVisualObject == NULL && pVisualContainer == NULL)
	{
		return FALSE;
	}

	CBCGPGraphicsManager* pGM = GetGraphicsManager();
	if (pGM == NULL)
	{
		return FALSE;
	}

	ASSERT_VALID(pGM);

	CDC* pDC = pDCIn;
	CPrintDialog* pPrintDlg = NULL;

	if (pDC == NULL)
	{
		pPrintDlg = new CPrintDialog(FALSE);
		
		if (pPrintDlg->DoModal() == IDCANCEL)
		{
			delete pPrintDlg;
			return FALSE;
		}

		pDC = CDC::FromHandle(pPrintDlg->GetPrinterDC());
		pDC->m_bPrinting = TRUE;
		
		CString strTitle;
		strTitle.LoadString(AFX_IDS_APP_TITLE);
		
		DOCINFO di;
		ZeroMemory(&di, sizeof (DOCINFO));
		di.cbSize = sizeof (DOCINFO);
		di.lpszDocName = strTitle;
		
		if (!pDC->StartDoc(&di))
		{	
			pDC->AbortDoc();
			delete pPrintDlg;
			return FALSE;
		}

		pInfo = new CPrintInfo();
		pInfo->m_rectDraw.SetRect(0,0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
	}

	CSize size(pInfo->m_rectDraw.Size());
	CBCGPRect rect(CBCGPPoint(), size);
	CBCGPRect rectControl(pVisualObject != NULL ? pVisualObject->GetRect() : pVisualContainer->GetRect());

	CBCGPSize sizeScaleRatio((double)size.cx / rectControl.Width(), (double)size.cy / rectControl.Height());

	double dAspect = min(sizeScaleRatio.cx, sizeScaleRatio.cy);
	sizeScaleRatio.cx = sizeScaleRatio.cy = dAspect;

	size.cx = bcg_clamp((int)(rectControl.Width() * dAspect), 0, size.cx);
	size.cy = bcg_clamp((int)(rectControl.Height() * dAspect), 0, size.cy);
	
	rect.SetSize(size);

	CDC	dcPrint;
	CBitmap	bmpPrint;
	CBitmap* pBmpPrintOld = NULL;
	CDC* pDCOut = NULL;

	CBrush brWhite(RGB(255, 255, 255));

	if (DYNAMIC_DOWNCAST(CBCGPGraphicsManagerGDI, pGM) != NULL)
	{
		dcPrint.CreateCompatibleDC(NULL);
		bmpPrint.Attach(CBCGPDrawManager::CreateBitmap_32(size, NULL));
		
		pBmpPrintOld = dcPrint.SelectObject (&bmpPrint);
		ASSERT(pBmpPrintOld != NULL);

		pDCOut = &dcPrint;
	}
	else
	{
		pGM->SetPrintInfo(pInfo);
		pDCOut = pDC;
	}

	pDCOut->FillRect((CRect)rect, &brWhite);
	pGM->BindDC(pDCOut);

	if (pGM->IsBindDCFailed())
	{
		pDCOut->FillRect((CRect)rect, &brWhite);
		pDCOut->TextOut(0, 0, _T("Out of memory"));
	}
	else
	{
		pGM->BeginDraw();

		CBCGPSize sizeScaleRatioOld;
		
		if (pVisualObject != NULL)
		{
			sizeScaleRatioOld = pVisualObject->GetScaleRatio();
			pVisualObject->SetScaleRatio(sizeScaleRatio);
			pVisualObject->SetRect(rect);
		}
		else
		{
			sizeScaleRatioOld = pVisualContainer->GetScaleRatio();
			pVisualContainer->SetScaleRatio(sizeScaleRatio);
			pVisualContainer->SetRect(rect);
		}

		pGM->Clear();

		if (pVisualObject != NULL)
		{
			pVisualObject->OnDraw (pGM, rect);
		}
		else
		{
			pVisualContainer->OnDraw (pGM, rect);
		}

		pGM->EndDraw();

		pGM->BindDC(NULL);

		if (pVisualObject != NULL)
		{
			pVisualObject->SetScaleRatio(sizeScaleRatioOld);
		}
		else
		{
			pVisualContainer->SetScaleRatio(sizeScaleRatioOld);
		}

		if (dcPrint.GetSafeHdc() != NULL)
		{
			CBCGPDrawManager::FillAlpha (rect, (HBITMAP)bmpPrint.GetSafeHandle (), 255);
		}
	}

	if (pVisualObject != NULL)
	{
		pVisualObject->SetRect(rectControl);
		pVisualObject->SetDirty ();
	}
	else
	{
		pVisualContainer->SetRect(rectControl);
		pVisualContainer->SetDirty ();
	}

	if (dcPrint.GetSafeHdc() != NULL)
	{
		BITMAP bmp = {0};
		bmpPrint.GetBitmap (&bmp);

		CRect rectOut(pInfo->m_rectDraw.TopLeft (), CSize(bmp.bmWidth, bmp.bmHeight));

		int mode = pDC->SetStretchBltMode(HALFTONE);

		pDC->BitBlt (rectOut.left, rectOut.top, rectOut.Width(), rectOut.Height(), &dcPrint, 0, 0, SRCCOPY);
		pDC->SetStretchBltMode(mode);

		dcPrint.SelectObject(pBmpPrintOld);
	}
	else
	{
		pGM->SetPrintInfo(NULL);
	}

	if (pPrintDlg != NULL)
	{
		pDC->EndDoc();
		delete pPrintDlg;
		delete pInfo;
	}

	return TRUE;
}