Page 1 of 2

rendering text performance - very poor

Posted: 2006-03-23T09:04:10-07:00
by rperez
Hi All.

I did some benchmarks on the library and found that drawing text on an image is very slow in comparison to composing images.
When I say very slow I mean by a factor of 10 approximatley.

I am running with one thread only.

What can be the cause of this?
Does the library reads the font from the disk every drawing ?
Is the time spent looking in the SplayTree for configuration ?
I am using the list<Drawable>, is this a problem ?

Thanks,
Ronen.

Posted: 2006-03-23T10:28:23-07:00
by magick
Fonts and glyths are not currently cached in ImageMagick which would be a great speedup. Its on our list of things to do.

Posted: 2006-03-23T10:34:40-07:00
by rperez
do you have an estimation on when this issue will be addressed?
this is very important to our project as it is what cause us to exceed our time requirements.

Thanks,
Ronen.

Posted: 2006-03-23T11:28:48-07:00
by magick
Implementing the font caching in ImageMagick will be quite time consuming to do it properly. Instead consider sending us a stripped down code/script of what you are doing and we will run a profile to see if we can identify opportunities for speed-ups. If we reproduce the slow-down you are getting, perhaps we can shoot for a short term improvement.

Posted: 2006-03-23T11:44:59-07:00
by rperez

Code: Select all

try
{
                mImage = new Image();
                mImage->size(Geometry(fWidth,fHeight));
                mImage->backgroundColor(fColor.getColor());
	mImage->erase();

                // render the text.
	list<Drawable> drawList;
	drawList.push_back(DrawableFont(fFontFace,fFontSyle,fFontWeight,NormalStretch));
	drawList.push_back(DrawablePointSize(fFontSize));
	drawList.push_back(DrawableTextDecoration(fTextDecoration));
	drawList.push_back(DrawableGravity(fGravity));
	drawList.push_back(DrawableFillColor(fFontColor));
	drawList.push_back(DrawableText(0,0,fText,"UTF-8"));
	mImage->draw(drawList);
}
catch (Magick::Exception& err)
{
	LOG_MESSAGE
	return false;
}

Posted: 2006-03-23T12:15:43-07:00
by magick
If you have more than one text string to render, you should get a substantial speed up by collecting all the strings into a drawable and only rendering them once rather than individually. Use DrawablePushGraphicContext() and DrawablePopGraphicContext() to separate the text attributes if need be.

Posted: 2006-03-26T01:51:39-07:00
by rperez
This solution is problematic for us because we render text on various Imageg and not only on one. if I understand your suggestion, this may help when all text item are on the same Image object.
do you have any idea on how can we improve our performance and still render text on more then one Image?

Thanks,
Ronen.

Posted: 2006-03-26T09:06:03-07:00
by magick
For a high performance needs we recommend drawing directly with the Freetype library and utilizing the font cache API they provide.

Posted: 2006-03-27T02:34:39-07:00
by rperez
Hi there,
I am not familiar with the FreeType usage in ImageMagick.
do you have a sample code to illustrate the way to render text with both libraries? (render the text with FreeType onto an ImageMagick Image object).

Thanks,
Ronen.

Posted: 2006-03-27T08:43:22-07:00
by magick
The best path forward would be to download the Freetype library and reads its documentation or we suspect there may be a Freetype book by now that would be helpful. All the ImageMagick Freetype related code can be found in the source distribution in the file magick/annotate.c.

Posted: 2006-04-02T03:42:58-07:00
by rperez
Hi and thanks for the quick response.
in order for us to render text directly with the Freetype library, we need to copy a huge amount of code from annotate.c in order to gain all the functionality we used up until now.
can you point out the place in the code where the fonts and glyphs are read from the file and not cached. I am trying to find the easiest way to use Freetype and ImageMagic to accomplished that.

Thanks,
Ronen.

Posted: 2006-04-02T11:32:39-07:00
by magick
Everything Freetype related is found in RenderFreetype() of magick/annotate.c. The FT_Open_Face() Freetype method opens a font file.

Posted: 2006-04-03T08:48:59-07:00
by rperez
Hi,
I used this information of FT_Open_Face that read the font from the file and it was very helpful.
My question is whether there are more actions that are "heavy" in performance.
I have some other suspects I wanted to ask about.
FT_Attach_File (also open file?)
FT_Load_Glyph
and FT_Init_FreeType - is there a problem to init the library only once instead of each time we render text? is it a heavy action?

Thanks in advance,
Ronen.

Posted: 2006-04-03T09:08:08-07:00
by magick
You will need to find a Freetype support forum for answers to your questions. This forum is about ImageMagick development.

Posted: 2007-01-30T06:29:52-07:00
by rperez
Hi there,
I asked you some monthes ago, about the performance of text rendering on an image and the reply was that text caching is not yet supported in ImageMagick but is on the "todo list".
are there any news on the subject? is this supported in the new versions of the library?

Thanks in advance,
Ronen.