summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c019589)
raw | patch | inline | side by side (parent: c019589)
author | jucablues <jucablues@users.sourceforge.net> | |
Wed, 25 Jul 2007 07:12:49 +0000 (07:12 +0000) | ||
committer | jucablues <jucablues@users.sourceforge.net> | |
Wed, 25 Jul 2007 07:12:49 +0000 (07:12 +0000) |
General setting of attributes and default values.
renderer method is still not correct. Needs some more effort.
renderer method is still not correct. Needs some more effort.
src/display/Makefile_insert | patch | blob | history | |
src/display/nr-filter-displacement-map.cpp | [new file with mode: 0644] | patch | blob |
src/display/nr-filter-displacement-map.h | [new file with mode: 0644] | patch | blob |
src/display/nr-filter.cpp | patch | blob | history | |
src/sp-fedisplacementmap.cpp | patch | blob | history | |
src/sp-fedisplacementmap.h | patch | blob | history |
index a72175b3f1a38ff3a2514a3bac727440557fe5c7..f31236674327889c27b25000b1732c7e750a4cdf 100644 (file)
display/nr-filter-composite.cpp \
display/nr-filter-convolve-matrix.cpp \
display/nr-filter-convolve-matrix.h \
+ display/nr-filter-displacement-map.cpp \
+ display/nr-filter-displacement-map.h \
display/nr-filter-slot.cpp \
display/nr-filter-slot.h \
display/nr-filter-getalpha.cpp \
diff --git a/src/display/nr-filter-displacement-map.cpp b/src/display/nr-filter-displacement-map.cpp
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * feDisplacementMap filter primitive renderer
+ *
+ * Authors:
+ * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
+ *
+ * Copyright (C) 2007 authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "display/nr-filter-displacement-map.h"
+#include "display/nr-filter-types.h"
+
+namespace NR {
+
+FilterDisplacementMap::FilterDisplacementMap()
+: Xchannel(3),
+ Ychannel(3),
+ scale(0),
+ _input2(NR_FILTER_SLOT_NOT_SET)
+{}
+
+FilterPrimitive * FilterDisplacementMap::create() {
+ return new FilterDisplacementMap();
+}
+
+FilterDisplacementMap::~FilterDisplacementMap()
+{}
+
+int FilterDisplacementMap::render(FilterSlot &slot, Matrix const &trans) {
+ g_warning("FIX-ME: FilterDisplacementMap::render method is still a bit buggy. Needs Love.");
+
+ NRPixBlock *texture = slot.get(_input);
+ NRPixBlock *map = slot.get(_input2);
+ NRPixBlock *out = new NRPixBlock;
+
+ // Bail out if either one of source images is missing
+ if (!map || !texture) {
+ g_warning("Missing source image for feDisplacementMap (map=%d texture=%d)", _input, _input2);
+ return 1;
+ }
+
+ nr_pixblock_setup_fast(out, map->mode,
+ map->area.x0, map->area.y0, map->area.x1, map->area.y1,
+ true);
+
+ unsigned char *map_data = NR_PIXBLOCK_PX(map);
+ unsigned char *texture_data = NR_PIXBLOCK_PX(texture);
+ unsigned char *out_data = NR_PIXBLOCK_PX(out);
+ int x, y, x0, y0, x1, y1, width;
+ double coordx, coordy;
+
+ x0 = out->area.x0;
+ y0 = out->area.y0;
+ x1 = out->area.x1;
+ y1 = out->area.y1;
+ width = x1 - x0;
+
+ for (x=x0 + scale/2; x < x1 - scale/2; x++){
+ for (y=y0 + scale/2; y < y1 - scale/2; y++){
+ coordx = x-x0 + scale * ( ((double)map_data[4*((x-x0) + width*(y-y0)) + Xchannel])/255 - 0.5);
+ coordy = y-y0 + scale * ( ((double)map_data[4*((x-x0) + width*(y-y0)) + Ychannel])/255 - 0.5);
+
+ out_data[4*((x-x0) + width*(y-y0))] = texture_data[4*(int)(coordx + coordy*width)];
+ out_data[4*((x-x0) + width*(y-y0)) + 1] = texture_data[4*(int)(coordx + coordy*width) + 1];
+ out_data[4*((x-x0) + width*(y-y0)) + 2] = texture_data[4*(int)(coordx + coordy*width) + 2];
+ out_data[4*((x-x0) + width*(y-y0)) + 3] = texture_data[4*(int)(coordx + coordy*width) + 3];
+ }
+ }
+
+ out->empty = FALSE;
+ slot.set(_output, out);
+ return 0;
+}
+
+void FilterDisplacementMap::set_input(int slot) {
+ _input = slot;
+}
+
+void FilterDisplacementMap::set_scale(int s) {
+ scale = s;
+}
+
+void FilterDisplacementMap::set_input(int input, int slot) {
+ if (input == 0) _input = slot;
+ if (input == 1) _input2 = slot;
+}
+
+void FilterDisplacementMap::set_channel_selector(int s, int channel) {
+ if (s == 0) Xchannel = channel;
+ if (s == 1) Ychannel = channel;
+}
+
+void FilterDisplacementMap::area_enlarge(NRRectL &area, Matrix const &trans)
+{
+ //I'm in doubt whether this affects all input buffers or only 'in'
+ area.x0 -= scale/2;
+ area.y0 -= scale/2;
+ area.x1 += scale/2;
+ area.y1 += scale/2;
+}
+
+} /* 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-displacement-map.h b/src/display/nr-filter-displacement-map.h
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef __NR_FILTER_DISPLACEMENT_MAP_H__
+#define __NR_FILTER_DISPLACEMENT_MAP_H__
+
+/*
+ * feDisplacementMap filter primitive renderer
+ *
+ * Authors:
+ * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
+ *
+ * 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 "libnr/nr-matrix.h"
+#include "libnr/nr-rect-l.h"
+
+namespace NR {
+
+class FilterDisplacementMap : public FilterPrimitive {
+public:
+ FilterDisplacementMap();
+ static FilterPrimitive *create();
+ virtual ~FilterDisplacementMap();
+
+ virtual void set_input(int slot);
+ virtual void set_input(int input, int slot);
+ virtual void set_scale(int s);
+ virtual void set_channel_selector(int channel, int s);
+ virtual int render(FilterSlot &slot, Matrix const &trans);
+ virtual void area_enlarge(NRRectL &area, Matrix const &trans);
+
+private:
+ int scale;
+ int _input2;
+ int Xchannel;
+ int Ychannel;
+};
+
+} /* namespace NR */
+
+#endif /* __NR_FILTER_DISPLACEMENT_MAP_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 :
index 47b05d0b89797f53392184b294c3242f64281c1c..2491fba35aa0d35d5c168f7bcf927299b8641a11 100644 (file)
#include "display/pixblock-scaler.h"
#include "display/pixblock-transform.h"
+#include "display/nr-filter-displacement-map.h"
#include "display/nr-filter-gaussian.h"
#include "display/nr-filter-convolve-matrix.h"
#include "display/nr-filter-blend.h"
_constructor[NR_FILTER_COMPOSITE] = &FilterComposite::create;
_constructor[NR_FILTER_CONVOLVEMATRIX] = &FilterConvolveMatrix::create;
_constructor[NR_FILTER_DIFFUSELIGHTING] = &FilterDiffuseLighting::create;
- _constructor[NR_FILTER_DISPLACEMENTMAP] = NULL;
+ _constructor[NR_FILTER_DISPLACEMENTMAP] = &FilterDisplacementMap::create;
_constructor[NR_FILTER_FLOOD] = NULL;
_constructor[NR_FILTER_GAUSSIANBLUR] = &FilterGaussian::create;
_constructor[NR_FILTER_IMAGE] = NULL;
index 8b861b85daaba97f4dda59acf6b1a11b5165c01b..6c606f6bf97caaa9f15627cece28d660fb16f808 100644 (file)
#include "svg/svg.h"
#include "sp-fedisplacementmap.h"
#include "xml/repr.h"
-
+#include "display/nr-filter-displacement-map.h"
/* FeDisplacementMap base class */
static void sp_feDisplacementMap_release(SPObject *object);
static void sp_feDisplacementMap_set(SPObject *object, unsigned int key, gchar const *value);
static void sp_feDisplacementMap_update(SPObject *object, SPCtx *ctx, guint flags);
+static void sp_feDisplacementMap_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
static Inkscape::XML::Node *sp_feDisplacementMap_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
static SPFilterPrimitiveClass *feDisplacementMap_parent_class;
sp_feDisplacementMap_class_init(SPFeDisplacementMapClass *klass)
{
SPObjectClass *sp_object_class = (SPObjectClass *)klass;
+ SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
feDisplacementMap_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
sp_object_class->write = sp_feDisplacementMap_write;
sp_object_class->set = sp_feDisplacementMap_set;
sp_object_class->update = sp_feDisplacementMap_update;
+ sp_primitive_class->build_renderer = sp_feDisplacementMap_build_renderer;
}
static void
sp_feDisplacementMap_init(SPFeDisplacementMap *feDisplacementMap)
{
+ feDisplacementMap->scale=0;
+ feDisplacementMap->xChannelSelector=3;
+ feDisplacementMap->yChannelSelector=3;
+ feDisplacementMap->in2 = NR::NR_FILTER_SLOT_NOT_SET;
}
/**
}
/*LOAD ATTRIBUTES FROM REPR HERE*/
+ sp_object_read_attr(object, "scale");
+ sp_object_read_attr(object, "in2");
+ sp_object_read_attr(object, "xChannelSelector");
+ sp_object_read_attr(object, "yChannelSelector");
}
/**
((SPObjectClass *) feDisplacementMap_parent_class)->release(object);
}
+static int sp_feDisplacementMap_readChannelSelector(gchar const *value)
+{
+ if (!value) return 0;
+ switch (value[0]) {
+ case 'R':
+ return 0;
+ break;
+ case 'G':
+ return 1;
+ break;
+ case 'B':
+ return 2;
+ break;
+ case 'A':
+ return 3;
+ break;
+ default:
+ // error
+ g_warning("Invalid attribute for Channel Selector. Valid modes are 'R', 'G', 'B' or 'A'");
+ break;
+ }
+ return 3; //default is Alpha Channel
+}
+
+static double
+sp_feDisplacementMap_read_number(gchar const *value) {
+ if (!value) return 0;
+ char *end;
+ double ret = g_ascii_strtod(value, &end);
+ if (*end) {
+ g_warning("Unable to convert \"%s\" to number", value);
+ // We could leave this out, too. If strtod can't convert
+ // anything, it will return zero.
+ ret = 0;
+ }
+ return ret;
+}
+
/**
* Sets a specific value in the SPFeDisplacementMap.
*/
@@ -109,9 +158,39 @@ sp_feDisplacementMap_set(SPObject *object, unsigned int key, gchar const *value)
{
SPFeDisplacementMap *feDisplacementMap = SP_FEDISPLACEMENTMAP(object);
(void)feDisplacementMap;
-
+ int input;
+ double read_num;
+ int read_selector;
switch(key) {
/*DEAL WITH SETTING ATTRIBUTES HERE*/
+ case SP_ATTR_XCHANNELSELECTOR:
+ read_selector = sp_feDisplacementMap_readChannelSelector(value);
+ if (read_selector != feDisplacementMap->xChannelSelector){
+ feDisplacementMap->xChannelSelector = read_selector;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
+ case SP_ATTR_YCHANNELSELECTOR:
+ read_selector = sp_feDisplacementMap_readChannelSelector(value);
+ if (read_selector != feDisplacementMap->yChannelSelector){
+ feDisplacementMap->yChannelSelector = read_selector;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
+ case SP_ATTR_SCALE:
+ read_num = sp_feDisplacementMap_read_number(value);
+ if (read_num != feDisplacementMap->scale) {
+ feDisplacementMap->scale = read_num;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
+ case SP_ATTR_IN2:
+ input = sp_filter_primitive_read_in(feDisplacementMap, value);
+ if (input != feDisplacementMap->in2) {
+ feDisplacementMap->in2 = input;
+ object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ break;
default:
if (((SPObjectClass *) feDisplacementMap_parent_class)->set)
((SPObjectClass *) feDisplacementMap_parent_class)->set(object, key, value);
@@ -161,6 +240,25 @@ sp_feDisplacementMap_write(SPObject *object, Inkscape::XML::Node *repr, guint fl
return repr;
}
+static void sp_feDisplacementMap_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
+ g_assert(primitive != NULL);
+ g_assert(filter != NULL);
+
+ SPFeDisplacementMap *sp_displacement_map = SP_FEDISPLACEMENTMAP(primitive);
+
+ int primitive_n = filter->add_primitive(NR::NR_FILTER_DISPLACEMENTMAP);
+ NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
+ NR::FilterDisplacementMap *nr_displacement_map = dynamic_cast<NR::FilterDisplacementMap*>(nr_primitive);
+ g_assert(nr_displacement_map != NULL);
+
+ sp_filter_primitive_renderer_common(primitive, nr_primitive);
+
+ nr_displacement_map->set_input(1, sp_displacement_map->in2);
+ nr_displacement_map->set_scale(sp_displacement_map->scale);
+ nr_displacement_map->set_channel_selector(0, sp_displacement_map->xChannelSelector);
+ nr_displacement_map->set_channel_selector(1, sp_displacement_map->yChannelSelector);
+}
+
/*
Local Variables:
index 1e4eb284584ba2731aabe61899252db918966182..427bce1538661d39c84174eeb07f17061080ee68 100644 (file)
struct SPFeDisplacementMap : public SPFilterPrimitive {
/** DISPLACEMENTMAP ATTRIBUTES HERE */
-
+ int in2;
+ double scale;
+ int xChannelSelector;
+ int yChannelSelector;
};
struct SPFeDisplacementMapClass {