From: jaspervdg Date: Tue, 21 Apr 2009 14:13:06 +0000 (+0000) Subject: Partial fix for bug 193926 , thanks to Preben Soeberg. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=09dfce974768e8ab363f1de92721703a60faf4ed;p=inkscape.git Partial fix for bug 193926 , thanks to Preben Soeberg. --- diff --git a/src/filters/convolvematrix.cpp b/src/filters/convolvematrix.cpp index 7402dc8cb..a5a40811c 100644 --- a/src/filters/convolvematrix.cpp +++ b/src/filters/convolvematrix.cpp @@ -175,31 +175,35 @@ 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."); - 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; + // This should actually be an error, but given our UI it is more useful to simply set divisor to the default. + for (unsigned int i = 0; i< feConvolveMatrix->kernelMatrix.size(); i++) + read_num += feConvolveMatrix->kernelMatrix[i]; + 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; } } - if (read_num != feConvolveMatrix->divisor){ - feConvolveMatrix->divisor = read_num; - object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); - } break; case SP_ATTR_BIAS: read_num = 0; diff --git a/src/helper-fns.h b/src/helper-fns.h index 18e065a8d..d2a6c9b22 100644 --- a/src/helper-fns.h +++ b/src/helper-fns.h @@ -32,7 +32,10 @@ * is not known beforehand. For example, see sp_feColorMatrix_set in * sp-fecolormatrix.cpp */ inline double helperfns_read_number(gchar const *value, bool warning = true) { - if (!value) return 0; + if (!value) { + g_warning("Called helperfns_read_number with value==null_ptr, this can lead to unexpected behaviour."); + return 0; + } char *end; double ret = g_strtod(value, &end); if (*end) { diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 1732b34a3..9b36de10c 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -2190,8 +2190,7 @@ void FilterEffectsDialog::init_settings_widgets() //TRANSLATORS: for info on "Kernel", see http://en.wikipedia.org/wiki/Kernel_(matrix) _convolve_matrix = _settings->add_matrix(SP_ATTR_KERNELMATRIX, _("Kernel"), _("This matrix describes the convolve operation that is applied to the input image in order to calculate the pixel colors at the output. Different arrangements of values in this matrix result in various possible visual effects. An identity matrix would lead to a motion blur effect (parallel to the matrix diagonal) while a matrix filled with a constant non-zero value would lead to a common blur effect.")); _convolve_order->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::convolve_order_changed)); - //TODO: svg spec: The default value is the sum of all values in kernelMatrix, with the exception that if the sum is zero, then the divisor is set to 1. - _settings->add_spinslider(1, SP_ATTR_DIVISOR, _("Divisor"), 1, 20, 1, 0.1, 2, _("After applying the kernelMatrix to the input image to yield a number, that number is divided by divisor to yield the final destination color value. A divisor that is the sum of all the matrix values tends to have an evening effect on the overall color intensity of the result.")); + _settings->add_spinslider(0, SP_ATTR_DIVISOR, _("Divisor"), 0, 20, 1, 0.1, 2, _("After applying the kernelMatrix to the input image to yield a number, that number is divided by divisor to yield the final destination color value. A divisor that is the sum of all the matrix values tends to have an evening effect on the overall color intensity of the result.")); _settings->add_spinslider(0, SP_ATTR_BIAS, _("Bias"), -10, 10, 1, 0.01, 1, _("This value is added to each component. This is useful to define a constant value as the zero response of the filter.")); _settings->add_combo(CONVOLVEMATRIX_EDGEMODE_DUPLICATE, SP_ATTR_EDGEMODE, _("Edge Mode"), ConvolveMatrixEdgeModeConverter, _("Determines how to extend the input image as necessary with color values so that the matrix operations can be applied when the kernel is positioned at or near the edge of the input image.")); _settings->add_checkbutton(false, SP_ATTR_PRESERVEALPHA, _("Preserve Alpha"), "true", "false", _("If set, the alpha channel won't be altered by this filter primitive."));