Page 1 of 1
Connection to X broken
Posted: 2008-07-18T20:08:54-07:00
by LeMacUser
Hello,
I am writing a program that generates large numbers of images (~100,000) from scientific data. I have this running on a headless server which i SSH into. However I find that when I attempt to abort my SSH session, which uses magick++ to generate the images, I get the following message:
"X connection to localhost:11.0 broken (explicit kill or server shutdown)."
I run this inside a gnome-terminal, using gnu screen, which I use to fork off jobs such that I can disconnect my SSH session without interurupting the program -- yet it still does, only with the magick++ app. Other apps are unaffected.
How can I stop this? Why is magick++ connecting to X? All I need is the ability to make dots on an image, scale, write some text, then write the image to file.
Any help is much appreciated.
Re: Connection to X broken
Posted: 2008-07-19T04:59:02-07:00
by magick
An X11 connection is made if you try to display an image or if you use an X11 font to render text. Post your Magick++ source code and we'll try to determine which method is causing the unanticipated X11 connection.
Re: Connection to X broken
Posted: 2008-07-19T20:09:18-07:00
by LeMacUser
Well it's true -- I do create a DrawableText() object to tag each frame with data about the information in the frame. Hmm. Is it possible to render text without having to stay connected?
The X11 server isn't shutting down per-se, just that the session is ending -- although the exact difference between the two is unclear to me. The remote machine still runs X11, its just that my connection gets killed.
I create a thread using the function "writeIm", which draws the text on top of an incoming image. The incoming image is generated in a master thread from a lot of lines followed by a composite.
To segregate slow IO and the CPU intensive image generation I split them up into a master thread, that spawns new threads (writeim) which then terminate after writing the file.
So this is what requires the X11 connection, the question then becomes how to avoid this, and still get the text?
I don't see a good solution for this -- Is there some alternate way to cache font-data so that I don't need a connection? Or if I move the DrawableFont call elsewhere will I be OK? Can I just call it once in the master thread and be done with it?
Thankyou.
Code: Select all
*SNIP*
void *writeIm(void *d)
{
THREAD_DATA *data = (THREAD_DATA *)d;
list<Magick::Drawable> drawList;
Image *a = (Image *)(data->im);
a->resize(Geometry(data->sizeX,data->sizeY));
string str,strTmp;
//Draw the hit number as "Event * to *"
drawList.push_back(DrawableFont("-*-helvetica-medium-r-normal-*-*-140-*-*-*-*-iso8859-1"));
str="Events ";
stream_cast(strTmp,data->hitStart);
str+=strTmp;
str+=" to ";
stream_cast(strTmp,data->hitEnd);
str+=strTmp;
drawList.push_back(DrawableTextAntialias(true));
drawList.push_back(DrawableText(30,20,str));
str = "Rate ";
stream_cast(strTmp,data->rateStart);
str+=strTmp;
str+=" to ";
stream_cast(strTmp,data->rateEnd);
str+=strTmp;
drawList.push_back(DrawableText(30,40,str));
a->draw(drawList);
a->write(data->filename.c_str());
cerr << "Wrote: " << data->filename << endl;
//Unlock
data->locked=false;
return 0;
}
*SNIP*
Re: Connection to X broken
Posted: 2008-07-20T04:55:17-07:00
by magick
Here's the problem, your font is -*-helvetica-medium-r-normal-*-*-140-*-*-*-*-iso8859-1 which requires an X11 server connection. Instead ensure your version of ImageMagick includes support for Freetype. Type
and verify that freetype is associated with the DELEGATES tag. Now see which fonts are supported:
Use one of the available fonts and your program will no longer require an X11 connection and the rendered fonts should have an improved look.
Re: Connection to X broken
Posted: 2008-07-20T05:01:14-07:00
by LeMacUser
That sounds like a great idea! thanks -- I will give it a try.
Re: Connection to X broken
Posted: 2008-07-21T19:34:48-07:00
by LeMacUser
I replaced the call to DrawableFont's constructor with:
drawList.push_back(DrawableFont(string("Helvetica"),
AnyStyle,400,AnyStretch));
Works like a charm, I can disconnect X and reconnect at will, no program stoppage.
My only question is this -- Is there a simple way to list available fonts directly inside the program so I don't have to hard-code in the need for the user to have Helvetica installed? It's not super-important though, at least for my purposes.
Re: Connection to X broken
Posted: 2008-07-23T17:57:27-07:00
by anthony
on older IM use
convert -list type
If you get a list including things like 'Bilevel' and 'TrueColor' you have a newer version
of ImageMagick.. In whcih case use...
convert -list font
For a way of determining exactly which version of IM you have (for testing purposes) see...
http://www.imagemagick.org/Usage/api/#version
or the PHP equivelent of this
http://www.rubblewebs.co.uk/imagemagick ... /fonts.php