summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3cb0f02)
raw | patch | inline | side by side (parent: 3cb0f02)
author | jaspervdg <jaspervdg@users.sourceforge.net> | |
Mon, 20 Apr 2009 15:48:18 +0000 (15:48 +0000) | ||
committer | jaspervdg <jaspervdg@users.sourceforge.net> | |
Mon, 20 Apr 2009 15:48:18 +0000 (15:48 +0000) |
src/display/nr-filter-convolve-matrix.cpp | patch | blob | history | |
src/filters/convolvematrix.cpp | patch | blob | history |
index 47978edd6bb8a822f04076ce7f879b2129d85c8d..7db13a5b27a1f7f9adbc8dbe87f431de917150ab 100644 (file)
@@ -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] );
index 41028fb201773097cd04ac525b8b5a966c049f71..7402dc8cb9bca1cf09f2e4fb99f280153f206d56 100644 (file)
@@ -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: