GraphicsMagick++ Slow and Memory Hungry

I am using Magick+ to produce frames for a game engine. I invested time in switching from GDI for a performance increase but I ended up getting the opposite; not only is it much slower but it chews up more ten times the memory (60 mb vs 800mb).

This is an engine for running Sierra AGI games from 30 years ago, something doesn't seem right here!

I figured that the culprit was probably the way in which I used the library, not the library.

I am going to show the important parts of my code to the experts here and hope for some tips to help me improve.

Note I am an experienced C# dev but only a beginner C++ dev.

Secondly I would love to remove starter image, and just generate one with a fill colour, but I don't know how to specify an image format if I do so.

I am compiling a C++ project against the CLI in mixed mode.

Wrapper.h
1
2
3
4
5
6
7
namespace CLIScumm {
	public ref class Wrapper {
	...
	private:
	...
         Magick::Blob* magicKBlob;
	};


Wrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
CLIScumm::Wrapper::Wrapper(System::String^ gameFolderLocation, CopyRectToScreen^ screenUpdated)
{
	...

	MagickLib::InitializeMagick(NULL);

	...
}


void CLIScumm::Wrapper::init()
{
				...
	
				Magick::Image magicKImage = Magick::Image("bmp:C:\\temp\\starterImage.bmp");
				magicKBlob = new Magick::Blob();
				magicKImage.write(magicKBlob);
				
				...
}

...

void CLIScumm::Wrapper::ScreenUpdated(const void* buf, int pitch, int x, int y, int w, int h, PalletteColor* color)
{
	Magick::Image magicKImage = Magick::Image(*magicKBlob);
	const unsigned char* bufCounter = static_cast<const unsigned char*>(buf);
	for (int hightCounter = 0; hightCounter < h; hightCounter++, bufCounter = bufCounter + pitch)
	{
		for (int widthCounter = 0; widthCounter < w; widthCounter++)
		{
			PalletteColor currentColor = ...
			magicKImage.pixelColor(x + widthCounter, y + hightCounter, Magick::Color(currentColor.r, currentColor.g, currentColor.b, currentColor.a));
		}
	}

	magicKImage.write(magicKBlob);

	_screenUpdated->Invoke(gcnew System::String(magicKBlob->base64().c_str()));
}

...


You chose the wrong library.

ImageMagik is for processing things like photos.
So what it's going to be doing is storing your images in floating point RGBA format, like maybe 64 bytes per pixel.
Very good for maintaining image fidelity in a photo.

But totally useless for real time frame rates from computer generated imagery.

Try https://www.libsdl.org/ instead.

Thank you for your help. I you are probably right. I am going to abandon that library and try something else. You live and you learn :).
Topic archived. No new replies allowed.