Difference between revisions of "Filter Effects"

From Inkscape Wiki
Jump to: navigation, search
(Status of filter primitives in trunk)
(Status of the filter primitives: Updated some notes)
Line 53: Line 53:
 
|-
 
|-
 
! [http://www.w3.org/TR/SVG11/filters.html#feGaussianBlurElement feGaussianBlur]
 
! [http://www.w3.org/TR/SVG11/filters.html#feGaussianBlurElement feGaussianBlur]
|style="background-color:#ddffbb;"| '''Implemented''' - bugs: [http://sourceforge.net/tracker/index.php?func=detail&aid=1760156&group_id=93438&atid=604306 ]
+
|style="background-color:#aaffbb;"| '''Implemented'''
 
|style="background-color:#ddffbb;"| '''Implemented''' - bugs: [http://sourceforge.net/tracker/index.php?func=detail&aid=1760161&group_id=93438&atid=604306]
 
|style="background-color:#ddffbb;"| '''Implemented''' - bugs: [http://sourceforge.net/tracker/index.php?func=detail&aid=1760161&group_id=93438&atid=604306]
 
|-
 
|-
Line 81: Line 81:
 
|-
 
|-
 
! [http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement feTurbulence]
 
! [http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement feTurbulence]
|style="background-color:#ffffbb;"| '''Work in progress''' - see [http://fedev.blogspot.com/2007/07/i-can-has-turbulence.html],[http://fedev.blogspot.com/2007/07/introducing-fecomposite.html]
+
|style="background-color:#ffffbb;"| '''Work in progress''' - see [http://fedev.blogspot.com/2007/07/i-can-has-turbulence.html],[http://fedev.blogspot.com/2007/07/introducing-fecomposite.html],[http://article.gmane.org/gmane.comp.graphics.inkscape.devel/21525]
 
|style="background-color:#ffbbbb;"| '''Not implemented'''
 
|style="background-color:#ffbbbb;"| '''Not implemented'''
 
|-
 
|-
 
|}
 
|}
 +
 
=== general bugs ===
 
=== general bugs ===
  

Revision as of 11:07, 25 July 2007

Filter effects is a part of SVG specification and worked on in Inkscape as part of Googles_Summer_Of_Code 2006 and COSS's Kesäkoodi 2007

For more info on this Kesäkoodi project, see the project blog or the project plan.

Also, there is an accepted proposal in GSoC 2007 for implementing the user interface for filter effects.

What works in Inkscape 0.45

Basic support for filter effects is included in 0.45 release. At the moment only gaussian blur is implemented, so while specifications define a bunch of other effects and some other programs can handle them, Inkscape cannot render them yet. Also, tools for editing other types of filters do not exist yet.

Gaussian blur can be applied to an object by using Blur slider in Fill and stroke dialog.

In Inkscape preferences dialog there is a setting controlling the filter rendering quality. Even low quality often produces good enough rendering quality, but it takes a lot less time to render. When exporting an image from Inkscape, the best quality is always used, regardless of this setting.

Filter Effect support in trunk

Status of the filter primitives

primitive renderer user interface
feBlend Implemented Implemented
feColorMatrix Not implemented Not implemented
feComponentTransfer Not implemented Not implemented
feComposite Implemented Implemented
feConvolveMatrix Implemented Implemented
feDiffuseLighting Implemented Not implemented
feDisplacementMap Work in progress - see [1] Not implemented
feFlood Not implemented Not implemented
feGaussianBlur Implemented Implemented - bugs: [2]
feImage Work in progress - see [3] Not implemented
feMerge Not implemented Not implemented
feMorphology Not implemented Not implemented
feOffset Implemented Implemented
feSpecularLighting Implemented Not implemented
feTile Not implemented Not implemented
feTurbulence Work in progress - see [4],[5],[6] Not implemented

general bugs

What next?

Now that this one filter works, most of the basic framework needed for filtering exists.

These are the basic steps to create a new filter primitive:

  • Write a new document model level class for this filter primitive (see src/sp-gaussian-blur.cpp) - note that while there are basic implementations for many filter primitives, they do need plenty of changes.
  • Write a renderer for this filter primitive (see src/display/nr-filter-gaussian.cpp)
  • Add a pointer to a function returning an instance of the renderer class to function Filter::_create_constructor_table in file src/display/nr-filter.cpp

(this is likely not an exhaustive list)

Before new filter primitives can be useful, there has to be an user interface for applying them to shapes. A really good thing would also be an UI for creating filters out of filter primitives.

See [1628343] for my filter UI suggestion - Mauve 01:44, 7 February 2007 (UTC)

NR::Filter initialization

This is a brief explanation on how NR::Filter (filter effects renderer) objects are constructed.

SPFilter has a single method sp_filter_build_renderer, which will initialize given renderer object (NR::Filter) to a correct state. Calling this method is all that needs to be done in those three nr-arena-* classes to set the correct filter renderer state. This method takes in the NR::Filter object instead of returning one, because this way that object can be reserved and freed on the same level in code. Also, this makes it easier to re-use the object instead of allocating new objects.

The inside workings of sp_filter_build_renderer are as follows: each filter primitive (SPFilterPrimitive subclasses) has a build_renderer virtual function that will add the correct NR::FilterPrimitive object in the filter renderer. Before doing any filter specific initialization, this function should call sp_filter_primitive_renderer_common, which will do the part of initialization, which is common for all filter primitives.

Modification signals for filters

This is explanation on how different parts of document tree are notified of changes to filter primitives. This is done so that the display can be updated as the filters are modified.

As the underlying XML representation of the drawing is modified, the corresponding document level objects are notified of the change. Let's suppose, that the changed value was stdDeviation in feGaussianBlur. For the SPGaussianBlur object, this will show as call to sp_gaussianBlur_set method, with key=SP_ATTR_STDDEVIATION and 'value' containing the new value.

After modifying its internal state according to new values, the _set method should pass the update notification onwards - this will allow objects using this filter to update their own state. As for now, this happens by calling ::requestModified(SP_OBJECT_MODIFIED_FLAG) on the filter primitive's parent (which should be SPFilter). This may not be the best way to do this, though.

Filters are referenced from object style. When SPStyle object is built, it subscribes for update notifications from SPFilter it references (if any). Now when ::requestModified is called on SPFilter, these update notifications are also called (eventually, as requestModified only schedules modification event, instead of executing the event immediately).

The SPStyle object in turn knows, which object it's part of - these objects are the actual drawable objects, to which the filters are applied to. SPStyle propagates the modification event to that object, which in turn applies the modifications to its internal state and schedules redraw for itself.