diff options
| author | Felipe Corr??a da Silva Sanches <juca@members.fsf.org> | 2007-08-14 06:15:05 +0000 |
|---|---|---|
| committer | jucablues <jucablues@users.sourceforge.net> | 2007-08-14 06:15:05 +0000 |
| commit | 6d119fb5208e1bf12ed590da44be7431ba264d71 (patch) | |
| tree | cbe3559b01b99ac70c492eec15de27f592288803 /src/display | |
| parent | * incomplete feImage implementation. (diff) | |
| download | inkscape-6d119fb5208e1bf12ed590da44be7431ba264d71.tar.gz inkscape-6d119fb5208e1bf12ed590da44be7431ba264d71.zip | |
added some more boilerplate code on feTurbulence.
(bzr r3462)
Diffstat (limited to 'src/display')
| -rw-r--r-- | src/display/nr-filter-turbulence.cpp | 58 | ||||
| -rw-r--r-- | src/display/nr-filter-turbulence.h | 8 |
2 files changed, 53 insertions, 13 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 */ |
