Code

Rename LPE: mirror reflect --> mirror symmetry
[inkscape.git] / src / display / nr-filter-specularlighting.cpp
index 7f24f3ec26055f0f46510d6680a30e3a06aaabba..3a14eb78f8af798a300b4f498bb91a9e927a8be4 100644 (file)
@@ -29,7 +29,7 @@
 
 namespace NR {
 
-FilterSpecularLighting::FilterSpecularLighting() 
+FilterSpecularLighting::FilterSpecularLighting()
 {
     light_type = NO_LIGHT;
     specularConstant = 1;
@@ -47,7 +47,7 @@ FilterSpecularLighting::~FilterSpecularLighting()
 
 //Investigating Phong Lighting model we should not take N.H but
 //R.E which equals to 2*N.H^2 - 1
-//replace the second line by 
+//replace the second line by
 //gdouble scal = scalar_product((N), (H)); scal = 2 * scal * scal - 1;
 //to get the expected formula
 #define COMPUTE_INTER(inter, H, N, ks, speculaExponent) \
@@ -60,11 +60,16 @@ do {\
 }while(0)
 
 int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) {
-    NRPixBlock *in = filter_get_alpha(slot.get(_input));
+    NRPixBlock *in = slot.get(_input);
+    if (!in) {
+        g_warning("Missing source image for feSpecularLighting (in=%d)", _input);
+        return 1;
+    }
+
     NRPixBlock *out = new NRPixBlock;
 
     //Fvector *L = NULL; //vector to the light
-    
+
     int w = in->area.x1 - in->area.x0;
     int h = in->area.y1 - in->area.y0;
     int x0 = in->area.x0;
@@ -80,15 +85,15 @@ int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) {
     gdouble ks = specularConstant; //diffuse lighting constant
     Fvector L, N, LC, H;
     gdouble inter;
-    
-    nr_pixblock_setup_fast(out, in->mode,
+
+    nr_pixblock_setup_fast(out, NR_PIXBLOCK_MODE_R8G8B8A8N,
             in->area.x0, in->area.y0, in->area.x1, in->area.y1,
             true);
     unsigned char *data_i = NR_PIXBLOCK_PX (in);
     unsigned char *data_o = NR_PIXBLOCK_PX (out);
     //No light, nothing to do
     switch (light_type) {
-        case DISTANT_LIGHT:  
+        case DISTANT_LIGHT:
             //the light vector is constant
             {
             DistantLight *dl = new DistantLight(light.distant, lighting_color);
@@ -103,7 +108,8 @@ int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) {
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]);
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_GREEN]);
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_BLUE]);
-                data_o[j++] = MAX(MAX(data_o[j-3], data_o[j-2]), data_o[j-1]);
+                data_o[j] = MAX(MAX(data_o[j-3], data_o[j-2]), data_o[j-1]);
+                ++j;
             }
             out->empty = FALSE;
             delete dl;
@@ -126,11 +132,12 @@ int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) {
                         ss * (double) data_i[4*i+3]/ 255);
                 normalized_sum(H, L, EYE_VECTOR);
                 COMPUTE_INTER(inter, N, H, ks, specularExponent);
-                
+
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]);
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_GREEN]);
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_BLUE]);
-                data_o[j++] = MAX(MAX(data_o[j-3], data_o[j-2]), data_o[j-1]);
+                data_o[j] = MAX(MAX(data_o[j-3], data_o[j-2]), data_o[j-1]);
+                ++j;
             }
             out->empty = FALSE;
             delete pl;
@@ -153,11 +160,12 @@ int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) {
                 sl->light_components(LC, L);
                 normalized_sum(H, L, EYE_VECTOR);
                 COMPUTE_INTER(inter, N, H, ks, specularExponent);
-                
+
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]);
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_GREEN]);
                 data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_BLUE]);
-                data_o[j++] = MAX(MAX(data_o[j-3], data_o[j-2]), data_o[j-1]);
+                data_o[j] = MAX(MAX(data_o[j-3], data_o[j-2]), data_o[j-1]);
+                ++j;
             }
             out->empty = FALSE;
             delete sl;
@@ -172,11 +180,11 @@ int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) {
             out->empty = false;
             }
     }
-        
+
     //finishing
     slot.set(_output, out);
-    nr_pixblock_release(in);
-    delete in;
+    //nr_pixblock_release(in);
+    //delete in;
     return 0;
 }