[cairo] Very large number of lines
necko necko
opustenom at hotmail.com
Mon Aug 30 11:20:37 PDT 2010
Thank you for your email. The code I provided is just a sample. I need to show
connections between a number of coordinates; so, in the real scenario the output file
should display various lines.
The stroke() invoked on every 1000000th line produces the pdf file (otherwise, only one
stroke at the end will not produce the pdf file). I know this because the size of the output
file is around 100MB (otherwise, around 400kb). Clearly, I have problems displaying this
file.
As the way to get around this problem was to output PNG file, with the same strategy of
invoking stroke() on every 1000000th line. The code I sent (for PNG files) spends *very*
long time on each stroke() invoked.
Therefore, I wonder whether there is a way to get the png output with this large number of connections.
I tried to use similar strategy as with pdf files, but it is very time consuming.
Perhaps you could try to invoke the code;
#include <cairo.h>
#include <cairo-pdf.h>
#include
<sstream>
#include <cmath>
#include <vector>
#include <limits.h>
#include <queue>
#include
<algorithm>
#include <numeric>
#include
<iostream>
int main() {
cairo_surface_t *surface;
cairo_t *cr;
std::stringstream myOut; int k=1;
//myOut<<"forGallery"<<k<< ".pdf";
//surface =
cairo_pdf_surface_create(myOut.str().c_str(), 1432, 1606);
surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1432, 1606);
//surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1432, 1606);
//surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1432, 1606);
//surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1432, 1606);
cr = cairo_create(surface);
//cairo_set_source_rgb(cr, 1, 1,
1);
//cairo_paint(cr);
//cairo_set_source_rgb(cr, 0, 0, 0);
cairo_translate (cr, -229770, 26573.7); // -40, 50: for margin
-37, 53
unsigned int t=0; unsigned int ITER_NO=20000000;
while(t<ITER_NO) {
cairo_move_to (cr, 229770, -26573.7);
cairo_line_to (cr, 231202, -24967.3);
if(t%1000000==0 ||
t==ITER_NO-1) {
cairo_stroke(cr);
}
std::cout<<"Drawn so
far:"<<((double)t/(double)ITER_NO)*100<<"%"<<std::endl;
++t;
}
//cairo_show_page(cr); // for PDF
cairo_surface_write_to_png(surface, "image.png"); // for PNG
cairo_surface_destroy(surface);
cairo_destroy(cr);
return
0;
}
Thanks
> Date: Mon, 30 Aug 2010 18:35:44 +0200
> Subject: Re: [cairo] Very large number of lines
> From: ranma42 at gmail.com
> To: opustenom at hotmail.com
> CC: a.g.nienhuis at gmail.com; cairo at cairographics.org
>
> On Mon, Aug 30, 2010 at 2:08 PM, necko necko <opustenom at hotmail.com> wrote:
> > Thank you for your email. I applied your approach of stoke() every Nth line
> > (but I take N=1000000 instead of 1000;
> > if you think it would be better to use smaller stride (N=1000), please let
> > me know).
> > This approach outputs the pdf file of size 1.5 MB, but the machine is still
> > trying to display it. I hope it will display
> > that single line. Did Evince display the pdf file properly at your machine?
> Please notice that you are testing a *very* degenerate case (all your
> segments overlap
> exactly) that triggers a slow path in cairo rasterizer. Please use
> real segment data.
> You might probably also want to check if all those strokes are actually needed.
> What are you trying to render?
> Andrea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100830/46dfb1a2/attachment.htm>
More information about the cairo
mailing list