From 0ef926ae59e9cffb15ca7cb8d7de20c2b74807ef Mon Sep 17 00:00:00 2001 From: jucablues Date: Sat, 4 Aug 2007 06:50:50 +0000 Subject: [PATCH] setting of attributes and default values for feColorMatrix. refactornig: moved read_kernel_matrix to helper-fns.h and renamed it to helperfns_read_vector. Used it on sp-fecolormatrix.cpp --- src/display/nr-filter-colormatrix.cpp | 22 +++++++++- src/display/nr-filter-colormatrix.h | 8 ++++ src/helper-fns.h | 11 ++++- src/sp-fecolormatrix.cpp | 61 ++++++++++++++++++++++++++- src/sp-fecolormatrix.h | 7 +-- src/sp-feconvolvematrix.cpp | 11 +---- 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 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 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 values); +private: + std::vector 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 helperfns_read_vector(const gchar* value, int size){ + std::vector v(size, (gdouble) 0); + int i; + gchar** values = g_strsplit(value , " ", size); + for (i=0;irelease(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 -#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 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 read_kernel_matrix(const gchar* value, int size){ - std::vector v(size, (gdouble) 0); - int i; - gchar** values = g_strsplit(value , " ", size); - for (i=0;iparent->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: -- 2.30.2