[cairo] Isn't there a way to pass multiple points to Cairo? (sorry for duplicate)

Jerónimo Barraco Mármol jerobarraco at yahoo.com.ar
Mon Aug 1 07:15:46 PDT 2011


sorry for my intromision.I'm not completely sure what are your intentions, but , afaik drawing a soundwave in cairo isnt particulary slow
i made this with cairo and i was able to watch it realtime in a modest notebookhttp://www.youtube.com/watch?v=oii-MqbjJWA
btw, i used line_to not move_to
Jerónimo Barraco Mármol



http://nande.com.ar

http://ar.linkedin.com/in/nande

--- El sáb 30-jul-11, Andrea Canciani <ranma42 at gmail.com> escribió:

De: Andrea Canciani <ranma42 at gmail.com>
Asunto: Re: [cairo] Isn't there a way to pass multiple points to Cairo? (sorry for duplicate)
Para: "Andrej Mitrovic" <andrej.mitrovich at gmail.com>
Cc: "cairo" <cairo at cairographics.org>
Fecha: sábado, 30 de julio de 2011, 15:04

On Sat, Jul 30, 2011 at 6:04 PM, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> I was temporarily unsubscribed and this could be a duplicate post, I
> apologize if that's so.
>
> If I want to draw a waveform made out of 400 points and connect the
> points together to form lines (meaning point one has a line to point
> two, point two to pint three, etc.), I have to call cairo_move_to()
> and cairo_line_to() 400 times each.
>
> Benchmarking shows this takes ~36 milliseconds when antialiasing is
> set to off, otherwise ~60 milliseconds with antialiasing on to draw on
> my machine.

In order to find out where the time is spent, you should profile your
application. The suggestions provided below assume that most of the time
is spent rasterizing the waveform.

>
> Here's an example image in Cairo: http://i.imgur.com/gaMSF.jpg
>
> Compare that to, say, using the WinAPI Polyline() function, which
> takes an array of Points (a Point is a struct with int x,y fields). It
> takes an average of 150 microseconds, or 0.15 milliseconds to connect
> the 400 points and draw them as lines on the screen.
>
> Here's the image using GDI: http://i.imgur.com/x8Ln9.jpg
>
> I believe GDI is hardware-accelerated by default so this could account
> for why it's fast, but still I have to wonder if the massive amount of
> function calls is what is slowing down Cairo. I'm dynamically linking
> to Cairo so I can't inline any function calls.

I believe that most of the difference between cairo and Polyline()
depends on the fact that Polyline() does not stroke the path
(it probably just runs Bresenham along all the segments).

>
> Isn't there a function in Cairo that can take a pointer to an array of
> some {int x, y} - like structure so we could make one function call
> and paint that with cairo_stroke/cairo_paint/etc? And if not, how
> come?

You could use
http://www.cairographics.org/manual/cairo-Paths.html#cairo-append-path
but I would be quite surprised if it actually improved the performance
significantly.

>
> I'm not too sure if it really is the amount of function calls that
> slows down the painting, or if the painting itself is slow with a
> large number of points on a path.

It's very unlikely that the slowness you're noticing depends on the
"many" calls to cairo_line_to().

You're trying to perform an operation which is known to be slow
(drawing many intersecting lines; even worse they are almost,
but not exactly, vertical).

Even if it might look weird, the same waveform rotated by 90
degrees might draw faster (depending on what the input is),
so you might want to try this.

You might also want to try stroking subpaths instead of the whole path.
This does not result in exactly the same output (especially if you're
using anti-aliasing) because pixels will be drawn multiple times
and might accumulate the color in a slightly different way, but
it might be a reasonable quality/speed compromise.

Please provide additional information (in particular cairo version
and the results of profiling) if these suggestions were not
sufficient.

Andrea
--
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110801/8e58b134/attachment.html>


More information about the cairo mailing list