36a048753a41b465ae130b361fb3b68c605e3e86kiirala/*
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * SVG filters rendering
36a048753a41b465ae130b361fb3b68c605e3e86kiirala *
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Author:
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Niko Kiirala <niko@kiirala.com>
36a048753a41b465ae130b361fb3b68c605e3e86kiirala *
fb86717633bfcfe161571aed7058ea6a39b7a69bkiirala * Copyright (C) 2006-2007 Niko Kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala *
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Released under GNU GPL, read the file 'COPYING' for more information
36a048753a41b465ae130b361fb3b68c605e3e86kiirala */
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosiński#ifndef SEEN_NR_FILTER_PRIMITIVE_H
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosiński#define SEEN_NR_FILTER_PRIMITIVE_H
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosiński#include <2geom/forward.h>
7bda77e763c0af49270427593108b66455dfd125Krzysztof Kosinski#include <2geom/rect.h>
7f18e8ab01ce21c98cc7b9f58ffe5e771ebbb64eLiam P. White
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński#include "display/nr-filter-types.h"
36a048753a41b465ae130b361fb3b68c605e3e86kiirala#include "svg/svg-length.h"
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
5c40454c286013e02d9ea7521a3bdaf72bea39d9tavmjong-freeclass SPStyle;
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free
d9a7c806ee7f408ddb61ff4f233c9d96111ee2b5johanengelennamespace Inkscape {
d9a7c806ee7f408ddb61ff4f233c9d96111ee2b5johanengelennamespace Filters {
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosińskiclass FilterSlot;
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosińskiclass FilterUnits;
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosiński
36a048753a41b465ae130b361fb3b68c605e3e86kiiralaclass FilterPrimitive {
36a048753a41b465ae130b361fb3b68c605e3e86kiiralapublic:
36a048753a41b465ae130b361fb3b68c605e3e86kiirala FilterPrimitive();
a72861cd83f11ef8b1247abca181a3ad31df0307kiirala virtual ~FilterPrimitive();
a72861cd83f11ef8b1247abca181a3ad31df0307kiirala
4d2111f1991274cf80f89219637fca969697e661Krzysztof Kosiński virtual void render_cairo(FilterSlot &slot);
7f18e8ab01ce21c98cc7b9f58ffe5e771ebbb64eLiam P. White virtual int render(FilterSlot & /*slot*/, FilterUnits const & /*units*/) { return 0; } // pure virtual?
7bda77e763c0af49270427593108b66455dfd125Krzysztof Kosinski virtual void area_enlarge(Geom::IntRect &area, Geom::Affine const &m);
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala /**
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Sets the input slot number 'slot' to be used as input in rendering
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * filter primitive 'primitive'
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * For filter primitive types accepting more than one input, this sets the
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * first input.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * If any of the required input slots is not set, the output of previous
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * filter primitive is used, or SourceGraphic if this is the first
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * primitive for this filter.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala */
36a048753a41b465ae130b361fb3b68c605e3e86kiirala virtual void set_input(int slot);
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala /**
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Sets the input slot number 'slot' to be user as input number 'input' in
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * rendering filter primitive 'primitive'
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * First input for a filter primitive is number 0. For primitives with
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * attributes 'in' and 'in2', these are numbered 0 and 1, respectively.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * If any of required input slots for a filter is not set, the output of
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * previous filter primitive is used, or SourceGraphic if this is the first
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * filter primitive for this filter.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala */
36a048753a41b465ae130b361fb3b68c605e3e86kiirala virtual void set_input(int input, int slot);
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala /**
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Sets the slot number 'slot' to be used as output from filter primitive
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * 'primitive'
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * If output slot for a filter element is not set, one of the unused image
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * slots is used.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * It is an error to specify a pre-defined slot as 'slot'. Such call does
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * not have any effect to the state of filter or its primitives.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala */
36a048753a41b465ae130b361fb3b68c605e3e86kiirala virtual void set_output(int slot);
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
1cf2607271f83cc4b20ccace552395d793055c90Krzysztof Kosiński // returns cache score factor, reflecting the cost of rendering this filter
1cf2607271f83cc4b20ccace552395d793055c90Krzysztof Kosiński // this should return how many times slower this primitive is that normal rendering
1cf2607271f83cc4b20ccace552395d793055c90Krzysztof Kosiński virtual double complexity(Geom::Affine const &/*ctm*/) { return 1.0; }
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński virtual bool uses_background() {
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński if (_input == NR_FILTER_BACKGROUNDIMAGE || _input == NR_FILTER_BACKGROUNDALPHA) {
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński return true;
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński } else {
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński return false;
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński }
d1eeafe871c5909edd05ee72dfa603533ad39a87Krzysztof Kosiński }
1cf2607271f83cc4b20ccace552395d793055c90Krzysztof Kosiński
36a048753a41b465ae130b361fb3b68c605e3e86kiirala /**
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Sets the filter primitive subregion. Passing an unset length
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free * (length._set == false) WILL change the parameter as it is
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free * important to know if a parameter is unset.
36a048753a41b465ae130b361fb3b68c605e3e86kiirala */
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free void set_x(SVGLength const &length);
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free void set_y(SVGLength const &length);
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free void set_width(SVGLength const &length);
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free void set_height(SVGLength const &length);
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free void set_subregion(SVGLength const &x, SVGLength const &y,
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free SVGLength const &width, SVGLength const &height);
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala /**
36a048753a41b465ae130b361fb3b68c605e3e86kiirala * Resets the filter primitive subregion to its default value
36a048753a41b465ae130b361fb3b68c605e3e86kiirala */
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free void reset_subregion(); // Not implemented
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free /**
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free * Returns the filter primitive area in user coordinate system.
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free */
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free Geom::Rect filter_primitive_area(FilterUnits const &units);
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
712a383b4aa88de4041f1d6247719e2c3a5800d8Jon A. Cruz /**
712a383b4aa88de4041f1d6247719e2c3a5800d8Jon A. Cruz *Indicate whether the filter primitive can handle the given affine.
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński *
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński * Results of some filter primitives depend on the coordinate system used when rendering.
8635140fb4734dae6ae5f42e1db9778749ef024aKrzysztof Kosiński * A gaussian blur with equal x and y deviation will remain unchanged by rotations.
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński * Per-pixel filters like color matrix and blend will not change regardless of
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński * the transformation.
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński *
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński * When any filter returns false, filter rendering is performed on an intermediate surface
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński * with edges parallel to the axes of the user coordinate system. This means
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński * the matrices from FilterUnits will contain at most a (possibly non-uniform) scale
1cf2607271f83cc4b20ccace552395d793055c90Krzysztof Kosiński * and a translation. When all primitives of the filter return true, the rendering is
712a383b4aa88de4041f1d6247719e2c3a5800d8Jon A. Cruz * performed in display coordinate space and no intermediate surface is used.
712a383b4aa88de4041f1d6247719e2c3a5800d8Jon A. Cruz */
dff9bb0d25ad38c515c32e2c76a20e747c8eed10Krzysztof Kosiński virtual bool can_handle_affine(Geom::Affine const &) { return false; }
7059798b454ecd2386eb02769ad8d9c6d9d5f98eKrzysztof Kosiński
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free /**
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free * Sets style for access to properties used by filter primitives.
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free */
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free void setStyle(SPStyle *style);
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free
36a048753a41b465ae130b361fb3b68c605e3e86kiiralaprotected:
36a048753a41b465ae130b361fb3b68c605e3e86kiirala int _input;
36a048753a41b465ae130b361fb3b68c605e3e86kiirala int _output;
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free /* Filter primitive subregion */
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free SVGLength _subregion_x;
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free SVGLength _subregion_y;
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free SVGLength _subregion_width;
7c89b734639fa72a5d2ffdc9cf1f7ab22eff67f1tavmjong-free SVGLength _subregion_height;
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free
9f6f7e74a1ded383518676e0ecb2ccc5caa73d25tavmjong-free SPStyle *_style;
36a048753a41b465ae130b361fb3b68c605e3e86kiirala};
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
d9a7c806ee7f408ddb61ff4f233c9d96111ee2b5johanengelen} /* namespace Filters */
d9a7c806ee7f408ddb61ff4f233c9d96111ee2b5johanengelen} /* namespace Inkscape */
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala
36a048753a41b465ae130b361fb3b68c605e3e86kiirala#endif /* __NR_FILTER_PRIMITIVE_H__ */
36a048753a41b465ae130b361fb3b68c605e3e86kiirala/*
36a048753a41b465ae130b361fb3b68c605e3e86kiirala Local Variables:
36a048753a41b465ae130b361fb3b68c605e3e86kiirala mode:c++
36a048753a41b465ae130b361fb3b68c605e3e86kiirala c-file-style:"stroustrup"
36a048753a41b465ae130b361fb3b68c605e3e86kiirala c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
36a048753a41b465ae130b361fb3b68c605e3e86kiirala indent-tabs-mode:nil
36a048753a41b465ae130b361fb3b68c605e3e86kiirala fill-column:99
36a048753a41b465ae130b361fb3b68c605e3e86kiirala End:
36a048753a41b465ae130b361fb3b68c605e3e86kiirala*/
a4030d5ca449e7e384bc699cd249ee704faaeab0Chris Morgan// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :