X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffilters%2Fconvolvematrix.cpp;h=3e1c36f0ad994afd8f6d3cc3edfc88a174a658c4;hb=43be2ed2178db96177d31205e4b9692535612136;hp=7402dc8cb9bca1cf09f2e4fb99f280153f206d56;hpb=a0ce949d080eec8c6fd4d7e13ac24579c8e706ba;p=inkscape.git diff --git a/src/filters/convolvematrix.cpp b/src/filters/convolvematrix.cpp index 7402dc8cb..3e1c36f0a 100644 --- a/src/filters/convolvematrix.cpp +++ b/src/filters/convolvematrix.cpp @@ -175,31 +175,38 @@ sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value) if (value){ feConvolveMatrix->kernelMatrixIsSet = true; feConvolveMatrix->kernelMatrix = helperfns_read_vector(value, (int) (feConvolveMatrix->order.getNumber() * feConvolveMatrix->order.getOptNumber())); + if (! feConvolveMatrix->divisorIsSet) { + feConvolveMatrix->divisor = 0; + for (unsigned int i = 0; i< feConvolveMatrix->kernelMatrix.size(); i++) + feConvolveMatrix->divisor += feConvolveMatrix->kernelMatrix[i]; + if (feConvolveMatrix->divisor == 0) feConvolveMatrix->divisor = 1; + } object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } else { g_warning("For feConvolveMatrix you MUST pass a kernelMatrix parameter!"); } break; case SP_ATTR_DIVISOR: - if (!value){ - read_num = 1; - } else { + if (value) { read_num = helperfns_read_number(value); if (read_num == 0) { - if (feConvolveMatrix->kernelMatrixIsSet){ - g_warning("You shouldn't pass a divisor value equal to 0! Assuming the sum of all values in kernelMatrix as the default value."); + // This should actually be an error, but given our UI it is more useful to simply set divisor to the default. + if (feConvolveMatrix->kernelMatrixIsSet) { for (unsigned int i = 0; i< feConvolveMatrix->kernelMatrix.size(); i++) read_num += feConvolveMatrix->kernelMatrix[i]; - } else { - g_warning("You shouldn't pass a divisor value equal to 0! Assuming 1 as the default value."); - read_num = 1; } + if (read_num == 0) read_num = 1; + if (feConvolveMatrix->divisorIsSet || feConvolveMatrix->divisor!=read_num) { + feConvolveMatrix->divisorIsSet = false; + feConvolveMatrix->divisor = read_num; + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + } + } else if (!feConvolveMatrix->divisorIsSet || feConvolveMatrix->divisor!=read_num) { + feConvolveMatrix->divisorIsSet = true; + feConvolveMatrix->divisor = read_num; + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } } - if (read_num != feConvolveMatrix->divisor){ - feConvolveMatrix->divisor = read_num; - object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); - } break; case SP_ATTR_BIAS: read_num = 0; @@ -290,16 +297,13 @@ sp_feConvolveMatrix_update(SPObject *object, SPCtx *ctx, guint flags) static Inkscape::XML::Node * sp_feConvolveMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { - // Inkscape-only object, not copied during an "plain SVG" dump: - if (flags & SP_OBJECT_WRITE_EXT) { - if (repr) { - // is this sane? - //repr->mergeFrom(SP_OBJECT_REPR(object), "id"); - } else { - repr = SP_OBJECT_REPR(object)->duplicate(doc); - } + /* TODO: Don't just clone, but create a new repr node and write all + * relevant values into it */ + if (!repr) { + repr = SP_OBJECT_REPR(object)->duplicate(doc); } + if (((SPObjectClass *) feConvolveMatrix_parent_class)->write) { ((SPObjectClass *) feConvolveMatrix_parent_class)->write(object, doc, repr, flags); }