<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Rechenzeit dieser Funktion minimieren für Performance]]></title><description><![CDATA[<p>ich benutze diese funktion, um bitmaps zu zeichnen:</p>
<pre><code class="language-cpp">void CXTGlobal::BltTransparentBitmap(CDC *cDC, CBitmap *bBitmap, int iPosX, int iPosY, int iWidth, int iHight, COLORREF cTransparent, UINT uFlags, int iBmpWidth, int iBmpHeight)
{
	COLORREF	crOldBack = cDC-&gt;SetBkColor(RGB(255, 255, 255)); 
	COLORREF	crOldText = cDC-&gt;SetTextColor(RGB(0, 0, 0));
	CDC			dcImage, dcTrans; 
	CBitmap		*pOldBitmapImage, *pOldBitmapTrans, bitmapTrans;
	CRect		rStretchPos;

	// Create two memory dcs for the image and the mask 
	dcImage.CreateCompatibleDC(cDC); 
	dcTrans.CreateCompatibleDC(cDC); 

	// Select the image into the appropriate dc 
	pOldBitmapImage = dcImage.SelectObject(bBitmap);

	// Build mask based on transparent colour 
	dcImage.SetBkColor(cTransparent); 

	if (uFlags &amp; BTB_STRETCH)
	{
		if ((iBmpWidth == -1) &amp;&amp; (iBmpHeight == -1))
		{
			iBmpWidth	= iWidth;
			iBmpHeight	= iHight;
		}

		rStretchPos.left	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (iBmpWidth - 1) : (0);
		rStretchPos.right	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (-iBmpWidth) : (iBmpWidth);
		rStretchPos.top		= (uFlags &amp; BTB_FLIP_VERTICAL) ? (iBmpHeight - 1) : (0);
		rStretchPos.bottom	= (uFlags &amp; BTB_FLIP_VERTICAL) ? (-iBmpHeight) : (iBmpHeight);
	}

	// Is the picture wanted to be smaller?
	if ((uFlags &amp; BTB_STRETCH) &amp;&amp; (iBmpWidth != -1) &amp;&amp; (iBmpHeight != -1) &amp;&amp; ((iWidth &lt; iBmpWidth) || (iHight &lt; iBmpHeight)))
	{
		CRect rNormal;

		// Mirror normal Size, too
		rNormal.left	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (iWidth - 1) : (0);
		rNormal.right	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (-iWidth) : (iWidth);
		rNormal.top		= (uFlags &amp; BTB_FLIP_VERTICAL) ? (iHight - 1) : (0);
		rNormal.bottom	= (uFlags &amp; BTB_FLIP_VERTICAL) ? (-iHight) : (iHight);

		// Create the mask bitmap 
		bitmapTrans.CreateBitmap(iBmpWidth, iBmpHeight, 1, 1, NULL); 

		// Select the mask bitmap into the appropriate dc 
		pOldBitmapTrans = dcTrans.SelectObject(&amp;bitmapTrans); 

		dcTrans.StretchBlt(0, 0, iWidth, iHight, &amp;dcImage, 0, 0, iBmpWidth, iBmpHeight, SRCCOPY); 

		cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT); 
		cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcTrans, rNormal.left, rNormal.top, rNormal.right, rNormal.bottom, SRCAND);
		cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT);
	}
	else
	{
		// Create the mask bitmap 
		bitmapTrans.CreateBitmap(iWidth, iHight, 1, 1, NULL); 

		// Select the mask bitmap into the appropriate dc 
		pOldBitmapTrans = dcTrans.SelectObject(&amp;bitmapTrans); 

		dcTrans.BitBlt(0, 0, iWidth, iHight, &amp;dcImage, 0, 0, SRCCOPY); 

		if (uFlags &amp; BTB_STRETCH)
		{
			cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT); 
			cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcTrans, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCAND);
			cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT);
		}
		else
		{
			cDC-&gt;BitBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, 0, 0, SRCINVERT); 
			cDC-&gt;BitBlt(iPosX, iPosY, iWidth, iHight, &amp;dcTrans, 0, 0, SRCAND);
			cDC-&gt;BitBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, 0, 0, SRCINVERT); 
		}
	}

	// Restore settings 
	dcImage.SelectObject(pOldBitmapImage); 
	dcTrans.SelectObject(pOldBitmapTrans); 

	cDC-&gt;SetBkColor(crOldBack); 
	cDC-&gt;SetTextColor(crOldText);
}
</code></pre>
<p>genauer gesagt wird mit hilfe dieser funktion ein spielfeld gemalt (Texturen, natürlich nur bitmaps, und einige objekte für das spiel).</p>
<p>das bild wird pro sekunge ca. 30 mal neugezeichnet, daher wird diese funktion sehr oft aufgerufen. logischer weise ist die auslastung meines rechners bei 90% und mehr.</p>
<p>kann man diese funktion vereinfachen und performance zu gewinnen?</p>
<p>Ich weis wenn ich ein spiel basteln will sollte ich auf DirectX umsteigen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> kann man da trotzdem was machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/142750/rechenzeit-dieser-funktion-minimieren-für-performance</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 02:33:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/142750.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 02 Apr 2006 14:56:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rechenzeit dieser Funktion minimieren für Performance on Sun, 02 Apr 2006 14:56:02 GMT]]></title><description><![CDATA[<p>ich benutze diese funktion, um bitmaps zu zeichnen:</p>
<pre><code class="language-cpp">void CXTGlobal::BltTransparentBitmap(CDC *cDC, CBitmap *bBitmap, int iPosX, int iPosY, int iWidth, int iHight, COLORREF cTransparent, UINT uFlags, int iBmpWidth, int iBmpHeight)
{
	COLORREF	crOldBack = cDC-&gt;SetBkColor(RGB(255, 255, 255)); 
	COLORREF	crOldText = cDC-&gt;SetTextColor(RGB(0, 0, 0));
	CDC			dcImage, dcTrans; 
	CBitmap		*pOldBitmapImage, *pOldBitmapTrans, bitmapTrans;
	CRect		rStretchPos;

	// Create two memory dcs for the image and the mask 
	dcImage.CreateCompatibleDC(cDC); 
	dcTrans.CreateCompatibleDC(cDC); 

	// Select the image into the appropriate dc 
	pOldBitmapImage = dcImage.SelectObject(bBitmap);

	// Build mask based on transparent colour 
	dcImage.SetBkColor(cTransparent); 

	if (uFlags &amp; BTB_STRETCH)
	{
		if ((iBmpWidth == -1) &amp;&amp; (iBmpHeight == -1))
		{
			iBmpWidth	= iWidth;
			iBmpHeight	= iHight;
		}

		rStretchPos.left	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (iBmpWidth - 1) : (0);
		rStretchPos.right	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (-iBmpWidth) : (iBmpWidth);
		rStretchPos.top		= (uFlags &amp; BTB_FLIP_VERTICAL) ? (iBmpHeight - 1) : (0);
		rStretchPos.bottom	= (uFlags &amp; BTB_FLIP_VERTICAL) ? (-iBmpHeight) : (iBmpHeight);
	}

	// Is the picture wanted to be smaller?
	if ((uFlags &amp; BTB_STRETCH) &amp;&amp; (iBmpWidth != -1) &amp;&amp; (iBmpHeight != -1) &amp;&amp; ((iWidth &lt; iBmpWidth) || (iHight &lt; iBmpHeight)))
	{
		CRect rNormal;

		// Mirror normal Size, too
		rNormal.left	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (iWidth - 1) : (0);
		rNormal.right	= (uFlags &amp; BTB_FLIP_HORIZONTAL) ? (-iWidth) : (iWidth);
		rNormal.top		= (uFlags &amp; BTB_FLIP_VERTICAL) ? (iHight - 1) : (0);
		rNormal.bottom	= (uFlags &amp; BTB_FLIP_VERTICAL) ? (-iHight) : (iHight);

		// Create the mask bitmap 
		bitmapTrans.CreateBitmap(iBmpWidth, iBmpHeight, 1, 1, NULL); 

		// Select the mask bitmap into the appropriate dc 
		pOldBitmapTrans = dcTrans.SelectObject(&amp;bitmapTrans); 

		dcTrans.StretchBlt(0, 0, iWidth, iHight, &amp;dcImage, 0, 0, iBmpWidth, iBmpHeight, SRCCOPY); 

		cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT); 
		cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcTrans, rNormal.left, rNormal.top, rNormal.right, rNormal.bottom, SRCAND);
		cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT);
	}
	else
	{
		// Create the mask bitmap 
		bitmapTrans.CreateBitmap(iWidth, iHight, 1, 1, NULL); 

		// Select the mask bitmap into the appropriate dc 
		pOldBitmapTrans = dcTrans.SelectObject(&amp;bitmapTrans); 

		dcTrans.BitBlt(0, 0, iWidth, iHight, &amp;dcImage, 0, 0, SRCCOPY); 

		if (uFlags &amp; BTB_STRETCH)
		{
			cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT); 
			cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcTrans, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCAND);
			cDC-&gt;StretchBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, rStretchPos.left, rStretchPos.top, rStretchPos.right, rStretchPos.bottom, SRCINVERT);
		}
		else
		{
			cDC-&gt;BitBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, 0, 0, SRCINVERT); 
			cDC-&gt;BitBlt(iPosX, iPosY, iWidth, iHight, &amp;dcTrans, 0, 0, SRCAND);
			cDC-&gt;BitBlt(iPosX, iPosY, iWidth, iHight, &amp;dcImage, 0, 0, SRCINVERT); 
		}
	}

	// Restore settings 
	dcImage.SelectObject(pOldBitmapImage); 
	dcTrans.SelectObject(pOldBitmapTrans); 

	cDC-&gt;SetBkColor(crOldBack); 
	cDC-&gt;SetTextColor(crOldText);
}
</code></pre>
<p>genauer gesagt wird mit hilfe dieser funktion ein spielfeld gemalt (Texturen, natürlich nur bitmaps, und einige objekte für das spiel).</p>
<p>das bild wird pro sekunge ca. 30 mal neugezeichnet, daher wird diese funktion sehr oft aufgerufen. logischer weise ist die auslastung meines rechners bei 90% und mehr.</p>
<p>kann man diese funktion vereinfachen und performance zu gewinnen?</p>
<p>Ich weis wenn ich ein spiel basteln will sollte ich auf DirectX umsteigen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> kann man da trotzdem was machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1029219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1029219</guid><dc:creator><![CDATA[Red Skall]]></dc:creator><pubDate>Sun, 02 Apr 2006 14:56:02 GMT</pubDate></item></channel></rss>