From: jaspervdg Date: Sat, 20 Dec 2008 16:53:19 +0000 (+0000) Subject: Some accuracy improvements for ComponentTransfer filters (should also be somewhat... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6504825b5bdda48ce2e0ca8d0f7d7bafe59b986c;p=inkscape.git Some accuracy improvements for ComponentTransfer filters (should also be somewhat faster). --- diff --git a/src/display/nr-filter-component-transfer.cpp b/src/display/nr-filter-component-transfer.cpp index 5c4fd4598..dbf5c44ed 100644 --- a/src/display/nr-filter-component-transfer.cpp +++ b/src/display/nr-filter-component-transfer.cpp @@ -14,6 +14,7 @@ #include "display/nr-filter-utils.h" #include "libnr/nr-pixblock.h" #include "libnr/nr-blit.h" +#include "libnr/nr-pixops.h" #include namespace NR { @@ -70,12 +71,11 @@ int FilterComponentTransfer::render(FilterSlot &slot, FilterUnits const &/*units for (int color=0;color<4;color++){ int _vsize = tableValues[color].size(); - std::vector _tableValues = tableValues[color]; double _intercept = intercept[color]; double _slope = slope[color]; double _amplitude = amplitude[color]; double _exponent = exponent[color]; - double _offset = offset[color]; + double _offset = offset[color]; switch(type[color]){ case COMPONENTTRANSFER_TYPE_IDENTITY: for(i=color;i _tableValues(tableValues[color]); + // Scale by 255 and add .5 to avoid having to add it later for rounding purposes + for(i=0;i<_vsize;i++) { + _tableValues[i] = std::max(0.,std::min(255.,255*_tableValues[i])) + .5; + } for(i=color;i((_vsize-1) * in_data[i]); + double dx = ((_vsize-1) * in_data[i])/255.0 - k; + out_data[i] = static_cast(_tableValues[k] + dx * (_tableValues[k+1] - _tableValues[k])); } } break; @@ -101,19 +109,28 @@ int FilterComponentTransfer::render(FilterSlot &slot, FilterUnits const &/*units out_data[i] = in_data[i]; } } else { + std::vector _tableValues(_vsize); + // Convert to unsigned char + for(i=0;i<_vsize;i++) { + _tableValues[i] = static_cast(std::max(0.,std::min(255.,255*tableValues[color][i])) + .5); + } for(i=color;i((_vsize-1) * in_data[i]); + out_data[i] = _tableValues[k]; } } break; case COMPONENTTRANSFER_TYPE_LINEAR: + _intercept = 255*_intercept + .5; for(i=color;i