From: jucablues Date: Sun, 5 Aug 2007 20:22:48 +0000 (+0000) Subject: refactoring: X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e6c36b3bb9fa1c5be9ecb416ec7ebbd6fec74620;p=inkscape.git refactoring: *using CLAMP_D_TO_U8 *Changed edgeMode field of ConvolveMatrix filter to use an enum rather than a plain int --- diff --git a/src/display/nr-filter-convolve-matrix.cpp b/src/display/nr-filter-convolve-matrix.cpp index 9c9cf5f21..8ce9241fe 100644 --- a/src/display/nr-filter-convolve-matrix.cpp +++ b/src/display/nr-filter-convolve-matrix.cpp @@ -10,6 +10,7 @@ */ #include "display/nr-filter-convolve-matrix.h" +#include "display/nr-filter-utils.h" #include namespace NR { @@ -19,7 +20,7 @@ FilterConvolveMatrix::FilterConvolveMatrix() targetX((int)(orderX/2)), targetY((int)(orderY/2)), bias(0), - edgeMode(0), + edgeMode((NR::FilterConvolveMatrixEdgeMode) 0), preserveAlpha(false) {} @@ -80,20 +81,11 @@ int FilterConvolveMatrix::render(FilterSlot &slot, Matrix const &trans) { } } } - result_R = result_R / div + bias; - result_G = result_G / div + bias; - result_B = result_B / div + bias; - result_A = result_A / div + bias; - - result_R = (result_R > 0 ? result_R : 0); - result_G = (result_G > 0 ? result_G : 0); - result_B = (result_B > 0 ? result_B : 0); - result_A = (result_A > 0 ? result_A : 0); - - out_data[4*( x + width*y )] = (result_R < 255 ? (unsigned char)result_R : 255); - out_data[4*( x + width*y )+1] = (result_G < 255 ? (unsigned char)result_G : 255); - out_data[4*( x + width*y )+2] = (result_B < 255 ? (unsigned char)result_B : 255); - out_data[4*( x + width*y )+3] = (result_A < 255 ? (unsigned char)result_A : 255); + + out_data[4*( x + width*y )] = CLAMP_D_TO_U8(result_R / div + bias); + out_data[4*( x + width*y )+1] = CLAMP_D_TO_U8(result_G / div + bias); + out_data[4*( x + width*y )+2] = CLAMP_D_TO_U8(result_B / div + bias); + out_data[4*( x + width*y )+3] = CLAMP_D_TO_U8(result_A / div + bias); } } @@ -130,7 +122,7 @@ void FilterConvolveMatrix::set_kernelMatrix(std::vector &km) { kernelMatrix = km; } -void FilterConvolveMatrix::set_edgeMode(int mode){ +void FilterConvolveMatrix::set_edgeMode(FilterConvolveMatrixEdgeMode mode){ edgeMode = mode; } diff --git a/src/display/nr-filter-convolve-matrix.h b/src/display/nr-filter-convolve-matrix.h index f4a823012..2a397abf2 100644 --- a/src/display/nr-filter-convolve-matrix.h +++ b/src/display/nr-filter-convolve-matrix.h @@ -20,6 +20,13 @@ namespace NR { +enum FilterConvolveMatrixEdgeMode { + CONVOLVEMATRIX_EDGEMODE_DUPLICATE, + CONVOLVEMATRIX_EDGEMODE_WRAP, + CONVOLVEMATRIX_EDGEMODE_NONE, + CONVOLVEMATRIX_EDGEMODE_ENDTYPE +}; + class FilterConvolveMatrix : public FilterPrimitive { public: FilterConvolveMatrix(); @@ -36,7 +43,7 @@ public: void set_kernelMatrix(std::vector& km); void set_bias(double b); void set_divisor(double d); - void set_edgeMode(int mode); + void set_edgeMode(FilterConvolveMatrixEdgeMode mode); void set_preserveAlpha(bool pa); private: @@ -45,7 +52,7 @@ private: int orderX, orderY; gdouble divisor, bias; int dx, dy, kernelUnitLength; - int edgeMode; + FilterConvolveMatrixEdgeMode edgeMode; bool preserveAlpha; }; diff --git a/src/sp-feconvolvematrix.cpp b/src/sp-feconvolvematrix.cpp index 87e737dfe..434689385 100644 --- a/src/sp-feconvolvematrix.cpp +++ b/src/sp-feconvolvematrix.cpp @@ -117,20 +117,20 @@ sp_feConvolveMatrix_release(SPObject *object) ((SPObjectClass *) feConvolveMatrix_parent_class)->release(object); } -static int sp_feConvolveMatrix_read_edgeMode(gchar const *value){ - if (!value) return 0; //duplicate is default +static NR::FilterConvolveMatrixEdgeMode sp_feConvolveMatrix_read_edgeMode(gchar const *value){ + if (!value) return NR::CONVOLVEMATRIX_EDGEMODE_DUPLICATE; //duplicate is default switch(value[0]){ case 'd': - if (strncmp(value, "duplicate", 9) == 0) return 0; + if (strncmp(value, "duplicate", 9) == 0) return NR::CONVOLVEMATRIX_EDGEMODE_DUPLICATE; break; case 'w': - if (strncmp(value, "wrap", 4) == 0) return 1; + if (strncmp(value, "wrap", 4) == 0) return NR::CONVOLVEMATRIX_EDGEMODE_WRAP; break; case 'n': - if (strncmp(value, "none", 4) == 0) return 2; + if (strncmp(value, "none", 4) == 0) return NR::CONVOLVEMATRIX_EDGEMODE_NONE; break; } - return 0; //duplicate is default + return NR::CONVOLVEMATRIX_EDGEMODE_DUPLICATE; //duplicate is default } /** @@ -144,6 +144,7 @@ sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value) double read_num; int read_int; bool read_bool; + NR::FilterConvolveMatrixEdgeMode read_mode; switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ @@ -187,9 +188,9 @@ sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_EDGEMODE: - read_int = (int) sp_feConvolveMatrix_read_edgeMode(value); - if (read_int != feConvolveMatrix->edgeMode){ - feConvolveMatrix->edgeMode = read_int; + read_mode = sp_feConvolveMatrix_read_edgeMode(value); + if (read_mode != feConvolveMatrix->edgeMode){ + feConvolveMatrix->edgeMode = read_mode; object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } break;