From 4725fe6079119573464ab4be16d58a616d2c93df Mon Sep 17 00:00:00 2001 From: jucablues Date: Sun, 5 Aug 2007 05:07:59 +0000 Subject: [PATCH] feColorMatrix filter primitive implementation --- src/display/nr-filter-colormatrix.cpp | 99 ++++++++++++++++++++++++--- src/display/nr-filter-colormatrix.h | 2 +- src/helper-fns.h | 4 +- src/sp-fecolormatrix.cpp | 36 +++------- 4 files changed, 101 insertions(+), 40 deletions(-) diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp index 417a106c1..94f8ee962 100644 --- a/src/display/nr-filter-colormatrix.cpp +++ b/src/display/nr-filter-colormatrix.cpp @@ -10,11 +10,13 @@ */ #include "display/nr-filter-colormatrix.h" +#include "display/nr-filter-utils.h" +#include + namespace NR { FilterColorMatrix::FilterColorMatrix() { - g_warning("FilterColorMatrix::render not implemented."); } FilterPrimitive * FilterColorMatrix::create() { @@ -34,17 +36,92 @@ int FilterColorMatrix::render(FilterSlot &slot, Matrix const &trans) { unsigned char *in_data = NR_PIXBLOCK_PX(in); unsigned char *out_data = NR_PIXBLOCK_PX(out); + unsigned char r,g,b,a; + int x,y,x0,y0,x1,y1,i; + double a00,a01,a02,a10,a11,a12,a20,a21,a22, coshue, sinhue; + x0=in->area.x0; + y0=in->area.y0; + x1=in->area.x1; + y1=in->area.y1; -//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]); + switch(type){ + case 0: //matrix + if (values.size()!=20) { + g_warning("ColorMatrix: values parameter error. Wrong size."); + return -1; + } + for (x=x0;xempty = FALSE; slot.set(_output, out); return 0; @@ -62,7 +139,7 @@ void FilterColorMatrix::set_value(gdouble v){ value = v; } -void FilterColorMatrix::set_values(std::vector v){ +void FilterColorMatrix::set_values(std::vector &v){ values = v; } diff --git a/src/display/nr-filter-colormatrix.h b/src/display/nr-filter-colormatrix.h index e87145c00..9cb628d50 100644 --- a/src/display/nr-filter-colormatrix.h +++ b/src/display/nr-filter-colormatrix.h @@ -28,7 +28,7 @@ public: 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); + virtual void set_values(std::vector &values); private: std::vector values; gdouble value; diff --git a/src/helper-fns.h b/src/helper-fns.h index f588b9905..29fd2ebec 100644 --- a/src/helper-fns.h +++ b/src/helper-fns.h @@ -44,8 +44,8 @@ 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;itype != 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; + if (str){ + feColorMatrix->values = helperfns_read_vector(str, 20); + feColorMatrix->value = helperfns_read_number(str); + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } + break; default: if (((SPObjectClass *) feColorMatrix_parent_class)->set) - ((SPObjectClass *) feColorMatrix_parent_class)->set(object, key, value); + ((SPObjectClass *) feColorMatrix_parent_class)->set(object, key, str); break; } } -- 2.30.2