Code

Patch from codedread. Prevents rendering of title/desc/metadata elements in text...
[inkscape.git] / src / display / nr-filter-diffuselighting.cpp
index 0fa0495e76ee3c02147c381448a15053f664bf75..32896712cb64c206acf5368cbd800957b67d90b8 100644 (file)
@@ -17,6 +17,7 @@
 #include "display/nr-filter-diffuselighting.h"
 #include "display/nr-filter-getalpha.h"
 #include "display/nr-filter-slot.h"
+#include "display/nr-filter-units.h"
 #include "display/nr-filter-utils.h"
 #include "display/nr-light.h"
 #include "libnr/nr-blit.h"
@@ -49,8 +50,13 @@ do {\
 }while(0)
 
 
-int FilterDiffuseLighting::render(FilterSlot &slot, Matrix const &trans) {
-    NRPixBlock *in = filter_get_alpha(slot.get(_input));
+int FilterDiffuseLighting::render(FilterSlot &slot, FilterUnits const &units) {
+    NRPixBlock *in = slot.get(_input);
+    if (!in) {
+        g_warning("Missing source image for feDiffuseLighting (in=%d)", _input);
+        return 1;
+    }
+
     NRPixBlock *out = new NRPixBlock;
 
     int w = in->area.x1 - in->area.x0;
@@ -63,7 +69,7 @@ int FilterDiffuseLighting::render(FilterSlot &slot, Matrix const &trans) {
     int dx = 1; //TODO setup
     int dy = 1; //TODO setup
     //surface scale
-    //TODO for the time being, assumes userSpaceOnUse
+    Matrix trans = units.get_matrix_primitiveunits2pb();
     gdouble ss = surfaceScale * trans[0];
     gdouble kd = diffuseConstant; //diffuse lighting constant
 
@@ -102,9 +108,9 @@ int FilterDiffuseLighting::render(FilterSlot &slot, Matrix const &trans) {
             PointLight *pl = new PointLight(light.point, lighting_color, trans);
             pl->light_components(LC);
         //TODO we need a reference to the filter to determine primitiveUnits
-        //slot._arena_item->filter seems to be ok on simple examples
-        //for now assume userSpaceOnUse
         //if objectBoundingBox is used, use a different matrix for light_vector
+        // UPDATE: trans is now correct matrix from primitiveUnits to
+        // pixblock coordinates
             //finish the work
             for (i = 0, j = 0; i < w*h; i++) {
                 compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
@@ -127,9 +133,9 @@ int FilterDiffuseLighting::render(FilterSlot &slot, Matrix const &trans) {
             {
             SpotLight *sl = new SpotLight(light.spot, lighting_color, trans);
         //TODO we need a reference to the filter to determine primitiveUnits
-        //slot._arena_item->filter seems to be ok on simple examples
-        //for now assume userSpaceOnUse
         //if objectBoundingBox is used, use a different matrix for light_vector
+        // UPDATE: trans is now correct matrix from primitiveUnits to
+        // pixblock coordinates
             //finish the work
             for (i = 0, j = 0; i < w*h; i++) {
                 compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
@@ -164,8 +170,8 @@ int FilterDiffuseLighting::render(FilterSlot &slot, Matrix const &trans) {
         
     //finishing
     slot.set(_output, out);
-    nr_pixblock_release(in);
-    delete in;
+    //nr_pixblock_release(in);
+    //delete in;
     return 0;
 }