summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aca3b33)
raw | patch | inline | side by side (parent: aca3b33)
author | jucablues <jucablues@users.sourceforge.net> | |
Tue, 14 Aug 2007 06:15:05 +0000 (06:15 +0000) | ||
committer | jucablues <jucablues@users.sourceforge.net> | |
Tue, 14 Aug 2007 06:15:05 +0000 (06:15 +0000) |
index 7a5fc1dcd7e3b6a6cf781b548d8242bb3962d6fc..f94081612d36b2cbd75cc93a295bd6b05b1d99ba 100644 (file)
*
* 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 {
: XbaseFrequency(0),
YbaseFrequency(0),
numOctaves(1),
- seed(0)
+ seed(0),
+ updated(false),
+ pix(NULL)
{
- g_warning("FilterTurbulence::render not implemented.");
}
FilterPrimitive * FilterTurbulence::create() {
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);
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;
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)];
}
}
index 8f7849f884264ac7381b35b33f541f1bc78a6eef..1e2171e83cda2152165ecc600bc766b596e0b6e2 100644 (file)
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 */
index dfff840e0faa8bb00abd1d939195a9bdf5f4d2db..7c5091c5412f5ed0ec75d2a96bf999fdd9f2607e 100644 (file)
--- a/src/sp-feturbulence.cpp
+++ b/src/sp-feturbulence.cpp
static void
sp_feTurbulence_init(SPFeTurbulence *feTurbulence)
{
+ feTurbulence->updated=false;
}
/**
//From SVG spec: If two <number>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;
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;
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;
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 40e1c0a4281fc1b030236c24cda3a56fbd79e256..6ae993d27999cd147f3abfefe58261be5c8795e1 100644 (file)
--- a/src/sp-feturbulence.h
+++ b/src/sp-feturbulence.h
int numOctaves;
double seed;
bool stitchTiles;
- NR::FilterTurbulenceType type;
+ NR::FilterTurbulenceType type;
+ SVGLength x, y, height, width;
+ bool updated;
};
struct SPFeTurbulenceClass {