nr-filter.cpp revision 6c3e745a94ef6b25a4ef9f018d350a7535aa45af
#define __NR_FILTER_CPP__
/*
* SVG filters rendering
*
* Author:
* Niko Kiirala <niko@kiirala.com>
*
* Copyright (C) 2006,2007 Niko Kiirala
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <glib.h>
#include <cmath>
#include <cstring>
#include <string>
#include "display/nr-filter.h"
#include "display/nr-filter-primitive.h"
#include "display/nr-filter-slot.h"
#include "display/nr-filter-types.h"
#include "display/nr-filter-units.h"
#include "display/nr-filter-blend.h"
#include "display/nr-filter-composite.h"
#include "display/nr-filter-convolve-matrix.h"
#include "display/nr-filter-colormatrix.h"
#include "display/nr-filter-component-transfer.h"
#include "display/nr-filter-diffuselighting.h"
#include "display/nr-filter-displacement-map.h"
#include "display/nr-filter-flood.h"
#include "display/nr-filter-gaussian.h"
#include "display/nr-filter-image.h"
#include "display/nr-filter-merge.h"
#include "display/nr-filter-morphology.h"
#include "display/nr-filter-offset.h"
#include "display/nr-filter-specularlighting.h"
#include "display/nr-filter-tile.h"
#include "display/nr-filter-turbulence.h"
#include "display/nr-arena-item.h"
#include "libnr/nr-pixblock.h"
#include "libnr/nr-matrix.h"
#include "libnr/nr-scale.h"
#include "svg/svg-length.h"
#include "sp-filter-units.h"
#include "preferences.h"
#include "round.h"
#endif
namespace NR {
{
_primitive_count = 0;
_primitive[0] = NULL;
//_primitive_count = 1;
//_primitive[0] = new FilterGaussian;
_common_init();
}
{
_primitive_count = 0;
_primitive = new FilterPrimitive*[n];
for ( int i = 0 ; i < n ; i++ ) {
_primitive[i] = NULL;
}
_common_init();
}
void Filter::_common_init() {
_slot_count = 1;
// Having "not set" here as value means the output of last filter
// primitive will be used as output of this filter
// These are the default values for filter region,
// as specified in SVG standard
// NB: SVGLength.set takes prescaled percent values: -.10 means -10%
// Filter resolution, negative value here stands for "automatic"
_x_pixels = -1.0;
_y_pixels = -1.0;
}
{
delete[] _primitive;
}
{
if (!_primitive[0]) {
// TODO: Should clear the input buffer instead of just returning
return 1;
}
} else {
// Bounding box might not exist, so create a dummy one.
}
{
// Code below assumes non-negative size.
return 1;
}
if (item_bbox.hasZeroArea()) {
// It's no use to try and filter an empty object.
return 1;
}
// TODO: with filterRes of 0x0 should return an empty image
if (_x_pixels > 0) {
double y_len;
if (_y_pixels > 0) {
} else {
}
units.set_automatic_resolution(false);
} else {
units.set_automatic_resolution(true);
}
units.set_paraller(false);
for (int i = 0 ; i < _primitive_count ; i++) {
units.set_paraller(true);
break;
}
}
g_warning("NR::Filter::render: failed to reserve temporary buffer");
return 0;
}
// Check that we are rendering a non-empty area
g_warning("NR::Filter::render: negative area! (%d, %d) (%d, %d)",
}
return 0;
}
for (int i = 0 ; i < _primitive_count ; i++) {
}
// Take note of the amount of used image slots
// -> next time this filter is rendered, we can reserve enough slots
// immediately
return 0;
}
for (int i = 0 ; i < _primitive_count ; i++) {
}
}
// Modifying empty bounding boxes confuses rest of the renderer, so
// let's not do that.
/* TODO: this is wrong. Should use bounding box in user coordinates
* and find its extents in display coordinates. */
}
{
/* TODO: fetch somehow the object ex and em lengths */
} else {
}
} else {
}
} else {
}
} else {
}
} else if (_filter_units == SP_FILTER_UNITS_USERSPACEONUSE) {
/* TODO: make sure bbox and fe region are in same coordinate system */
} else {
g_warning("Error in NR::Filter::bbox_enlarge: unrecognized value of _filter_units");
}
return area;
}
/* Constructor table holds pointers to static methods returning filter
* primitives. This table is indexed with FilterPrimitiveType, so that
* for example method in _constructor[NR_FILTER_GAUSSIANBLUR]
* returns a filter object of type NR::FilterGaussian.
*/
typedef FilterPrimitive*(*FilterConstructor)();
void Filter::_create_constructor_table()
{
// Constructor table won't change in run-time, so no need to recreate
static bool created = false;
if(created) return;
/* Some filter classes are not implemented yet.
Some of them still have only boilerplate code.*/
created = true;
}
/** Helper method for enlarging table of filter primitives. When new
* primitives are added, but we have no space for them, this function
* makes some more space.
*/
void Filter::_enlarge_primitive_table() {
for (int i = 0 ; i < _primitive_count ; i++) {
new_tbl[i] = _primitive[i];
}
_primitive_table_size *= 2;
for (int i = _primitive_count ; i < _primitive_table_size ; i++) {
}
delete[] _primitive;
}
{
// Check that we can create a new filter of specified type
return -1;
// If there is no space for new filter primitive, enlarge the table
if (_primitive_count >= _primitive_table_size) {
}
int handle = _primitive_count;
return handle;
}
{
// Check that target is valid primitive inside this filter
if (target < 0) return -1;
// Check that we can create a new filter of specified type
return -1;
// If there is no space for new filter primitive, enlarge the table
if (_primitive_count >= _primitive_table_size) {
}
delete _primitive[target];
return target;
}
return _primitive[handle];
}
void Filter::clear_primitives()
{
for (int i = 0 ; i < _primitive_count ; i++) {
if (_primitive[i]) delete _primitive[i];
}
_primitive_count = 0;
}
{
}
{
}
{
}
{
}
if (pixels > 0) {
}
}
}
}
void Filter::reset_resolution() {
_x_pixels = -1;
_y_pixels = -1;
}
double divisor = 1;
switch (quality) {
case FILTER_QUALITY_WORST:
divisor = 8;
break;
case FILTER_QUALITY_WORSE:
divisor = 4;
break;
case FILTER_QUALITY_NORMAL:
divisor = 2;
break;
case FILTER_QUALITY_BETTER:
case FILTER_QUALITY_BEST:
default:
break;
}
return divisor;
}
} /* 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 :