Code

partially implemented xlink:href parameter loading. (It still just
authorjucablues <jucablues@users.sourceforge.net>
Mon, 5 Nov 2007 07:00:34 +0000 (07:00 +0000)
committerjucablues <jucablues@users.sourceforge.net>
Mon, 5 Nov 2007 07:00:34 +0000 (07:00 +0000)
works for filenames.) Removed a hardcoded string.

This part of the code must be improved in order to reference other
pieces of SVG. I need somebody to help me on working with proper URI
handling!

Also fixed gdk pixbuf handling.

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

index b8abb0317f0eefead705016fd88437c3d39cf2b7..d96d2013b9dce6160fe3d8efac4570d160b85c56 100644 (file)
@@ -17,12 +17,8 @@ namespace NR {
 
 FilterImage::FilterImage()
 {
-// 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();
+    feImageHref=NULL;
+    image_pixbuf=NULL;
 }
 
 FilterPrimitive * FilterImage::create() {
@@ -30,9 +26,21 @@ FilterPrimitive * FilterImage::create() {
 }
 
 FilterImage::~FilterImage()
-{}
+{
+        if (feImageHref) g_free(feImageHref);
+        if (image_pixbuf) g_free(image_pixbuf);
+}
 
 int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
+    if  (!feImageHref) return 0;
+    
+    if (!image_pixbuf){
+            if ( (image = Gdk::Pixbuf::create_from_file(feImageHref)) < 0 ) return 0;
+            width = image->get_width();
+            height = image->get_height();
+            rowstride = image->get_rowstride();
+            image_pixbuf = image->get_pixels();
+    }
     int w,x,y;
     NRPixBlock *in = slot.get(_input);
     NRPixBlock *out = new NRPixBlock;
@@ -56,9 +64,9 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
             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))] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy]; //Red
+                out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 1]; //Green
+                out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 2]; //Blue
                 out_data[4*((x - x0)+w*(y - y0)) + 3] = 255; //Alpha
             }
         }
@@ -68,6 +76,12 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
     slot.set(_output, out);
     return 0;
 }
+
+void FilterImage::set_href(const gchar *href){
+    if (feImageHref) g_free (feImageHref);
+    feImageHref = (href) ? g_strdup (href) : NULL;
+}
+
 void FilterImage::set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height){
         feImageX=x.computed;
         feImageY=y.computed;
index 9d4057826de38f04f17b8154233017e8300624ef..47bfe157b8f4acce6f8540858f22623c17e96a2c 100644 (file)
@@ -27,11 +27,13 @@ public:
 
     virtual int render(FilterSlot &slot, FilterUnits const &units);
     virtual FilterTraits get_input_traits();
+    void set_href(const gchar *href);
     void set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height);
 private:
+    gchar *feImageHref;
     guint8* image_pixbuf;
     Glib::RefPtr<Gdk::Pixbuf> image;
-    int width, height;
+    int width, height, rowstride;
     float feImageX,feImageY,feImageWidth,feImageHeight;
 };
 
index a360151803d7cbbec92b8e6e938a4318b31afea9..9456b5966928a5c9fe752b281e7ce7c9b41bdb73 100644 (file)
@@ -98,14 +98,12 @@ sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re
     }
 
     /*LOAD ATTRIBUTES FROM REPR HERE*/
-/* apparently there's no attribute to load here
-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");
+    sp_object_read_attr(object, "xlink:href");
 
 }
 
@@ -131,6 +129,11 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
 
     switch(key) {
        /*DEAL WITH SETTING ATTRIBUTES HERE*/
+       case SP_ATTR_XLINK_HREF:
+           if (feImage->href) g_free(feImage->href);
+           feImage->href = (value) ? g_strdup (value) : NULL;
+           object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
         case SP_ATTR_X:
             feImage->x.readOrUnset(value);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
@@ -209,6 +212,7 @@ static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *
 
     sp_filter_primitive_renderer_common(primitive, nr_primitive);
     nr_image->set_region(sp_image->x, sp_image->y, sp_image->width, sp_image->height);
+    nr_image->set_href(sp_image->href);
 }
 
 /*
index 6786471ad14fa19e14acfb6c7c1418a28459c9e4..0c0289d6e5196da77f2639d421ee3b8bc380a975 100644 (file)
@@ -23,11 +23,7 @@ class SPFeImageClass;
 
 struct SPFeImage : public SPFilterPrimitive {
     /** IMAGE ATTRIBUTES HERE */
-    /*
-        Apparently there's no attribute to keep here 
-        since 'in' and 'xlink:href' are common filter attributes.
-        --Juca
-    */
+    gchar *href;
     SVGLength x, y, height, width;
 };