summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorFelipe Corr??a da Silva Sanches <juca@members.fsf.org>2007-11-05 07:00:34 +0000
committerjucablues <jucablues@users.sourceforge.net>2007-11-05 07:00:34 +0000
commit84742f7082d08e4338348a4aca1c64f4b34cd93c (patch)
tree0a3ef3e2c9cb752b16b6c1f7a0c272b1212ec19b /src/display
parentnoop: Slight simplification now that we already require gtk >= 2.6 (and indee... (diff)
downloadinkscape-84742f7082d08e4338348a4aca1c64f4b34cd93c.tar.gz
inkscape-84742f7082d08e4338348a4aca1c64f4b34cd93c.zip
partially implemented xlink:href parameter loading. (It still just
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. (bzr r4030)
Diffstat (limited to 'src/display')
-rw-r--r--src/display/nr-filter-image.cpp34
-rw-r--r--src/display/nr-filter-image.h4
2 files changed, 27 insertions, 11 deletions
diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp
index b8abb0317..d96d2013b 100644
--- a/src/display/nr-filter-image.cpp
+++ b/src/display/nr-filter-image.cpp
@@ -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;
diff --git a/src/display/nr-filter-image.h b/src/display/nr-filter-image.h
index 9d4057826..47bfe157b 100644
--- a/src/display/nr-filter-image.h
+++ b/src/display/nr-filter-image.h
@@ -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;
};