<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><p>sorry for my intromision.</p><p>I'm not completely sure what are your intentions, but , afaik drawing a soundwave in cairo isnt particulary slow<br></p><p>i made this with cairo and i was able to watch it realtime in a modest notebook</p><p>http://www.youtube.com/watch?v=oii-MqbjJWA</p><p><br></p><p>btw, i used line_to not move_to</p><br>Jerónimo Barraco Mármol<br>
<br>
http://nande.com.ar<br>
http://ar.linkedin.com/in/nande<br><br>--- El <b>sáb 30-jul-11, Andrea Canciani <i><ranma42@gmail.com></i></b> escribió:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>De: Andrea Canciani <ranma42@gmail.com><br>Asunto: Re: [cairo] Isn't there a way to pass multiple points to Cairo? (sorry for duplicate)<br>Para: "Andrej Mitrovic" <andrej.mitrovich@gmail.com><br>Cc: "cairo" <cairo@cairographics.org><br>Fecha: sábado, 30 de julio de 2011, 15:04<br><br><div class="plainMail">On Sat, Jul 30, 2011 at 6:04 PM, Andrej Mitrovic<br><<a ymailto="mailto:andrej.mitrovich@gmail.com" href="/mc/compose?to=andrej.mitrovich@gmail.com">andrej.mitrovich@gmail.com</a>> wrote:<br>> I was temporarily unsubscribed and this could be a duplicate post, I<br>> apologize if that's so.<br>><br>> If I want to draw a waveform made out of 400 points and connect the<br>> points
together to form lines (meaning point one has a line to point<br>> two, point two to pint three, etc.), I have to call cairo_move_to()<br>> and cairo_line_to() 400 times each.<br>><br>> Benchmarking shows this takes ~36 milliseconds when antialiasing is<br>> set to off, otherwise ~60 milliseconds with antialiasing on to draw on<br>> my machine.<br><br>In order to find out where the time is spent, you should profile your<br>application. The suggestions provided below assume that most of the time<br>is spent rasterizing the waveform.<br><br>><br>> Here's an example image in Cairo: <a href="http://i.imgur.com/gaMSF.jpg" target="_blank">http://i.imgur.com/gaMSF.jpg</a><br>><br>> Compare that to, say, using the WinAPI Polyline() function, which<br>> takes an array of Points (a Point is a struct with int x,y fields). It<br>> takes an average of 150 microseconds, or 0.15 milliseconds to connect<br>> the 400 points and
draw them as lines on the screen.<br>><br>> Here's the image using GDI: <a href="http://i.imgur.com/x8Ln9.jpg" target="_blank">http://i.imgur.com/x8Ln9.jpg</a><br>><br>> I believe GDI is hardware-accelerated by default so this could account<br>> for why it's fast, but still I have to wonder if the massive amount of<br>> function calls is what is slowing down Cairo. I'm dynamically linking<br>> to Cairo so I can't inline any function calls.<br><br>I believe that most of the difference between cairo and Polyline()<br>depends on the fact that Polyline() does not stroke the path<br>(it probably just runs Bresenham along all the segments).<br><br>><br>> Isn't there a function in Cairo that can take a pointer to an array of<br>> some {int x, y} - like structure so we could make one function call<br>> and paint that with cairo_stroke/cairo_paint/etc? And if not, how<br>> come?<br><br>You could use<br><a
href="http://www.cairographics.org/manual/cairo-Paths.html#cairo-append-path" target="_blank">http://www.cairographics.org/manual/cairo-Paths.html#cairo-append-path</a><br>but I would be quite surprised if it actually improved the performance<br>significantly.<br><br>><br>> I'm not too sure if it really is the amount of function calls that<br>> slows down the painting, or if the painting itself is slow with a<br>> large number of points on a path.<br><br>It's very unlikely that the slowness you're noticing depends on the<br>"many" calls to cairo_line_to().<br><br>You're trying to perform an operation which is known to be slow<br>(drawing many intersecting lines; even worse they are almost,<br>but not exactly, vertical).<br><br>Even if it might look weird, the same waveform rotated by 90<br>degrees might draw faster (depending on what the input is),<br>so you might want to try this.<br><br>You might also want to try stroking subpaths instead
of the whole path.<br>This does not result in exactly the same output (especially if you're<br>using anti-aliasing) because pixels will be drawn multiple times<br>and might accumulate the color in a slightly different way, but<br>it might be a reasonable quality/speed compromise.<br><br>Please provide additional information (in particular cairo version<br>and the results of profiling) if these suggestions were not<br>sufficient.<br><br>Andrea<br>--<br>cairo mailing list<br><a ymailto="mailto:cairo@cairographics.org" href="/mc/compose?to=cairo@cairographics.org">cairo@cairographics.org</a><br><a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br></div></blockquote></td></tr></table>