summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/display/nr-filter-colormatrix.cpp22
-rw-r--r--src/display/nr-filter-colormatrix.h8
-rw-r--r--src/helper-fns.h11
-rw-r--r--src/sp-fecolormatrix.cpp61
-rw-r--r--src/sp-fecolormatrix.h7
-rw-r--r--src/sp-feconvolvematrix.cpp11
6 files changed, 103 insertions, 17 deletions
diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp
index 060703ada..417a106c1 100644
--- a/src/display/nr-filter-colormatrix.cpp
+++ b/src/display/nr-filter-colormatrix.cpp
@@ -36,7 +36,15 @@ int FilterColorMatrix::render(FilterSlot &slot, Matrix const &trans) {
unsigned char *out_data = NR_PIXBLOCK_PX(out);
//IMPLEMENT ME!
-
+ printf("type = %d\n", type);
+ if (type==0){
+ for (int i=0;i<20;i++){
+ printf("values[%d]=%f\n", i, values[i]);
+ }
+ } else {
+ printf("value = %f\n", value);
+ }
+
out->empty = FALSE;
slot.set(_output, out);
return 0;
@@ -46,6 +54,18 @@ void FilterColorMatrix::area_enlarge(NRRectL &area, Matrix const &trans)
{
}
+void FilterColorMatrix::set_type(int t){
+ type = t;
+}
+
+void FilterColorMatrix::set_value(gdouble v){
+ value = v;
+}
+
+void FilterColorMatrix::set_values(std::vector<gdouble> v){
+ values = v;
+}
+
} /* namespace NR */
/*
diff --git a/src/display/nr-filter-colormatrix.h b/src/display/nr-filter-colormatrix.h
index cf93a75cb..e87145c00 100644
--- a/src/display/nr-filter-colormatrix.h
+++ b/src/display/nr-filter-colormatrix.h
@@ -14,6 +14,7 @@
#include "display/nr-filter-primitive.h"
#include "display/nr-filter-slot.h"
+#include<vector>
namespace NR {
@@ -25,6 +26,13 @@ public:
virtual int render(FilterSlot &slot, Matrix const &trans);
virtual void area_enlarge(NRRectL &area, Matrix const &trans);
+ virtual void set_type(int type);
+ virtual void set_value(gdouble value);
+ virtual void set_values(std::vector<gdouble> values);
+private:
+ std::vector<gdouble> values;
+ gdouble value;
+ int type;
};
} /* namespace NR */
diff --git a/src/helper-fns.h b/src/helper-fns.h
index 10c311eda..f588b9905 100644
--- a/src/helper-fns.h
+++ b/src/helper-fns.h
@@ -39,7 +39,16 @@ static bool helperfns_read_bool(gchar const *value, bool default_value){
}
return default_value;
}
-
+
+static std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
+ std::vector<gdouble> v(size, (gdouble) 0);
+ int i;
+ gchar** values = g_strsplit(value , " ", size);
+ for (i=0;i<size;i++)
+ v[i] = g_ascii_strtod(values[i], NULL);
+ return v;
+}
+
#endif /* !SEEN_HELPER_FNS_H */
/*
diff --git a/src/sp-fecolormatrix.cpp b/src/sp-fecolormatrix.cpp
index f8378135a..cc7ee6138 100644
--- a/src/sp-fecolormatrix.cpp
+++ b/src/sp-fecolormatrix.cpp
@@ -21,7 +21,9 @@
#include "svg/svg.h"
#include "sp-fecolormatrix.h"
#include "xml/repr.h"
+#include "helper-fns.h"
+#include "display/nr-filter-colormatrix.h"
/* FeColorMatrix base class */
@@ -92,6 +94,7 @@ sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::No
}
/*LOAD ATTRIBUTES FROM REPR HERE*/
+
}
/**
@@ -104,6 +107,25 @@ sp_feColorMatrix_release(SPObject *object)
((SPObjectClass *) feColorMatrix_parent_class)->release(object);
}
+static int sp_feColorMatrix_read_type(gchar const *value){
+ if (!value) return 0; //matrix is default
+ switch(value[0]){
+ case 'm':
+ if (strcmp(value, "matrix") == 0) return 0;
+ break;
+ case 's':
+ if (strcmp(value, "saturate") == 0) return 1;
+ break;
+ case 'h':
+ if (strcmp(value, "hueRotate") == 0) return 2;
+ break;
+ case 'l':
+ if (strcmp(value, "luminanceToAlpha") == 0) return 3;
+ break;
+ }
+ return 0; //matrix is default
+}
+
/**
* Sets a specific value in the SPFeColorMatrix.
*/
@@ -113,14 +135,46 @@ sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *value)
SPFeColorMatrix *feColorMatrix = SP_FECOLORMATRIX(object);
(void)feColorMatrix;
- switch(key) {
+ int read_int;
+ gdouble read_num;
/*DEAL WITH SETTING ATTRIBUTES HERE*/
+ switch(key) {
+ case SP_ATTR_TYPE:
+ read_int = sp_feColorMatrix_read_type(value);
+ if (feColorMatrix->type != read_int){
+ feColorMatrix->type = read_int;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
+ case SP_ATTR_VALUES:
+ switch(feColorMatrix->type){
+ case '0': //matrix
+ feColorMatrix->values = helperfns_read_vector(value, 20);
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ break;
+ case '1': //saturate
+ read_num = helperfns_read_number(value);
+ if (feColorMatrix->value != read_num){ //TODO: check if it is a real number between 0 and 1;
+ feColorMatrix->value = read_num;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
+ case '2': //hueRotate
+ read_num = helperfns_read_number(value);
+ if (feColorMatrix->value != read_num){
+ feColorMatrix->value = read_num;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
+ case '3': //luminanceToAlpha
+ g_warning("value attribute is not applicable for feColorMatrix type='luminanceToAlpha'.");
+ break;
+ }
default:
if (((SPObjectClass *) feColorMatrix_parent_class)->set)
((SPObjectClass *) feColorMatrix_parent_class)->set(object, key, value);
break;
}
-
}
/**
@@ -176,6 +230,9 @@ static void sp_feColorMatrix_build_renderer(SPFilterPrimitive *primitive, NR::Fi
g_assert(nr_colormatrix != NULL);
sp_filter_primitive_renderer_common(primitive, nr_primitive);
+ nr_colormatrix->set_type(sp_colormatrix->type);
+ nr_colormatrix->set_value(sp_colormatrix->value);
+ nr_colormatrix->set_values(sp_colormatrix->values);
}
/*
diff --git a/src/sp-fecolormatrix.h b/src/sp-fecolormatrix.h
index 6dc0b6966..bf04c5489 100644
--- a/src/sp-fecolormatrix.h
+++ b/src/sp-fecolormatrix.h
@@ -15,15 +15,16 @@
#include "sp-filter.h"
#include "sp-fecolormatrix-fns.h"
+#include <vector>
-#include "display/nr-filter.h"
-#include "display/nr-filter-colormatrix.h"
/* FeColorMatrix base class */
class SPFeColorMatrixClass;
struct SPFeColorMatrix : public SPFilterPrimitive {
/** COLORMATRIX ATTRIBUTES HERE */
-
+ int type;
+ gdouble value;
+ std::vector<gdouble> values;
};
struct SPFeColorMatrixClass {
diff --git a/src/sp-feconvolvematrix.cpp b/src/sp-feconvolvematrix.cpp
index adabc1bac..87e737dfe 100644
--- a/src/sp-feconvolvematrix.cpp
+++ b/src/sp-feconvolvematrix.cpp
@@ -117,15 +117,6 @@ sp_feConvolveMatrix_release(SPObject *object)
((SPObjectClass *) feConvolveMatrix_parent_class)->release(object);
}
-static std::vector<gdouble> read_kernel_matrix(const gchar* value, int size){
- std::vector<gdouble> v(size, (gdouble) 0);
- int i;
- gchar** values = g_strsplit(value , " ", size);
- for (i=0;i<size;i++)
- v[i] = g_ascii_strtod(values[i], NULL);
- return v;
-}
-
static int sp_feConvolveMatrix_read_edgeMode(gchar const *value){
if (!value) return 0; //duplicate is default
switch(value[0]){
@@ -164,7 +155,7 @@ sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value)
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_KERNELMATRIX:
- feConvolveMatrix->kernelMatrix = read_kernel_matrix(value, (int) (feConvolveMatrix->order.getNumber() * feConvolveMatrix->order.getOptNumber()));
+ feConvolveMatrix->kernelMatrix = helperfns_read_vector(value, (int) (feConvolveMatrix->order.getNumber() * feConvolveMatrix->order.getOptNumber()));
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_DIVISOR: