Commit 4ba2e8f5 authored by Bruno Coudoin's avatar Bruno Coudoin

Performance improvement, now first detect a full size image in case

and avoid analyzing each pixel

svn path=/branches/gcomprixogoo/; revision=3733
parent 00d595ce
...@@ -87,6 +87,29 @@ _autocrop(cairo_surface_t *src_surface, ...@@ -87,6 +87,29 @@ _autocrop(cairo_surface_t *src_surface,
return dst_surface; return dst_surface;
} }
static inline void
_search_limits(GooCanvasSvg *canvas_svg,
unsigned char *data,
int stride, int step)
{
int x;
for (x=0; x<stride/4; x+=step)
{
int y;
for (y=0; y<canvas_svg->height; y+=step)
{
guint32 point = *(guint32*)&data[y*stride + x*4];
if (point != 0)
{
((x > canvas_svg->x2) ? canvas_svg->x2 = x : x);
((x < canvas_svg->x1) ? canvas_svg->x1 = x : x);
((y > canvas_svg->y2) ? canvas_svg->y2 = y : y);
((y < canvas_svg->y1) ? canvas_svg->y1 = y : y);
}
}
}
}
static void _init_surface(GooCanvasSvg *canvas_svg, static void _init_surface(GooCanvasSvg *canvas_svg,
RsvgHandle *svg_handle) RsvgHandle *svg_handle)
{ {
...@@ -120,23 +143,18 @@ static void _init_surface(GooCanvasSvg *canvas_svg, ...@@ -120,23 +143,18 @@ static void _init_surface(GooCanvasSvg *canvas_svg,
canvas_svg->y1 = canvas_svg->height; canvas_svg->y1 = canvas_svg->height;
canvas_svg->y2 = 0; canvas_svg->y2 = 0;
unsigned char* data = cairo_image_surface_get_data(cst); unsigned char* data = cairo_image_surface_get_data(cst);
int x;
int stride = cairo_image_surface_get_stride(cst); int stride = cairo_image_surface_get_stride(cst);
for (x=0; x<stride/4; x++)
{ /* Search first the top left / right limits first */
int y; _search_limits(canvas_svg, data, stride, stride/4);
for (y=0; y<canvas_svg->height; y++) if ( canvas_svg->x1 != 0 ||
{ canvas_svg->x2 != canvas_svg->width ||
guint32 point = *(guint32*)&data[y*stride + x*4]; canvas_svg->y1 != 0 ||
if (point != 0) canvas_svg->y2 != canvas_svg->height )
{ /* Search the whole image */
((x > canvas_svg->x2) ? canvas_svg->x2 = x : x); _search_limits(canvas_svg, data, stride, 2);
((x < canvas_svg->x1) ? canvas_svg->x1 = x : x);
((y > canvas_svg->y2) ? canvas_svg->y2 = y : y);
((y < canvas_svg->y1) ? canvas_svg->y1 = y : y);
}
}
}
if(stride > 0 && canvas_svg->autocrop) if(stride > 0 && canvas_svg->autocrop)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment