Commit 4187301e authored by Caleb Michael Moore's avatar Caleb Michael Moore

little optimisation thingie

parent a6d164bd
2004-07-17 Caleb Moore <c.moore@student.unsw.edu.au>
* rsvg-shapes.c, rsvg-styles.c, rsvg-private.h: Made it remember how bit the vboxes of discrete layers are for alpha optimisations and better filter positioning
2004-07-12 Dom Lachowicz <cinamod@hotmail.com>
* rsvg.1: Update documentation
......
......@@ -19,7 +19,7 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Caleb Moore <calebmm@tpg.com.au>
Author: Caleb Moore <c.moore@student.unsw.edu.au>
*/
#include "rsvg-private.h"
......@@ -325,54 +325,20 @@ alpha_blt (GdkPixbuf * src, gint srcx, gint srcy, gint srcwidth,
static void
rsvg_filter_fix_coordinate_system (RsvgFilterContext * ctx, RsvgState * state)
{
int i, j;
int x, y, height, width, x2, y2;
int x, y, height, width;
int i;
guchar *pixels;
int stride;
int currentindex;
i = j = 0;
/* First for object bounding box coordinates we need to know how much of the
source has been drawn on */
pixels = gdk_pixbuf_get_pixels (ctx->source);
stride = gdk_pixbuf_get_rowstride (ctx->source);
x = gdk_pixbuf_get_width (ctx->source);
y = gdk_pixbuf_get_height (ctx->source);
x2 = 0; y2 = 0;
if (ctx->filter->filterunits == objectBoundingBox ||
ctx->filter->primitiveunits != objectBoundingBox)
{
/* move in from the top to find the y value */
for (i = 0; i < gdk_pixbuf_get_height (ctx->source); i++)
{
for (j = 0; j < gdk_pixbuf_get_width (ctx->source); j++)
{
currentindex = i * stride + j * 4;
if (pixels[currentindex + 0] != 0 || pixels[currentindex + 1] != 0
|| pixels[currentindex + 2] != 0
|| pixels[currentindex + 3] != 0)
{
if (j < x)
x = j;
if (i < y)
y = i;
if (j > x2)
x2 = j;
if (i > y2)
y2 = i;
}
}
}
}
width = x2 - x;
height = y2 - y;
x = ctx->ctx->bbox.x0;
y = ctx->ctx->bbox.y0;
width = ctx->ctx->bbox.x1 - ctx->ctx->bbox.x0;
height = ctx->ctx->bbox.y1 - ctx->ctx->bbox.y0;
ctx->width = gdk_pixbuf_get_width (ctx->source);
ctx->height = gdk_pixbuf_get_height (ctx->source);
......@@ -468,6 +434,10 @@ rsvg_filter_render (RsvgFilter * self, GdkPixbuf * source, GdkPixbuf * output,
alpha_blt (ctx->lastresult.result, bounds.x1, bounds.y1, bounds.x2 - bounds.x1,
bounds.y2 - bounds.y1, output, bounds.x1, bounds.y1);
context->bbox.x0 = bounds.x1;
context->bbox.y0 = bounds.y1;
context->bbox.x1 = bounds.x2;
context->bbox.y1 = bounds.y2;
g_object_unref (G_OBJECT (ctx->lastresult.result));
g_free(ctx);
}
......@@ -936,15 +906,15 @@ rsvg_filter_primitive_blend_render (RsvgFilterPrimitive * self,
g_object_unref (G_OBJECT (output));
}
void rsvg_filter_adobe_blend(gint modenum, GdkPixbuf *in, GdkPixbuf *bg, GdkPixbuf *output)
void rsvg_filter_adobe_blend(gint modenum, GdkPixbuf *in, GdkPixbuf *bg, GdkPixbuf *output, RsvgHandle * ctx)
{
FPBox boundarys;
RsvgFilterPrimitiveBlendMode mode;
boundarys.x1 = 0;
boundarys.y1 = 0;
boundarys.x2 = gdk_pixbuf_get_width (in);
boundarys.y2 = gdk_pixbuf_get_height (in);
boundarys.x1 = ctx->bbox.x0;
boundarys.y1 = ctx->bbox.y0;
boundarys.x2 = ctx->bbox.x1;
boundarys.y2 = ctx->bbox.y1;
mode = normal;
......
......@@ -117,7 +117,8 @@ void
rsvg_start_filter_primitive_tile (RsvgHandle * ctx, RsvgPropertyBag * atts);
void
rsvg_filter_adobe_blend(gint modenum, GdkPixbuf *in, GdkPixbuf *bg, GdkPixbuf *output);
rsvg_filter_adobe_blend(gint modenum, GdkPixbuf *in, GdkPixbuf *bg, GdkPixbuf *output,
RsvgHandle * ctx);
G_END_DECLS
......
......@@ -31,6 +31,7 @@
#include <libxml/SAX.h>
#include <libxml/xmlmemory.h>
#include <pango/pango.h>
#include <libart_lgpl/art_rect.h>
G_BEGIN_DECLS
......@@ -58,7 +59,8 @@ struct RsvgHandle {
gpointer user_data;
GDestroyNotify user_data_destroy;
GdkPixbuf *pixbuf;
ArtIRect bbox;
/* stack; there is a state for each element */
RsvgState *state;
int n_state;
......
......@@ -192,6 +192,8 @@ rsvg_render_svp (RsvgHandle *ctx, const ArtSVP *svp,
temprect = rsvg_calculate_svp_bounds(svp);
art_irect_union(&ctx->bbox, &ctx->bbox, &temprect);
gradctx.x0 = temprect.x0;
gradctx.y0 = temprect.y0;
gradctx.x1 = temprect.x1;
......@@ -1665,7 +1667,7 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
const char * klazz = NULL, * id = NULL, *value;
gboolean has_alpha;
int aspect_ratio = RSVG_ASPECT_RATIO_NONE;
ArtIRect temprect;
GdkPixbuf *img;
GError *err = NULL;
......@@ -1783,6 +1785,13 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
rsvg_pop_discrete_layer(ctx);
temprect.x0 = state->affine[4] + x;
temprect.y0 = state->affine[5] + y;
temprect.x1 = state->affine[4] + x + gdk_pixbuf_get_width (img);
temprect.y1 = state->affine[5] + y + gdk_pixbuf_get_height (img);
art_irect_union(&ctx->bbox, &ctx->bbox, &temprect);
g_object_unref (G_OBJECT (img));
g_free (rgb);
}
......
......@@ -106,6 +106,7 @@ rsvg_pixbuf_new_from_href (const char *href,
void rsvg_defs_drawable_draw (RsvgDefsDrawable * self, RsvgHandle *ctx,
int dominate);
G_END_DECLS
#endif /* RSVG_SHAPES_H */
......@@ -1374,7 +1374,12 @@ rsvg_push_discrete_layer (RsvgHandle *ctx)
return;
state->save_pixbuf = pixbuf;
state->underbbox = ctx->bbox;
ctx->bbox.x0 = 0;
ctx->bbox.x1 = 0;
ctx->bbox.y0 = 0;
ctx->bbox.y1 = 0;
if (pixbuf == NULL)
{
/* FIXME: What warning/GError here? */
......@@ -1435,10 +1440,13 @@ rsvg_use_opacity (RsvgHandle *ctx, int opacity,
tos_pixels = gdk_pixbuf_get_pixels (tos);
nos_pixels = gdk_pixbuf_get_pixels (nos);
tos_pixels += rowstride * MAX(ctx->bbox.y0, 0);
nos_pixels += rowstride * MAX(ctx->bbox.y0, 0);
for (y = 0; y < height; y++)
for (y = MAX(ctx->bbox.y0, 0); y < MIN(ctx->bbox.y1 + 1, height); y++)
{
for (x = 0; x < width; x++)
for (x = MAX(ctx->bbox.x0, 0); x < MIN(ctx->bbox.x1 + 1, width); x++)
{
art_u8 r, g, b, a;
a = tos_pixels[4 * x + 3];
......@@ -1583,7 +1591,7 @@ rsvg_composite_layer(RsvgHandle *ctx, RsvgState *state, GdkPixbuf *tos, GdkPixbu
if (adobe_blend)
{
out = get_next_out(&operationsleft, in, tos, nos, intermediate);
rsvg_filter_adobe_blend (adobe_blend, in, insidebg, out);
rsvg_filter_adobe_blend (adobe_blend, in, insidebg, out, ctx);
in = out;
}
......@@ -1625,6 +1633,7 @@ rsvg_pop_discrete_layer(RsvgHandle *ctx)
g_object_unref (tos);
ctx->pixbuf = nos;
art_irect_union(&ctx->bbox, &ctx->bbox, &state->underbbox);
}
gboolean
......
......@@ -144,6 +144,7 @@ struct _RsvgState {
gboolean has_endMarker;
GdkPixbuf *save_pixbuf;
ArtIRect underbbox;
};
void rsvg_state_init (RsvgState *state);
......
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