summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7740e81)
raw | patch | inline | side by side (parent: 7740e81)
author | jaspervdg <jaspervdg@users.sourceforge.net> | |
Tue, 21 Apr 2009 14:13:06 +0000 (14:13 +0000) | ||
committer | jaspervdg <jaspervdg@users.sourceforge.net> | |
Tue, 21 Apr 2009 14:13:06 +0000 (14:13 +0000) |
src/filters/convolvematrix.cpp | patch | blob | history | |
src/helper-fns.h | patch | blob | history | |
src/ui/dialog/filter-effects-dialog.cpp | patch | blob | history |
index 7402dc8cb9bca1cf09f2e4fb99f280153f206d56..a5a40811c6d14df094703618d0c06bd65f5463cc 100644 (file)
@@ -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 18e065a8dc85074842e37ac3bf2e807871846ad0..d2a6c9b22bc971d48e2efee119764ccaad0c2397 100644 (file)
--- a/src/helper-fns.h
+++ b/src/helper-fns.h
* 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) {
index 1732b34a306f751650ee256479bf3ec67cf56a41..9b36de10c8b59cc4080cf9a15e6105d463248627 100644 (file)
//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."));