From: jaspervdg Date: Mon, 20 Apr 2009 15:48:18 +0000 (+0000) Subject: Fix to prevent convolvematrix.cpp from setting targetX/Y to zero if no value is given. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a0ce949d080eec8c6fd4d7e13ac24579c8e706ba;p=inkscape.git Fix to prevent convolvematrix.cpp from setting targetX/Y to zero if no value is given. --- diff --git a/src/display/nr-filter-convolve-matrix.cpp b/src/display/nr-filter-convolve-matrix.cpp index 47978edd6..7db13a5b2 100644 --- a/src/display/nr-filter-convolve-matrix.cpp +++ b/src/display/nr-filter-convolve-matrix.cpp @@ -52,29 +52,24 @@ int FilterConvolveMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) unsigned char *in_data = NR_PIXBLOCK_PX(in); unsigned char *out_data = NR_PIXBLOCK_PX(out); - double result_R, result_G, result_B, result_A; - int i, j, x, y; - int width = in->area.x1 - in->area.x0; - int height = in->area.y1 - in->area.y0; - - unsigned int index; - unsigned int kernel_index; - + unsigned int const width = in->area.x1 - in->area.x0; + unsigned int const height = in->area.y1 - in->area.y0; + if (in->mode==NR_PIXBLOCK_MODE_R8G8B8A8P) { - for (y=targetY; y < height - (orderY - targetY); y++){ - for (x=targetX; x < width - (orderX - targetX); x++){ - result_R = 0; - result_G = 0; - result_B = 0; - result_A = 0; - for (i=0; i < orderY; i++){ - for (j=0; j < orderX; j++){ - index = 4*( x - targetX + j + width*(y - targetY + i) ); - kernel_index = orderX-j-1 + orderX*(orderY-i-1); - result_R += ( (double) in_data[index++] * kernelMatrix[kernel_index] ); - result_G += ( (double) in_data[index++] * kernelMatrix[kernel_index] ); - result_B += ( (double) in_data[index++] * kernelMatrix[kernel_index] ); - result_A += ( (double) in_data[index] * kernelMatrix[kernel_index] ); + for (unsigned int y=targetY; y < height - (orderY - targetY); y++){ + for (unsigned int x=targetX; x < width - (orderX - targetX); x++){ + double result_R = 0; + double result_G = 0; + double result_B = 0; + double result_A = 0; + for (unsigned int i=0; i < orderY; i++){ + for (int j=0; j < orderX; j++){ + unsigned int index = 4*( x - targetX + j + width*(y - targetY + i) ); + unsigned int kernel_index = orderX-j-1 + orderX*(orderY-i-1); + result_R += ( (double) in_data[index+0] * kernelMatrix[kernel_index] ); + result_G += ( (double) in_data[index+1] * kernelMatrix[kernel_index] ); + result_B += ( (double) in_data[index+2] * kernelMatrix[kernel_index] ); + result_A += ( (double) in_data[index+3] * kernelMatrix[kernel_index] ); } } unsigned int out_index = 4*( x + width*y ); @@ -89,16 +84,16 @@ int FilterConvolveMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) } } } else { - for (y=targetY; y < height - (orderY - targetY); y++){ - for (x=targetX; x < width - (orderX - targetX); x++){ - result_R = 0; - result_G = 0; - result_B = 0; - result_A = 0; - for (i=0; i < orderY; i++){ - for (j=0; j < orderX; j++){ - index = 4*( x - targetX + j + width*(y - targetY + i) ); - kernel_index = orderX-j-1 + orderX*(orderY-i-1); + for (unsigned int y=targetY; y < height - (orderY - targetY); y++){ + for (unsigned int x=targetX; x < width - (orderX - targetX); x++){ + double result_R = 0; + double result_G = 0; + double result_B = 0; + double result_A = 0; + for (unsigned int i=0; i < orderY; i++){ + for (unsigned int j=0; j < orderX; j++){ + unsigned int index = 4*( x - targetX + j + width*(y - targetY + i) ); + unsigned int kernel_index = orderX-j-1 + orderX*(orderY-i-1); result_R += ( (double) in_data[index+0] * in_data[index+3] * kernelMatrix[kernel_index] ); result_G += ( (double) in_data[index+1] * in_data[index+3] * kernelMatrix[kernel_index] ); result_B += ( (double) in_data[index+2] * in_data[index+3] * kernelMatrix[kernel_index] ); diff --git a/src/filters/convolvematrix.cpp b/src/filters/convolvematrix.cpp index 41028fb20..7402dc8cb 100644 --- a/src/filters/convolvematrix.cpp +++ b/src/filters/convolvematrix.cpp @@ -210,27 +210,31 @@ sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_TARGETX: - read_int = (int) helperfns_read_number(value); - if (read_int < 0 || read_int > feConvolveMatrix->order.getNumber()){ - g_warning("targetX must be a value between 0 and orderX! Assuming orderX as default value."); - read_int = (int) feConvolveMatrix->order.getNumber(); - } - feConvolveMatrix->targetXIsSet = true; - if (read_int != feConvolveMatrix->targetX){ - feConvolveMatrix->targetX = read_int; - object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + if (value) { + read_int = (int) helperfns_read_number(value); + if (read_int < 0 || read_int > feConvolveMatrix->order.getNumber()){ + g_warning("targetX must be a value between 0 and orderX! Assuming floor(orderX/2) as default value."); + read_int = (int) floor(feConvolveMatrix->order.getNumber()/2.0); + } + feConvolveMatrix->targetXIsSet = true; + if (read_int != feConvolveMatrix->targetX){ + feConvolveMatrix->targetX = read_int; + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + } } break; case SP_ATTR_TARGETY: - read_int = (int) helperfns_read_number(value); - if (read_int < 0 || read_int > feConvolveMatrix->order.getOptNumber()){ - g_warning("targetY must be a value between 0 and orderY! Assuming orderY as default value."); - read_int = (int) feConvolveMatrix->order.getOptNumber(); - } - feConvolveMatrix->targetYIsSet = true; - if (read_int != feConvolveMatrix->targetY){ - feConvolveMatrix->targetY = read_int; - object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + if (value) { + read_int = (int) helperfns_read_number(value); + if (read_int < 0 || read_int > feConvolveMatrix->order.getOptNumber()){ + g_warning("targetY must be a value between 0 and orderY! Assuming floor(orderY/2) as default value."); + read_int = (int) floor(feConvolveMatrix->order.getOptNumber()/2.0); + } + feConvolveMatrix->targetYIsSet = true; + if (read_int != feConvolveMatrix->targetY){ + feConvolveMatrix->targetY = read_int; + object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + } } break; case SP_ATTR_EDGEMODE: