nr-filter.cpp revision 55a7b883cd44d9d59767e06d857d9d364f9e996c
#define __NR_FILTER_CPP__
/*
* SVG filters rendering
*
* Author:
* Niko Kiirala <niko@kiirala.com>
*
* Copyright (C) 2006 Niko Kiirala
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <glib.h>
#include <cmath>
#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/pixblock-scaler.h"
#include "display/pixblock-transform.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"
#if defined (SOLARIS_2_8)
#include "round.h"
#endif
__attribute__ ((const))
inline static int _max4(const double a, const double b,
const double c, const double d) {
double ret = a;
}
__attribute__ ((const))
inline static int _min4(const double a, const double b,
const double c, const double d) {
double ret = a;
}
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]) { // if there are no primitives, do nothing
return 0;
}
bool notparaller = false;
// If filter effects region is not paraller to viewport,
// we must first undo the rotation / shear.
// It will be redone after filtering.
// If there is only scaling, let's skip this, as it will not make
// a difference with gaussian blur.
// TODO: This should be done in FilterSlot and for all input images
notparaller = true;
// TODO: if filter resolution is specified, scaling should be set
// according to that
trans *= scaling_inv;
return 0;
} else if (_x_pixels >= 0) {
// If filter resolution is not set to automatic, we should
// scale the input image to correct resolution
/* If filter resolution is zero, the object should not be rendered */
* NR_PIXBLOCK_BPP(pb);
return 0;
}
// Resolution is specified as pixel length of our internal buffer.
// Though, we might not be rendering the whole object at time,
// so we need to calculate the correct pixel size
int x_len = (int)round(((pb->area.x1 - pb->area.x0) * _x_pixels) / (item->bbox.x1 - item->bbox.x0));
// If y-resolution is also set, count y-area in the same way as x-area
// Otherwise, make y-area so, that aspect ratio of input pixblock and
// internal pixblock are the same.
int y_len;
if (_y_pixels > 0) {
} else {
}
return 0;
} else {
// If filter resolution is automatic, just make copy of input image
return 0;
}
for (int i = 0 ; i < _primitive_count ; i++) {
}
// Clear the pixblock, where the output will be put
// -> the original image does not show through
* NR_PIXBLOCK_BPP(pb);
if (notparaller) {
} else if (_x_pixels < 0) {
// If the filter resolution is automatic, just copy our final image
// to output pixblock, otherwise use bicubic scaling
} else {
}
// 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++) {
}
}
{
/* 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");
}
}
/* 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;
}
} /* 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 :