convolvematrix.cpp revision fb5a7ba023a314d8b8085d95e10eac8f4da17172
#define __SP_FECONVOLVEMATRIX_CPP__
/** \file
* SVG <feConvolveMatrix> implementation.
*
*/
/*
* Authors:
* Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
* hugo Rodrigues <haa.rodrigues@gmail.com>
*
* Copyright (C) 2006 Hugo Rodrigues
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <vector>
#include "attributes.h"
#include "convolvematrix.h"
#include "helper-fns.h"
#include "display/nr-filter-convolve-matrix.h"
#include <math.h>
/* FeConvolveMatrix base class */
static void sp_feConvolveMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
static Inkscape::XML::Node *sp_feConvolveMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static void sp_feConvolveMatrix_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter);
{
static GType feConvolveMatrix_type = 0;
if (!feConvolveMatrix_type) {
sizeof(SPFeConvolveMatrixClass),
sizeof(SPFeConvolveMatrix),
16,
NULL, /* value_table */
};
feConvolveMatrix_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeConvolveMatrix", &feConvolveMatrix_info, (GTypeFlags)0);
}
return feConvolveMatrix_type;
}
static void
{
}
static void
{
//Setting default values:
feConvolveMatrix->preserveAlpha = false;
//some helper variables:
feConvolveMatrix->targetXIsSet = false;
feConvolveMatrix->targetYIsSet = false;
feConvolveMatrix->kernelMatrixIsSet = false;
}
/**
* Reads the Inkscape::XML::Node, and initializes SPFeConvolveMatrix variables. For this to get called,
* our name must be associated with a repr via "sp_object_type_register". Best done through
* sp-object-repr.cpp's repr_name_entries array.
*/
static void
{
}
/*LOAD ATTRIBUTES FROM REPR HERE*/
}
/**
* Drops any allocated memory.
*/
static void
{
}
static Inkscape::Filters::FilterConvolveMatrixEdgeMode sp_feConvolveMatrix_read_edgeMode(gchar const *value){
switch(value[0]){
case 'd':
if (strncmp(value, "duplicate", 9) == 0) return Inkscape::Filters::CONVOLVEMATRIX_EDGEMODE_DUPLICATE;
break;
case 'w':
break;
case 'n':
break;
}
}
/**
* Sets a specific value in the SPFeConvolveMatrix.
*/
static void
{
(void)feConvolveMatrix;
double read_num;
int read_int;
bool read_bool;
switch(key) {
/*DEAL WITH SETTING ATTRIBUTES HERE*/
case SP_ATTR_ORDER:
//From SVG spec: If <orderY> is not provided, it defaults to <orderX>.
if (feConvolveMatrix->targetXIsSet == false) feConvolveMatrix->targetX = (int) floor(feConvolveMatrix->order.getNumber()/2);
if (feConvolveMatrix->targetYIsSet == false) feConvolveMatrix->targetY = (int) floor(feConvolveMatrix->order.getOptNumber()/2);
break;
case SP_ATTR_KERNELMATRIX:
if (value){
feConvolveMatrix->kernelMatrixIsSet = true;
feConvolveMatrix->kernelMatrix = helperfns_read_vector(value, (int) (feConvolveMatrix->order.getNumber() * feConvolveMatrix->order.getOptNumber()));
if (! feConvolveMatrix->divisorIsSet) {
feConvolveMatrix->divisor = 0;
}
} else {
g_warning("For feConvolveMatrix you MUST pass a kernelMatrix parameter!");
}
break;
case SP_ATTR_DIVISOR:
if (value) {
if (read_num == 0) {
// This should actually be an error, but given our UI it is more useful to simply set divisor to the default.
if (feConvolveMatrix->kernelMatrixIsSet) {
}
feConvolveMatrix->divisorIsSet = false;
}
feConvolveMatrix->divisorIsSet = true;
}
}
break;
case SP_ATTR_BIAS:
read_num = 0;
}
break;
case SP_ATTR_TARGETX:
if (value) {
g_warning("targetX must be a value between 0 and orderX! Assuming floor(orderX/2) as default value.");
}
feConvolveMatrix->targetXIsSet = true;
}
}
break;
case SP_ATTR_TARGETY:
if (value) {
g_warning("targetY must be a value between 0 and orderY! Assuming floor(orderY/2) as default value.");
}
feConvolveMatrix->targetYIsSet = true;
}
}
break;
case SP_ATTR_EDGEMODE:
}
break;
case SP_ATTR_KERNELUNITLENGTH:
//From SVG spec: If the <dy> value is not specified, it defaults to the same value as <dx>.
break;
case SP_ATTR_PRESERVEALPHA:
}
break;
default:
break;
}
}
/**
* Receives update notifications.
*/
static void
{
/* do something to trigger redisplay, updates? */
}
}
}
/**
* Writes its settings to an incoming repr object, if any.
*/
sp_feConvolveMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
{
// Inkscape-only object, not copied during an "plain SVG" dump:
if (flags & SP_OBJECT_WRITE_EXT) {
if (repr) {
// is this sane?
//repr->mergeFrom(SP_OBJECT_REPR(object), "id");
} else {
}
}
}
return repr;
}
static void sp_feConvolveMatrix_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter) {
Inkscape::Filters::FilterConvolveMatrix *nr_convolve = dynamic_cast<Inkscape::Filters::FilterConvolveMatrix*>(nr_primitive);
}
/*
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 :