# Low framerate using GT1030 and ReceiveImage

**URL:** <https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602>\
**Category:** Developer\
**Created:** [April 19, 2024, 1:22pm UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602 "2024-04-19T13:22:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mystery123sk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mystery123sk](https://spout.discourse.group/u/mystery123sk)\
**Post date:** [April 19, 2024, 1:22pm UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/1 "2024-04-19T13:22:03Z")

</div>

Hi, I’m using Nvidia GT1030, but I need to receive Spout image to memory. This is the approximate code:

```
int width = m_rcv.GetSenderWidth();
int height = m_rcv.GetSenderHeight();

if (m_rcv.IsUpdated())
{
	SAFE_DELETE_ARRAY(m_pBuffer);
	return SPOUT_ERR_FAIL;
}

if (width <= 0 || height <= 0)
{
	m_rcv.ReceiveImage(0);
	return SPOUT_ERR_FAIL;
}

if (!m_pBuffer)
{
	m_bufferSize = width * height * 4;
	m_pBuffer = new byte[m_bufferSize];
}

if (!m_rcv.ReceiveImage(m_pBuffer))
	return SPOUT_ERR_FAIL;

double fps = m_rcv.GetSenderFps();
return SPOUT_ERR_OK;

```

The variable m\_rcv is the SpoutReceiver. I’m getting about 40fps in the fps variable, but the real output is maybe 2 FPS (resolution about 2000x2000). Is there a way to have smooth animation using CPU? I need to use the RGB values in CPU, I can’t use just the DX/GL bitmap.

---

<div class="post-metadata">

**Author:** ![spout](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@spout](https://spout.discourse.group/u/spout)\
**Post date:** [April 20, 2024, 12:12am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/2 "2024-04-20T00:12:13Z")

</div>

How are you measuring the fps?

Try this re-arranged version -

```auto
if (m_rcv.ReceiveImage(m_pBuffer)) {
	if (m_rcv.IsUpdated()) {
		SAFE_DELETE_ARRAY(m_pBuffer);
		m_bufferSize = m_rcv.GetSenderWidth() * m_rcv.GetSenderHeight()t * 4;
		m_pBuffer = new byte[m_bufferSize];
	}
	double fps = m_rcv.GetSenderFps();
	return SPOUT_ERR_OK;
}

```

---

<div class="post-metadata">

**Author:** ![mystery123sk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mystery123sk](https://spout.discourse.group/u/mystery123sk)\
**Post date:** [April 22, 2024, 11:53am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/3 "2024-04-22T11:53:15Z")

</div>

Thank you for your reply. I’ve updated the code as you’ve recommended:

```auto
	if (m_rcv.ReceiveImage(m_pBuffer))
	{
		if (m_rcv.IsUpdated()) {
			SAFE_DELETE_ARRAY(m_pBuffer);
			int width = m_rcv.GetSenderWidth();
			int height = m_rcv.GetSenderHeight();
			m_bufferSize = width * height * 4;
			m_pBuffer = new byte[m_bufferSize];
		}
		double fps = m_rcv.GetSenderFps();
		return SPOUT_ERR_OK;
	}

	return SPOUT_ERR_FAIL;

```

I’ve made a screen capture, where you can see the source (on the right) and received image over Spout (small image on the left in MainWindow). You can see it’s about 2FPS:

[![](https://global.discourse-cdn.com/free1/uploads/spout/original/1X/7a2e8f0c0d797655ef2df136de5d9146a9526dac.jpeg "spout error") ](https://www.youtube.com/watch?v=Th0sMbjRF2s)

I’ve measured the FPS also in my code (how many frames I’m receiving) - it’s showing about 4-6 fps.

Is there some easy to use example available for Spout using CPU bitmaps? So I avoid my code and test the recommended way? Because all examples I’ve found used OpenGL render directly to screen.

---

<div class="post-metadata">

**Author:** ![spout](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@spout](https://spout.discourse.group/u/spout)\
**Post date:** [April 22, 2024, 12:20pm UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/4 "2024-04-22T12:20:57Z")

</div>

There must be a reason for your finding but I can’t reproduce it. There is a [DirectX example](https://github.com/leadedge/Spout2/tree/master/SPOUTSDK/SpoutDirectX/SpoutDX/Windows/Sender) for image sending. This does not require any framework, so it would be useful If you could build this solution to see if it has the same problem.

---

<div class="post-metadata">

**Author:** ![mystery123sk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mystery123sk](https://spout.discourse.group/u/mystery123sk)\
**Post date:** [April 22, 2024, 2:03pm UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/5 "2024-04-22T14:03:19Z")

</div>

You’re right, the problem was in C# bitmap creation process. Now it’s running at 30FPS. Just to explain the issue, I was using C# Bitmap LockBits to access RGBA data directly and copy from incoming Spout buffer:

```auto
var btmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
				System.Drawing.Imaging.ImageLockMode.ReadOnly,
				System.Drawing.Imaging.PixelFormat.Format32bppArgb);

			byte* pBitmapSrc = (byte*)receivedData.ToPointer();
			int srcStride = 4 * bitmap.Width;
			byte* pBitmapDest = (byte*)btmpData.Scan0.ToPointer();
			int wb = bitmap.Width;
			int hb = bitmap.Height;
			for (int y = 0; y < bitmap.Height; y++)
			{
				byte* pLineSrc = pBitmapSrc + y * srcStride;
				byte* pLineDest = pBitmapDest + y * btmpData.Stride;

				for (int x = 0; x < bitmap.Width; x++)
				{
					pLineDest[0] = pLineSrc[2];
					pLineDest[1] = pLineSrc[1];
					pLineDest[2] = pLineSrc[0];
					pLineDest[3] = pLineSrc[3];
					pLineSrc += 4;
					pLineDest += 4;
				}
			}
			bitmap.UnlockBits(btmpData);

```

The problem is in bitmap.Width and bitmap.Height - those slow down the process a lot. When I used local variables (int wb = bitmap.Width) instead, all is working fast. Strange …

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![spout](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@spout](https://spout.discourse.group/u/spout)\
**Post date:** [April 23, 2024, 1:13am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/6 "2024-04-23T01:13:04Z")

</div>

That’s good news. There must be an overhead for bitmap.Width and bitmap.Height but you would not expect it. If the bitmap stride is the same as the source stride, could you just copy the data.

```auto
	memcpy((void*)btmpData.Scan0.ToPointer(),
		(void*)receivedData.ToPointer(),
		bitmap.Width*bitmap.Height*4);

```

Or for additional speed, you might try a SpoutCopy function that uses SSE if the width is 16 byte aligned.

```auto
	m_rcv.spoutcopy.CopyPixels((const unsigned char*)receivedData.ToPointer(),
		(unsigned char*)btmpData.Scan0.ToPointer(),
		bitmap.Width, bitmap.Height);

```

There are also “rgba2rgba” functions that use SSE and allow for source and destination pitch.

---

<div class="post-metadata">

**Author:** ![mystery123sk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mystery123sk](https://spout.discourse.group/u/mystery123sk)\
**Post date:** [April 23, 2024, 9:16am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/7 "2024-04-23T09:16:59Z")

</div>

Unfortunately that’s not possible, since the color order is different (in C# Bitmap class). Anyway, thank you for your help, really appreciated!

Edit: I noticed, there’s rgba2bgra function, that might work. Thank you.

---

<div class="post-metadata">

**Author:** ![spout](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@spout](https://spout.discourse.group/u/spout)\
**Post date:** [April 24, 2024, 12:48am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/8 "2024-04-24T00:48:40Z")

</div>

OK, I missed the reason for the copy.

If that is the only problem, you can receive directly to the Bitmap buffer and specify GL\_BGRA for the format. I checked that this works with the OpenGL example.

Originally this was only an RGBA/RGB option, but since then there have been updates to formats. I will look into revising the documentation and example.

---

<div class="post-metadata">

**Author:** ![mystery123sk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mystery123sk](https://spout.discourse.group/u/mystery123sk)\
**Post date:** [May 17, 2024, 8:58am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/9 "2024-05-17T08:58:53Z")

</div>

Hi, thank you for the help, it’s working like a charm now. I want to ask, we are developing software for pixel LED mapping for about 10 years now ([www.ledstripstudio.com](http://www.ledstripstudio.com)) and it’s widely used across the world. Is it possible to add also our icon and link to your website, so the people know, we support Spout?

Thank you again.

 ![spout in lss](https://global.discourse-cdn.com/free1/uploads/spout/original/1X/48270f505d7b15f0883ef25c4bb691e5cce0c3e7.jpeg)

---

<div class="post-metadata">

**Author:** ![spout](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@spout](https://spout.discourse.group/u/spout)\
**Post date:** [May 18, 2024, 7:32am UTC](https://spout.discourse.group/t/low-framerate-using-gt1030-and-receiveimage/602/10 "2024-05-18T07:32:26Z")

</div>

Yes of course. Please contact me using the email shown on the [GitHub Page](https://github.com/leadedge).
