Code

setting of attributes and default values
authorjucablues <jucablues@users.sourceforge.net>
Mon, 6 Aug 2007 22:14:47 +0000 (22:14 +0000)
committerjucablues <jucablues@users.sourceforge.net>
Mon, 6 Aug 2007 22:14:47 +0000 (22:14 +0000)
src/display/nr-filter-component-transfer.cpp
src/display/nr-filter-component-transfer.h
src/sp-fecomponenttransfer.cpp
src/sp-fecomponenttransfer.h

index 1f519335dcf55fe75a4c55e7f8d400bd0e9b989b..909dc7d90607cbb1a22da8bebb20d0aaa4993ff5 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include "display/nr-filter-component-transfer.h"
+
 namespace NR {
 
 FilterComponentTransfer::FilterComponentTransfer()
@@ -46,6 +47,35 @@ void FilterComponentTransfer::area_enlarge(NRRectL &area, Matrix const &trans)
 {
 }
 
+void FilterComponentTransfer::set_type(FilterComponentTransferType t){
+    type = t;
+}
+
+void FilterComponentTransfer::set_slope(double s){
+        slope = s;
+}
+
+void FilterComponentTransfer::set_tableValues(std::vector<double> &tv){
+        tableValues = tv;
+}
+
+
+void FilterComponentTransfer::set_intercept(double i){
+        intercept = i;
+}
+
+void FilterComponentTransfer::set_amplitude(double a){
+        amplitude = a;
+}
+
+void FilterComponentTransfer::set_exponent(double e){
+        exponent = e;
+}
+
+void FilterComponentTransfer::set_offset(double o){
+        offset = o;
+}
+
 } /* namespace NR */
 
 /*
index b3045780971ca4d02f4eb57f61c7ae189b298874..9036a6644688aa01bcac37de5d74a644aa442748 100644 (file)
 
 #include "display/nr-filter-primitive.h"
 #include "display/nr-filter-slot.h"
+#include <vector>
 
 namespace NR {
 
+enum FilterComponentTransferType {
+    COMPONENTTRANSFER_TYPE_IDENTITY,
+    COMPONENTTRANSFER_TYPE_TABLE,
+    COMPONENTTRANSFER_TYPE_DISCRETE,
+    COMPONENTTRANSFER_TYPE_LINEAR,
+    COMPONENTTRANSFER_TYPE_GAMMA,
+    COMPONENTTRANSFER_TYPE_ERROR
+};
+
 class FilterComponentTransfer : public FilterPrimitive {
 public:
     FilterComponentTransfer();
@@ -25,6 +35,23 @@ public:
 
     virtual int render(FilterSlot &slot, Matrix const &trans);
     virtual void area_enlarge(NRRectL &area, Matrix const &trans);
+
+    void set_type(FilterComponentTransferType t);    
+    void set_tableValues(std::vector<gdouble>& tv);
+    void set_slope(double s);
+    void set_intercept(double i);
+    void set_amplitude(double a);
+    void set_exponent(double e);
+    void set_offset(double o);
+
+private:
+    FilterComponentTransferType type;
+    std::vector<gdouble> tableValues;
+    double slope;
+    double intercept;
+    double amplitude;
+    double exponent;
+    double offset;
 };
 
 } /* namespace NR */
index 9909511921febc810ea86e18342f65702fd66de2..2bf3e809a0346ea0373be2d9479da67086748d87 100644 (file)
@@ -21,7 +21,7 @@
 #include "svg/svg.h"
 #include "sp-fecomponenttransfer.h"
 #include "xml/repr.h"
-
+#include "display/nr-filter-component-transfer.h"
 
 /* FeComponentTransfer base class */
 
@@ -74,6 +74,14 @@ sp_feComponentTransfer_class_init(SPFeComponentTransferClass *klass)
 static void
 sp_feComponentTransfer_init(SPFeComponentTransfer *feComponentTransfer)
 {
+    //Setting default values:
+//TODO: tableValues = "" (empty list);
+    feComponentTransfer->slope = 1;
+    feComponentTransfer->intercept = 0;
+    feComponentTransfer->amplitude = 1;
+    feComponentTransfer->exponent = 1;
+    feComponentTransfer->offset = 0;
+//    feComponentTransfer->type = NR::COMPONENTTRANSFER_TYPE_ERROR;
 }
 
 /**
@@ -89,6 +97,13 @@ sp_feComponentTransfer_build(SPObject *object, SPDocument *document, Inkscape::X
     }
 
     /*LOAD ATTRIBUTES FROM REPR HERE*/
+    sp_object_read_attr(object, "type");
+    sp_object_read_attr(object, "tableValues");
+    sp_object_read_attr(object, "slope");
+    sp_object_read_attr(object, "intercept");
+    sp_object_read_attr(object, "amplitude");
+    sp_object_read_attr(object, "exponent");
+    sp_object_read_attr(object, "offset");
 }
 
 /**
@@ -101,6 +116,28 @@ sp_feComponentTransfer_release(SPObject *object)
         ((SPObjectClass *) feComponentTransfer_parent_class)->release(object);
 }
 
+static NR::FilterComponentTransferType sp_feComponenttransfer_read_type(gchar const *value){
+    if (!value) return NR::COMPONENTTRANSFER_TYPE_ERROR; //type attribute is REQUIRED.
+    switch(value[0]){
+        case 'i':
+            if (strncmp(value, "identity", 8) == 0) return NR::COMPONENTTRANSFER_TYPE_IDENTITY;
+            break;
+        case 't':
+            if (strncmp(value, "table", 5) == 0) return NR::COMPONENTTRANSFER_TYPE_TABLE;
+            break;
+        case 'd':
+            if (strncmp(value, "discrete", 8) == 0) return NR::COMPONENTTRANSFER_TYPE_DISCRETE;
+            break;
+        case 'l':
+            if (strncmp(value, "linear", 6) == 0) return NR::COMPONENTTRANSFER_TYPE_LINEAR;
+            break;
+        case 'g':
+            if (strncmp(value, "gamma", 5) == 0) return NR::COMPONENTTRANSFER_TYPE_GAMMA;
+            break;
+    }
+    return NR::COMPONENTTRANSFER_TYPE_ERROR; //type attribute is REQUIRED.
+}
+
 /**
  * Sets a specific value in the SPFeComponentTransfer.
  */
index 8c4544613da88f4b0cdcb6ba9a24bc21f35fa960..2a0fa01ed41ae577c99e59327326cbc4839333df 100644 (file)
 
 #include "sp-filter.h"
 #include "sp-fecomponenttransfer-fns.h"
+#include "display/nr-filter-component-transfer.h"
+#include <vector>
 
 /* FeComponentTransfer base class */
 class SPFeComponentTransferClass;
 
 struct SPFeComponentTransfer : public SPFilterPrimitive {
     /** COMPONENTTRANSFER ATTRIBUTES HERE */
-    
+    NR::FilterComponentTransferType type;
+    std::vector<double> tableValues;
+    double slope;
+    double intercept;
+    double amplitude;
+    double exponent;
+    double offset;
 };
 
 struct SPFeComponentTransferClass {