rendering text performance - very poor
Re: rendering text performance - very poor
I'm hitting this same problem. From a little test of rendering a couple sentences in a single string using MagickCore::MagickReadImage passing it "caption:" followed by the text, it's taking on average about 240ms on my faster machine. Unfortunately this is a far cry from the <1ms I need for use in a real-time app.
I tried hacking around in annotate.c to see if anything simple could be done to improve it. These aren't feasible permanent solutions by any means, just hacking up the code to see what made a difference yet still happens to work in the one scenario I'm testing.
If I change RenderFreeType to only call FT_Init_FreeType once then comment out the calls to FT_Done_FreeType it brings it to around 220ms.
If I additionally change RenderFreeType to only call FT_Open_Face once and comment out the calls to FT_Done_Face, it brings it down to around 90ms.
I didn't see anything else obvious that would be simple to test, so that's where I've stopped. This shows that a couple simple changes (only init ft once then cache the faces) has potential to improve performance a bunch. Unfortunately it's still far out of the speed range I need, so I might end up using ImageMagic to render all the characters once then build the image myself from that as needed.
Code: Select all
//render the text
MagickCore::MagickWand *wand=MagickCore::NewMagickWand();
MagickCore::MagickSetSize(wand, TextWidth, 0);
MagickCore::MagickSetPointsize(wand, 12);
MagickCore::MagickSetOption(wand, "fill", "black");
MagickCore::MagickSetOption(wand, "background", "transparent");
MagickCore::MagickSetGravity(wand, MagickCore::NorthWestGravity);
MagickCore::MagickReadImage(wand, (std::string("caption:")+Text).c_str());
//save the pixels for later
textHeight=MagickCore::MagickGetImageHeight(wand);
textPixels.resize(TextWidth*textHeight);
MagickCore::MagickExportImagePixels(wand, 0, 0, TextWidth, textHeight, "RGBA", MagickCore::CharPixel, &textPixels[0]);
If I change RenderFreeType to only call FT_Init_FreeType once then comment out the calls to FT_Done_FreeType it brings it to around 220ms.
If I additionally change RenderFreeType to only call FT_Open_Face once and comment out the calls to FT_Done_Face, it brings it down to around 90ms.
I didn't see anything else obvious that would be simple to test, so that's where I've stopped. This shows that a couple simple changes (only init ft once then cache the faces) has potential to improve performance a bunch. Unfortunately it's still far out of the speed range I need, so I might end up using ImageMagic to render all the characters once then build the image myself from that as needed.