Re: [OT, maybe] C library for doing graphics




"Beej Jorgensen" <beej@xxxxxxx> wrote in message
news:h3qh3q$7pj$2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
superpollo <user@xxxxxxxxxxx> wrote:
i know that graphics is outside the scope of standard C, but i was
somewhat interested in knowing what clc "regulars" use when they want
to "visualize" some data produced by their code, graphically. (perhaps
in various graphics format).

I've never written anything using Cairo, but I would:

http://cairographics.org/FAQ/

It's been ported to Unix/OSX/Windows, is really featureful, and is
LGPL'd.

RH's suggestion for DIY is great, because writing such things can be fun
learning exercises. (I've written so many PPM encoders I can't even
remember.) But if you decided you wanted antialiased vector graphics
and font support, you might have a big coding task ahead of you. :)


antialiasing and fonts are not "too" big of an issue...


the main trick to AA is to just draw everything at a higher resolution and
then downsampling.

the simplest option is to upscale by a power-of-2 factor, and then
downsample by averaging...
the problems is that, though this approach works, it manages to re-introduce
almost as much aliasing as it eliminates. however, if 2 passes are used for
each reduction, namely the first being a filter (essentially, a small scale
blur filter), followed by the average, the results are much better.


sinc is also an option, but IME the problem with sinc is that it is too
computationally expensive to be practical, and using a windowed sinc with a
window small enough to get done in a reasonably short timeframe IME tends to
produce unacceptably poor quality.

the main advantage though would be that it could scale to an arbitrary
resolution (sinc works well for both upscaling and downscaling).

another option is cubic splines, which are much faster than sinc, and offer
similar advantages, but the problem with cubic splines is that implementing
them in the full 2D case unleashes a sort of mathematical demon (note that
one could apply a horizontal and vertical image scale and get a much simpler
algo, however, in this case it will only have a sort of rectangular
symmetry, and is not strictly transpose-symmetric).

however, prefilter+log2 downsample, and LERP for upsample, is fairly simple,
and by combining these approaches one can get an analogue of trilinear or
anistropic filtering...


note that if doing line-based vector graphics and using AA, it is necessary
to add some "thickness" to the lines, otherwise they will generally
disappear when downsampling. simple options are:
A: draw several parallel lines;
B: draw a circular or rectangular glob of pixels for each virtual pixel.


fonts are not TOO bad either, especially if one opts for bitmapped fonts.

one recommendation here is "unifont", which handles the entire UTF-16 BMP
(Basic Multilingual Plane). the people in this project went through the
effort of producing images for all the characters in a reasonably
easy-to-process file format.


granted, these are not vector fonts...

so, for example, drawing TrueType fonts would be a little more work
(especially if antialiased, where then the issue is both making the font
look good and avoiding losing the small details). additional complexity is
added if one tries for "proper" TTF rendering, which may involve curved
lines and the use of Bezier-Splines...

http://en.wikipedia.org/wiki/B%C3%A9zier_curve


however, for my uses, using the prior mentioned image-scaling techniques and
bitmapped fonts has usually produced "good enough" results...


granted though, by the time one is considering all of this stuff, it is
probably really worthwhile to consider using OpenGL or similar for doing a
lot of the rendering, given it is generally much faster (due to the GPU),
and also saves a lot of coding effort.

granted though, one may still need some of the above tricks if trying for
higher-quality than usually provided by GL (such as a cubic scaler to both
get the textures into power-of-2 sizes, and maybe also perform a
higher-quality upsampling than one will get with the built in LERP, as used
bilinear and trilinear filtering...).

or such...


-Beej



.



Relevant Pages

  • Re: Import Vector Graphics to Word - Best Format
    ... fonts just don't matter. ... High-end graphics software such as CorelDRAW enable the choice of either ... almost entirely in the corporate space, where the customer wants to maintain ... and I avoid having text in pictures as far as possible. ...
    (microsoft.public.mac.office.word)
  • Re: typesetting tech question
    ... printing process looks like from the printer's point of view. ... If you use Microsoft Word, either do _not_ embed graphics or, if you do, ... Be sure to include all fonts. ... If you use a professional layout app, such as InDesign or ...
    (rec.arts.sf.composition)
  • Re: Graphics and Fonts: Best Practices??
    ... Not sure what you mean by boundary boxes on the TIFs, but PPT will ... While I agree with your recommendations, still, not all TT fonts ... Including Images in a Presentation ... (Is there a rule of thumb for sizing bitmap graphics - resolution in dpi ...
    (microsoft.public.powerpoint)
  • Re: Convert text to graphics (.gif & .jpg)
    ... I try to use the easiest procedure to get a job done, ... believe in the KISS principle (I'm a teacher and KISS to me ... can I convert text to graphics. ... my website in order to keep the fonts becoming a default ...
    (microsoft.public.office.misc)
  • Re: Word Document Size Increase
    ... (certainly not for common fonts). ... recommended if there are a lot of large graphics. ... I'm not sure how this impacts PDF creation, ... Fast Saves, versioning, True type fonts, ...
    (microsoft.public.word.newusers)