From: nicholasbishop Date: Sun, 5 Aug 2007 06:23:46 +0000 (+0000) Subject: Filter effects: X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3d408b5e5a2327b0f8e777e5c540e8da2a3491fa;p=inkscape.git Filter effects: * Changed type field of ColorMatrix filter to use an enum rather than a plain int * Added control for the ColorMatrix type to the filter dialog --- diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp index 94f8ee962..74394bfc1 100644 --- a/src/display/nr-filter-colormatrix.cpp +++ b/src/display/nr-filter-colormatrix.cpp @@ -45,7 +45,7 @@ int FilterColorMatrix::render(FilterSlot &slot, Matrix const &trans) { y1=in->area.y1; switch(type){ - case 0: //matrix + case COLORMATRIX_MATRIX: if (values.size()!=20) { g_warning("ColorMatrix: values parameter error. Wrong size."); return -1; @@ -64,7 +64,7 @@ int FilterColorMatrix::render(FilterSlot &slot, Matrix const &trans) { } } break; - case 1: //saturate + case COLORMATRIX_SATURATE: for (x=x0;xempty = FALSE; slot.set(_output, out); @@ -131,7 +133,7 @@ void FilterColorMatrix::area_enlarge(NRRectL &area, Matrix const &trans) { } -void FilterColorMatrix::set_type(int t){ +void FilterColorMatrix::set_type(FilterColorMatrixType t){ type = t; } diff --git a/src/display/nr-filter-colormatrix.h b/src/display/nr-filter-colormatrix.h index 9cb628d50..32b57ce0c 100644 --- a/src/display/nr-filter-colormatrix.h +++ b/src/display/nr-filter-colormatrix.h @@ -18,6 +18,14 @@ namespace NR { +enum FilterColorMatrixType { + COLORMATRIX_MATRIX, + COLORMATRIX_SATURATE, + COLORMATRIX_HUEROTATE, + COLORMATRIX_LUMINANCETOALPHA, + COLORMATRIX_ENDTYPE +}; + class FilterColorMatrix : public FilterPrimitive { public: FilterColorMatrix(); @@ -26,13 +34,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_type(FilterColorMatrixType type); virtual void set_value(gdouble value); virtual void set_values(std::vector &values); private: std::vector values; gdouble value; - int type; + FilterColorMatrixType type; }; } /* namespace NR */ diff --git a/src/filter-enums.cpp b/src/filter-enums.cpp index 624ed8889..2d26095a4 100644 --- a/src/filter-enums.cpp +++ b/src/filter-enums.cpp @@ -46,15 +46,26 @@ const EnumData FPInputData[FPINPUT_END] = { }; const EnumDataConverter FPInputConverter(FPInputData, FPINPUT_END); +// feBlend const EnumData BlendModeData[NR::BLEND_ENDMODE] = { - {NR::BLEND_NORMAL, _("Normal"), "normal"}, + {NR::BLEND_NORMAL, _("Normal"), "normal"}, {NR::BLEND_MULTIPLY, _("Multiply"), "multiply"}, - {NR::BLEND_SCREEN, _("Screen"), "screen"}, - {NR::BLEND_DARKEN, _("Darken"), "darken"}, - {NR::BLEND_LIGHTEN, _("Lighten"), "lighten"} + {NR::BLEND_SCREEN, _("Screen"), "screen"}, + {NR::BLEND_DARKEN, _("Darken"), "darken"}, + {NR::BLEND_LIGHTEN, _("Lighten"), "lighten"} }; const EnumDataConverter BlendModeConverter(BlendModeData, NR::BLEND_ENDMODE); + +const EnumData ColorMatrixTypeData[NR::COLORMATRIX_ENDTYPE] = { + {NR::COLORMATRIX_MATRIX, _("Matrix"), "matrix"}, + {NR::COLORMATRIX_SATURATE, _("Saturate"), "saturate"}, + {NR::COLORMATRIX_HUEROTATE, _("Hue Rotate"), "hueRotate"}, + {NR::COLORMATRIX_LUMINANCETOALPHA, _("Luminance to Alpha"), "luminanceToAlpha"} +}; +const EnumDataConverter ColorMatrixTypeConverter(ColorMatrixTypeData, NR::COLORMATRIX_ENDTYPE); + +// feComposite const EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR] = { {COMPOSITE_DEFAULT, _("Default"), ""}, {COMPOSITE_OVER, _("Over"), "over"}, @@ -66,6 +77,7 @@ const EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR] }; const EnumDataConverter CompositeOperatorConverter(CompositeOperatorData, COMPOSITE_ENDOPERATOR); +// Light source const EnumData LightSourceData[LIGHT_ENDSOURCE] = { {LIGHT_DISTANT, _("Distance Light"), "svg:feDistanceLight"}, {LIGHT_POINT, _("Point Light"), "svg:fePointLight"}, diff --git a/src/filter-enums.h b/src/filter-enums.h index 76ec019ec..cbea5545b 100644 --- a/src/filter-enums.h +++ b/src/filter-enums.h @@ -13,6 +13,7 @@ */ #include "display/nr-filter-blend.h" +#include "display/nr-filter-colormatrix.h" #include "display/nr-filter-composite.h" #include "display/nr-filter-types.h" #include "util/enums.h" @@ -37,6 +38,9 @@ extern const Inkscape::Util::EnumDataConverter FPInputConv // Blend mode extern const Inkscape::Util::EnumData BlendModeData[NR::BLEND_ENDMODE]; extern const Inkscape::Util::EnumDataConverter BlendModeConverter; +// ColorMatrix type +extern const Inkscape::Util::EnumData ColorMatrixTypeData[NR::COLORMATRIX_ENDTYPE]; +extern const Inkscape::Util::EnumDataConverter ColorMatrixTypeConverter; // Composite operator extern const Inkscape::Util::EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR]; extern const Inkscape::Util::EnumDataConverter CompositeOperatorConverter; diff --git a/src/sp-fecolormatrix.cpp b/src/sp-fecolormatrix.cpp index d20c11456..6ff107b9f 100644 --- a/src/sp-fecolormatrix.cpp +++ b/src/sp-fecolormatrix.cpp @@ -108,23 +108,23 @@ 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 +static NR::FilterColorMatrixType sp_feColorMatrix_read_type(gchar const *value){ + if (!value) return NR::COLORMATRIX_MATRIX; //matrix is default switch(value[0]){ case 'm': - if (strcmp(value, "matrix") == 0) return 0; + if (strcmp(value, "matrix") == 0) return NR::COLORMATRIX_MATRIX; break; case 's': - if (strcmp(value, "saturate") == 0) return 1; + if (strcmp(value, "saturate") == 0) return NR::COLORMATRIX_SATURATE; break; case 'h': - if (strcmp(value, "hueRotate") == 0) return 2; + if (strcmp(value, "hueRotate") == 0) return NR::COLORMATRIX_HUEROTATE; break; case 'l': - if (strcmp(value, "luminanceToAlpha") == 0) return 3; + if (strcmp(value, "luminanceToAlpha") == 0) return NR::COLORMATRIX_LUMINANCETOALPHA; break; } - return 0; //matrix is default + return NR::COLORMATRIX_MATRIX; //matrix is default } /** @@ -136,14 +136,14 @@ sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *str) SPFeColorMatrix *feColorMatrix = SP_FECOLORMATRIX(object); (void)feColorMatrix; - int read_int; + NR::FilterColorMatrixType read_type; gdouble read_num; /*DEAL WITH SETTING ATTRIBUTES HERE*/ switch(key) { case SP_ATTR_TYPE: - read_int = sp_feColorMatrix_read_type(str); - if (feColorMatrix->type != read_int){ - feColorMatrix->type = read_int; + read_type = sp_feColorMatrix_read_type(str); + if (feColorMatrix->type != read_type){ + feColorMatrix->type = read_type; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; diff --git a/src/sp-fecolormatrix.h b/src/sp-fecolormatrix.h index bf04c5489..e091a0725 100644 --- a/src/sp-fecolormatrix.h +++ b/src/sp-fecolormatrix.h @@ -15,6 +15,7 @@ #include "sp-filter.h" #include "sp-fecolormatrix-fns.h" +#include "display/nr-filter-colormatrix.h" #include /* FeColorMatrix base class */ @@ -22,7 +23,7 @@ class SPFeColorMatrixClass; struct SPFeColorMatrix : public SPFilterPrimitive { /** COLORMATRIX ATTRIBUTES HERE */ - int type; + NR::FilterColorMatrixType type; gdouble value; std::vector values; }; diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index f3fa074d5..f842e97ad 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1572,6 +1572,9 @@ void FilterEffectsDialog::init_settings_widgets() _settings->type(NR_FILTER_BLEND); _settings->add_combo(SP_ATTR_MODE, _("Mode"), BlendModeConverter); + _settings->type(NR_FILTER_COLORMATRIX); + _settings->add_combo(SP_ATTR_TYPE, _("Type"), ColorMatrixTypeConverter); + _settings->type(NR_FILTER_COMPOSITE); _settings->add_combo(SP_ATTR_OPERATOR, _("Operator"), CompositeOperatorConverter); _k1 = _settings->add_spinslider(SP_ATTR_K1, _("K1"), -10, 10, 1, 0.01, 1);