Another metafile translator: gxyat

Arlindo da Silva arlindo.dasilva at GMAIL.COM
Wed Aug 1 19:29:41 EDT 2007


All,

Some of you may find this useful....

I've been looking into ways of creating antialised GrADS images which do not
have those distracting horizontal lines into them. After several hacks which
were too slow to meet my real time requirements (including a metafile
translator based on the ImageMagick API) I ended up using the Cairo Vector
Graphics Library:

  http://cairographics.org/

to write yet another gx translator: gxyat.c (see source and gxyat.1 man page
attached). Cairo is being used by many big projects such as gtk and firefox
and it is very simple to use. This translator produces PNG, SVG, PS or PDF,
although I'd still recommend Matt's gxeps for postscript output.

Sorry, but I am not providing binaries, just the attached sources. Details
on building gxyat and comparison to other translators are bellow.

  Enjoy,

    Arlindo


1) Building gxyat

To build gxyat, first build cairo. I'd suggest grabbing the latest
v1.4.6tarball from the site above and doing configure+make. Don't
worry if it
cannot find freetype or any font related dependency as GrADS draws its own
fonts. Cairo is amazingly self-contained for a package of this nature. I
have easily built cairo on Linux and on my G5 laptop running Mac OS/X 10.4;
it also builds natively on Windows, and pre-compiled libcairo.dll are
available (I have done this yet). Once you have cairo, building gxyat is
trivial:

% gcc -o gxyat -I/usr/local/include/cairo gxyat.c -L/usr/local/lib -lcairo

Type 'gxyat' for a man page (see gxyat.1 attached) and try the examples.
When running it, make sure it finds the libcairo.so you just built, not the
one in /usr/lib. Although this usually works, in one case I got a float
point exception when an ancient version of cairo was already installed on my
system. To check which  .so's are being seen, type "ldd gxyat", and set
LD_LIBRARY_PATH if you need to. On Mac OS X you set DYLD_LIBRRAY_PATH
instead - how annoying!

2) Comparison to other translators

I am attaching some GrADS images generated with various translators for
comparison. The built in printim is fast but has the poorest quality,
particularly the fonts;  I suspect one of its problems may the integer
arithmetic in the reimplemented line drawing code (I had a similar quality
problem in gximg until I switched some of the coordinate variables to
double).

One alternative to have smoother fonts is to go through gm->eps->png using
convert, which in turn uses ghostscript to render the  image; the result is
file " ghostscript.png" which has the now classic horizontal lines due to
"fringing" in the antialiasing algorithm; this process is also slow. The
file gxyat.png was produced with the new utility; there I draw all lines
with anti-aliasing on, but turn it off when doing color fills. Because
anti-aliasing usually makes the lines wider, any potential mismatch between
shaded contours and contour lines is hardly noticeable (specially if you are
40 or older :-). The new utility is also very fast. As a bonus, one is also
able to create PS, PDF and Scalar Vector Graphics (SVG). The latter is a W3C
specification and  has native support in firefox since v1.5 (IE still needs
a plugin from Adobe). SVG also allows you to use vector editors such as
Adobe illustrator or Inkscape on Linux to embelish your images, yet keeping
it fully scalable. I'd think that GIS applications would support SVG as
well, but I have no experience with these. SVG is growing on me. The PDF
option can also be handy to e-mail someone a whole batch of images in a
single file. I'd stick with gxeps for postscript at this point.


--
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20070801/b7a3c511/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: printim.png
Type: image/png
Size: 30832 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070801/b7a3c511/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ghostscript.png
Type: image/png
Size: 313769 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070801/b7a3c511/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gxyat.png
Type: image/png
Size: 278261 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070801/b7a3c511/attachment-0002.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gxyat.1
Type: application/octet-stream
Size: 5345 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070801/b7a3c511/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gxyat.c
Type: text/x-csrc
Size: 24956 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070801/b7a3c511/attachment.bin 


More information about the gradsusr mailing list