summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 76f8b79)
raw | patch | inline | side by side (parent: 76f8b79)
author | jucablues <jucablues@users.sourceforge.net> | |
Sat, 4 Aug 2007 06:50:50 +0000 (06:50 +0000) | ||
committer | jucablues <jucablues@users.sourceforge.net> | |
Sat, 4 Aug 2007 06:50:50 +0000 (06:50 +0000) |
refactornig: moved read_kernel_matrix to helper-fns.h and renamed it to
helperfns_read_vector. Used it on sp-fecolormatrix.cpp
helperfns_read_vector. Used it on sp-fecolormatrix.cpp
index 060703ada35ed58400c086012596a4654dfa88e6..417a106c1f8c980fb7d5a5d41b4849c21b433d74 100644 (file)
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;
{
}
+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 */
/*
index cf93a75cb09dc6cd4863a4922c4d31ee19b1848b..e87145c009dad4b0e2e13256408a003940373ccc 100644 (file)
#include "display/nr-filter-primitive.h"
#include "display/nr-filter-slot.h"
+#include<vector>
namespace NR {
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 10c311edab5e6578f3bd15ee0962f508e1f30a25..f588b9905970fd355fc6485b644e0011a9f3fad9 100644 (file)
--- a/src/helper-fns.h
+++ b/src/helper-fns.h
}
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 */
/*
index f8378135a1124b2dd62c0c0d972d11f240c472c8..cc7ee61381e447c106be6a01e8ab665df965a108 100644 (file)
--- a/src/sp-fecolormatrix.cpp
+++ b/src/sp-fecolormatrix.cpp
#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 */
}
/*LOAD ATTRIBUTES FROM REPR HERE*/
+
}
/**
((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.
*/
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 6dc0b6966a83c36eb1aa09db548ef6132e19a02e..bf04c54891fd2541f6c5e58ba12138ccde83f4fc 100644 (file)
--- a/src/sp-fecolormatrix.h
+++ b/src/sp-fecolormatrix.h
#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 {
index adabc1bac06d1362551897906d7087f4c3ebab49..87e737dfeaada7b616ba570d60713f286b35151f 100644 (file)
((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]){
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: