Code

Mnemonics in fill and stroke dialog and menu
[inkscape.git] / src / display / nr-filter-colormatrix.cpp
index e640ce4fb6883f367129e9bfadd3869f11d41ec8..7d0792325cd861655249af2f67f0e1f7f1c86bef 100644 (file)
@@ -2,7 +2,7 @@
  * feColorMatrix filter primitive renderer
  *
  * Authors:
- *   Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
+ *   Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
  *   Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
  *
  * Copyright (C) 2007 authors
@@ -16,7 +16,8 @@
 #include "libnr/nr-blit.h"
 #include <math.h>
 
-namespace NR {
+namespace Inkscape {
+namespace Filters {
 
 FilterColorMatrix::FilterColorMatrix()
 {
@@ -37,19 +38,15 @@ int FilterColorMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) {
     }
 
     NRPixBlock *out = new NRPixBlock;
-
-    bool premultiplied;
     if ((type==COLORMATRIX_SATURATE || type==COLORMATRIX_HUEROTATE) && in->mode != NR_PIXBLOCK_MODE_R8G8B8A8N) {
         // saturate and hueRotate do not touch the alpha channel and are linear (per-pixel) operations, so no premultiplied -> non-premultiplied operation is necessary
         nr_pixblock_setup_fast(out, NR_PIXBLOCK_MODE_R8G8B8A8P,
                                in->area.x0, in->area.y0, in->area.x1, in->area.y1,
                                true);
-        premultiplied = true;
     } else {
         nr_pixblock_setup_fast(out, NR_PIXBLOCK_MODE_R8G8B8A8N,
                                in->area.x0, in->area.y0, in->area.x1, in->area.y1,
                                true);
-        premultiplied = false;
     }
 
     // this primitive is defined for non-premultiplied RGBA values,
@@ -83,10 +80,10 @@ int FilterColorMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) {
                     g_warning("ColorMatrix: values parameter error. Wrong size: %i.", static_cast<int>(values.size()));
                     return -1;
                 }
-                double a04 = 255*values[4] + .5;
-                double a14 = 255*values[9] + .5;
-                double a24 = 255*values[14] + .5;
-                double a34 = 255*values[19] + .5;
+                double a04 = 255*values[4];
+                double a14 = 255*values[9];
+                double a24 = 255*values[14];
+                double a34 = 255*values[19];
                 for (x=x0;x<x1;x++){
                     for (y=y0;y<y1;y++){
                         i = ((x-x0) + (x1-x0)*(y-y0))*4;
@@ -94,7 +91,7 @@ int FilterColorMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) {
                         g = in_data[i+1];
                         b = in_data[i+2];
                         a = in_data[i+3];
-                        out_data[i] = CLAMP_D_TO_U8( r*values[0] + g*values[1] + b*values[2] + a*values[3] + a04 );
+                        out_data[i] = CLAMP_D_TO_U8( r*values[0] + g*values[1] + b*values[2] + a*values[3] + a04 ); // CLAMP includes rounding!
                         out_data[i+1] = CLAMP_D_TO_U8( r*values[5] + g*values[6] + b*values[7] + a*values[8] + a14 );
                         out_data[i+2] = CLAMP_D_TO_U8( r*values[10] + g*values[11] + b*values[12] + a*values[13] + a24 );
                         out_data[i+3] = CLAMP_D_TO_U8( r*values[15] + g*values[16] + b*values[17] + a*values[18] + a34 );
@@ -136,7 +133,7 @@ int FilterColorMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) {
                 double a20 = 0.213 + coshue*(-0.213) + sinhue*(-0.787);
                 double a21 = 0.715 + coshue*(-0.715) + sinhue*( 0.715);
                 double a22 = 0.072 + coshue*( 0.928) + sinhue*( 0.072);
-                if (premultiplied) {
+                if (in->mode==NR_PIXBLOCK_MODE_R8G8B8A8P) {
                     // Although it does not change the alpha channel, it can give "out-of-bound" results, and in this case the bound is determined by the alpha channel
                     for (x=x0;x<x1;x++){
                         for (y=y0;y<y1;y++){
@@ -161,9 +158,9 @@ int FilterColorMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) {
                             b = in_data[i+2];
                             a = in_data[i+3];
 
-                            out_data[i]   = CLAMP_D_TO_U8( r*a00 + g*a01 + b*a02 + .5 );
-                            out_data[i+1] = CLAMP_D_TO_U8( r*a10 + g*a11 + b*a12 + .5 );
-                            out_data[i+2] = CLAMP_D_TO_U8( r*a20 + g*a21 + b*a22 + .5 );
+                            out_data[i]   = CLAMP_D_TO_U8( r*a00 + g*a01 + b*a02);
+                            out_data[i+1] = CLAMP_D_TO_U8( r*a10 + g*a11 + b*a12);
+                            out_data[i+2] = CLAMP_D_TO_U8( r*a20 + g*a21 + b*a22);
                             out_data[i+3] = a;
                         }
                     }
@@ -214,7 +211,8 @@ void FilterColorMatrix::set_values(std::vector<gdouble> &v){
         values = v;
 }
 
-} /* namespace NR */
+} /* namespace Filters */
+} /* namespace Inkscape */
 
 /*
   Local Variables:
@@ -225,4 +223,4 @@ void FilterColorMatrix::set_values(std::vector<gdouble> &v){
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :