diff options
author | Caleb Michael Moore <cmoore@src.gnome.org> | 2005-02-11 15:48:58 +0000 |
---|---|---|
committer | Caleb Michael Moore <cmoore@src.gnome.org> | 2005-02-11 15:48:58 +0000 |
commit | 37a84c4f7dadfa3127deaeaed46852b321018320 (patch) | |
tree | 0b6c04dd0c03084ccc89b8d84d96e4403d9a608e /rsvg-styles.c | |
parent | 7072c08c2c0e054fef272927fcb0b62ce6c7108d (diff) | |
download | librsvg-37a84c4f7dadfa3127deaeaed46852b321018320.tar.gz |
took the really pixel dependant stuff out of rsvg-styles.c and put it in a file of it's own
Diffstat (limited to 'rsvg-styles.c')
-rw-r--r-- | rsvg-styles.c | 308 |
1 files changed, 0 insertions, 308 deletions
diff --git a/rsvg-styles.c b/rsvg-styles.c index ce99f2b4..928f19c3 100644 --- a/rsvg-styles.c +++ b/rsvg-styles.c @@ -34,7 +34,6 @@ #include "rsvg-mask.h" #include "rsvg-marker.h" -#include <libart_lgpl/art_rgba.h> #include <libart_lgpl/art_affine.h> #include <libart_lgpl/art_svp_ops.h> @@ -1352,313 +1351,6 @@ rsvg_parse_style_attrs (RsvgHandle * ctx, } } -static void -rsvg_pixmap_destroy (gchar *pixels, gpointer data) -{ - g_free (pixels); -} - -/** - * rsvg_push_opacity_group: Begin a new transparency group. - * @ctx: Context in which to push. - * - * Pushes a new transparency group onto the stack. The top of the stack - * is stored in the context, while the "saved" value is in the state - * stack. - **/ -void -rsvg_push_discrete_layer (RsvgDrawingCtx *ctx) -{ - RsvgState *state; - GdkPixbuf *pixbuf; - art_u8 *pixels; - int width, height, rowstride; - - state = rsvg_state_current(ctx); - pixbuf = ctx->pixbuf; - - rsvg_state_clip_path_assure(ctx); - - if (state->filter == NULL && state->opacity == 0xFF && - !state->backgroundnew && state->mask == NULL && !state->adobe_blend) - 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? */ - return; - } - - if (!gdk_pixbuf_get_has_alpha (pixbuf)) - { - g_warning (_("push/pop transparency group on non-alpha buffer nyi\n")); - return; - } - - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (pixbuf); - pixels = g_new (art_u8, rowstride * height); - memset (pixels, 0, rowstride * height); - - pixbuf = gdk_pixbuf_new_from_data (pixels, - GDK_COLORSPACE_RGB, - TRUE, - gdk_pixbuf_get_bits_per_sample (pixbuf), - width, - height, - rowstride, - (GdkPixbufDestroyNotify)rsvg_pixmap_destroy, - NULL); - ctx->pixbuf = pixbuf; -} - -static void -rsvg_use_opacity (RsvgDrawingCtx *ctx, int opacity, - GdkPixbuf *tos, GdkPixbuf *nos) -{ - art_u8 *tos_pixels, *nos_pixels; - int width; - int height; - int rowstride; - int x, y; - int tmp; - - - if (tos == NULL || nos == NULL) - { - /* FIXME: What warning/GError here? */ - return; - } - - if (!gdk_pixbuf_get_has_alpha (nos)) - { - g_warning (_("push/pop transparency group on non-alpha buffer nyi\n")); - return; - } - - width = gdk_pixbuf_get_width (tos); - height = gdk_pixbuf_get_height (tos); - rowstride = gdk_pixbuf_get_rowstride (tos); - - 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 = MAX(ctx->bbox.y0, 0); y < MIN(ctx->bbox.y1 + 1, height); y++) - { - 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]; - if (a) - { - r = tos_pixels[4 * x]; - g = tos_pixels[4 * x + 1]; - b = tos_pixels[4 * x + 2]; - tmp = a * opacity + 0x80; - a = (tmp + (tmp >> 8)) >> 8; - art_rgba_run_alpha (nos_pixels + 4 * x, r, g, b, a, 1); - } - } - tos_pixels += rowstride; - nos_pixels += rowstride; - } -} - -static GdkPixbuf * -get_next_out(gint * operationsleft, GdkPixbuf * in, GdkPixbuf * tos, - GdkPixbuf * nos, GdkPixbuf *intermediate) -{ - GdkPixbuf * out; - - if (*operationsleft == 1) - out = nos; - else - { - if (in == tos) - out = intermediate; - else - out = tos; - gdk_pixbuf_fill(out, 0x00000000); - } - (*operationsleft)--; - - return out; -} - -static GdkPixbuf * -rsvg_compile_bg(RsvgDrawingCtx *ctx, RsvgState *topstate) -{ - int i, foundstate; - GdkPixbuf *intermediate, *lastintermediate; - RsvgState *state, *lastvalid; - ArtIRect save; - - lastvalid = NULL; - - foundstate = 0; - - lastintermediate = gdk_pixbuf_copy(topstate->save_pixbuf); - - save = ctx->bbox; - - ctx->bbox.x0 = 0; - ctx->bbox.y0 = 0; - ctx->bbox.x1 = gdk_pixbuf_get_width(ctx->pixbuf); - ctx->bbox.y1 = gdk_pixbuf_get_height(ctx->pixbuf); - - for (i = 0; (state = g_slist_nth_data(ctx->state, i)) != NULL; i++) - { - if (state == topstate) - { - foundstate = 1; - } - else if (!foundstate) - continue; - if (state->backgroundnew) - break; - if (state->save_pixbuf) - { - if (lastvalid) - { - intermediate = gdk_pixbuf_copy(state->save_pixbuf); - rsvg_use_opacity(ctx, 0xFF, lastintermediate, intermediate); - g_object_unref(lastintermediate); - lastintermediate = intermediate; - } - lastvalid = state; - } - } - - ctx->bbox = save; - return lastintermediate; -} - -static void -rsvg_composite_layer(RsvgDrawingCtx *ctx, RsvgState *state, GdkPixbuf *tos, GdkPixbuf *nos) -{ - RsvgFilter *filter = state->filter; - int opacity = state->opacity; - RsvgDefsDrawable * mask = state->mask; - GdkPixbuf *intermediate; - GdkPixbuf *in, *out, *insidebg; - int operationsleft; - gint adobe_blend = state->adobe_blend; - - intermediate = NULL; - - operationsleft = 0; - - if (opacity != 0xFF) - operationsleft++; - if (filter != NULL) - operationsleft++; - if (mask != NULL) - operationsleft++; - if (adobe_blend) - operationsleft++; - - if (operationsleft > 1) - intermediate = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 1, 8, - gdk_pixbuf_get_width (tos), - gdk_pixbuf_get_height (tos)); - - in = tos; - - if (operationsleft == 0) - { - rsvg_use_opacity (ctx, 0xFF, tos, nos); - } - - if (filter != NULL || adobe_blend) - { - insidebg = rsvg_compile_bg(ctx, state); - } - else - insidebg = NULL; - - if (filter != NULL) - { - out = get_next_out(&operationsleft, in, tos, nos, intermediate); - rsvg_filter_render (filter, in, out, insidebg, ctx); - in = out; - } - if (opacity != 0xFF) - { - out = get_next_out(&operationsleft, in, tos, nos, intermediate); - rsvg_use_opacity (ctx, opacity, in, out); - in = out; - } - if (mask != NULL) - { - out = get_next_out(&operationsleft, in, tos, nos, intermediate); - rsvg_mask_render ((RsvgMask *)mask, in, out, ctx); - in = out; - } - if (adobe_blend) - { - out = get_next_out(&operationsleft, in, tos, nos, intermediate); - rsvg_filter_adobe_blend (adobe_blend, in, insidebg, out, ctx); - in = out; - } - - if (filter != NULL || adobe_blend) - { - g_object_unref (insidebg); - } - - if (intermediate != NULL) - g_object_unref (intermediate); - -} - -/** - * rsvg_pop_discrete_layer: End a transparency group. - * @ctx: Context in which to push. - * - * Pops a new transparency group from the stack, recompositing with the - * next on stack using a filter, transperency value, or a mask to do so - **/ - -void -rsvg_pop_discrete_layer(RsvgDrawingCtx *ctx) -{ - GdkPixbuf *tos, *nos; - RsvgState *state; - - state = rsvg_state_current(ctx); - - if (state->filter == NULL && state->opacity == 0xFF && - !state->backgroundnew && state->mask == NULL && !state->adobe_blend) - return; - - tos = ctx->pixbuf; - nos = state->save_pixbuf; - - if (nos != NULL) - rsvg_composite_layer(ctx, state, tos, nos); - - g_object_unref (tos); - ctx->pixbuf = nos; - art_irect_union(&ctx->bbox, &ctx->bbox, &state->underbbox); -} - -gboolean -rsvg_needs_discrete_layer(RsvgState *state) -{ - return state->filter || state->mask || state->adobe_blend || state->backgroundnew; -} - RsvgState * rsvg_state_current (RsvgDrawingCtx *ctx) { |