From 9a3bd4fde0634126efeedaa71a0b66acf6ef07a2 Mon Sep 17 00:00:00 2001 From: jucablues Date: Tue, 14 Aug 2007 06:15:05 +0000 Subject: [PATCH] added some more boilerplate code on feTurbulence. --- src/display/nr-filter-turbulence.cpp | 58 ++++++++++++++++++++++------ src/display/nr-filter-turbulence.h | 8 +++- src/sp-feturbulence.cpp | 7 ++++ src/sp-feturbulence.h | 4 +- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/display/nr-filter-turbulence.cpp b/src/display/nr-filter-turbulence.cpp index 7a5fc1dcd..f94081612 100644 --- a/src/display/nr-filter-turbulence.cpp +++ b/src/display/nr-filter-turbulence.cpp @@ -8,7 +8,9 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - + +#include "display/nr-arena-item.h" +#include "display/nr-filter.h" #include "display/nr-filter-turbulence.h" namespace NR { @@ -17,9 +19,10 @@ FilterTurbulence::FilterTurbulence() : XbaseFrequency(0), YbaseFrequency(0), numOctaves(1), - seed(0) + seed(0), + updated(false), + pix(NULL) { - g_warning("FilterTurbulence::render not implemented."); } FilterPrimitive * FilterTurbulence::create() { @@ -50,12 +53,27 @@ void FilterTurbulence::set_type(FilterTurbulenceType t){ type=t; } +void FilterTurbulence::set_updated(bool u){ + updated=u; +} -int FilterTurbulence::render(FilterSlot &slot, Matrix const &trans) { -/* TODO: Implement this renderer method. - Specification: http://www.w3.org/TR/SVG11/filters.html#feTurbulence +void FilterTurbulence::update_pixbuffer(FilterSlot &slot) { + int bbox_x0 = (int) slot.get_arenaitem()->bbox.x0; + int bbox_y0 = (int) slot.get_arenaitem()->bbox.y0; + int bbox_x1 = (int) slot.get_arenaitem()->bbox.x1; + int bbox_y1 = (int) slot.get_arenaitem()->bbox.y1; -*/ + int w = bbox_x1 - bbox_x0; + int h = bbox_y1 - bbox_y0; + int x,y; + + if (!pix){ + pix = new NRPixBlock; + nr_pixblock_setup_fast(pix, NR_PIXBLOCK_MODE_R8G8B8A8P, bbox_x0, bbox_y0, bbox_x1, bbox_y1, true); + pix_data = NR_PIXBLOCK_PX(pix); + } + +// TODO: implement here the turbulence rendering. /*debug: these are the available parameters printf("XbaseFrequency = %f; ", XbaseFrequency); @@ -66,7 +84,20 @@ int FilterTurbulence::render(FilterSlot &slot, Matrix const &trans) { printf("type = %s;\n\n", type==0 ? "FractalNoise" : "turbulence"); */ -//sample code: the following fills the whole area in semi-transparent red. + for (x=0; x < w; x++){ + for (y=0; y < h; y++){ + pix_data[4*(x + w*y)] = (unsigned char)(int(XbaseFrequency)%256); + pix_data[4*(x + w*y) + 1] = (unsigned char)(int(YbaseFrequency)%256); + pix_data[4*(x + w*y) + 2] = (unsigned char)(int(numOctaves)%256); + pix_data[4*(x + w*y) + 3] = (unsigned char)(int(seed)%256); + } + } + updated=true; +} + +int FilterTurbulence::render(FilterSlot &slot, Matrix const &trans) { + if (!updated) update_pixbuffer(slot); + NRPixBlock *in = slot.get(_input); NRPixBlock *out = new NRPixBlock; int x,y; @@ -75,13 +106,16 @@ int FilterTurbulence::render(FilterSlot &slot, Matrix const &trans) { int w = x1 - x0; nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true); + int bbox_x0 = (int) slot.get_arenaitem()->bbox.x0; + int bbox_y0 = (int) slot.get_arenaitem()->bbox.y0; + unsigned char *out_data = NR_PIXBLOCK_PX(out); for (x=x0; x < x1; x++){ for (y=y0; y < y1; y++){ - out_data[4*((x - x0)+w*(y - y0)) + 0] = 255; - out_data[4*((x - x0)+w*(y - y0)) + 1] = 0; - out_data[4*((x - x0)+w*(y - y0)) + 2] = 0; - out_data[4*((x - x0)+w*(y - y0)) + 3] = 128; + out_data[4*((x - x0)+w*(y - y0))] = pix_data[x - bbox_x0 + w*(y - bbox_y0)]; + out_data[4*((x - x0)+w*(y - y0)) + 1] = pix_data[x - bbox_x0 + w*(y - bbox_y0)]; + out_data[4*((x - x0)+w*(y - y0)) + 2] = pix_data[x - bbox_x0 + w*(y - bbox_y0)]; + out_data[4*((x - x0)+w*(y - y0)) + 3] = pix_data[x - bbox_x0 + w*(y - bbox_y0)]; } } diff --git a/src/display/nr-filter-turbulence.h b/src/display/nr-filter-turbulence.h index 8f7849f88..1e2171e83 100644 --- a/src/display/nr-filter-turbulence.h +++ b/src/display/nr-filter-turbulence.h @@ -31,17 +31,23 @@ public: virtual ~FilterTurbulence(); virtual int render(FilterSlot &slot, Matrix const &trans); + virtual void update_pixbuffer(FilterSlot &slot); + virtual void set_baseFrequency(int axis, double freq); virtual void set_numOctaves(int num); virtual void set_seed(double s); virtual void set_stitchTiles(bool st); virtual void set_type(FilterTurbulenceType t); + virtual void set_updated(bool u); private: double XbaseFrequency, YbaseFrequency; int numOctaves; double seed; bool stitchTiles; - FilterTurbulenceType type; + FilterTurbulenceType type; + bool updated; + NRPixBlock *pix; + unsigned char *pix_data; }; } /* namespace NR */ diff --git a/src/sp-feturbulence.cpp b/src/sp-feturbulence.cpp index dfff840e0..7c5091c54 100644 --- a/src/sp-feturbulence.cpp +++ b/src/sp-feturbulence.cpp @@ -84,6 +84,7 @@ sp_feTurbulence_class_init(SPFeTurbulenceClass *klass) static void sp_feTurbulence_init(SPFeTurbulence *feTurbulence) { + feTurbulence->updated=false; } /** @@ -164,12 +165,14 @@ sp_feTurbulence_set(SPObject *object, unsigned int key, gchar const *value) //From SVG spec: If two s are provided, the first number represents a base frequency in the X direction and the second value represents a base frequency in the Y direction. If one number is provided, then that value is used for both X and Y. if (feTurbulence->baseFrequency.optNumIsSet() == false) feTurbulence->baseFrequency.setOptNumber(feTurbulence->baseFrequency.getNumber()); + feTurbulence->updated = false; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_NUMOCTAVES: read_int = (int) helperfns_read_number(value); if (read_int != feTurbulence->numOctaves){ feTurbulence->numOctaves = read_int; + feTurbulence->updated = false; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -177,6 +180,7 @@ sp_feTurbulence_set(SPObject *object, unsigned int key, gchar const *value) read_num = helperfns_read_number(value); if (read_num != feTurbulence->seed){ feTurbulence->seed = read_num; + feTurbulence->updated = false; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -184,6 +188,7 @@ sp_feTurbulence_set(SPObject *object, unsigned int key, gchar const *value) read_bool = sp_feTurbulence_read_stitchTiles(value); if (read_bool != feTurbulence->stitchTiles){ feTurbulence->stitchTiles = read_bool; + feTurbulence->updated = false; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -191,6 +196,7 @@ sp_feTurbulence_set(SPObject *object, unsigned int key, gchar const *value) read_type = sp_feTurbulence_read_type(value); if (read_type != feTurbulence->type){ feTurbulence->type = read_type; + feTurbulence->updated = false; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -262,6 +268,7 @@ static void sp_feTurbulence_build_renderer(SPFilterPrimitive *primitive, NR::Fil nr_turbulence->set_seed(sp_turbulence->seed); nr_turbulence->set_stitchTiles(sp_turbulence->stitchTiles); nr_turbulence->set_type(sp_turbulence->type); + nr_turbulence->set_updated(sp_turbulence->updated); } /* diff --git a/src/sp-feturbulence.h b/src/sp-feturbulence.h index 40e1c0a42..6ae993d27 100644 --- a/src/sp-feturbulence.h +++ b/src/sp-feturbulence.h @@ -28,7 +28,9 @@ struct SPFeTurbulence : public SPFilterPrimitive { int numOctaves; double seed; bool stitchTiles; - NR::FilterTurbulenceType type; + NR::FilterTurbulenceType type; + SVGLength x, y, height, width; + bool updated; }; struct SPFeTurbulenceClass { -- 2.30.2