Code

* incomplete feImage implementation.
authorjucablues <jucablues@users.sourceforge.net>
Tue, 14 Aug 2007 04:39:37 +0000 (04:39 +0000)
committerjucablues <jucablues@users.sourceforge.net>
Tue, 14 Aug 2007 04:39:37 +0000 (04:39 +0000)
* contains a hardcoded href parameter. TODO: fix it.
* added a getter method to access arenaitem from FilterSlot.

src/display/nr-filter-image.cpp
src/display/nr-filter-image.h
src/display/nr-filter-slot.cpp
src/display/nr-filter-slot.h
src/display/nr-filter.h
src/sp-feimage.cpp
src/sp-feimage.h

index b1a5b4d7aca4ca0a07954bcdee12bc524d89ede3..8e89cdc81adf5fa77a10dac56f5cde1834b90340 100644 (file)
@@ -8,22 +8,20 @@
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
-
+#include "display/nr-arena-item.h"
+#include "display/nr-filter.h"
 #include "display/nr-filter-image.h"
-// #include <string.h>
-// #include <gtkmm.h>
 
 namespace NR {
 
 FilterImage::FilterImage()
 {
-    g_warning("FilterImage::render not implemented.");
-/* Testing with hardcoded xlink:href :  
-    image = Gdk::Pixbuf::create_from_file("/home/felipe/images/image1.jpg");
+// Testing with hardcoded xlink:href :  
+    image = Gdk::Pixbuf::create_from_file("../images/image1.jpg");
     //TODO: handle errors
     width = image->get_width()+1;
     height = image->get_height()+1;
-    image_pixbuf = image->get_pixels();*/
+    image_pixbuf = image->get_pixels();
 }
 
 FilterPrimitive * FilterImage::create() {
@@ -34,43 +32,48 @@ FilterImage::~FilterImage()
 {}
 
 int FilterImage::render(FilterSlot &slot, Matrix const &trans) {
-    return 0;
-/* TODO: Implement this renderer method.
-        Specification: http://www.w3.org/TR/SVG11/filters.html#feImage
-
-        It would be good to findout how to reuse sp-image.cpp code
-*/
-/*    int w,x,y;
+    int w,x,y;
     NRPixBlock *in = slot.get(_input);
     NRPixBlock *out = new NRPixBlock;
 
     int x0 = in->area.x0, y0 = in->area.y0;
     int x1 = in->area.x1, y1 = in->area.y1;
-    if (x0<0) x0 = 0;
-    if (x1>width-1) x1 = width-1;
-
-    if (y0<0) y0 = 0;
-    if (y1>height-1) y1 = height-1;
+    int bbox_x0 = (int) slot.get_arenaitem()->bbox.x0;
+    int bbox_y0 = (int) slot.get_arenaitem()->bbox.y0;
     
     nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true);
 
     w = x1 - x0;
+    double scaleX = width/feImageWidth;
+    double scaleY = height/feImageHeight;
+    int coordx,coordy;
     unsigned char *out_data = NR_PIXBLOCK_PX(out);
     for (x=x0; x < x1; x++){
         for (y=y0; y < y1; y++){
-            out_data[4*((x - x0)+w*(y - y0))] = (unsigned char) image_pixbuf[3*(x+width*y)]; //Red
-            out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*(x+width*y) + 1]; //Green
-            out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*(x+width*y) + 2]; //Blue
-            out_data[4*((x - x0)+w*(y - y0)) + 3] = 255; //Alpha
+            //TODO: use interpolation
+            coordx = int((x - feImageX - bbox_x0)*scaleX);
+            coordy = int((y - feImageY - bbox_y0)*scaleY);
+
+            if (coordx > 0 && coordx < width && coordy > 0 && coordy < height){
+                out_data[4*((x - x0)+w*(y - y0))] = (unsigned char) image_pixbuf[3*(coordx + width*coordy)]; //Red
+                out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*(coordx + width*coordy) + 1]; //Green
+                out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*(coordx + width*coordy) + 2]; //Blue
+                out_data[4*((x - x0)+w*(y - y0)) + 3] = 255; //Alpha
+            }
         }
     }
 
     out->empty = FALSE;
     slot.set(_output, out);
-    return 0;*/
+    return 0;
 }
-
+void FilterImage::set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height){
+        feImageX=x.computed;
+        feImageY=y.computed;
+        feImageWidth=width.computed;
+        feImageHeight=height.computed;
+}
+    
 } /* namespace NR */
 
 /*
index cad5d4ee12d6126b2ee310b1350be80d2b94d1ca..5841ad86a881b86257ad706c0510bf5012bf2f72 100644 (file)
@@ -25,11 +25,12 @@ public:
     virtual ~FilterImage();
 
     virtual int render(FilterSlot &slot, Matrix const &trans);
-
+    void set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height);
 private:
     guint8* image_pixbuf;
     Glib::RefPtr<Gdk::Pixbuf> image;
     int width, height;
+    float feImageX,feImageY,feImageWidth,feImageHeight;
 };
 
 } /* namespace NR */
index 3cdc20ede9cd554f4a4a66cfc62baaf56e052815..9775a99a7e5f913d173ec7d03dcf9c535d6fbf3c 100644 (file)
@@ -133,6 +133,11 @@ int FilterSlot::get_slot_count()
     return seek + 1;
 }
 
+NRArenaItem const* FilterSlot::get_arenaitem()
+{
+        return _arena_item;
+}
+
 int FilterSlot::_get_index(int slot_nr)
 {
     assert(slot_nr >= 0 ||
index 09190a9b0a105502d76df79a27d76aaea9f26dfc..8c24a36416014382a379548b2081618c218f8f15 100644 (file)
@@ -57,6 +57,9 @@ public:
     /** Returns the number of slots in use. */
     int get_slot_count();
 
+    /** arenaitem getter method*/
+    NRArenaItem const* get_arenaitem();
+
 private:
     NRPixBlock **_slot;
     int *_slot_number;
index 835266e738e4092006a20805b2ba888ffaa99c3f..9f26a1f3b95fa9c3b4933d1701e288d77cac2892 100644 (file)
@@ -77,7 +77,7 @@ public:
      */
     void set_output(int slot);
 
-    void set_x(SVGLength const &lenght);
+    void set_x(SVGLength const &length);
     void set_y(SVGLength const &length);
     void set_width(SVGLength const &length);
     void set_height(SVGLength const &length);
index 810e4b5d77453aee8b25c965c110a62dc9ce4324..4288faa10f685a31830b0ea31811455d03369f77 100644 (file)
@@ -102,6 +102,10 @@ sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re
 since 'in' and 'xlink:href' are common filter attributes.
 --Juca
 */
+    sp_object_read_attr(object, "x");
+    sp_object_read_attr(object, "y");
+    sp_object_read_attr(object, "width");
+    sp_object_read_attr(object, "height");            
 
 }
 
@@ -124,9 +128,25 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
 {
     SPFeImage *feImage = SP_FEIMAGE(object);
     (void)feImage;
-
+    
     switch(key) {
        /*DEAL WITH SETTING ATTRIBUTES HERE*/
+        case SP_ATTR_X:
+            feImage->x.readOrUnset(value);
+            object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
+        case SP_ATTR_Y:
+            feImage->y.readOrUnset(value);
+            object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
+        case SP_ATTR_WIDTH:
+            feImage->width.readOrUnset(value);
+            object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
+        case SP_ATTR_HEIGHT:
+            feImage->height.readOrUnset(value);
+            object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
         default:
             if (((SPObjectClass *) feImage_parent_class)->set)
                 ((SPObjectClass *) feImage_parent_class)->set(object, key, value);
@@ -141,11 +161,11 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
 static void
 sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags)
 {
     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
                  SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
 
         /* do something to trigger redisplay, updates? */
-
     }
 
     if (((SPObjectClass *) feImage_parent_class)->update) {
@@ -181,14 +201,14 @@ static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *
     g_assert(filter != NULL);
 
     SPFeImage *sp_image = SP_FEIMAGE(primitive);
-
+    
     int primitive_n = filter->add_primitive(NR::NR_FILTER_IMAGE);
     NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
     NR::FilterImage *nr_image = dynamic_cast<NR::FilterImage*>(nr_primitive);
     g_assert(nr_image != NULL);
 
     sp_filter_primitive_renderer_common(primitive, nr_primitive);
-
+    nr_image->set_region(sp_image->x, sp_image->y, sp_image->width, sp_image->height);
 }
 
 /*
index 819eac20e5c9b3b99caf09a516a9fc86f2f4145f..6786471ad14fa19e14acfb6c7c1418a28459c9e4 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "sp-filter.h"
 #include "sp-feimage-fns.h"
+#include "svg/svg-length.h"
 
 /* FeImage base class */
 class SPFeImageClass;
@@ -27,6 +28,7 @@ struct SPFeImage : public SPFilterPrimitive {
         since 'in' and 'xlink:href' are common filter attributes.
         --Juca
     */
+    SVGLength x, y, height, width;
 };
 
 struct SPFeImageClass {