From: jucablues Date: Wed, 16 Jan 2008 10:35:46 +0000 (+0000) Subject: implementation of Flood Filter Effect renderer X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d1810810be20a1ab8d7da67ba5472ab020f44320;p=inkscape.git implementation of Flood Filter Effect renderer --- diff --git a/src/display/nr-filter-flood.cpp b/src/display/nr-filter-flood.cpp index 7eade2789..951e5e460 100644 --- a/src/display/nr-filter-flood.cpp +++ b/src/display/nr-filter-flood.cpp @@ -10,14 +10,12 @@ */ #include "display/nr-filter-flood.h" -#include "display/nr-filter-units.h" +#include "display/nr-filter-utils.h" namespace NR { FilterFlood::FilterFlood() -{ - g_warning("FilterFlood::render not implemented."); -} +{} FilterPrimitive * FilterFlood::create() { return new FilterFlood(); @@ -33,24 +31,44 @@ int FilterFlood::render(FilterSlot &slot, FilterUnits const &/*units*/) { return 1; } + int i; + int in_w = in->area.x1 - in->area.x0; + int in_h = in->area.y1 - in->area.y0; + NRPixBlock *out = new NRPixBlock; nr_pixblock_setup_fast(out, in->mode, in->area.x0, in->area.y0, in->area.x1, in->area.y1, true); - unsigned char *in_data = NR_PIXBLOCK_PX(in); unsigned char *out_data = NR_PIXBLOCK_PX(out); -//IMPLEMENT ME! - (void)in_data; - (void)out_data; + unsigned char r,g,b,a; + r = (unsigned char) (color >> 24) % 256; + g = (unsigned char) (color >> 16) % 256; + b = (unsigned char) (color >> 8) % 256; + a = CLAMP_D_TO_U8(opacity*256); + + for(i=0; i < 4*in_h*in_w; i+=4){ + out_data[i]=r; + out_data[i+1]=g; + out_data[i+2]=b; + out_data[i+3]=a; + } out->empty = FALSE; slot.set(_output, out); return 0; } +void FilterFlood::set_color(guint32 c) { + color = c; +} + +void FilterFlood::set_opacity(double o) { + opacity = o; +} + void FilterFlood::area_enlarge(NRRectL &/*area*/, Matrix const &/*trans*/) { } diff --git a/src/display/nr-filter-flood.h b/src/display/nr-filter-flood.h index 34cde5a78..6f7779a73 100644 --- a/src/display/nr-filter-flood.h +++ b/src/display/nr-filter-flood.h @@ -23,9 +23,14 @@ public: FilterFlood(); static FilterPrimitive *create(); virtual ~FilterFlood(); - + + virtual void set_opacity(double o); + virtual void set_color(guint32 c); virtual int render(FilterSlot &slot, FilterUnits const &units); virtual void area_enlarge(NRRectL &area, Matrix const &trans); +private: + double opacity; + guint32 color; }; } /* namespace NR */ diff --git a/src/sp-feflood.cpp b/src/sp-feflood.cpp index b3b9ac1d5..685859c63 100644 --- a/src/sp-feflood.cpp +++ b/src/sp-feflood.cpp @@ -21,7 +21,8 @@ #include "svg/svg.h" #include "sp-feflood.h" #include "xml/repr.h" - +#include "helper-fns.h" +#include "svg/svg-color.h" /* FeFlood base class */ @@ -92,6 +93,8 @@ sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re } /*LOAD ATTRIBUTES FROM REPR HERE*/ + sp_object_read_attr(object, "flood-opacity"); + sp_object_read_attr(object, "flood-color"); } /** @@ -112,9 +115,27 @@ sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value) { SPFeFlood *feFlood = SP_FEFLOOD(object); (void)feFlood; - + gchar const *cend_ptr = NULL; + guint32 read_color; + double read_num; + switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ + case SP_PROP_FLOOD_COLOR: + cend_ptr = NULL; + read_color = sp_svg_read_color(value, &cend_ptr, 0xffffffff); + if (cend_ptr && read_color != feFlood->color){ + feFlood->color = read_color; + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + } + break; + case SP_PROP_FLOOD_OPACITY: + read_num = helperfns_read_number(value); + if (read_num != feFlood->opacity){ + feFlood->opacity = read_num; + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + } + break; default: if (((SPObjectClass *) feFlood_parent_class)->set) ((SPObjectClass *) feFlood_parent_class)->set(object, key, value); @@ -177,6 +198,9 @@ static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, NR::Filter * g_assert(nr_flood != NULL); sp_filter_primitive_renderer_common(primitive, nr_primitive); + + nr_flood->set_opacity(sp_flood->opacity); + nr_flood->set_color(sp_flood->color); } diff --git a/src/sp-feflood.h b/src/sp-feflood.h index c0df0d312..4d1702258 100644 --- a/src/sp-feflood.h +++ b/src/sp-feflood.h @@ -24,7 +24,8 @@ class SPFeFloodClass; struct SPFeFlood : public SPFilterPrimitive { /** FLOOD ATTRIBUTES HERE */ - + guint32 color; + double opacity; }; struct SPFeFloodClass {