From: jucablues Date: Thu, 26 Jul 2007 03:08:18 +0000 (+0000) Subject: feImage boilerplate code. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7ff3d8615ffd56344e2207fbf34e5c2dfbfe1255;p=inkscape.git feImage boilerplate code. --- diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index f31236674..baeaaec62 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -85,6 +85,8 @@ display_libspdisplay_a_SOURCES = \ display/nr-filter-convolve-matrix.h \ display/nr-filter-displacement-map.cpp \ display/nr-filter-displacement-map.h \ + display/nr-filter-image.cpp \ + display/nr-filter-image.h \ display/nr-filter-slot.cpp \ display/nr-filter-slot.h \ display/nr-filter-getalpha.cpp \ diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp new file mode 100644 index 000000000..62a8caf20 --- /dev/null +++ b/src/display/nr-filter-image.cpp @@ -0,0 +1,86 @@ +/* + * feImage filter primitive renderer + * + * Authors: + * Felipe Corrêa da Silva Sanches + * + * Copyright (C) 2007 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/nr-filter-image.h" +// #include +// #include + +namespace NR { + +FilterImage::FilterImage() +{ +/* Testing with hardcoded xlink:href : + image = Gdk::Pixbuf::create_from_file("/home/felipe/images/image1.jpg"); + //TODO: handle errors + width = image->get_width()+1; + height = image->get_height()+1; + image_pixbuf = image->get_pixels();*/ +} + +FilterPrimitive * FilterImage::create() { + return new FilterImage(); +} + +FilterImage::~FilterImage() +{} + +int FilterImage::render(FilterSlot &slot, Matrix const &trans) { +/* 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 + +After implementing it, add a reference to FilterImage::create + on Filter::_create_constructor_table() (nr-filter.cpp file) +*/ + +/* 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; + + nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true); + + w = x1 - x0; + 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 + } + } + + out->empty = FALSE; + slot.set(_output, out); + return 0;*/ +} + +} /* namespace NR */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-filter-image.h b/src/display/nr-filter-image.h new file mode 100644 index 000000000..cad5d4ee1 --- /dev/null +++ b/src/display/nr-filter-image.h @@ -0,0 +1,47 @@ +#ifndef __NR_FILTER_IMAGE_H__ +#define __NR_FILTER_IMAGE_H__ + +/* + * feImage filter primitive renderer + * + * Authors: + * Niko Kiirala + * + * Copyright (C) 2007 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/nr-filter-primitive.h" +#include "display/nr-filter-slot.h" +#include + +namespace NR { + +class FilterImage : public FilterPrimitive { +public: + FilterImage(); + static FilterPrimitive *create(); + virtual ~FilterImage(); + + virtual int render(FilterSlot &slot, Matrix const &trans); + +private: + guint8* image_pixbuf; + Glib::RefPtr image; + int width, height; +}; + +} /* namespace NR */ + +#endif /* __NR_FILTER_IMAGE_H__ */ +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index 2491fba35..eb6a48e6c 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -29,6 +29,7 @@ #include "display/nr-filter-composite.h" #include "display/nr-filter-diffuselighting.h" #include "display/nr-filter-specularlighting.h" +#include "display/nr-filter-image.h" #include "display/nr-arena-item.h" #include "libnr/nr-pixblock.h" diff --git a/src/sp-feimage.cpp b/src/sp-feimage.cpp index 6c0aa9e4f..810e4b5d7 100644 --- a/src/sp-feimage.cpp +++ b/src/sp-feimage.cpp @@ -6,8 +6,10 @@ */ /* * Authors: + * Felipe Corrêa da Silva Sanches * hugo Rodrigues * + * Copyright (C) 2007 Felipe Sanches * Copyright (C) 2006 Hugo Rodrigues * * Released under GNU GPL, read the file 'COPYING' for more information @@ -21,7 +23,10 @@ #include "svg/svg.h" #include "sp-feimage.h" #include "xml/repr.h" +#include +#include "display/nr-filter.h" +#include "display/nr-filter-image.h" /* FeImage base class */ @@ -33,6 +38,7 @@ static void sp_feImage_release(SPObject *object); static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value); static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter); static SPFilterPrimitiveClass *feImage_parent_class; @@ -61,6 +67,7 @@ static void sp_feImage_class_init(SPFeImageClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *)klass; + SPFilterPrimitiveClass * sp_primitive_class = (SPFilterPrimitiveClass *)klass; feImage_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); @@ -69,6 +76,8 @@ sp_feImage_class_init(SPFeImageClass *klass) sp_object_class->write = sp_feImage_write; sp_object_class->set = sp_feImage_set; sp_object_class->update = sp_feImage_update; + + sp_primitive_class->build_renderer = sp_feImage_build_renderer; } static void @@ -89,6 +98,11 @@ 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 +*/ + } /** @@ -162,6 +176,20 @@ sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) return repr; } +static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) { + g_assert(primitive != NULL); + 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_primitive); + g_assert(nr_image != NULL); + + sp_filter_primitive_renderer_common(primitive, nr_primitive); + +} /* Local Variables: diff --git a/src/sp-feimage.h b/src/sp-feimage.h index cb6f48f40..819eac20e 100644 --- a/src/sp-feimage.h +++ b/src/sp-feimage.h @@ -6,6 +6,7 @@ */ /* * Authors: + * Felipe Corrêa da Silva Sanches * Hugo Rodrigues * * Copyright (C) 2006 Hugo Rodrigues @@ -21,7 +22,11 @@ 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 + */ }; struct SPFeImageClass {