Copyright © 2013 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
Filter effects are a way of processing an element's rendering before it is displayed in the document. Typically, rendering an element via CSS or SVG can conceptually be described as if the element, including its children, are drawn into a buffer (such as a raster image) and then that buffer is composited into the elements parent. Filters apply an effect before the compositing stage. Examples of such effects are blurring, changing color intensity and warping the image.
Although originally designed for use in SVG, filter effects are a
set of operations to apply on an image buffer and therefore can be applied
to nearly any presentational environment, including CSS. They are
triggered by a style instruction (the ‘filter
’ property). This specification
describes filters in a manner that allows them to be used in content
styled by CSS, such as HTML and SVG. It also defines a CSS property value
function that produces a CSS <image> value.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
The (archived) public mailing list public-fx@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “filter-effects” in the subject, preferably like this: “[filter-effects] …summary of comment…”
This document was produced by the CSS Working Group (part of the Style Activity) and the SVG Working Group (part of the Graphics Activity).
This document was produced by groups operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures (CSS) and a public list of any patent disclosures (SVG) made in connection with the deliverables of each group; these pages also include instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
The list of changes made to this specification is available.
filter
’ property
<filter>
element
<feBlend>
<feColorMatrix>
<feComponentTransfer>
<feComposite>
<feConvolveMatrix>
<feCustom>
<feDiffuseLighting>
<feDisplacementMap>
<feDropShadow>
<feFlood>
<feGaussianBlur>
<feImage>
<feMerge>
<feMorphology>
<feOffset>
<feSpecularLighting>
<feTile>
<feTurbulence>
color-interpolation-filters
’
property
@supports
’ condition: ‘filter
’
<filter>
element
enable-background
’ property
A filter effect is a graphical operation that is applied to an element as it is drawn into the document. It is an image-based effect, in that it takes zero or more images as input, a number of parameters specific to the effect, and then produces an image as output. The output image is either rendered into the document instead of the original element, used as an input image to another filter effect, or provided as a CSS image value.
A simple example of a filter effect is a "flood". It takes no image inputs but has a parameter defining a color. The effect produces an output image that is completely filled with the given color. A slightly more complex example is an "inversion" which takes a single image input (typically an image of the element as it would normally be rendered into its parent) and adjusts each pixel such that they have the opposite color values.
Filter effects are exposed with three levels of complexity:
The following shows an example of a filter effect.
Initial example for a filtered object.
View this example as SVG
The filter effect used in the example above is repeated here with reference numbers in the left column before each of the six filter primitives:
1 2 3 4 5 6 |
<filter id="MyFilter" filterUnits="userSpaceOnUse" x="0" y="0" width="200" height="120"> <desc>Produces a 3D lighting effect.</desc> <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/> <feOffset in="blur" dx="4" dy="4" result="offsetBlur"/> <feSpecularLighting in="blur" surfaceScale="5" specularConstant=".75" specularExponent="20" lighting-color="#bbbbbb" result="specOut"> <fePointLight x="-5000" y="-10000" z="20000"/> </feSpecularLighting> <feComposite in="specOut" in2="SourceAlpha" operator="in" result="specOut"/> <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="litPaint"/> <feMerge> <feMergeNode in="offsetBlur"/> <feMergeNode in="litPaint"/> </feMerge> </filter> |
The following pictures show the intermediate image results from each of the six filter elements:
|
|
|
| |||
|
|
|
<feGaussianBlur>
takes input SourceAlpha, which is the alpha channel of the
source graphic. The result is stored in a temporary buffer named "blur".
Note that "blur" is used as input to both filter primitives 2 and 3.
<feOffset>
takes buffer "blur", shifts
the result in a positive direction in both x and y, and creates a new
buffer named "offsetBlur". The effect is that of a drop shadow.
<feSpecularLighting>
, uses buffer "blur"
as a model of a surface elevation and generates a lighting effect from a
single point source. The result is stored in buffer "specOut".
<feComposite>
masks out the result of
filter primitive 3 by the original source graphics alpha channel so that
the intermediate result is no bigger than the original source graphic.
<feComposite>
composites the result of
the specular lighting with the original source graphic.
<feMerge>
composites two layers
together. The lower layer consists of the drop shadow result from filter
primitive 2. The upper layer consists of the specular lighting result
from filter primitive 5.
This specification defines a set of CSS properties that affect the visual rendering of elements to which those properties are applied; these effects are applied after elements have been sized and positioned according to the Visual formatting model from [CSS21]. Some values of these properties result in the creation of a containing block, and/or the creation of a stacking context.
Some property and element definitions in this specification require an
SVG 1.1 implementation [SVG11]. UAs without support for SVG
must not implement the ‘color-interpolation-filters
’, ‘flood-color
’, ‘flood-opacity
’ and
‘lightning-color
’ properties as well as
the <filter>
element, the <feMergeNode>
element, the <feCustomParam>
element, the transfer function elements and the
filter primitive elements.
This specification follows the CSS property definition conventions from [CSS21]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [CSS21].
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.
When used in this specification, terms have the meanings assigned in this section.
The null filter output is all transparent black pixels. If applied to an element it means that the element (and children if any) becomes invisible. Note that it does not affect event processing.
<feFuncR>
, <feFuncG>
,
<feFuncB>
, <feFuncA>
elements, that define the transfer function for the <feComponentTransfer>
filter primitive.
The union of all border boxes for the element that has an associated
CSS layout box and is not in the http://www.w3.org/2000/svg
namespace and it's descendant elements. Or the object bounding box [SVG11], if the
element does not have an associated CSS layout box and is in the
http://www.w3.org/2000/svg
namespace (See getBoundingClientRect
[CSSOM]]).
In general, a coordinate system defines locations and distances on the current canvas. The current local coordinate system (also user coordinate system) is the coordinate system that is currently active and which is used to define how coordinates and lengths are located and computed, respectively, on the current canvas [CSS3-TRANSFORMS].
For elements that have an associated CSS layout box, the current user coordinate system has its origin at the top-left corner of the bounding client rect and one unit equals one CSS pixel. The viewport for resolving percentage values is defined by the width and height of the bounding client rect.
If the element does not have an associated CSS layout box and is in
the http://www.w3.org/2000/svg
namespace, the current local
coordinate system has its origin at the top-left corner of the element's
nearest viewport.
The set of elements that control the output of a <filter>
element, particularly: <feSpotLight>
, <feBlend>
,
<feColorMatrix>
, <feComponentTransfer>
, <feComposite>
, <feConvolveMatrix>
, <feCustom>
. <feDiffuseLighting>
, <feDisplacementMap>
, <feDropShadow>
, <feFlood>
,
<feGaussianBlur>
, <feImage>
,
<feMerge>
, <feMorphology>
, <feOffset>
, <feSpecularLighting>
, <feTile>
,
<feTurbulence>
,
The following elements are light sources: <feDistantLight>
, <fePointLight>
, <feSpotLight>
.
x
’, ‘y
’, ‘width
’ and ‘height
’ as filter primitive attributes.
filter
’ property The description of the ‘filter
’ property is as follows:
Name: | filter |
Value: | none | <filter-function>+ |
---|---|
Initial: | none |
Applies to: | All elements In SVG 1.1 it applies only to "container elements (except ‘mask’) and graphics elements" |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | yes |
If the value of the ‘filter
’ property is ‘none
’ then there is no filter effect applied.
Otherwise, the list of functions are applied in the order provided.
<filter-function> = <URL> | grayscale(<number> | <percentage>) | sepia(<number> | <percentage>) | saturate(<number> | <percentage>) | hue-rotate(<angle>) | invert(<number> | <percentage>) | opacity(<number> | <percentage>) | brightness(<number> | <percentage>) | contrast(<number> | <percentage>) | blur(<length>) | drop-shadow([<length>{2,3} && <color>?]#) | custom(IDENT [, <param>]*)
<filter>
element. For example ‘url(commonmasks.xml#mask)
’. If the URL references a
non-existent object or the referenced object is not a <filter>
element, then the null filter will be applied
instead.
The opacity filter function is not meant to be a shorthand
of the ‘opacity
’ property. Furthermore,
it allows setting the transparency of intermediate filter primitive
results before passing to the next filter primitive. If the opacity
filter function is set as last filter primitive, the value of the
‘opacity
’ property is multiplied on top
of the value of the filter function, which may result in a more
transparent content.
0%
’ will create an
image that is completely black. A value of ‘100%
’ leaves the input unchanged. Other values are
linear multipliers on the effect. Values of amount over 100% are allowed,
providing brighter results. If the parameter is missing, a value of 100%
is used. The markup equivalent of this function is given below.
0%
’ will create an image that is completely gray. A
value of ‘100%
’ leaves the input unchanged.
Values of amount over 100% are allowed, providing results with less
contrast. If the parameter is missing, a value of 100% is used. The
markup equivalent of this function is given
below.
The FXTF is looking into distinguish between vertical and horizontal blur radii.
box-shadow
’ [CSS3BG]. (But note
that spread values are not allowed.) The markup equivalent of this
function is given below.
The first function in the list takes the element (SourceGraphic) as the input image. Subsequent
operations take the output from the previous function as the input image.
The exception is the function that references a <filter>
element, which can specify an alternate input, but still uses the previous
output as its SourceGraphic.
The application of the ‘filter
’ property to an element formatted with
the CSS box model establishes a new stacking context the same way that CSS
‘opacity
’ does, and all the element's
descendants are rendered together as a group with the filter effect
applied to the group as a whole.
The ‘filter
’
property has no effect on the geometry of the target element's CSS boxes,
even though ‘filter
’
can cause painting outside of an element's border box.
Conceptually, any parts of the drawing are effected by filter operations. This includes any content, background, borders, text decoration, outline and visible scrolling mechanism of the element to which the filter is applied, and those of its descendants. The filter operations are applied in the element's local coordinate system.
The compositing model follows the SVG compositing
model [SVG11]:
first any filter effect is applied, then any clipping, masking and
opacity. As per SVG, the application of ‘filter
’ has no effect on hit-testing.
The CSS WG wants to look into how to apply the filter to certain parts of an object (background, border) instead of just the whole group with descendants.
<filter>
elementName: | filter |
---|---|
Categories: | None. |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFilterElement |
The description of the <filter>
element follows:
Attribute definitions:
primitiveUnits
’ is equal to ‘userSpaceOnUse
’, any length values within the filter
definitions represent values in the current user coordinate system in place at
the time when the <filter>
element is referenced (i.e.,
the user coordinate system for the element referencing the <filter>
element via a ‘filter
’ property).primitiveUnits
’ is equal to ‘objectBoundingBox
’, then any length values within the
filter definitions represent fractions or percentages of the bounding
box on the referencing element (see object bounding box units). Note
that if only one number was specified in a <number-optional-number>
value this number is expanded out before the ‘primitiveUnits
’ computation takes place.
primitiveUnits
’ is userSpaceOnUse.<filter>
element within the current SVG
document fragment. Any attributes which are defined on the
referenced <filter>
element which are not defined
on this element are inherited by this element. If this element has no
defined filter nodes, and the referenced element has defined filter
nodes (possibly due to its own href
attribute), then this element inherits the filter nodes defined from the
referenced <filter>
element. Inheritance can be
indirect to an arbitrary level; thus, if the referenced <filter>
element inherits attributes or its filter node specification due to its
own href attribute, then the current
element can inherit those attributes or filter node specifications.
Properties inherit into the <filter>
element from its ancestors;
properties do not inherit from the element referencing the <filter>
element.
<filter>
elements are never rendered directly; their only usage is as something
that can be referenced using the ‘filter
’ property. The ‘display
’ property does not apply to the <filter>
element; thus, <filter>
elements are not directly
rendered even if the ‘display
’ property is set to a value other than
none, and <filter>
elements are available for
referencing even when the ‘display
’ property on the <filter>
element or any of its ancestors is set to none.
A <filter>
element can define a region on
the canvas to which a given filter effect applies and can provide a
resolution for any intermediate continuous tone images used to process any
raster-based filter primitives.
The <filter>
element has the following
attributes which work together to define the filter effects region:
filterUnits
’
Defines the coordinate system for attributes ‘x
’,
‘y
’, ‘width
’, ‘height
’.
If ‘filterUnits
’ is equal to ‘userSpaceOnUse
’, ‘x
’,
‘y
’, ‘width
’, ‘height
’ represent values in the current user
coordinate system in place at the time when the <filter>
element is referenced (i.e., the user coordinate system for the element
referencing the <filter>
element via a ‘filter
’ property).
If ‘filterUnits
’ is equal to ‘objectBoundingBox
’, then ‘x
’,
‘y
’, ‘width
’, ‘height
’ represent fractions or percentages
of the bounding box on the referencing element (see object
bounding box units).
The lacuna
value for ‘filterUnits
’ is ‘objectBoundingBox
’.
Animatable: yes.
x
’,
‘y
’, ‘width
’, ‘height
’
These attributes define a rectangular region on the canvas to which this filter applies.
The amount of memory and processing time required to apply the filter
are related to the size of this rectangle and the ‘filterRes
’ attribute of the filter.
The coordinate system for these attributes depends on the value for
attribute ‘filterUnits
’.
The bounds of this rectangle act as a hard clipping region for each
filter primitive included with
a given <filter>
element; thus, if the effect
of a given filter primitive would extend beyond the bounds of the
rectangle (this sometimes happens when using a <feGaussianBlur>
filter primitive with
a very large ‘stdDeviation
’), parts of the effect will get
clipped.
The lacuna
value for ‘x
’
and ‘y
’ is -10%.
The lacuna
value for ‘width
’ and ‘height
’ is 120%.
Negative or zero values for ‘width
’ or ‘height
’ disable rendering of the element
which referenced the filter.
Animatable: yes.
filterRes
’
Defines the width and height of the intermediate images in pixels. If not provided, then the user agent will use reasonable values to produce a high-quality result on the output device.
Care should be taken when assigning a non-default value to this attribute. Too small of a value may result in unwanted pixelation in the result. Too large of a value may result in slow processing and large memory usage.
Non-integer values are truncated, i.e rounded to the closest integer value towards zero.
Negative or zero values disable rendering of the element which referenced the filter.
Animatable: yes.
Note that both of the two possible value for ‘filterUnits
’ (i.e., objectBoundingBox and userSpaceOnUse) result in a filter region whose coordinate system has
its X-axis and Y-axis each parallel to the X-axis and Y-axis,
respectively, of the user coordinate
system for the element to which the filter will be applied.
Sometimes implementers can achieve faster
performance when the filter region can be mapped directly to device
pixels; thus, for best performance on display devices, it is suggested
that authors define their region such that the user agent can align the filter region pixel-for-pixel with the
background. In particular, for best filter effects performance, avoid
rotating or skewing the user coordinate system. Explicit values for
attribute ‘filterRes
’ can either help or harm
performance. If ‘filterRes
’ is smaller than the automatic
(i.e., default) filter resolution, then filter effect might have faster
performance (usually at the expense of quality). If ‘filterRes
’ is larger than the automatic (i.e.,
default) filter resolution, then filter effects performance will usually
be slower.
This section describes the various filter primitives that can be assembled to achieve a particular filter effect.
Unless otherwise stated, all image filters operate on premultiplied
RGBA samples. Filters which work more naturally on non-premultiplied data
(<feColorMatrix>
, <feCustom>
and <feComponentTransfer>
) will temporarily
undo and redo premultiplication as specified. All raster effect filtering
operations take 1 to N input RGBA images, additional attributes as
parameters, and produce a single output RGBA image.
The RGBA result from each filter primitive will be clamped into the allowable ranges for colors and opacity values. Thus, for example, the result from a given filter primitive will have any negative color values or opacity values adjusted up to color/opacity of zero.
The color space in which a particular filter primitive performs its
operations is determined by the value of property ‘color-interpolation-filters
’ on the given filter primitive. A different
property, ‘color-interpolation
’ determines the color
space for other color operations. Because these two properties have
different initial values (‘color-interpolation-filters
’ has an initial
value of linearRGB whereas ‘color-interpolation
’ has an initial value of
‘sRGB
’), in some cases to achieve certain
results (e.g., when coordinating gradient interpolation with a filtering
operation) it will be necessary to explicitly set ‘color-interpolation
’ to ‘linearRGB
’ or ‘color-interpolation-filters
’ to ‘sRGB
’ on particular elements. Note that the examples
below do not explicitly set either ‘color-interpolation
’ or ‘color-interpolation-filters
’, so the initial
values for these properties apply to the examples.
Sometimes filter primitives result in
undefined pixels. For example, filter primitive <feOffset>
can shift an image down and to the right, leaving undefined pixels at the
top and left. In these cases, the undefined pixels are set to transparent
black.
The following attributes are available for most of the filter primitives:
Attribute definitions:
The minimum x coordinate for the subregion which restricts calculation and rendering of the given filter primitive. See filter primitive subregion.
The lacuna value for x is 0%.
Animatable: yes.
The minimum y coordinate for the subregion which restricts calculation and rendering of the given filter primitive. See filter primitive subregion.
The lacuna value for y is 0%.
Animatable: yes.
The width of the subregion which restricts calculation and rendering of the given filter primitive. See filter primitive subregion.
A negative or zero value disables the effect of the given filter primitive (i.e., the result is a transparent black image).
The lacuna value for width is 100%.
Animatable: yes.
The height of the subregion which restricts calculation and rendering of the given filter primitive. See filter primitive subregion.
A negative or zero value disables the effect of the given filter primitive (i.e., the result is a transparent black image).
The lacuna value for height is 100%.
Animatable: yes.
<filter-primitive-reference> is an <author-ident> and an assigned name for this filter primitive. If supplied,
then graphics that result from processing this filter primitive can be
referenced by an ‘in
’ attribute on a subsequent filter
primitive within the same <filter>
element. If no value is
provided, the output will only be available for re-use as the implicit
input into the next filter
primitive if that filter
primitive provides no value for its ‘in
’ attribute.
Identifies input for the given filter primitive. The value can be
either one of six keywords or can be a string which matches a previous
‘result
’ attribute value within the same <filter>
element. If no value is provided and this is the first filter primitive, then this filter primitive will use SourceGraphic as its input. If no value is
provided and this is a subsequent filter
primitive, then this filter primitive will use the
result from the previous filter
primitive as its input.
If the value for result appears
multiple times within a given <filter>
element, then a reference to
that result will use the closest preceding filter primitive with the given
value for attribute ‘result
’. Forward references to results are
not allowed, and will be treated as if no result was specified.
Definitions for the six keywords:
This keyword represents the graphics elements that were the
original input into the <filter>
element. For raster effects
filter primitives, the
graphics elements will be rasterized into an initially clear RGBA
raster in image space. Pixels left untouched by the original graphic
will be left clear. The image is specified to be rendered in linear
RGBA pixels. The alpha channel of this image captures any
anti-aliasing specified by SVG. (Since the raster is linear, the
alpha channel of this image will represent the exact percent coverage
of each pixel.)
This keyword represents the graphics elements that were the
original input into the <filter>
element. SourceAlpha has all of the same rules as SourceGraphic except that only the alpha
channel is used. The input image is an RGBA image consisting of
implicitly black color values for the RGB channels, but whose alpha
channel is the same as SourceGraphic.
If this option is used, then some implementations might need to rasterize the graphics elements in order to extract the alpha channel.
This keyword represents an image snapshot of the canvas under the
filter region at the time that the
<filter>
element was invoked. See
‘enable-background
’ property.
Same as BackgroundImage except only
the alpha channel is used. See SourceAlpha
and the ‘enable-background
’ property.
This keyword represents the value of the ‘fill
’ property on the target element for
the filter effect. The FillPaint image has
conceptually infinite extent. Frequently this image is opaque
everywhere, but it might not be if the "paint" itself has alpha, as
in the case of a gradient or pattern which itself includes
transparent or semi-transparent parts.
This keyword represents the value of the ‘stroke
’ property on the target element
for the filter effect. The StrokePaint
image has conceptually infinite extent. Frequently this image is
opaque everywhere, but it might not be if the "paint" itself has
alpha, as in the case of a gradient or pattern which itself includes
transparent or semi-transparent parts.
Animatable: yes.
Define filter primitive subregion for shorthands. E.g. the out bounds of the previous filter functions, extended by affected area of current filter function.
All filter primitives have
attributes ‘x
’, ‘y
’,
‘width
’ and ‘height
’ which together identify a subregion
which restricts calculation and rendering of the given filter primitive. The ‘x
’, ‘y
’,
‘width
’ and ‘height
’ attributes are defined according to
the same rules as other filter
primitives coordinate and length attributes and thus represent values
in the coordinate system established by attribute ‘primitiveUnits
’ on the <filter>
element.
‘x
’, ‘y
’,
‘width
’ and ‘height
’ default to the union (i.e., tightest
fitting bounding box) of the subregions defined for all referenced nodes.
If there are no referenced nodes (e.g., for <feImage>
or
<feTurbulence>
), or one or more of the
referenced nodes is a standard input (one of SourceGraphic, SourceAlpha, BackgroundImage, BackgroundAlpha, FillPaint or StrokePaint), or for <feTile>
(which is special because its principal function is to replicate the
referenced node in X and Y and thereby produce a usually larger result),
the default subregion is 0%, 0%, 100%, 100%,
where as a special-case the percentages are relative to the dimensions of
the filter region, thus making the
default filter primitive subregion
equal to the filter region.
If the filter primitive subregion has a negative or zero width or height, the effect of the filter primitive is disabled.
The filter primitive subregion act as a hard clip clipping rectangle on both the filter primitive's input image(s) and the filter primitive result.
All intermediate offscreens are defined to not exceed the intersection of the filter primitive subregion with the filter region. The filter region and any of the filter primitive subregions are to be set up such that all offscreens are made big enough to accommodate any pixels which even partly intersect with either the filter region or the filter primitive subregions.
<feTile>
references a previous filter
primitive and then stitches the tiles together based on the filter primitive subregion of the
referenced filter primitive in order to fill its own filter primitive subregion.
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg"> <defs> <filter id="flood" x="0" y="0" width="100%" height="100%" primitiveUnits="objectBoundingBox"> <feFlood x="25%" y="25%" width="50%" height="50%" flood-color="green" flood-opacity="0.75"/> </filter> <filter id="blend" primitiveUnits="objectBoundingBox"> <feBlend x="25%" y="25%" width="50%" height="50%" in2="SourceGraphic" mode="multiply"/> </filter> <filter id="merge" primitiveUnits="objectBoundingBox"> <feMerge x="25%" y="25%" width="50%" height="50%"> <feMergeNode in="SourceGraphic"/> <feMergeNode in="FillPaint"/> </feMerge> </filter> </defs> <g fill="none" stroke="blue" stroke-width="4"> <rect width="200" height="200"/> <line x2="200" y2="200"/> <line x1="200" y2="200"/> </g> <circle fill="green" filter="url(#flood)" cx="100" cy="100" r="90"/> <g transform="translate(200 0)"> <g fill="none" stroke="blue" stroke-width="4"> <rect width="200" height="200"/> <line x2="200" y2="200"/> <line x1="200" y2="200"/> </g> <circle fill="green" filter="url(#blend)" cx="100" cy="100" r="90"/> </g> <g transform="translate(0 200)"> <g fill="none" stroke="blue" stroke-width="4"> <rect width="200" height="200"/> <line x2="200" y2="200"/> <line x1="200" y2="200"/> </g> <circle fill="green" fill-opacity="0.5" filter="url(#merge)" cx="100" cy="100" r="90"/> </g> </svg>
View this example as SVG (SVG-enabled browsers only)
In the example above there are three rects that each have a cross and a circle in them. The circle element in each one has a different filter applied, but with the same filter primitive subregion. The filter output should be limited to the filter primitive subregion, so you should never see the circles themselves, just the rects that make up the filter primitive subregion.
<feFlood>
with flood-opacity="75%" so the cross should be visible through the
green rect in the middle.
<feMerge>
that merges SourceGraphic with FillPaint. Since the circle has fill-opacity="0.5"
it will also be transparent so that the cross is visible through the
green rect in the middle.
<feBlend>
that has mode="multiply".
Since the circle in this case isn't transparent the result is totally
opaque. The rect should be dark green and the cross should not be
visible through it.
<feBlend>
Name: | feBlend |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEBlendElement |
This filter composites two objects together using commonly used imaging software blending modes. It performs a pixel-wise combination of two input images.
Attribute definitions:
mode
’ is normal.For all feBlend modes, the result opacity is computed as follows:
qr = 1 - (1-qa)*(1-qb)
For the compositing formulas below, the following definitions apply:
image A = in image B = in2 cr = Result color (RGB) - premultiplied qa = Opacity value at a given pixel for image A qb = Opacity value at a given pixel for image B ca = Color (RGB) at a given pixel for image A - premultiplied cb = Color (RGB) at a given pixel for image B - premultiplied
The following table provides the list of available image blending modes:
Image Blending Mode | Formula for computing result color |
---|---|
normal |
cr = (1 - qa) * cb + ca |
multiply |
cr = (1 - qa) * cb + (1 - qb) * ca + ca * cb |
screen |
cr = cb + ca - ca * cb |
darken |
cr = Min ((1 - qa) * cb + ca, (1 - qb) * ca + cb) |
lighten |
cr = Max ((1 - qa) * cb + ca, (1 - qb) * ca + cb) |
The ‘normal
’ blend mode is equivalent to operator="over" on the <feComposite>
filter primitive, matches
the blending method used by <feMerge>
and matches the simple
alpha compositing technique used in SVG for all compositing outside of
filter effects.
<?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="5cm" height="5cm" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example feBlend - Examples of feBlend modes</title> <desc>Five text strings blended into a gradient, with one text string for each of the five feBlend modes.</desc> <defs> <linearGradient id="MyGradient" gradientUnits="userSpaceOnUse" x1="100" y1="0" x2="300" y2="0"> <stop offset="0" stop-color="#000000" /> <stop offset=".33" stop-color="#ffffff" /> <stop offset=".67" stop-color="#ff0000" /> <stop offset="1" stop-color="#808080" /> </linearGradient> <filter id="Normal"> <feBlend mode="normal" in2="BackgroundImage" in="SourceGraphic"/> </filter> <filter id="Multiply"> <feBlend mode="multiply" in2="BackgroundImage" in="SourceGraphic"/> </filter> <filter id="Screen"> <feBlend mode="screen" in2="BackgroundImage" in="SourceGraphic"/> </filter> <filter id="Darken"> <feBlend mode="darken" in2="BackgroundImage" in="SourceGraphic"/> </filter> <filter id="Lighten"> <feBlend mode="lighten" in2="BackgroundImage" in="SourceGraphic"/> </filter> </defs> <rect fill="none" stroke="blue" x="1" y="1" width="498" height="498"/> <g enable-background="new" > <rect x="100" y="20" width="300" height="460" fill="url(#MyGradient)" /> <g font-family="Verdana" font-size="75" fill="#888888" fill-opacity=".6" > <text x="50" y="90" filter="url(#Normal)" >Normal</text> <text x="50" y="180" filter="url(#Multiply)" >Multiply</text> <text x="50" y="270" filter="url(#Screen)" >Screen</text> <text x="50" y="360" filter="url(#Darken)" >Darken</text> <text x="50" y="450" filter="url(#Lighten)" >Lighten</text> </g> </g> </svg>
<feColorMatrix>
Name: | feColorMatrix |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEColorMatrixElement |
This filter applies a matrix transformation:
on the RGBA color and alpha values of every pixel on the input graphics to produce a result with a new set of RGBA color and alpha values.
The calculations are performed on non-premultiplied color values. If the input graphics consists of premultiplied color values, those values are automatically converted into non-premultiplied color values for this operation.
These matrices often perform an identity mapping in the alpha channel. If that is the case, an implementation can avoid the costly undoing and redoing of the premultiplication for all pixels with A = 1.
Attribute definitions:
type
’ is matrix. type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"
where the terms a00, a01, etc. are calculated as follows:
Thus, the upper left term of the hue matrix turns out to be:
type
’. If type="matrix", then this attribute defaults to
the identity matrix. If type="saturate",
then this attribute defaults to the value 1, which results in the identity matrix. If
type="hueRotate", then this attribute
defaults to the value 0, which results in
the identity matrix.<?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="8cm" height="5cm" viewBox="0 0 800 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example feColorMatrix - Examples of feColorMatrix operations</title> <desc>Five text strings showing the effects of feColorMatrix: an unfiltered text string acting as a reference, use of the feColorMatrix matrix option to convert to grayscale, use of the feColorMatrix saturate option, use of the feColorMatrix hueRotate option, and use of the feColorMatrix luminanceToAlpha option.</desc> <defs> <linearGradient id="MyGradient" gradientUnits="userSpaceOnUse" x1="100" y1="0" x2="500" y2="0"> <stop offset="0" stop-color="#ff00ff" /> <stop offset=".33" stop-color="#88ff88" /> <stop offset=".67" stop-color="#2020ff" /> <stop offset="1" stop-color="#d00000" /> </linearGradient> <filter id="Matrix" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feColorMatrix type="matrix" in="SourceGraphic" values=".33 .33 .33 0 0 .33 .33 .33 0 0 .33 .33 .33 0 0 .33 .33 .33 0 0"/> </filter> <filter id="Saturate40" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feColorMatrix type="saturate" in="SourceGraphic" values="0.4"/> </filter> <filter id="HueRotate90" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feColorMatrix type="hueRotate" in="SourceGraphic" values="90"/> </filter> <filter id="LuminanceToAlpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feColorMatrix type="luminanceToAlpha" in="SourceGraphic" result="a"/> <feComposite in="SourceGraphic" in2="a" operator="in" /> </filter> </defs> <rect fill="none" stroke="blue" x="1" y="1" width="798" height="498"/> <g font-family="Verdana" font-size="75" font-weight="bold" fill="url(#MyGradient)" > <rect x="100" y="0" width="500" height="20" /> <text x="100" y="90">Unfiltered</text> <text x="100" y="190" filter="url(#Matrix)" >Matrix</text> <text x="100" y="290" filter="url(#Saturate40)" >Saturate</text> <text x="100" y="390" filter="url(#HueRotate90)" >HueRotate</text> <text x="100" y="490" filter="url(#LuminanceToAlpha)" >Luminance</text> </g> </svg>
<feComponentTransfer>
Name: | feComponentTransfer |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEComponentTransferElement |
This filter primitive performs component-wise remapping of data as follows:
R' = feFuncR( R ) G' = feFuncG( G ) B' = feFuncB( B ) A' = feFuncA( A )
for every pixel. It allows operations like brightness adjustment, contrast adjustment, color balance or thresholding.
The calculations are performed on non-premultiplied color values. If
the input graphics consists of premultiplied color values, those values
are automatically converted into non-premultiplied color values for this
operation. (Note that the undoing and redoing of the premultiplication can
be avoided if <feFuncA>
is the identity transform and
all alpha values on the source graphic are set to 1.)
The child elements of a <feComponentTransfer>
element specify the
transfer functions for the
four channels:
<feFuncR>
— transfer function for the
red component of the input graphic
<feFuncG>
— transfer function for the
green component of the input graphic
<feFuncB>
— transfer function for the
blue component of the input graphic
<feFuncA>
— transfer function for the
alpha component of the input graphic
The following rules apply to the processing of the <feComponentTransfer>
element:
<feComponentTransfer>
must be processed
as if those transfer function
elements were specified with their ‘type
’ attributes set to ‘identity
’.
Name: | feFuncR |
---|---|
Categories: | Transfer function element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEFuncRElement |
Name: | feFuncG |
---|---|
Categories: | Transfer function element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEFuncGElement |
Name: | feFuncB |
---|---|
Categories: | Transfer function element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEFuncBElement |
Name: | feFuncA |
---|---|
Categories: | Transfer function element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEFuncAElement |
The attributes below are the transfer function element attributes, which apply to the transfer function elements.
Attribute definitions:
Indicates the type of component transfer function. The type of function determines the applicability of the other attributes.
In the following, C is the initial component (e.g., <feFuncR>
), C' is the remapped
component; both in the closed interval [0,1].
identity
’:
C' = C
table
’, the function is defined
by linear interpolation between values given in the attribute ‘tableValues
’. The table has
n+1 values (i.e., v0 to vn)
specifying the start and end values for n evenly sized
interpolation regions. Interpolations use the following formula:
For a value C < 1
find k
such
that:
k/n <= C < (k+1)/n
The result C'
is given by:
C' = vk + (C - k/n)*n * (vk+1 - vk)
If C = 1
then:
C' = vn.
discrete
’, the function is
defined by the step function given in the attribute ‘tableValues
’, which provides a list of
n values (i.e., v0 to vn-1) in
order to identify a step function consisting of n steps.
The step function is defined by the following formula:
For a value C < 1
find k
such
that:
k/n <= C < (k+1)/n
The result C'
is given by:
C' = vk
If C = 1
then:
C' = vn-1.
linear
’, the function is
defined by the following linear equation:
gamma
’, the function is defined
by the following exponential function:
slope
’ is 1.intercept
’ is 0.amplitude
’ is 1.exponent
’ is 1.offset
’ is 0.<?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="8cm" height="4cm" viewBox="0 0 800 400" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example feComponentTransfer - Examples of feComponentTransfer operations</title> <desc>Four text strings showing the effects of feComponentTransfer: an identity function acting as a reference, use of the feComponentTransfer table option, use of the feComponentTransfer linear option, and use of the feComponentTransfer gamma option.</desc> <defs> <linearGradient id="MyGradient" gradientUnits="userSpaceOnUse" x1="100" y1="0" x2="600" y2="0"> <stop offset="0" stop-color="#ff0000" /> <stop offset=".33" stop-color="#00ff00" /> <stop offset=".67" stop-color="#0000ff" /> <stop offset="1" stop-color="#000000" /> </linearGradient> <filter id="Identity" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feComponentTransfer> <feFuncR type="identity"/> <feFuncG type="identity"/> <feFuncB type="identity"/> <feFuncA type="identity"/> </feComponentTransfer> </filter> <filter id="Table" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feComponentTransfer> <feFuncR type="table" tableValues="0 0 1 1"/> <feFuncG type="table" tableValues="1 1 0 0"/> <feFuncB type="table" tableValues="0 1 1 0"/> </feComponentTransfer> </filter> <filter id="Linear" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feComponentTransfer> <feFuncR type="linear" slope=".5" intercept=".25"/> <feFuncG type="linear" slope=".5" intercept="0"/> <feFuncB type="linear" slope=".5" intercept=".5"/> </feComponentTransfer> </filter> <filter id="Gamma" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feComponentTransfer> <feFuncR type="gamma" amplitude="2" exponent="5" offset="0"/> <feFuncG type="gamma" amplitude="2" exponent="3" offset="0"/> <feFuncB type="gamma" amplitude="2" exponent="1" offset="0"/> </feComponentTransfer> </filter> </defs> <rect fill="none" stroke="blue" x="1" y="1" width="798" height="398"/> <g font-family="Verdana" font-size="75" font-weight="bold" fill="url(#MyGradient)" > <rect x="100" y="0" width="600" height="20" /> <text x="100" y="90">Identity</text> <text x="100" y="190" filter="url(#Table)" >TableLookup</text> <text x="100" y="290" filter="url(#Linear)" >LinearFunc</text> <text x="100" y="390" filter="url(#Gamma)" >GammaFunc</text> </g> </svg>
<feComposite>
Name: | feComposite |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFECompositeElement |
This filter performs the combination of the two input images pixel-wise in image space using one of the Porter-Duff [PORTERDUFF] compositing operations: over, in, atop, out, xor [COMPOSITING]. Additionally, a component-wise arithmetic operation (with the result clamped between [0..1]) can be applied.
The arithmetic operation is useful for combining the
output from the <feDiffuseLighting>
and <feSpecularLighting>
filters with
texture data. It is also useful for implementing dissolve. If
the arithmetic operation is chosen, each result pixel is
computed using the following formula:
result = k1*i1*i2 + k2*i1 + k3*i2 + k4where:
i1
and i2
indicate the corresponding
pixel channel values of the input image, which map to ‘in
’ and ‘in2
’
respectively
k1, k2, k3
and k4
indicate the values
of the attributes with the same name
For this filter primitive, the extent of the resulting image might grow as described in the section that describes the filter primitive subregion.
Attribute definitions:
operator
’ is over. k1
’
is 0. k2
’
is 0. k3
’
is 0. k4
’
is 0. <?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="330" height="195" viewBox="0 0 1100 650" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Example feComposite - Examples of feComposite operations</title> <desc>Four rows of six pairs of overlapping triangles depicting the six different feComposite operators under different opacity values and different clearing of the background.</desc> <defs> <desc>Define two sets of six filters for each of the six compositing operators. The first set wipes out the background image by flooding with opaque white. The second set does not wipe out the background, with the result that the background sometimes shines through and is other cases is blended into itself (i.e., "double-counting").</desc> <filter id="overFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="over" result="comp"/> <feMerge> <feMergeNode in="flood"/> <feMergeNode in="comp"/> </feMerge> </filter> <filter id="inFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="in" result="comp"/> <feMerge> <feMergeNode in="flood"/> <feMergeNode in="comp"/> </feMerge> </filter> <filter id="outFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="out" result="comp"/> <feMerge> <feMergeNode in="flood"/> <feMergeNode in="comp"/> </feMerge> </filter> <filter id="atopFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="atop" result="comp"/> <feMerge> <feMergeNode in="flood"/> <feMergeNode in="comp"/> </feMerge> </filter> <filter id="xorFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="xor" result="comp"/> <feMerge> <feMergeNode in="flood"/> <feMergeNode in="comp"/> </feMerge> </filter> <filter id="arithmeticFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/> <feComposite in="SourceGraphic" in2="BackgroundImage" result="comp" operator="arithmetic" k1=".5" k2=".5" k3=".5" k4=".5"/> <feMerge> <feMergeNode in="flood"/> <feMergeNode in="comp"/> </feMerge> </filter> <filter id="overNoFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="over" result="comp"/> </filter> <filter id="inNoFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="in" result="comp"/> </filter> <filter id="outNoFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="out" result="comp"/> </filter> <filter id="atopNoFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="atop" result="comp"/> </filter> <filter id="xorNoFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feComposite in="SourceGraphic" in2="BackgroundImage" operator="xor" result="comp"/> </filter> <filter id="arithmeticNoFlood" filterUnits="objectBoundingBox" x="-5%" y="-5%" width="110%" height="110%"> <feComposite in="SourceGraphic" in2="BackgroundImage" result="comp" operator="arithmetic" k1=".5" k2=".5" k3=".5" k4=".5"/> </filter> <path id="Blue100" d="M 0 0 L 100 0 L 100 100 z" fill="#00ffff" /> <path id="Red100" d="M 0 0 L 0 100 L 100 0 z" fill="#ff00ff" /> <path id="Blue50" d="M 0 125 L 100 125 L 100 225 z" fill="#00ffff" fill-opacity=".5" /> <path id="Red50" d="M 0 125 L 0 225 L 100 125 z" fill="#ff00ff" fill-opacity=".5" /> <g id="TwoBlueTriangles"> <use xlink:href="#Blue100"/> <use xlink:href="#Blue50"/> </g> <g id="BlueTriangles"> <use transform="translate(275,25)" xlink:href="#TwoBlueTriangles"/> <use transform="translate(400,25)" xlink:href="#TwoBlueTriangles"/> <use transform="translate(525,25)" xlink:href="#TwoBlueTriangles"/> <use transform="translate(650,25)" xlink:href="#TwoBlueTriangles"/> <use transform="translate(775,25)" xlink:href="#TwoBlueTriangles"/> <use transform="translate(900,25)" xlink:href="#TwoBlueTriangles"/> </g> </defs> <rect fill="none" stroke="blue" x="1" y="1" width="1098" height="648"/> <g font-family="Verdana" font-size="40" shape-rendering="crispEdges"> <desc>Render the examples using the filters that draw on top of an opaque white surface, thus obliterating the background.</desc> <g enable-background="new"> <text x="15" y="75">opacity 1.0</text> <text x="15" y="115" font-size="27">(with feFlood)</text> <text x="15" y="200">opacity 0.5</text> <text x="15" y="240" font-size="27">(with feFlood)</text> <use xlink:href="#BlueTriangles"/> <g transform="translate(275,25)"> <use xlink:href="#Red100" filter="url(#overFlood)" /> <use xlink:href="#Red50" filter="url(#overFlood)" /> <text x="5" y="275">over</text> </g> <g transform="translate(400,25)"> <use xlink:href="#Red100" filter="url(#inFlood)" /> <use xlink:href="#Red50" filter="url(#inFlood)" /> <text x="35" y="275">in</text> </g> <g transform="translate(525,25)"> <use xlink:href="#Red100" filter="url(#outFlood)" /> <use xlink:href="#Red50" filter="url(#outFlood)" /> <text x="15" y="275">out</text> </g> <g transform="translate(650,25)"> <use xlink:href="#Red100" filter="url(#atopFlood)" /> <use xlink:href="#Red50" filter="url(#atopFlood)" /> <text x="10" y="275">atop</text> </g> <g transform="translate(775,25)"> <use xlink:href="#Red100" filter="url(#xorFlood)" /> <use xlink:href="#Red50" filter="url(#xorFlood)" /> <text x="15" y="275">xor</text> </g> <g transform="translate(900,25)"> <use xlink:href="#Red100" filter="url(#arithmeticFlood)" /> <use xlink:href="#Red50" filter="url(#arithmeticFlood)" /> <text x="-25" y="275">arithmetic</text> </g> </g> <g transform="translate(0,325)" enable-background="new"> <desc>Render the examples using the filters that do not obliterate the background, thus sometimes causing the background to continue to appear in some cases, and in other cases the background image blends into itself ("double-counting").</desc> <text x="15" y="75">opacity 1.0</text> <text x="15" y="115" font-size="27">(without feFlood)</text> <text x="15" y="200">opacity 0.5</text> <text x="15" y="240" font-size="27">(without feFlood)</text> <use xlink:href="#BlueTriangles"/> <g transform="translate(275,25)"> <use xlink:href="#Red100" filter="url(#overNoFlood)" /> <use xlink:href="#Red50" filter="url(#overNoFlood)" /> <text x="5" y="275">over</text> </g> <g transform="translate(400,25)"> <use xlink:href="#Red100" filter="url(#inNoFlood)" /> <use xlink:href="#Red50" filter="url(#inNoFlood)" /> <text x="35" y="275">in</text> </g> <g transform="translate(525,25)"> <use xlink:href="#Red100" filter="url(#outNoFlood)" /> <use xlink:href="#Red50" filter="url(#outNoFlood)" /> <text x="15" y="275">out</text> </g> <g transform="translate(650,25)"> <use xlink:href="#Red100" filter="url(#atopNoFlood)" /> <use xlink:href="#Red50" filter="url(#atopNoFlood)" /> <text x="10" y="275">atop</text> </g> <g transform="translate(775,25)"> <use xlink:href="#Red100" filter="url(#xorNoFlood)" /> <use xlink:href="#Red50" filter="url(#xorNoFlood)" /> <text x="15" y="275">xor</text> </g> <g transform="translate(900,25)"> <use xlink:href="#Red100" filter="url(#arithmeticNoFlood)" /> <use xlink:href="#Red50" filter="url(#arithmeticNoFlood)" /> <text x="-25" y="275">arithmetic</text> </g> </g> </g> </svg>
<feConvolveMatrix>
Name: | feConvolveMatrix |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEConvolveMatrixElement |
feConvolveMatrix applies a matrix convolution filter effect. A convolution combines pixels in the input image with neighboring pixels to produce a resulting image. A wide variety of imaging operations can be achieved through convolutions, including blurring, edge detection, sharpening, embossing and beveling.
A matrix convolution is based on an n-by-m matrix (the convolution kernel) which describes how a given pixel value in the input image is combined with its neighboring pixel values to produce a resulting pixel value. Each result pixel is determined by applying the kernel matrix to the corresponding source pixel and its neighboring pixels. The basic convolution formula which is applied to each color value for a given pixel is:
where "orderX" and "orderY" represent the X and Y values for the ‘order
’ attribute, "targetX" represents the
value of the ‘targetX
’ attribute, "targetY" represents
the value of the ‘targetY
’ attribute, "kernelMatrix"
represents the value of the ‘kernelMatrix
’ attribute, "divisor"
represents the value of the ‘divisor
’ attribute, and "bias" represents
the value of the ‘bias
’ attribute.
Note in the above formulas that the values in the kernel matrix are applied such that the kernel matrix is rotated 180 degrees relative to the source and destination images in order to match convolution theory as described in many computer graphics textbooks.
To illustrate, suppose you have a input image which is 5 pixels by 5 pixels, whose color values for one of the color channels are as follows:
and you define a 3-by-3 convolution kernel as follows:
Let's focus on the color value at the second row and second column
of the image (source pixel value is 120). Assuming the simplest case
(where the input image's pixel grid aligns perfectly with the kernel's
pixel grid) and assuming default values for attributes ‘divisor
’, ‘targetX
’ and ‘targetY
’, then resulting color value will
be:
Because they operate on pixels, matrix convolutions are inherently
resolution-dependent. To make <feConvolveMatrix>
produce
resolution-independent results, an explicit value should be provided
for either the ‘filterRes
’ attribute on the <filter>
element and/or attribute ‘kernelUnitLength
’.
‘kernelUnitLength
’, in combination with the
other attributes, defines an implicit pixel grid in the filter effects
coordinate system (i.e., the coordinate system established by the ‘primitiveUnits
’ attribute). If the pixel
grid established by ‘kernelUnitLength
’ is not scaled to match
the pixel grid established by attribute ‘filterRes
’ (implicitly or explicitly),
then the input image will be temporarily rescaled to match its pixels
with ‘kernelUnitLength
’. The convolution happens
on the resampled image. After applying the convolution, the image is
resampled back to the original resolution.
When the image must be resampled to match the coordinate system
defined by ‘kernelUnitLength
’ prior to convolution, or
resampled to match the device coordinate system after convolution, it
is recommended that high quality viewers make use of appropriate
interpolation techniques, for example bilinear or bicubic. Depending
on the speed of the available interpolents, this choice may be
affected by the ‘image-rendering
’ property setting. Note
that implementations might choose approaches that minimize or
eliminate resampling when not necessary to produce proper results,
such as when the document is zoomed out such that ‘kernelUnitLength
’ is considerably smaller
than a device pixel.
Attribute definitions:
kernelMatrix
’. The values provided must
be <integer>
s greater than zero. Values that are not integers will be truncated,
i.e. rounded to the closest integer value towards zero. The first
number, <orderX>, indicates the number of columns in the
matrix. The second number, <orderY>, indicates the number of
rows in the matrix. If <orderY> is not provided, it defaults
to <orderX>.order
’ is 3. divisor
’ to yield the final destination
color value. A divisor that is the sum of all the matrix values
tends to have an evening effect on the overall color intensity of
the result. If the specified divisor is zero then the default value
will be used instead. The lacuna
value is the sum of all values in kernelMatrix, with the
exception that if the sum is zero, then the divisor is set to 1.divisor
’, the ‘bias
’ attribute is added to each
component. One application of ‘bias
’ is when it is desirable to have
.5 gray value be the zero response of
the filter. The bias property shifts the range of the filter. This
allows representation of values that would otherwise be clamped to 0
or 1.bias
’ is 0.Determines how to extend the input image as necessary with color values so that the matrix operations can be applied when the kernel is positioned at or near the edge of the input image.
"duplicate" indicates that the input image is extended along each of its borders as necessary by duplicating the color values at the given edge of the input image.
Original N-by-M image, where m=M-1 and n=N-1:
Extended by two pixels using "duplicate":
"wrap" indicates that the input image is extended by taking the color values from the opposite edge of the image.
Extended by two pixels using "wrap":
The value none indicates that the input image is extended with pixel values of zero for R, G, B and A.
The lacuna
value for ‘edgeMode
’ is duplicate.
Animatable: yes.
primitiveUnits
’) between successive
columns and rows, respectively, in the ‘kernelMatrix
’. By specifying value(s)
for ‘kernelUnitLength
’, the kernel becomes
defined in a scalable, abstract coordinate system. If ‘kernelUnitLength
’ is not specified, the
default value is one pixel in the offscreen bitmap, which is a
pixel-based coordinate system, and thus potentially not scalable.
For some level of consistency across display media and user agents,
it is necessary that a value be provided for at least one of ‘filterRes
’ and ‘kernelUnitLength
’. In some
implementations, the most consistent results and the fastest
performance will be achieved if the pixel grid of the temporary
offscreen images aligns with the pixel grid of the kernel.ALPHAX,Y
of the convolution formula for a
given pixel is:
ALPHAX,Y = (
SUM I=0 to [‘orderY
’-1] {
SUM J=0 to [‘orderX
’-1] {
SOURCE X-‘targetX
’+J, Y-‘targetY
’+I * ‘kernelMatrix
’‘orderX
’-J-1, ‘orderY
’-I-1
}
}
) / ‘divisor
’ + ‘bias
’
ALPHAX,Y
of the convolution formula for a
given pixel is:
ALPHAX,Y = SOURCEX,Y
The lacuna value for ‘preserveAlpha
’ is false.<feCustom>
Name: | feCustom |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFECustomElement |
Attribute definitions:
The calculations are performed on non-premultiplied color values. If the input graphics consists of premultiplied color values, those values are converted into non-premultiplied color values for this operation.
Each ‘feCustom
’ element can have any number of
‘feCustomSource
’ subelements. Each ‘feCustomSource
’ references one resource.
Name: | feCustomSource |
---|---|
Categories: | None. |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFECustomSourceElement |
Attribute definitions:
Each ‘feCustom
’ element can have any number of
‘feCustomParam
’ subelements. Each ‘feCustomParam
’
node passes one parameter.
Name: | feCustomParam |
---|---|
Categories: | None. |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFECustomParamElement |
Attribute definitions:
number
’, ‘array
’, ‘vec2
’,
‘vec3
’, ‘vec4
’, ‘mat2
’,
‘mat3
’ and ‘mat4
’, the ‘values
’ attribute passes the values to
the shader. For all other types, the attributes with the same name
pass the parameter to the shader. The lacuna
value for ‘type
’ is number. If the attribute is not specified, then the default behavior
depends on the value of attribute type. If type
is ‘mat2
’, ‘mat3
’ or ‘mat4
’, then
this attribute defaults to the identity matrix. If type is ‘number
’
or ‘array
’, then this attribute defaults
to the value 0. If type is ‘vec2
’, ‘vec3
’ or
‘vec4
’, then this attribute defaults to
a number list with values of 0. The length of the number list
depends on the size of the specified vector.
<feDiffuseLighting>
Name: | feDiffuseLighting |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of descriptive elements and exactly one light source element, in any order. |
Attributes: | |
DOM Interfaces: | SVGFEDiffuseLightingElement |
This filter primitive lights an image using the alpha channel as a bump map. The resulting image is an RGBA opaque image based on the light color with alpha = 1.0 everywhere. The lighting calculation follows the standard diffuse component of the Phong lighting model. The resulting image depends on the light color, light position and surface geometry of the input bump map.
The light map produced by this filter primitive can be combined
with a texture image using the multiply term of the
arithmetic <feComposite>
compositing method.
Multiple light sources can be simulated by adding several of these
light maps together before applying it to the texture image.
The formulas below make use of 3x3 filters. Because they operate on
pixels, such filters are inherently resolution-dependent. To make <feDiffuseLighting>
produce
resolution-independent results, an explicit value should be provided
for either the ‘filterRes
’ attribute on the <filter>
element and/or attribute ‘kernelUnitLength
’.
‘kernelUnitLength
’, in combination with the
other attributes, defines an implicit pixel grid in the filter effects
coordinate system (i.e., the coordinate system established by the ‘primitiveUnits
’ attribute). If the pixel
grid established by ‘kernelUnitLength
’ is not scaled to match
the pixel grid established by attribute ‘filterRes
’ (implicitly or explicitly),
then the input image will be temporarily rescaled to match its pixels
with ‘kernelUnitLength
’. The 3x3 filters are
applied to the resampled image. After applying the filter, the image
is resampled back to its original resolution.
When the image must be
resampled, it is recommended that high quality viewers make use of
appropriate interpolation techniques, for example bilinear or
bicubic. Depending on the speed of the available interpolents,
this choice may be affected by the ‘image-rendering
’ property setting. Note
that implementations might choose approaches that minimize or
eliminate resampling when not necessary to produce proper results,
such as when the document is zoomed out such that ‘kernelUnitLength
’ is considerably smaller
than a device pixel.
For the formulas that follow, the
Norm(Ax,Ay,Az)
function
is defined as:
Norm(Ax,Ay,Az) = sqrt(Ax^2+Ay^2+Az^2)
The resulting RGBA image is computed as follows:
Dr = kd * N.L *
Lr
Dg = kd * N.L * Lg
Db = kd * N.L * Lb
Da = 1.0
where
N is a function of x and y and depends on the surface gradient as follows:
The surface described by the input alpha image I(x,y) is:
Z (x,y) = surfaceScale * I(x,y)
Surface normal is calculated using the Sobel gradient 3x3 filter. Different filter kernels are used depending on whether the given pixel is on the interior or an edge. For each case, the formula is:
Nx (x,y) = - surfaceScale *
FACTORx *
(Kx(0,0)*I(x-dx,y-dy) +
Kx(1,0)*I(x,y-dy) + Kx(2,0)*I(x+dx,y-dy) +
Kx(0,1)*I(x-dx,y) +
Kx(1,1)*I(x,y) +
Kx(2,1)*I(x+dx,y) +
Kx(0,2)*I(x-dx,y+dy) +
Kx(1,2)*I(x,y+dy) + Kx(2,2)*I(x+dx,y+dy))
Ny (x,y) = - surfaceScale * FACTORy *
(Ky(0,0)*I(x-dx,y-dy) +
Ky(1,0)*I(x,y-dy) + Ky(2,0)*I(x+dx,y-dy) +
Ky(0,1)*I(x-dx,y) +
Ky(1,1)*I(x,y) +
Ky(2,1)*I(x+dx,y) +
Ky(0,2)*I(x-dx,y+dy) +
Ky(1,2)*I(x,y+dy) + Ky(2,2)*I(x+dx,y+dy))
Nz (x,y) = 1.0
N = (Nx, Ny, Nz) /
Norm((Nx,Ny,Nz))
In these formulas, the dx
and dy
values
(e.g., I(x-dx,y-dy)
), represent deltas relative to a
given (x,y)
position for the purpose of estimating the
slope of the surface at that point. These deltas are determined by the
value (explicit or implicit) of attribute ‘kernelUnitLength
’.
Top/left corner: FACTORx=2/(3*dx) |
Top row: FACTORx=1/(3*dx) |
Top/right corner: FACTORx=2/(3*dx) |
Left column: FACTORx=1/(2*dx) |
Interior pixels: FACTORx=1/(4*dx) |
Right column: FACTORx=1/(2*dx) |
Bottom/left corner: FACTORx=2/(3*dx) |
Bottom row: FACTORx=1/(3*dx) |
Bottom/right corner: FACTORx=2/(3*dx) |
L, the unit vector from the image sample to the light, is calculated as follows:
For Infinite light sources it is constant:
Lx = cos(azimuth)*cos(elevation)
Ly = sin(azimuth)*cos(elevation)
Lz = sin(elevation)
For Point and spot lights it is a function of position:
Lx = Lightx - x
Ly = Lighty - y
Lz = Lightz - Z(x,y)
L = (Lx, Ly, Lz) /
Norm(Lx, Ly, Lz)
where Lightx, Lighty, and Lightz are the input light position.
Lr,Lg,Lb, the light color vector, is a function of position in the spot light case only:
Lr =
Lightr*pow((-L.S),specularExponent)
Lg = Lightg*pow((-L.S),specularExponent)
Lb = Lightb*pow((-L.S),specularExponent)
where S is the unit vector pointing from the light to the point (pointsAtX, pointsAtY, pointsAtZ) in the x-y plane:
Sx = pointsAtX -
Lightx
Sy = pointsAtY - Lighty
Sz = pointsAtZ - Lightz
S = (Sx, Sy, Sz) /
Norm(Sx, Sy, Sz)
If L.S is positive, no light is present. (Lr =
Lg = Lb = 0). If ‘limitingConeAngle
’ is specified, -L.S <
cos(limitingConeAngle) also indicates that no light is present.
Attribute definitions:
primitiveUnits
’) for dx
and
dy
, respectively, in the surface normal calculation
formulas. By specifying value(s) for kernelUnitLength, the kernel becomes defined
in a scalable, abstract coordinate system. If kernelUnitLength is not specified, the
dx
and dy
values should represent very
small deltas relative to a given (x,y)
position, which
might be implemented in some cases as one pixel in the intermediate
image offscreen bitmap, which is a pixel-based coordinate system,
and thus potentially not scalable. For some level of consistency
across display media and user agents, it is necessary that a value
be provided for at least one of ‘filterRes
’ and kernelUnitLength. Discussion of intermediate
images are in the Introduction and in
the description of attribute ‘filterRes
’. The light source is defined by one of the child elements <feDistantLight>
, <fePointLight>
or <feSpotLight>
. The light color is
specified by property ‘lighting-color
’.
<feDisplacementMap>
Name: | feDisplacementMap |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEDisplacementMapElement |
This filter primitive uses the pixels values from the image from ‘in2
’ to spatially displace the image from ‘in
’. This is the transformation to be
performed:
P'(x,y) ← P( x + scale * (XC(x,y) - .5), y + scale * (YC(x,y) - .5))
where P(x,y) is the input image, ‘in
’, and P'(x,y) is the destination.
XC(x,y) and YC(x,y) are the component values of the channel designated
by the ‘xChannelSelector
’ and ‘yChannelSelector
’. For example, to use the
R component of ‘in2
’ to control displacement in x and the G
component of Image2 to control displacement in y, set ‘xChannelSelector
’ to "R" and ‘yChannelSelector
’ to "G".
The displacement map, ‘in2
’, defines the inverse of the mapping
performed.
The input image in is to remain premultiplied for this filter
primitive. The calculations using the pixel values from ‘in2
’ are performed using non-premultiplied
color values. If the image from ‘in2
’ consists of premultiplied color values,
those values are automatically converted into non-premultiplied color
values before performing this operation.
This filter can have arbitrary non-localized effect on the input
which might require substantial buffering in the processing pipeline.
However with this formulation, any intermediate buffering needs can be
determined by ‘scale
’ which represents the maximum range
of displacement in either x or y.
When applying this filter, the source pixel location will often lie
between several source pixels. In this case it is recommended that
high quality viewers apply an interpolent on the surrounding pixels,
for example bilinear or bicubic, rather than simply selecting the
nearest source pixel. Depending on the speed of the available
interpolents, this choice may be affected by the ‘image-rendering
’ property setting.
The ‘color-interpolation-filters
’ property only
applies to the ‘in2
’ source image and does not apply to the ‘in
’ source image. The ‘in
’ source image must remain in its
current color space.
Attribute definitions:
primitiveUnits
’ on the <filter>
element. The lacuna
value for ‘scale
’ is 0.
in2
’ to use to displace the pixels in ‘in
’ along the x-axis. The lacuna
value for ‘xChannelSelector
’ is A. in2
’ to use to displace the pixels in ‘in
’ along the y-axis. The lacuna
value for ‘yChannelSelector
’ is A. in
’ attribute)"
in
’. This attribute can take on the same
values as the ‘in
’ attribute.<feDropShadow>
Name: | feDropShadow |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEDropShadowElement |
This filter creates a drop shadow of the input image. It is a shorthand filter, and is defined in terms of combinations of other filter primitives. The expectation is that it can be optimized more easily by implementations.
The result of a <feDropShadow>
filter primitive is
equivalent to the following:
<feGaussianBlur in="alpha-channel-of-feDropShadow-in" stdDeviation="stdDeviation-of-feDropShadow"/> <feOffset dx="dx-of-feDropShadow" dy="dy-of-feDropShadow" result="offsetblur"/> <feFlood flood-color="flood-color-of-feDropShadow" flood-opacity="flood-opacity-of-feDropShadow"/> <feComposite in2="offsetblur" operator="in"/> <feMerge> <feMergeNode/> <feMergeNode in="in-of-feDropShadow"/> </feMerge>
The above divided into steps:
<feDropShadow>
filter primitive and
the ‘stdDeviation
’ on the <feDropShadow>
and do processing as
if the following <feGaussianBlur>
was applied:
<feGaussianBlur in="alpha-channel-of-feDropShadow-in" stdDeviation="stdDeviation-of-feDropShadow"/>
dx
’ and ‘dy
’ as specified on the <feDropShadow>
element, equivalent
to applying an <feOffset>
with these parameters:
<feOffset dx="dx-of-feDropShadow" dy="dy-of-feDropShadow" result="offsetblur"/>
<feFlood>
element with ‘flood-color
’ and ‘flood-opacity
’ as specified on the <feDropShadow>
was applied:
<feFlood flood-color="flood-color-of-feDropShadow" flood-opacity="flood-opacity-of-feDropShadow"/>
<feFlood>
in step 3 with the result
of the <feOffset>
in step 2 as if an <feComposite>
filter primitive with
operator=‘in
’ was applied:
<feComposite in2="offsetblur" operator="in"/>
<feMerge>
was performed:
<feMerge> <feMergeNode/> <feMergeNode in="in-of-feDropShadow"/> </feMerge>
Note that while the definition of the <feDropShadow>
filter primitive says
that it can be expanded into an equivalent tree it is not required
that it is implemented like that. The expectation is that user agents
can optimize the handling by not having to do all the steps
separately.
Beyond the DOM interface SVGFEDropShadowElement
there is no way of accessing the internals of the <feDropShadow>
filter primitive,
meaning if
the filter primitive is implemented as an equivalent tree then that
tree must not be exposed to the DOM.
Attribute definitions:
The x offset of the drop shadow.
The lacuna
value for ‘dx
’ is 2.
This attribute is then forwarded to the ‘dx
’ attribute of the internal <feOffset>
element.
Animatable: yes.
The y offset of the drop shadow.
The lacuna
value for ‘dy
’ is 2.
This attribute is then forwarded to the ‘dy
’ attribute of the internal <feOffset>
element.
Animatable: yes.
The standard deviation for the blur operation in the drop shadow.
The lacuna
value for ‘stdDeviation
’ is 2.
This attribute is then forwarded to the ‘stdDeviation
’ attribute of the internal
<feGaussianBlur>
element.
Animatable: yes.
<feFlood>
Name: | feFlood |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEFloodElement |
This filter primitive creates a rectangle filled with the color and
opacity values from properties ‘flood-color
’ and ‘flood-opacity
’. The rectangle is as large
as the filter primitive
subregion established by the <feFlood>
element.
flood-color
’
property The ‘flood-color
’ property indicates what color
to use to flood the current filter
primitive subregion. The keyword ‘currentColor
’ and ICC colors can be specified in
the same manner as within a <paint> specification for the
‘fill
’ and ‘stroke
’ properties.
Name: | flood-color |
Value: | currentColor | <color> <icccolor>? |
---|---|
Initial: | black |
Applies to: | <feFlood> and <feDropShadow> elements
|
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | yes |
flood-opacity
’
property The ‘flood-opacity
’ property defines the
opacity value to use across the entire filter primitive subregion.
Name: | flood-opacity |
---|---|
Value: | <number> | <percentage> |
Initial: | 1 |
Applies to: | <feFlood> and <feDropShadow> elements
|
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | yes |
<feGaussianBlur>
Name: | feGaussianBlur |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEGaussianBlurElement |
This filter primitive performs a Gaussian blur on the input image.
The Gaussian blur kernel is an approximation of the normalized convolution:
G(x,y) = H(x)I(y)
where
H(x) = exp(-x2/ (2s2)) / sqrt(2* pi*s2)
and
I(x) = exp(-y2/ (2t2)) / sqrt(2* pi*t2)
with ‘s
’ being the standard
deviation in the x direction and ‘t
’
being the standard deviation in the y direction, as specified by ‘stdDeviation
’.
The value of ‘stdDeviation
’ can be either one or two
numbers. If two numbers are provided, the first number represents a
standard deviation value along the x-axis of the current coordinate
system and the second value represents a standard deviation in Y. If
one number is provided, then that value is used for both X and Y.
Even if only one value is provided for ‘stdDeviation
’, this can be implemented as
a separable convolution.
For larger values of ‘s
’ (s >=
2.0), an approximation can be used: Three successive box-blurs build a
piece-wise quadratic convolution kernel, which approximates the
Gaussian kernel to within roughly 3%.
let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
... if d is odd, use three box-blurs of size ‘d
’, centered on the output pixel.
... if d is even, two box-blurs of size ‘d
’ (the first one centered on the pixel
boundary between the output pixel and the one to the left, the second
one centered on the pixel boundary between the output pixel and the
one to the right) and one box blur of size ‘d+1
’ centered on the output pixel.
The approximation formula also applies correspondingly to ‘t
’.
Frequently this operation will take place on alpha-only images,
such as that produced by the built-in input, SourceAlpha. The
implementation may notice this and optimize the single channel case.
If the input has infinite extent and is constant (e.g FillPaint where the
fill is a solid color), this operation has no effect. If the input has
infinite extent and the filter resultwhere the fill is a solid color)
is the input to an <feTile>
, the filter is evaluated
with periodic boundary conditions.
By default, the subregion interacts as input and output clipping and this sentence would be irrelevant. However, this changes if the WG decides to allow a choice between input and output clipping.
What about
other inputs with infinite extents? What is the ‘periodic boundary condition
’?
Attribute definitions:
primitiveUnits
’ on the <filter>
element. The second value
represents a standard deviation in Y. If one number is provided,
then that value is used for both X and Y.stdDeviation
’ is 0 in only one of X or Y, then the effect is
that the blur is only applied in the direction that has a non-zero
value. stdDeviation
’ is 0.The example at the start of this chapter
makes use of the <feGaussianBlur>
filter primitive to
create a drop shadow effect.
<feImage>
Name: | feImage |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEImageElement |
This filter primitive refers to a graphic external to this filter element, which is loaded or rendered into an RGBA raster and becomes the result of the filter primitive.
This filter primitive can refer to an external image or can be a reference to another piece of SVG. It produces an image similar to the built-in image source SourceGraphic except that the graphic comes from an external source.
If the xlink:href references a
stand-alone image resource such as a JPEG, PNG or SVG file, then the
image resource is rendered according to the behavior of the <image>
element; otherwise, the
referenced resource is rendered according to the behavior of the <use>
element. In either case, the
current user coordinate system depends on the value of attribute ‘primitiveUnits
’ on the <filter>
element. The processing of the preserveAspectRatio attribute on the <feImage>
element is identical to
that of the <image>
element.
When the
referenced image must be resampled to match the device coordinate
system, it is recommended that high quality viewers make use of
appropriate interpolation techniques, for example bilinear or
bicubic. Depending on the speed of the available interpolents,
this choice may be affected by the ‘image-rendering
’ property setting.
Attribute definitions:
The lacuna value for ‘preserveAspectRatio
’ is xMidYMid meet.
Animatable: yes.
The following example illustrates how images are placed relative to an object. From left to right:
x
’ and ‘y
’ values relative to the viewport the
object is in.
<svg width="600" height="250" viewBox="0 0 600 250" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Example feImage - Examples of feImage use</title> <desc>Three examples of using feImage, the first showing the default rendering, the second showing the image fit to a box and the third showing the image shifted and clipped.</desc> <defs> <filter id="Default"> <feImage xlink:href="smiley.png" /> </filter> <filter id="Fitted" primitiveUnits="objectBoundingBox"> <feImage xlink:href="smiley.png" x="0" y="0" width="100%" height="100%" preserveAspectRatio="none"/> </filter> <filter id="Shifted"> <feImage xlink:href="smiley.png" x="500" y="5"/> </filter> </defs> <rect fill="none" stroke="blue" x="1" y="1" width="598" height="248"/> <g> <rect x="50" y="25" width="100" height="200" filter="url(#Default)"/> <rect x="50" y="25" width="100" height="200" fill="none" stroke="green"/> <rect x="250" y="25" width="100" height="200" filter="url(#Fitted)"/> <rect x="250" y="25" width="100" height="200" fill="none" stroke="green"/> <rect x="450" y="25" width="100" height="200" filter="url(#Shifted)"/> <rect x="450" y="25" width="100" height="200" fill="none" stroke="green"/> </g> </svg>
<feMerge>
Name: | feMerge |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEMergeElement |
This filter primitive composites input image layers on top of each
other using the over operator with Input1
(corresponding to the first <feMergeNode>
child element) on the
bottom and the last specified input, InputN (corresponding to
the last <feMergeNode>
child element), on top.
Many effects produce a number of intermediate layers in order to create the final output image. This filter allows us to collapse those into a single image. Although this could be done by using n-1 Composite-filters, it is more convenient to have this common operation available in this form, and offers the implementation some additional flexibility.
Each ‘feMerge
’ element can have any number of
‘feMergeNode
’ subelements, each of which
has an in
attribute.
Name: | feMergeNode |
---|---|
Categories: | None. |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEMergeNodeElement |
The canonical implementation of feMerge is to render the entire effect into one RGBA layer, and then render the resulting layer on the output device. In certain cases (in particular if the output device itself is a continuous tone device), and since merging is associative, it might be a sufficient approximation to evaluate the effect one layer at a time and render each layer individually onto the output device bottom to top.
If the topmost image input is SourceGraphic and this <feMerge>
is the last filter
primitive in the filter, the implementation is encouraged to render
the layers up to that point, and then render the SourceGraphic
directly from its vector description on top.
The example at the start of this chapter
makes use of the <feMerge>
filter primitive to
composite two intermediate filter results together.
<feMorphology>
Name: | feMorphology |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEMorphologyElement |
This filter primitive performs "fattening" or "thinning" of artwork. It is particularly useful for fattening or thinning an alpha channel.
The dilation (or erosion) kernel is a rectangle with a width of 2*x-radius and a height of 2*y-radius. In dilation, the output pixel is the individual component-wise maximum of the corresponding R,G,B,A values in the input image's kernel rectangle. In erosion, the output pixel is the individual component-wise minimum of the corresponding R,G,B,A values in the input image's kernel rectangle.
Frequently this operation will take place on alpha-only images, such as that produced by the built-in input, SourceAlpha. In that case, the implementation might want to optimize the single channel case.
If the input has infinite extent and is constant (e.g FillPaint where the
fill is a solid color), this operation has no effect. If the input has
infinite extent and the filter result is the input to an <feTile>
,
the filter is evaluated with periodic boundary conditions.
By default, the subregion interacts as input and output clipping and this sentence would be irrelevant. However, this changes if the WG decides to allow a choice between input and output clipping.
What about other
inputs with infinite extents? What is the ‘periodic
boundary condition
’?
Because <feMorphology>
operates on
premultipied color values, it will always result in color values less
than or equal to the alpha channel.
Attribute definitions:
operator
’ is erode. primitiveUnits
’ on the <filter>
element.<?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="5cm" height="7cm" viewBox="0 0 700 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example feMorphology - Examples of erode and dilate</title> <desc>Five text strings drawn as outlines. The first is unfiltered. The second and third use 'erode'. The fourth and fifth use 'dilate'.</desc> <defs> <filter id="Erode3"> <feMorphology operator="erode" in="SourceGraphic" radius="3" /> </filter> <filter id="Erode6"> <feMorphology operator="erode" in="SourceGraphic" radius="6" /> </filter> <filter id="Dilate3"> <feMorphology operator="dilate" in="SourceGraphic" radius="3" /> </filter> <filter id="Dilate6"> <feMorphology operator="dilate" in="SourceGraphic" radius="6" /> </filter> </defs> <rect fill="none" stroke="blue" stroke-width="2" x="1" y="1" width="698" height="498"/> <g enable-background="new" > <g font-family="Verdana" font-size="75" fill="none" stroke="black" stroke-width="6" > <text x="50" y="90">Unfiltered</text> <text x="50" y="180" filter="url(#Erode3)" >Erode radius 3</text> <text x="50" y="270" filter="url(#Erode6)" >Erode radius 6</text> <text x="50" y="360" filter="url(#Dilate3)" >Dilate radius 3</text> <text x="50" y="450" filter="url(#Dilate6)" >Dilate radius 6</text> </g> </g> </svg>
<feOffset>
Name: | feOffset |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEOffsetElement |
This filter primitive offsets the input image relative to its current position in the image space by the specified vector.
This is important for effects like drop shadows.
When applying this filter, the destination location may be offset
by a fraction of a pixel in device space. In this case a high quality viewer
should make use of appropriate interpolation techniques, for example
bilinear or bicubic. This is especially recommended for dynamic
viewers where this interpolation provides visually smoother movement
of images. For static viewers this is less of a concern. Close
attention should be made to the ‘image-rendering
’ property setting to
determine the authors intent.
Attribute definitions:
primitiveUnits
’ on the <filter>
element.primitiveUnits
’ on the <filter>
element.The example at the start of this chapter
makes use of the <feOffset>
filter primitive to offset
the drop shadow from the original source graphic.
<feSpecularLighting>
Name: | feSpecularLighting |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of descriptive elements and exactly one light source element, in any order. |
Attributes: | |
DOM Interfaces: | SVGFESpecularLightingElement |
This filter primitive lights a source graphic using the alpha channel as a bump map. The resulting image is an RGBA image based on the light color. The lighting calculation follows the standard specular component of the Phong lighting model. The resulting image depends on the light color, light position and surface geometry of the input bump map. The result of the lighting calculation is added. The filter primitive assumes that the viewer is at infinity in the z direction (i.e., the unit vector in the eye direction is (0,0,1) everywhere).
This filter primitive produces an image which contains the specular
reflection part of the lighting calculation. Such a map is intended to
be combined with a texture using the add term of the
arithmetic <feComposite>
method. Multiple light
sources can be simulated by adding several of these light maps before
applying it to the texture image.
The resulting RGBA image is computed as follows:
Sr = ks * pow(N.H,
specularExponent) * Lr
Sg = ks * pow(N.H, specularExponent) *
Lg
Sb = ks * pow(N.H, specularExponent) *
Lb
Sa = max(Sr, Sg,
Sb)
where
See <feDiffuseLighting>
for definition of
N and (Lr, Lg, Lb).
The definition of H reflects our assumption of the constant eye vector E = (0,0,1):
H = (L + E) / Norm(L+E)
where L is the light unit vector.
Unlike the <feDiffuseLighting>
, the <feSpecularLighting>
filter produces
a non-opaque image. This is due to the fact that the specular result
(Sr,Sg,Sb,Sa) is meant to
be added to the textured image. The alpha channel of the result is the
max of the color components, so that where the specular light is zero,
no additional coverage is added to the image and a fully white
highlight will add opacity.
The <feDiffuseLighting>
and <feSpecularLighting>
filters will
often be applied together. An implementation may detect this and
calculate both maps in one pass, instead of two.
Attribute definitions:
primitiveUnits
’) for dx
and
dy
, respectively, in the surface normal calculation
formulas. By specifying value(s) for kernelUnitLength, the kernel becomes defined
in a scalable, abstract coordinate system. If kernelUnitLength is not specified, the
dx
and dy
values should represent very
small deltas relative to a given (x,y)
position, which
might be implemented in some cases as one pixel in the intermediate
image offscreen bitmap, which is a pixel-based coordinate system,
and thus potentially not scalable. For some level of consistency
across display media and user agents, it is necessary that a value
be provided for at least one of filterRes and kernelUnitLength. Discussion of intermediate
images are in the Introduction and in
the description of attribute ‘filterRes
’. The light source is defined by one of the child elements <feDistantLight>
, <fePointLight>
or <feDistantLight>
. The light color is
specified by property ‘lighting-color
’.
The example at the start of this chapter
makes use of the <feSpecularLighting>
filter primitive
to achieve a highly reflective, 3D glowing effect.
<feTile>
Name: | feTile |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFETileElement |
This filter primitive fills a target rectangle with a repeated,
tiled pattern of an input image. The target rectangle is as large as
the filter primitive subregion
established by the <feTile>
element.
Typically, the input image has been defined with its own filter primitive subregion in
order to define a reference tile. <feTile>
replicates the reference
tile in both X and Y to completely fill the target rectangle. The
top/left corner of each given tile is at location
(x+i*width,y+j*height)
, where (x,y)
represents the top/left of the input image's filter primitive subregion,
width
and height
represent the width and
height of the input image's filter
primitive subregion, and i
and j
can be
any integer value. In most cases, the input image will have a smaller
filter primitive subregion
than the <feTile>
in order to achieve a
repeated pattern effect.
Implementers must take appropriate measures in constructing the tiled image to avoid artifacts between tiles, particularly in situations where the user to device transform includes shear and/or rotation. Unless care is taken, interpolation can lead to edge pixels in the tile having opacity values lower or higher than expected due to the interaction of painting adjacent tiles which each have partial overlap with particular pixels.
<feTurbulence>
Name: | feTurbulence |
---|---|
Categories: | Filter primitive element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFETurbulenceElement |
This filter primitive creates an image using the Perlin turbulence function. It allows the synthesis of artificial textures like clouds or marble. For a detailed description the of the Perlin turbulence function, see "Texturing and Modeling", Ebert et al, AP Professional, 1994. The resulting image will fill the entire filter primitive subregion for this filter primitive.
It is possible to create bandwidth-limited noise by synthesizing only one octave.
The C code below shows the exact algorithm used for this filter effect. The filter primitive subregion is to be passed as the arguments fTileX, fTileY, fTileWidth and fTileHeight.
For fractalSum, you get a turbFunctionResult that is aimed at a
range of -1 to 1 (the actual result might exceed this range in some
cases). To convert to a color value, use the formula colorValue
= ((turbFunctionResult * 255) + 255) / 2
, then clamp to the
range 0 to 255.
For turbulence, you get a turbFunctionResult that is aimed at a
range of 0 to 1 (the actual result might exceed this range in some
cases). To convert to a color value, use the formula colorValue
= (turbFunctionResult * 255)
, then clamp to the range 0 to 255.
The following order is used for applying the pseudo random numbers.
An initial seed value is computed based on the ‘seed
’ attribute. Then the implementation
computes the lattice points for R, then continues getting additional
pseudo random numbers relative to the last generated pseudo random
number and computes the lattice points for G, and so on for B and A.
The generated color and alpha values are in the color space
determined by the ‘color-interpolation-filters
’ property:
/* Produces results in the range [1, 2**31 - 2]. Algorithm is: r = (a * r) mod m where a = 16807 and m = 2**31 - 1 = 2147483647 See [Park & Miller], CACM vol. 31 no. 10 p. 1195, Oct. 1988 To test: the algorithm should produce the result 1043618065 as the 10,000th generated number if the original seed is 1. */ #define RAND_m 2147483647 /* 2**31 - 1 */ #define RAND_a 16807 /* 7**5; primitive root of m */ #define RAND_q 127773 /* m / a */ #define RAND_r 2836 /* m % a */ long setup_seed(long lSeed) { if (lSeed <= 0) lSeed = -(lSeed % (RAND_m - 1)) + 1; if (lSeed > RAND_m - 1) lSeed = RAND_m - 1; return lSeed; } long random(long lSeed) { long result; result = RAND_a * (lSeed % RAND_q) - RAND_r * (lSeed / RAND_q); if (result <= 0) result += RAND_m; return result; } #define BSize 0x100 #define BM 0xff #define PerlinN 0x1000 #define NP 12 /* 2^PerlinN */ #define NM 0xfff static uLatticeSelector[BSize + BSize + 2]; static double fGradient[4][BSize + BSize + 2][2]; struct StitchInfo { int nWidth; // How much to subtract to wrap for stitching. int nHeight; int nWrapX; // Minimum value to wrap. int nWrapY; }; static void init(long lSeed) { double s; int i, j, k; lSeed = setup_seed(lSeed); for(k = 0; k < 4; k++) { for(i = 0; i < BSize; i++) { uLatticeSelector[i] = i; for (j = 0; j < 2; j++) fGradient[k][i][j] = (double)(((lSeed = random(lSeed)) % (BSize + BSize)) - BSize) / BSize; s = double(sqrt(fGradient[k][i][0] * fGradient[k][i][0] + fGradient[k][i][1] * fGradient[k][i][1])); fGradient[k][i][0] /= s; fGradient[k][i][1] /= s; } } while(--i) { k = uLatticeSelector[i]; uLatticeSelector[i] = uLatticeSelector[j = (lSeed = random(lSeed)) % BSize]; uLatticeSelector[j] = k; } for(i = 0; i < BSize + 2; i++) { uLatticeSelector[BSize + i] = uLatticeSelector[i]; for(k = 0; k < 4; k++) for(j = 0; j < 2; j++) fGradient[k][BSize + i][j] = fGradient[k][i][j]; } } #define s_curve(t) ( t * t * (3. - 2. * t) ) #define lerp(t, a, b) ( a + t * (b - a) ) double noise2(int nColorChannel, double vec[2], StitchInfo *pStitchInfo) { int bx0, bx1, by0, by1, b00, b10, b01, b11; double rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v; register i, j; t = vec[0] + PerlinN; bx0 = (int)t; bx1 = bx0+1; rx0 = t - (int)t; rx1 = rx0 - 1.0f; t = vec[1] + PerlinN; by0 = (int)t; by1 = by0+1; ry0 = t - (int)t; ry1 = ry0 - 1.0f; // If stitching, adjust lattice points accordingly. if(pStitchInfo != NULL) { if(bx0 >= pStitchInfo->nWrapX) bx0 -= pStitchInfo->nWidth; if(bx1 >= pStitchInfo->nWrapX) bx1 -= pStitchInfo->nWidth; if(by0 >= pStitchInfo->nWrapY) by0 -= pStitchInfo->nHeight; if(by1 >= pStitchInfo->nWrapY) by1 -= pStitchInfo->nHeight; } bx0 &= BM; bx1 &= BM; by0 &= BM; by1 &= BM; i = uLatticeSelector[bx0]; j = uLatticeSelector[bx1]; b00 = uLatticeSelector[i + by0]; b10 = uLatticeSelector[j + by0]; b01 = uLatticeSelector[i + by1]; b11 = uLatticeSelector[j + by1]; sx = double(s_curve(rx0)); sy = double(s_curve(ry0)); q = fGradient[nColorChannel][b00]; u = rx0 * q[0] + ry0 * q[1]; q = fGradient[nColorChannel][b10]; v = rx1 * q[0] + ry0 * q[1]; a = lerp(sx, u, v); q = fGradient[nColorChannel][b01]; u = rx0 * q[0] + ry1 * q[1]; q = fGradient[nColorChannel][b11]; v = rx1 * q[0] + ry1 * q[1]; b = lerp(sx, u, v); return lerp(sy, a, b); } double turbulence(int nColorChannel, double *point, double fBaseFreqX, double fBaseFreqY, int nNumOctaves, bool bFractalSum, bool bDoStitching, double fTileX, double fTileY, double fTileWidth, double fTileHeight) { StitchInfo stitch; StitchInfo *pStitchInfo = NULL; // Not stitching when NULL. // Adjust the base frequencies if necessary for stitching. if(bDoStitching) { // When stitching tiled turbulence, the frequencies must be adjusted // so that the tile borders will be continuous. if(fBaseFreqX != 0.0) { double fLoFreq = double(floor(fTileWidth * fBaseFreqX)) / fTileWidth; double fHiFreq = double(ceil(fTileWidth * fBaseFreqX)) / fTileWidth; if(fBaseFreqX / fLoFreq < fHiFreq / fBaseFreqX) fBaseFreqX = fLoFreq; else fBaseFreqX = fHiFreq; } if(fBaseFreqY != 0.0) { double fLoFreq = double(floor(fTileHeight * fBaseFreqY)) / fTileHeight; double fHiFreq = double(ceil(fTileHeight * fBaseFreqY)) / fTileHeight; if(fBaseFreqY / fLoFreq < fHiFreq / fBaseFreqY) fBaseFreqY = fLoFreq; else fBaseFreqY = fHiFreq; } // Set up initial stitch values. pStitchInfo = &stitch; stitch.nWidth = int(fTileWidth * fBaseFreqX + 0.5f); stitch.nWrapX = fTileX * fBaseFreqX + PerlinN + stitch.nWidth; stitch.nHeight = int(fTileHeight * fBaseFreqY + 0.5f); stitch.nWrapY = fTileY * fBaseFreqY + PerlinN + stitch.nHeight; } double fSum = 0.0f; double vec[2]; vec[0] = point[0] * fBaseFreqX; vec[1] = point[1] * fBaseFreqY; double ratio = 1; for(int nOctave = 0; nOctave < nNumOctaves; nOctave++) { if(bFractalSum) fSum += double(noise2(nColorChannel, vec, pStitchInfo) / ratio); else fSum += double(fabs(noise2(nColorChannel, vec, pStitchInfo)) / ratio); vec[0] *= 2; vec[1] *= 2; ratio *= 2; if(pStitchInfo != NULL) { // Update stitch values. Subtracting PerlinN before the multiplication and // adding it afterward simplifies to subtracting it once. stitch.nWidth *= 2; stitch.nWrapX = 2 * stitch.nWrapX - PerlinN; stitch.nHeight *= 2; stitch.nWrapY = 2 * stitch.nWrapY - PerlinN; } } return fSum; }
Attribute definitions:
The base frequency (frequencies) parameter(s) for the noise function. If two <number>s are provided, the first number represents a base frequency in the X direction and the second value represents a base frequency in the Y direction. If one number is provided, then that value is used for both X and Y.
The lacuna
value for ‘baseFrequency
’ is 0.
Negative values are unsupported.
Animatable: yes.
The numOctaves parameter for the noise function.
The lacuna
value for ‘numOctaves
’ is 1.
Negative values are unsupported.
Animatable: yes.
The starting number for the pseudo random number generator.
The
lacuna
value for ‘seed
’ is 0.
When the seed number is handed over to the algorithm above it must first be truncated, i.e. rounded to the closest integer value towards zero.
Animatable: yes.
If stitchTiles="noStitch", no
attempt is made to achieve smooth transitions at the border of
tiles which contain a turbulence function. Sometimes the result
will show clear discontinuities at the tile borders.
If stitchTiles="stitch", then the
user agent will automatically adjust baseFrequency-x and
baseFrequency-y values such that the <feTurbulence>
node's width and
height (i.e., the width and height of the current subregion)
contains an integral number of the Perlin tile width and height for
the first octave. The baseFrequency will be adjusted up or down
depending on which way has the smallest relative (not absolute)
change as follows: Given the frequency, calculate
lowFreq=floor(width*frequency)/width
and
hiFreq=ceil(width*frequency)/width
. If
frequency/lowFreq < hiFreq/frequency then use lowFreq, else use
hiFreq. While generating turbulence values, generate lattice
vectors as normal for Perlin Noise, except for those lattice points
that lie on the right or bottom edges of the active area (the size
of the resulting tile). In those cases, copy the lattice vector
from the opposite edge of the active area.
The lacuna
value for ‘stitchTiles
’ is noStitch.
Animatable: yes.
Indicates whether the filter primitive should perform a noise or turbulence function.
The
lacuna
value for ‘type
’ is turbulence.
Animatable: yes.
<?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="450px" height="325px" viewBox="0 0 450 325" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example feTurbulence - Examples of feTurbulence operations</title> <desc>Six rectangular areas showing the effects of various parameter settings for feTurbulence.</desc> <g font-family="Verdana" text-anchor="middle" font-size="10" > <defs> <filter id="Turb1" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feTurbulence type="turbulence" baseFrequency="0.05" numOctaves="2"/> </filter> <filter id="Turb2" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feTurbulence type="turbulence" baseFrequency="0.1" numOctaves="2"/> </filter> <filter id="Turb3" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feTurbulence type="turbulence" baseFrequency="0.05" numOctaves="8"/> </filter> <filter id="Turb4" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feTurbulence type="fractalNoise" baseFrequency="0.1" numOctaves="4"/> </filter> <filter id="Turb5" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feTurbulence type="fractalNoise" baseFrequency="0.4" numOctaves="4"/> </filter> <filter id="Turb6" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%"> <feTurbulence type="fractalNoise" baseFrequency="0.1" numOctaves="1"/> </filter> </defs> <rect x="1" y="1" width="448" height="323" fill="none" stroke="blue" stroke-width="1" /> <rect x="25" y="25" width="100" height="75" filter="url(#Turb1)" /> <text x="75" y="117">type=turbulence</text> <text x="75" y="129">baseFrequency=0.05</text> <text x="75" y="141">numOctaves=2</text> <rect x="175" y="25" width="100" height="75" filter="url(#Turb2)" /> <text x="225" y="117">type=turbulence</text> <text x="225" y="129">baseFrequency=0.1</text> <text x="225" y="141">numOctaves=2</text> <rect x="325" y="25" width="100" height="75" filter="url(#Turb3)" /> <text x="375" y="117">type=turbulence</text> <text x="375" y="129">baseFrequency=0.05</text> <text x="375" y="141">numOctaves=8</text> <rect x="25" y="180" width="100" height="75" filter="url(#Turb4)" /> <text x="75" y="272">type=fractalNoise</text> <text x="75" y="284">baseFrequency=0.1</text> <text x="75" y="296">numOctaves=4</text> <rect x="175" y="180" width="100" height="75" filter="url(#Turb5)" /> <text x="225" y="272">type=fractalNoise</text> <text x="225" y="284">baseFrequency=0.4</text> <text x="225" y="296">numOctaves=4</text> <rect x="325" y="180" width="100" height="75" filter="url(#Turb6)" /> <text x="375" y="272">type=fractalNoise</text> <text x="375" y="284">baseFrequency=0.1</text> <text x="375" y="296">numOctaves=1</text> </g> </svg>
color-interpolation-filters
’ property The description of the ‘color-interpolation-filters
’ property is
as follows:
Name: | color-interpolation-filters |
---|---|
Value: | auto | sRGB | linearRGB |
Initial: | linearRGB |
Applies to: | filter primitives |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | yes |
auto
’
sRGB
’ or ‘linearRGB
’
spaces for filter effects color operations. This option indicates
that the author doesn't require that color operations occur in a
particular color space.
sRGB
’
linearRGB
’
The ‘color-interpolation-filters
’ property
specifies the color space for imaging operations performed via filter
effects.
Note that ‘color-interpolation-filters
’ has a
different initial value than ‘color-interpolation
’. ‘color-interpolation-filters
’ has an
initial value of ‘linearRGB
’, where as
‘color-interpolation
’ has an initial
value of ‘sRGB
’. Thus, in the default case,
filter effects operations occur in the linearRGB color space, whereas
all other color interpolations occur by default in the sRGB color
space.
Note that the ‘color-interpolation-filters
’ propert has
no effect on Filter Functions, which operate in the sRGB
color space.
The following sections define the elements that define a light source, <feDistantLight>
, <fePointLight>
and <feSpotLight>
, and property ‘lighting-color
’, which defines the color
of the light.
<feDistantLight>
Name: | feDistantLight |
---|---|
Categories: | Light source element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEDistantLightElement |
Attribute definitions:
azimuth
’ is 0.elevation
’ is 0. The following diagram illustrates the angles which ‘azimuth
’ and ‘elevation
’ represent in an XYZ coordinate
system.
Use other color then red and green
<fePointLight>
Name: | fePointLight |
---|---|
Categories: | Light source element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFEPointLightElement |
Attribute definitions:
primitiveUnits
’ on the <filter>
element.x
’ is 0.primitiveUnits
’ on the <filter>
element.y
’ is 0.primitiveUnits
’ on the <filter>
element, assuming that, in
the initial
coordinate system , the positive Z-axis comes out towards the
person viewing the content and assuming that one unit along the
Z-axis equals one
unit in X and Y.z
’ is 0.<feSpotLight>
Name: | feSpotLight |
---|---|
Categories: | Light source element |
Content model: | Any number of the following elements, in any order: |
Attributes: | |
DOM Interfaces: | SVGFESpotLightElement |
Attribute definitions:
primitiveUnits
’ on the <filter>
element.x
’ is 0.primitiveUnits
’ on the <filter>
element.y
’ is 0.primitiveUnits
’ on the <filter>
element, assuming that, in
the initial
coordinate system , the positive Z-axis comes out towards the
person viewing the content and assuming that one unit along the
Z-axis equals one
unit in X and Y.z
’ is 0.primitiveUnits
’ on the <filter>
element of the point at
which the light source is pointing.pointsAtX
’ is 0.primitiveUnits
’ on the <filter>
element of the point at
which the light source is pointing.pointsAtY
’ is 0.primitiveUnits
’ on the <filter>
element of the point at
which the light source is pointing, assuming that, in the initial
coordinate system, the positive Z-axis comes out towards the
person viewing the content and assuming that one unit along the
Z-axis equals
one unit in X and Y.pointsAtZ
’ is 0.specularExponent
’ is 1.lighting-color
’ property The ‘lighting-color
’ property defines the color
of the light source for filter
primitives <feDiffuseLighting>
and <feSpecularLighting>
.
Name: | lighting-color |
---|---|
Value: | currentColor | <color> <icccolor>? |
Initial: | white |
Applies to: | <feDiffuseLighting> and <feSpecularLighting> elements
|
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | yes |
The custom-filter function allows extending this specification with a customized filter effect. Customized filter effects are described by the @filter rule or feCustom element element and referenced internal or external resources. External resource must be described by a host language. Each @filter rule has a unique identifier that can be referenced by the custom-filter function.
@supports
’ condition: ‘filter
’Value: | <custom-filter-type> |
To verify if a UA supports a certain customized filter effect type,
the support condition syntax [CSS3-CONDITIONAL]
gets extended by adding the media feature ‘filter
’.
<custom-filter-type> = webgl
This specification supports the custom filter type ‘webgl
’ to indicate support for the shading language based on WebGL. Future
versions may allow additional keywords.
@support filter(webgl) {
...
}
The @filter rule allows specifying custom-filter definitions (like
shaders) for the use of the ‘filter
’ property. A
@filter rule consists of the keyword "@filter", followed by an
identifier giving a name for the custom-filter (which will be
referenced using the ‘custom()
’ filter
function), followed by a set of custom-filter descriptors.
The general form of an @filter at-rule is:
@filter IDENT { <custom-filter-description> }
where <custom-filter-description> has the form:
descriptor: value; descriptor: value; [...] descriptor: value;
Each @filter rule specifies a value for every custom-filter descriptor, either implicitly or explicitly. Those not given explicit values in the rule take the initial value listed with each descriptor in this specification. When a given descriptor occurs multiple times in a given @filter rule, only the last specified value is used, all prior values for that descriptor are ignored.
The following is the grammar for the custom-filter at-rule and extends the lexical scanner in the Grammar of CSS 2.1 ([CSS21], Appendix G):
filter_rule : FILTER_SYM S+ IDENT S* '{' S* group_rule_body '}' S*; @{F}{I}{L}{T}{E}{R} {return FILTER_SYM;}
group_rule_body as defined in [CSS3-CONDITIONAL].
Furthermore, the nested_statement
rule [CSS3-CONDITIONAL]
gets extended by adding "filter_rule
".
Name: | src |
Value: | [ <uri> [format(<string>)]?]# |
Initial: | N/A |
The ‘src
’
descriptor takes a comma separated list of resource references with an
optional format function. The resource format is either determined by
a provided custom filter format string with the format function, or by
the MIME type of the resource (e.g. transfered MIME type from the
resource providing server). If a format function is provided, then the
passed string overrides the MIME type definition of the resource. The
type of a customized filter effect depends on the format of the
resources.
It is possible to reference custom filter resources in a document
by a fragment identifier. The format may be identified by the context
of the referenced resource. If the referenced resource is a ‘<script>
’ element, the ‘type
’ attribute defines the format of the content.
The following document
from Mozilla describes how WebGL vertex and fragment shaders can be
defined in <script>
elements.
<script id="warp" type="x-shader/x-vertex" > <-- source code here --> </script> <style> @filter warp { src: url(#warp); } </style>
Format strings defined by this specification:
String | Custom-filter Format | Common extensions |
---|---|---|
"x-shader/x-vertex" | WebGL 1.0 vertex shader | .vs |
"x-shader/x-fragment" | WebGL 1.0 fragment shader | .fs |
Name: | parameters |
Value: | <param># |
Initial: | N/A |
The list of parameters define variables, that get passed into the custom filter effect (e.g. parameters passed to a shader). Each parameter has an identifier. If a parameter with the same identifier occurs more then once in the list of parameters, the latest parameter definition overrides all previous definitions. A parameter definition can be overloaded by a parameter definition in the referencing custom filter function.
<param> = IDENT <param-value>
<param-value> = <transform-function>+ | <number>{1,4} | <array> | <mat> | <color> | <URI>
<array> = array(<number>#)
<mat> = mat2(<number> [ , <number> ]{3,3}) | mat3(<number> [ , <number> ]{8,8}) | mat4(<number> [ , <number> ]{15,15})
The following function definitions describe matrices in column-major order.
Name: | geometry |
Value: | <geometry-shape> |
Initial: | grid(1 1 attached) |
<geometry-shape> = grid(<integer>{1,2} || [ detached | attached ]?)
1
1
’ there is a single row and a single column, resulting in
a four-vertices mesh (top-left, top-right, bottom-right,
bottom-left). If the second parameter is not provided, it takes a
value equal to the first. A value of ‘n
m
’ results in a vertex mesh that has n columns and m rows.
This results in a total of (n + 1) * (m + 1) vertices. If one of
the passed parameters is zero or negative, the UA must use the
initial mesh.
detached
’
detached
’ implies
that the vertices are detached.
attached
’
attached
’ implies
that the vertices are attached.
If no value for attachmeny of verices is specified, it computes
to ‘attached
’.
Name: | mix |
Value: | auto | [<blend-mode> || <composite-mode>] |
Initial: | auto |
auto
’
Name: | margin |
Value: | <margin-width>{1,4} |
Initial: | auto |
Computed Value: | the percentage as specified or the absolute length. A value of auto computes to 10% of the input Filter primitive subregion. |
The ‘margin
’
descriptor values and the input Filter primitive subregion define
the filter primitive subregion of the custom filter primitive.
<margin-width> = <length> | <percentage> | auto
For the definition of the <margin-width> values see CSS Box Model [CSS21].
With Custom Shaders, authors can manipulate the color and shape of a graphical element in granular ways. The following sections describe the host language Custom Shaders as extension for Custom Filter Functions.
There are many precedents for shading languages, for example:
This document recommends the adoption of the subset of GLSL ES [GLSLES] defined in the WebGL 1.0 WEBGL] specification.
In particular, the same restrictions as defined in WebGL should apply to shaders for CSS:
All the parameters specified in the <param> values (e.g., the custom-filter at-rule or the ‘custom()
’ filter function) will be available as
uniforms to the shader(s) referenced by the ‘shader
’ property.
The group may consider applying further restrictions to the GLSL ES language to make it easier to write vertex and fragment shaders.
The OpenGL ES shading language provides a number of variables that can be passed to shaders, exchanged between shaders or set by shaders. In particular, a vertex shader can provide specific data to the fragment shader in the form of "varying" parameters (parameters that vary per pixel). The following sections describe particular variables that are assumed for the vertex and fragment shaders.
Custom Filter Function values have the following meaning for Custom Shaders:
mix
’ descriptor
auto
’
mix
’
descriptor value computes to ‘auto
’, the
effect is as if ‘normal source-atop
’ was
specified.
This section illustrates the shader processing model as it applies to an element whose unfiltered rendering is shown in the figure below.
Prior to the shader processing, the input of the filter primitive gets rendered into an off-screen image (the source texture). The off-screen size and position is controlled by the filter primitive subregion.
An <feCustom>
element or a ‘custom()
’ filter function defines a custom filter
primitive. The following figure illustrates its model.
In a first step the source texture is used on a vertex mesh. By default, the vertex mesh has the position and size of the filter primitive subregion. In the following figure, the red markers represent the default vertices in the default vertex mesh. The diagonal line illustrate how the vertices define two triangles.
The ‘geometry
’ attribute on the <feCustom>
element and the ‘geometry
’
descriptor on the custom-filter at-rule
give more granularity control over the vertex mesh.
In a second step, the vertex mesh gets processed through the vertex shader, which produces a set of transformed vertices. These transformed vertices are the output as shown in the figure below.
The third step is the rasterization step. The filter primitive invokes the fragment shader for every pixel location inside the vertex mesh to perform per pixel operation and produce the final pixel color at that vertex mesh location.
Note that the fragment shader may be called several times for what corresponds to the same pixel coordinate on the output, for example when the vertex mesh folds over itself. Overlaying pixel values do neither composite nor blend. The pixel value with the least depth will be choosen.
The ‘mix
’
descriptor provides basic functionalities for color manipulation like
blending and alpha compositing on a fragment shader. The processing
model of ‘mix
’ is
illustrated in the following figure:
Each color value passed to the fragment shader gets multiplied with the color matrix, a predefined fragment shader variable that represents a 4x4 matrix. The matrix is initialized to an identity matrix, but can be set by a fragment shader. The resulting color is the multiplied color.
The mix color is a second, predefined
fragment shader variable and represents an ‘RGBA
’ <color> value. The mix color can be set by the fragment
shader. If not specified, the default value is transparent black. The
‘RGB
’ channels of the multiplied color get blended with
the ‘RGB
’ channels of the mix color with the multiplied color as destination
and the mix color as source [COMPOSITING]. The applied
blend mode depends on the passed <blend-mode> parameter which is
‘normal
’ by default. The result of the
blending and the opacity of the mix
color define the blended color.
The multiplied color and the mix color get composed using the
alpha-compositing rules as described in the Compositing and Blending
spec [COMPOSITING]. The applied
alpha-compositing mode is specified by the passed
<composite-mode> parameter and is ‘source-atop
’ by default.
The last step, step 4, shows rasterized output. If the custom filter primitive is the last primitive in the filter chain, then this output is the filtered rendering of the element. Otherwise, the output of the primitive becomes the input to the next filter primitive using it.
A normal GLSL shader requires that the fragment shader computes a
gl_FragColor
value which is the color value for the
processed fragment (pixel).
Because of the security restrictions, fragment shaders are not allowed to access rendered content pixel values directly. However, fragment shaders in this specification have the option to compute a value that is automatically mixed with the rendered content pixel values (but without ever providing direct access to these values to the shader code).
In the context of this specification, fragment shaders have the options to compute the following values:
gl_FragColor
. If the compositing and blending values
for the ‘mix
’
descriptor compute to ‘none
’ the shader
computes a gl_FragColor
value. This may be useful, for
example, to compute complex patterns.
css_MixColor
. If the compositing and blending values
for the ‘mix
’
descriptor do not compute to ‘none
’, then
the shader computes a mix color
value that is composited with the rendered content as explained in
the shaders processing model.
css_ColorMatrix
. If the compositing and blending
values for the ‘mix
’ descriptor do not compute to
‘none
’, then the shader computes a color matrix value that is
multiplied with the rendered content as explained in the shaders processing model.
The following example shows a fragment shader which computes a simple solid red color:
CSS
@filter red { src: url('simple.vs') format('x-shader/x-vertex'), url(simple.fs) format('x-shader/x-fragment'); } #filtered-element { filter: custom(red); }
simple.vs
attribute vec4 a_position; void main() { gl_Position = a_position; }
simple.fs
void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }
The following example shows a fragment shader which darkens the
rendered content by computing a css_MixColor
which is
multiplied with the rendered content:
CSS
@filter darken { src: url('simple2.vs') format('x-shader/x-vertex'), url(simple2.fs) format('x-shader/x-fragment'); mix: multiply; } #filtered-element { filter: custom(mix); }
simple2.vs
attribute vec4 a_position; void main() { gl_Position = a_position; }
simple2.fs
void main() { css_MixColor = vec4(0.8, 0.8, 0.8, 1.0); }
The following example shows a fragment shader which darkens the
rendered content by computing a css_ColorMatrix
which
varies depending on the texture coordinate:
CSS
@filter colormatrix { src: url('simple.vs') format('x-shader/x-vertex'), url(simple3.fs) format('x-shader/x-fragment'); } #filtered-element { filter: custom(colormatrix); }
simple3.vs
attribute vec4 a_position; varying vec2 v_texCoord; void main() { v_texCoord = a_position.xy; gl_Position = a_position; }
simple3.fs
varying vec2 v_texCoord; void main() { float x = v_texCoord.x; css_ColorMatrix = mat4( vec4(x, x, x, x), // 1st column vec4(x, x, x, x), // 2nd column vec4(x, x, x, x), // 3rd column vec4(x, x, x, x), // 4th column ); }
The following attribute variables are available to the vertex shader.
attribute variables | description |
---|---|
attribute vec4 a_position
| The vertex coordinates in the Filter primitive subregion. Coordinates are normalized to the [0, 1] range along the x, y and z axis. |
attribute vec3 a_triangleCoord
|
The x and y values provide the coordinate of the current
‘ The z coordinate is computed according to the following figure. The z coordinate value is provided for each vertex and corresponding triangle. For example, for the bottom right vertex of the top triangle, the z coordinate will be 2. For the bottom right vertex of the bottom triangle, the z coordinate will be 4. |
The following uniform variables are set to specific values by the user agent:
uniform variable | description |
---|---|
uniform vec2 u_textureSize
| The input texture's size. Includes the filter margins. The texture size is given in the actual device pixels and incorporates the device pixel ratio. |
uniform vec2 u_meshSize
| The size of the current mesh in terms of tiles. The x coordinate provides the number of columns and the y coordinate provides the number of rows. |
When there parameters are passed to the custom filter function or
the <feCustom>
filter primitive, the user
agent pass uniforms of the corresponding name and type to the shaders.
The following table shows the mapping between CSS shader parameters and uniform types.
CSS param type | GLSL uniform type |
---|---|
<color> | vec4 |
<number>{1,4} | float, vec2, vec3 or vec4 |
<array> | float[n] |
<transform-function>+ | mat4 |
mat2(<number> [ , <number> ]{3,3}) | mat3(<number> [ , <number> ]{8,8}) | mat4(<number> [ , <number> ]{15,15}) | mat2, mat3 or mat4 |
<image-list> | sampler2D |
The following code sample illustrates that mechanism.
CSS @filter distort { src: url(distort.vs), url(tint.fs); parameters: distortAmount 0.5, lightVector 1.0 1.0 0.0, disp texture(disp.png); } .shaded { filter: custom(distort); } Shader (vertex or fragment) ... uniform float distortAmount; uniform vec3 lightVector; uniform sampler2D disp; uniform vec2 dispSize; ...
As illustrated in the example, for each <textureName>
texture()
parameter, an additional vec2
uniform is
passed to the shaders with the size of the corresponding texture.
If no vertex shader is provided, the default one is as shown below.
attribute vec4 a_position; void main() { gl_Position = a_position; }
If no fragment shader is provided, the default one is shown below.
void main() { }
If shaders access texture values outside the [0, 1]
range on both axis, the returned value is a fully translucent black
pixel.
The filter() function produces a CSS <image> value. It has the following syntax:
<filter> = filter(
<image>,
none | <filter-function>+
)
The function takes two parameters. The first is a CSS
<image> value. The second is the value of a ‘filter
’ property. The
function take the input image parameter and apply the filter rules,
returning a processing image.
The filter functions may increase the dimension of the image in comparison to the original image. Does it influence the offset when passed to a CSS property?
<filter>
element Below are the equivalents for each of the filter functions
expressed in terms of the ‘filter element
’
element. The parameters from the function are labelled with brackets
in the following style: [amount]. In the case of parameters that are
percentage values, they are converted to real numbers.
<filter id="grayscale"> <feColorMatrix type="matrix" values="(0.2126 + 0.7874 * [1 - amount]) (0.7152 - 0.7152 * [1 - amount]) (0.0722 - 0.0722 * [1 - amount]) 0 0 (0.2126 - 0.2126 * [1 - amount]) (0.7152 + 0.2848 * [1 - amount]) (0.0722 - 0.0722 * [1 - amount]) 0 0 (0.2126 - 0.2126 * [1 - amount]) (0.7152 - 0.7152 * [1 - amount]) (0.0722 + 0.9278 * [1 - amount]) 0 0 0 0 0 1 0"/> </filter>
<filter id="sepia"> <feColorMatrix type="matrix" values="(0.393 + 0.607 * [1 - amount]) (0.769 - 0.769 * [1 - amount]) (0.189 - 0.189 * [1 - amount]) 0 0 (0.349 - 0.349 * [1 - amount]) (0.686 + 0.314 * [1 - amount]) (0.168 - 0.168 * [1 - amount]) 0 0 (0.272 - 0.272 * [1 - amount]) (0.534 - 0.534 * [1 - amount]) (0.131 + 0.869 * [1 - amount]) 0 0 0 0 0 1 0"/> </filter>
<filter id="saturate"> <feColorMatrix type="saturate" values="(1 - [amount])"/> </filter>
<filter id="hue-rotate"> <feColorMatrix type="hueRotate" values="[angle]"/> </filter>
<filter id="invert"> <feComponentTransfer> <feFuncR type="table" tableValues="[amount] (1 - [amount])"/> <feFuncG type="table" tableValues="[amount] (1 - [amount])"/> <feFuncB type="table" tableValues="[amount] (1 - [amount])"/> </feComponentTransfer> </filter>
<filter id="opacity"> <feComponentTransfer> <feFuncA type="table" tableValues="0 [amount]"/> </feComponentTransfer> </filter>
<filter id="brightness"> <feComponentTransfer> <feFuncR type="linear" slope="[amount]"/> <feFuncG type="linear" slope="[amount]"/> <feFuncB type="linear" slope="[amount]"/> </feComponentTransfer> </filter>
<filter id="contrast"> <feComponentTransfer> <feFuncR type="linear" slope="[amount]" intercept="-(0.5 * [amount] + 0.5)"/> <feFuncG type="linear" slope="[amount]" intercept="-(0.5 * [amount] + 0.5)"/> <feFuncB type="linear" slope="[amount]" intercept="-(0.5 * [amount] + 0.5)"/> </feComponentTransfer> </filter>
<filter id="blur"> <feGaussianBlur stdDeviation="[radius radius]"> </filter>
<filter id="drop-shadow"> <feGaussianBlur in="[alpha-channel-of-input]" stdDeviation="[radius]"/> <feOffset dx="[offset-x]" dy="[offset-y]" result="offsetblur"/> <feFlood flood-color="[color]"/> <feComposite in2="offsetblur" operator="in"/> <feMerge> <feMergeNode/> <feMergeNode in="[input-image]"/> </feMerge> </filter>
<filter id="custom"> <feCustom mix="[blend-mode || composite-mode]" geometry="[geometry-shape]"> <feCustomParam ident="[ident]" type="[type]" values="values"/> ... <feCustomSource src="[resource]" format="[format]"/> ... </feCustom> </filter>
enable-background
’ propertyName: | enable-background |
---|---|
Value: | accumulate | new |
Initial: | accumulate |
Applies to: | Typically elements that can contain renderable elements. language is responsible for defining the applicable set of elements. For SVG: container elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
The property which enables access to the background image is ‘enable-background
’:
new
accumulate (the initial/default value)
enable-background: new
’, then all renderable child
elements of the current container
element element are rendered both onto the parent container
element element's background image canvas and onto the target
device.
The ‘enable-background
’ property has no affect
if the ‘isolation
’ property has a
value of ‘isolate
’ [COMPOSITING]. The
isolation group defined by the ‘isolation
’ property will establish a new
background image canvas.
Two possible pseudo input images for
filter effects are BackgroundImage and
BackgroundAlpha, which each represent
an image snapshot of the canvas under the filter region at the time that the <filter>
element is invoked. BackgroundImage
represents both the color values and alpha channel of the canvas
(i.e., RGBA pixel values), whereas BackgroundAlpha represents only the alpha
channel.
Implementations will often need to maintain supplemental background image buffers in order to support the BackgroundImage and BackgroundAlpha pseudo input images. Sometimes, the background image buffers will contain an in-memory copy of the accumulated painting operations on the current canvas.
Because in-memory image buffers can take up significant system resources, content must explicitly indicate to the user agent that the document needs access to the background image before BackgroundImage and BackgroundAlpha pseudo input images can be used.
A background image is what's been rendered before the current element. The host language is responsible for defining what rendered before in this context means. For SVG, that uses the painter's algorithm, rendered before means all of the prior elements in pre order traversal previous to the element to which the filter is applied. If a filter effect specifies either the BackgroundImage or the BackgroundAlpha pseudo input images and no
ancestor container
element element has a property value of ‘enable-background: new
’, then the background image
request is technically in error. Processing will proceed without
interruption (i.e., no error message) and a transparent black image
shall be provided in response to the request.
This section only applies to the SVG definition of enable-background.
Assume you have an element E in the document and that E has a
series of ancestors A1 (its immediate parent),
A2, etc. (Note: A0 is E.) Each ancestor
Ai will have a corresponding temporary background image
offscreen buffer BUFi. The contents of the background
image available to a <filter>
referenced by E is defined
as follows:
enable-background
’ property has the value
‘new
’.
Note that if there is no such ancestor element, then the outermost element An will be chosen.
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="13.5cm" height="2.7cm" viewBox="0 0 1350 270" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Example enable-background01</title> <desc>This test case shows five pictures which illustrate the rules for background image processing.</desc> <defs> <filter id="ShiftBGAndBlur" filterUnits="userSpaceOnUse" x="0" y="0" width="1200" height="400"> <desc> This filter discards the SourceGraphic, if any, and just produces a result consisting of the BackgroundImage shifted down 125 units and then blurred. </desc> <feOffset in="BackgroundImage" dx="0" dy="125" /> <feGaussianBlur stdDeviation="8" /> </filter> <filter id="ShiftBGAndBlur_WithSourceGraphic" filterUnits="userSpaceOnUse" x="0" y="0" width="1200" height="400"> <desc> This filter takes the BackgroundImage, shifts it down 125 units, blurs it, and then renders the SourceGraphic on top of the shifted/blurred background. </desc> <feOffset in="BackgroundImage" dx="0" dy="125" /> <feGaussianBlur stdDeviation="8" result="blur" /> <feMerge> <feMergeNode in="blur"/> <feMergeNode in="SourceGraphic"/> </feMerge> </filter> </defs> <g transform="translate(0,0)"> <desc>The first picture is our reference graphic without filters.</desc> <rect x="25" y="25" width="100" height="100" fill="red"/> <g opacity=".5"> <circle cx="125" cy="75" r="45" fill="green"/> <polygon points="160,25 160,125 240,75" fill="blue"/> </g> <rect x="5" y="5" width="260" height="260" fill="none" stroke="blue"/> </g> <g enable-background="new" transform="translate(270,0)"> <desc>The second adds an empty 'g' element which invokes ShiftBGAndBlur.</desc> <rect x="25" y="25" width="100" height="100" fill="red"/> <g opacity=".5"> <circle cx="125" cy="75" r="45" fill="green"/> <polygon points="160,25 160,125 240,75" fill="blue"/> </g> <g filter="url(#ShiftBGAndBlur)"/> <rect x="5" y="5" width="260" height="260" fill="none" stroke="blue"/> </g> <g enable-background="new" transform="translate(540,0)"> <desc>The third invokes ShiftBGAndBlur on the inner group.</desc> <rect x="25" y="25" width="100" height="100" fill="red"/> <g filter="url(#ShiftBGAndBlur)" opacity=".5"> <circle cx="125" cy="75" r="45" fill="green"/> <polygon points="160,25 160,125 240,75" fill="blue"/> </g> <rect x="5" y="5" width="260" height="260" fill="none" stroke="blue"/> </g> <g enable-background="new" transform="translate(810,0)"> <desc>The fourth invokes ShiftBGAndBlur on the triangle.</desc> <rect x="25" y="25" width="100" height="100" fill="red"/> <g opacity=".5"> <circle cx="125" cy="75" r="45" fill="green"/> <polygon points="160,25 160,125 240,75" fill="blue" filter="url(#ShiftBGAndBlur)"/> </g> <rect x="5" y="5" width="260" height="260" fill="none" stroke="blue"/> </g> <g enable-background="new" transform="translate(1080,0)"> <desc>The fifth invokes ShiftBGAndBlur_WithSourceGraphic on the triangle.</desc> <rect x="25" y="25" width="100" height="100" fill="red"/> <g opacity=".5"> <circle cx="125" cy="75" r="45" fill="green"/> <polygon points="160,25 160,125 240,75" fill="blue" filter="url(#ShiftBGAndBlur_WithSourceGraphic)"/> </g> <rect x="5" y="5" width="260" height="260" fill="none" stroke="blue"/> </g> </svg>
View this example as SVG (SVG-enabled browsers only)
The example above contains five parts, described as follows:
<g>
element. Inside the <g>
is a green circle that
partially overlaps the rectangle and a a blue triangle that
partially overlaps the circle. The three objects are then outlined
by a rectangle stroked with a thin blue line. No filters are applied
to the reference graphic.
<g>
element which invokes the
ShiftBGAndBlur filter. This filter takes the current accumulated
background image (i.e., the entire reference graphic) as input,
shifts its offscreen down, blurs it, and then writes the result to
the canvas. Note that the offscreen for the filter is initialized to
transparent black, which allows the already rendered rectangle,
circle and triangle to show through after the filter renders its own
result to the canvas.
<g>
element. The accumulated
background at the time the filter is applied contains only the red
rectangle. Because the children of the inner <g>
(i.e., the circle and triangle)
are not part of the inner <g>
element's background and
because ShiftBGAndBlur ignores SourceGraphic, the children of the
inner <g>
do not appear in the result.
<polygon>
element that draws the
triangle. The accumulated background at the time the filter is
applied contains the red rectangle plus the green circle ignoring
the effect of the ‘opacity
’ property on the inner <g>
element. (Note that the blurred
green circle at the bottom does not let the red rectangle show
through on its left side. This is due to ignoring the effect of the
‘opacity
’ property.) Because the
triangle itself is not part of the accumulated background and
because ShiftBGAndBlur ignores SourceGraphic, the triangle does not
appear in the result.
The CSS ‘filter
’ property is animatable.
Interpolation happens between the filter functions only if the ‘filter
’ values have
the same number of filter functions, and the same functions appearing
in the same order.
The CSS WG may define different fading transitions in the future.
All properties defined as animatable, provided they are one of the property types listed in CSS3 Transitions [CSS3-TRANSITIONS], can be animated.
To interpolate between ‘parameters
’ values in a
custom()
filter function or between <feCustomParam>
attribute values, the
user agent should interpolate between each of the parameter values
according to its type. List of values need to be of the same length.
Matrices need to be of the same dimension. Arrays need to be of the
same size.
Interpolation between shader params only happens if all the other shader properties are identical: vertex shader, fragment shader, filter margins and vertex mesh.
<number>[wsp<number>{0-3}]
| Interpolate between each of the values. |
<true|false>[wsp<true|fals>{0-3}]
| Interpolate between each of the values using a step function. |
<array>
| Interpolate between the array elements. |
<transform-function>
| Follows the CSS3 transform interpolation rules. |
<mat>
| Interpolate between the matrix components (applies to mat2, mat3 and mat4). |
transform
’ property, it is not possible to
animate the different components of the custom() filter parameters on
different timelines or with different keyframes. This is a generic
issue of animating properties that have multiple components to them.The following description of the security model is not sufficient and detailed enough. See public-fx mailing list.
Since a custom filter primitive is applying a processing operation on input values, it is important that no protected information leaks from that operation.
A study of the security issues has led to the requirement that vertex shaders and fragment shaders do not get access to the rendered content in order to prevent timing attacks.
If a custom filter primitive does not fulfill these requirements, the primitive is a pass through.
Input to a filter effect must not include anything as input that would violate same origin restrictions. If cross-origin access is required, then the requested content should be explicitly marked with CORS data.
This restriction includes:
For content that falls under this restriction, the filter has no
affect. For example, a filter effect that is applying to a
cross-origin ‘iframe
’ element does not
have any affect on this element.
The SVGFilterElement
interface corresponds to the <filter>
element.
interface SVGFilterElement : SVGElement { readonly attribute SVGAnimatedEnumeration filterUnits; readonly attribute SVGAnimatedEnumeration primitiveUnits; readonly attribute SVGAnimatedLength x; readonly attribute SVGAnimatedLength y; readonly attribute SVGAnimatedLength width; readonly attribute SVGAnimatedLength height; readonly attribute SVGAnimatedInteger filterResX; readonly attribute SVGAnimatedInteger filterResY; void setFilterRes(in unsigned long filterResX, in unsigned long filterResY); ImageData apply(in ImageData source); }; SVGFilterElement implements SVGURIReference; SVGFilterElement implements SVGUnitTypes;
filterUnits
’ on the given <filter>
element. Takes one of
the constants defined in SVGUnitTypes.primitiveUnits
’ on the given <filter>
element. Takes one of
the constants defined in SVGUnitTypes.filterRes
’ on the given <filter>
element. Contains the X
component of attribute ‘filterRes
’.filterRes
’ on the given <filter>
element. Contains the Y
component (possibly computed automatically) of attribute ‘filterRes
’.filterRes
’.filterRes
’.filterRes
’.This interface defines the set of DOM attributes that are common across the filter primitive interfaces.
[NoInterfaceObject] interface SVGFilterPrimitiveStandardAttributes { readonly attribute SVGAnimatedLength x; readonly attribute SVGAnimatedLength y; readonly attribute SVGAnimatedLength width; readonly attribute SVGAnimatedLength height; readonly attribute SVGAnimatedString result; };
filter primitive/x
’ on the given
element.filter primitive/y
’ on the given
element.filter primitive/width
’ on the given
element.filter primitive/height
’ on the given
element.filter primitive/result
’ on the given
element. The SVGFEBlendElement
interface corresponds to the <feBlend>
element.
interface SVGFEBlendElement : SVGElement { // Blend Mode Types const unsigned short SVG_FEBLEND_MODE_UNKNOWN = 0; const unsigned short SVG_FEBLEND_MODE_NORMAL = 1; const unsigned short SVG_FEBLEND_MODE_MULTIPLY = 2; const unsigned short SVG_FEBLEND_MODE_SCREEN = 3; const unsigned short SVG_FEBLEND_MODE_DARKEN = 4; const unsigned short SVG_FEBLEND_MODE_LIGHTEN = 5; readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedString in2; readonly attribute SVGAnimatedEnumeration mode; }; SVGFEBlendElement implements SVGFilterPrimitiveStandardAttributes;
normal
’.multiply
’.screen
’.darken
’.lighten
’.filter primitive/in
’ on the given <feBlend>
element. The SVGFEColorMatrixElement interface corresponds to the <feColorMatrix>
element.
interface SVGFEColorMatrixElement : SVGElement { // Color Matrix Types const unsigned short SVG_FECOLORMATRIX_TYPE_UNKNOWN = 0; const unsigned short SVG_FECOLORMATRIX_TYPE_MATRIX = 1; const unsigned short SVG_FECOLORMATRIX_TYPE_SATURATE = 2; const unsigned short SVG_FECOLORMATRIX_TYPE_HUEROTATE = 3; const unsigned short SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA = 4; readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedEnumeration type; readonly attribute SVGAnimatedNumberList values; }; SVGFEColorMatrixElement implements SVGFilterPrimitiveStandardAttributes;
matrix
’.saturate
’.hueRotate
’.luminanceToAlpha
’.filter primitive/in
’ on the given <feColorMatrix>
element.type
’ on the given <feColorMatrix>
element. Takes
one of the SVG_FECOLORMATRIX_TYPE_* constants defined on this
interface.values
’ on the given <feColorMatrix>
element. The SVGFEComponentTransferElement
interface corresponds to the <feComponentTransfer>
element.
interface SVGFEComponentTransferElement : SVGElement { readonly attribute SVGAnimatedString in1; }; SVGFEComponentTransferElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feComponentTransfer>
element.This interface defines a base interface used by the component transfer function interfaces.
interface SVGComponentTransferFunctionElement : SVGElement { // Component Transfer Types const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN = 0; const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY = 1; const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_TABLE = 2; const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE = 3; const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_LINEAR = 4; const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_GAMMA = 5; readonly attribute SVGAnimatedEnumeration type; readonly attribute SVGAnimatedNumberList tableValues; readonly attribute SVGAnimatedNumber slope; readonly attribute SVGAnimatedNumber intercept; readonly attribute SVGAnimatedNumber amplitude; readonly attribute SVGAnimatedNumber exponent; readonly attribute SVGAnimatedNumber offset; };
identity
’.table
’.discrete
’.linear
’.gamma
’.feComponentTransferFunction/type
’ on the
given element. Takes one of the SVG_FECOMPONENTTRANSFER_TYPE_*
constants defined on this interface.feComponentTransferFunction/tableValues
’
on the given element.feComponentTransferFunction/slope
’ on
the given element.feComponentTransferFunction/intercept
’
on the given element.feComponentTransferFunction/amplitude
’
on the given element.feComponentTransferFunction/exponent
’ on
the given element.feComponentTransferFunction/offset
’ on
the given element. The SVGFEFuncRElement
interface corresponds to the <feFuncR>
element.
interface SVGFEFuncRElement : SVGComponentTransferFunctionElement { };
The SVGFEFuncRElement
interface corresponds to the <feFuncG>
element.
interface SVGFEFuncGElement : SVGComponentTransferFunctionElement { };
The SVGFEFuncBElement
interface corresponds to the <feFuncB>
element.
interface SVGFEFuncBElement : SVGComponentTransferFunctionElement { };
The SVGFEFuncAElement
interface corresponds to the <feFuncA>
element.
interface SVGFEFuncAElement : SVGComponentTransferFunctionElement { };
The SVGFECompositeElement
interface corresponds to the <feComposite>
element.
interface SVGFECompositeElement : SVGElement { // Composite Operators const unsigned short SVG_FECOMPOSITE_OPERATOR_UNKNOWN = 0; const unsigned short SVG_FECOMPOSITE_OPERATOR_OVER = 1; const unsigned short SVG_FECOMPOSITE_OPERATOR_IN = 2; const unsigned short SVG_FECOMPOSITE_OPERATOR_OUT = 3; const unsigned short SVG_FECOMPOSITE_OPERATOR_ATOP = 4; const unsigned short SVG_FECOMPOSITE_OPERATOR_XOR = 5; const unsigned short SVG_FECOMPOSITE_OPERATOR_ARITHMETIC = 6; readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedString in2; readonly attribute SVGAnimatedEnumeration operator; readonly attribute SVGAnimatedNumber k1; readonly attribute SVGAnimatedNumber k2; readonly attribute SVGAnimatedNumber k3; readonly attribute SVGAnimatedNumber k4; }; SVGFECompositeElement implements SVGFilterPrimitiveStandardAttributes;
over
’.in
’.out
’.atop
’.xor
’.arithmetic
’.filter primitive/in
’ on the given <feComposite>
element.in2
’ on the given <feComposite>
element.operator
’ on the given <feComposite>
element. Takes one
of the SVG_FECOMPOSITE_OPERATOR_* constants defined on this
interface.k1
’
on the given <feComposite>
element.k2
’
on the given <feComposite>
element.k3
’
on the given <feComposite>
element.k4
’
on the given <feComposite>
element. The SVGFEConvolveMatrixElement
interface corresponds to the <feConvolveMatrix>
element.
interface SVGFEConvolveMatrixElement : SVGElement { // Edge Mode Values const unsigned short SVG_EDGEMODE_UNKNOWN = 0; const unsigned short SVG_EDGEMODE_DUPLICATE = 1; const unsigned short SVG_EDGEMODE_WRAP = 2; const unsigned short SVG_EDGEMODE_NONE = 3; readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedInteger orderX; readonly attribute SVGAnimatedInteger orderY; readonly attribute SVGAnimatedNumberList kernelMatrix; readonly attribute SVGAnimatedNumber divisor; readonly attribute SVGAnimatedNumber bias; readonly attribute SVGAnimatedInteger targetX; readonly attribute SVGAnimatedInteger targetY; readonly attribute SVGAnimatedEnumeration edgeMode; readonly attribute SVGAnimatedNumber kernelUnitLengthX; readonly attribute SVGAnimatedNumber kernelUnitLengthY; readonly attribute SVGAnimatedBoolean preserveAlpha; }; SVGFEConvolveMatrixElement implements SVGFilterPrimitiveStandardAttributes;
duplicate
’.wrap
’.none
’.filter primitive/in
’ on the given <feConvolveMatrix>
element.order
’ on the given <feConvolveMatrix>
element.order
’ on the given <feConvolveMatrix>
element.kernelMatrix
’ on the given <feConvolveMatrix>
element.divisor
’ on the given <feConvolveMatrix>
element.bias
’ on the given <feConvolveMatrix>
element.targetX
’ on the given <feConvolveMatrix>
element.targetY
’ on the given <feConvolveMatrix>
element.edgeMode
’ on the given <feConvolveMatrix>
element. Takes
one of the SVG_EDGEMODE_* constants defined on this interface.kernelUnitLength
’ on the given <feConvolveMatrix>
element.kernelUnitLength
’ on the given <feConvolveMatrix>
element.preserveAlpha
’ on the given <feConvolveMatrix>
element. The SVGFECustomElement
interface corresponds to the <feCustom>
element.
interface SVGFECustomElement : SVGElement { readonly attribute SVGAnimatedString in; readonly attribute SVGAnimatedString geometry; }; SVGFECustomElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feCustom>
element.geometry
’ on the given <feCustom>
element. The SVGFECustomSourceElement
interface corresponds to the <feCustomSource>
element.
interface SVGFECustomSourceElement : SVGElement { readonly attribute SVGAnimatedString src; readonly attribute SVGAnimatedString format; };
src
’ on the given <feCustomSource>
element.format
’ on the given <feCustomSource>
element. The SVGFECustomParamElement
interface corresponds to the <feCustomParam>
element.
interface SVGFECustomParamElement : SVGElement { // Custom Parameter Types const unsigned short SVG_CUSTOM_PARAM_UNKNOWN = 0; const unsigned short SVG_CUSTOM_PARAM_NUMBER = 1; const unsigned short SVG_CUSTOM_PARAM_ARRAY = 2; const unsigned short SVG_CUSTOM_PARAM_VEC2 = 3; const unsigned short SVG_CUSTOM_PARAM_VEC3 = 4; const unsigned short SVG_CUSTOM_PARAM_VEC4 = 5; const unsigned short SVG_CUSTOM_PARAM_MAT2 = 6; const unsigned short SVG_CUSTOM_PARAM_MAT3 = 7; const unsigned short SVG_CUSTOM_PARAM_MAT4 = 8; const unsigned short SVG_CUSTOM_PARAM_COLOR = 9; const unsigned short SVG_CUSTOM_PARAM_TEXTURE = 10; const unsigned short SVG_CUSTOM_PARAM_TRANSFORM = 11; readonly attribute SVGAnimatedEnumeration type; readonly attribute SVGAnimatedString ident; readonly attribute SVGAnimatedNumberList values; readonly attribute SVGAnimatedString texture; readonly attribute SVGAnimatedColor color; readonly attribute SVGAnimatedTransformList transform; };
number
’.
array
’.
vec2
’.
vec3
’.
vec4
’.
mat2
’.
mat3
’.
mat4
’.
color
’.
texture
’.
transform
’.
type
’ on the given <feCustomParam>
element.ident
’ on the given <feCustomParam>
element.values
’ on the given <feCustomParam>
element.texture
’ on the given <feCustomParam>
element.color
’ on the given <feCustomParam>
element.transform
’ on the given <feCustomParam>
element. The SVGFEDiffuseLightingElement
interface corresponds to the <feDiffuseLighting>
element.
interface SVGFEDiffuseLightingElement : SVGElement { readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedNumber surfaceScale; readonly attribute SVGAnimatedNumber diffuseConstant; readonly attribute SVGAnimatedNumber kernelUnitLengthX; readonly attribute SVGAnimatedNumber kernelUnitLengthY; }; SVGFEDiffuseLightingElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feDiffuseLighting>
element.surfaceScale
’ on the given <feDiffuseLighting>
element.diffuseConstant
’ on the given <feDiffuseLighting>
element.kernelUnitLength
’ on the given <feDiffuseLighting>
element.kernelUnitLength
’ on the given <feDiffuseLighting>
element. The SVGFEDistantLightElement
interface corresponds to the <feDistantLight>
element.
interface SVGFEDistantLightElement : SVGElement { readonly attribute SVGAnimatedNumber azimuth; readonly attribute SVGAnimatedNumber elevation; };
azimuth
’ on the given <feDistantLight>
element.elevation
’ on the given <feDistantLight>
element. The SVGFEPointLightElement
interface corresponds to the <fePointLight>
element.
interface SVGFEPointLightElement : SVGElement { readonly attribute SVGAnimatedNumber x; readonly attribute SVGAnimatedNumber y; readonly attribute SVGAnimatedNumber z; };
x
’ on the given <fePointLight>
element.y
’ on the given <fePointLight>
element.z
’ on the given <fePointLight>
element. The SVGFESpotLightElement
interface corresponds to the <feSpotLight>
element.
interface SVGFESpotLightElement : SVGElement { readonly attribute SVGAnimatedNumber x; readonly attribute SVGAnimatedNumber y; readonly attribute SVGAnimatedNumber z; readonly attribute SVGAnimatedNumber pointsAtX; readonly attribute SVGAnimatedNumber pointsAtY; readonly attribute SVGAnimatedNumber pointsAtZ; readonly attribute SVGAnimatedNumber specularExponent; readonly attribute SVGAnimatedNumber limitingConeAngle; };
x
’ on the given <feSpotLight>
element.y
’ on the given <feSpotLight>
element.z
’ on the given <feSpotLight>
element.pointsAtX
’ on the given <feSpotLight>
element.pointsAtY
’ on the given <feSpotLight>
element.pointsAtZ
’ on the given <feSpotLight>
element.specularExponent
’ on the given <feSpotLight>
element.limitingConeAngle
’ on the given <feSpotLight>
element. The SVGFEDisplacementMapElement
interface corresponds to the <feDisplacementMap>
element.
interface SVGFEDisplacementMapElement : SVGElement { // Channel Selectors const unsigned short SVG_CHANNEL_UNKNOWN = 0; const unsigned short SVG_CHANNEL_R = 1; const unsigned short SVG_CHANNEL_G = 2; const unsigned short SVG_CHANNEL_B = 3; const unsigned short SVG_CHANNEL_A = 4; readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedString in2; readonly attribute SVGAnimatedNumber scale; readonly attribute SVGAnimatedEnumeration xChannelSelector; readonly attribute SVGAnimatedEnumeration yChannelSelector; }; SVGFEDisplacementMapElement implements SVGFilterPrimitiveStandardAttributes;
R
’.G
’.B
’.A
’.filter primitive/in
’ on the given <feDisplacementMap>
element.in2
’ on the given <feDisplacementMap>
element.scale
’ on the given <feDisplacementMap>
element.xChannelSelector
’ on the given <feDisplacementMap>
element.
Takes one of the SVG_CHANNEL_* constants defined on this
interface.yChannelSelector
’ on the given <feDisplacementMap>
element.
Takes one of the SVG_CHANNEL_* constants defined on this
interface. The SVGFEDropShadowElement
interface corresponds to the <feDropShadow>
element.
interface SVGFEDropShadowElement : SVGElement { readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedNumber dx; readonly attribute SVGAnimatedNumber dy; readonly attribute SVGAnimatedNumber stdDeviationX; readonly attribute SVGAnimatedNumber stdDeviationY; void setStdDeviation(in float stdDeviationX, in float stdDeviationY); }; SVGFEDropShadowElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feDropShadow>
element.dx
’ on the given <feDropShadow>
element.dy
’ on the given <feDropShadow>
element.stdDeviation
’ on the given <feDropShadow>
element. Contains
the X component of attribute ‘stdDeviation
’.stdDeviation
’ on the given <feDropShadow>
element. Contains
the Y component (possibly computed automatically) of attribute ‘stdDeviation
’.stdDeviation
’.stdDeviation
’.stdDeviation
’. The SVGFEFloodElement
interface corresponds to the <feFlood>
element.
interface SVGFEFloodElement : SVGElement { }; SVGFEFloodElement implements SVGFilterPrimitiveStandardAttributes;
The SVGFEGaussianBlurElement
interface corresponds to the <feGaussianBlur>
element.
interface SVGFEGaussianBlurElement : SVGElement { readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedNumber stdDeviationX; readonly attribute SVGAnimatedNumber stdDeviationY; void setStdDeviation(in float stdDeviationX, in float stdDeviationY); }; SVGFEGaussianBlurElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feGaussianBlur>
element.stdDeviation
’ on the given <feGaussianBlur>
element.
Contains the X component of attribute ‘stdDeviation
’.stdDeviation
’ on the given <feGaussianBlur>
element.
Contains the Y component (possibly computed automatically) of
attribute ‘stdDeviation
’.stdDeviation
’.stdDeviation
’.stdDeviation
’. The SVGFEImageElement
interface corresponds to the <feImage>
element.
interface SVGFEImageElement : SVGElement { readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; }; SVGFEImageElement implements SVGFilterPrimitiveStandardAttributes; SVGFEImageElement implements SVGURIReference;
preserveAspectRatio
’ on the given <feImage>
element. The SVGFEMergeElement
interface corresponds to the <feMerge>
element.
interface SVGFEMergeElement : SVGElement { }; SVGFEMergeElement implements SVGFilterPrimitiveStandardAttributes;
The SVGFEMergeNodeElement
interface corresponds to the <feMergeNode>
element.
interface SVGFEMergeNodeElement : SVGElement { readonly attribute SVGAnimatedString in1; };
filter primitive/in
’ on the given <feMergeNode>
element. The SVGFEMorphologyElement
interface corresponds to the <feMorphology>
element.
interface SVGFEMorphologyElement : SVGElement { // Morphology Operators const unsigned short SVG_MORPHOLOGY_OPERATOR_UNKNOWN = 0; const unsigned short SVG_MORPHOLOGY_OPERATOR_ERODE = 1; const unsigned short SVG_MORPHOLOGY_OPERATOR_DILATE = 2; readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedEnumeration operator; readonly attribute SVGAnimatedNumber radiusX; readonly attribute SVGAnimatedNumber radiusY; }; SVGFEMorphologyElement implements SVGFilterPrimitiveStandardAttributes;
erode
’.dilate
’.filter primitive/in
’ on the given <feMorphology>
element.operator
’ on the given <feMorphology>
element. Takes one
of the SVG_MORPHOLOGY_OPERATOR_* constants defined on this
interface.radius
’ on the given <feMorphology>
element.radius
’ on the given <feMorphology>
element. The SVGFEOffsetElement
interface corresponds to the <feOffset>
element.
interface SVGFEOffsetElement : SVGElement { readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedNumber dx; readonly attribute SVGAnimatedNumber dy; }; SVGFEOffsetElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feOffset>
element.dx
’ on the given <feOffset>
element.dy
’ on the given <feOffset>
element. The SVGFESpecularLightingElement
interface corresponds to the <feSpecularLighting>
element.
interface SVGFESpecularLightingElement : SVGElement { readonly attribute SVGAnimatedString in1; readonly attribute SVGAnimatedNumber surfaceScale; readonly attribute SVGAnimatedNumber specularConstant; readonly attribute SVGAnimatedNumber specularExponent; readonly attribute SVGAnimatedNumber kernelUnitLengthX; readonly attribute SVGAnimatedNumber kernelUnitLengthY; }; SVGFESpecularLightingElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feSpecularLighting>
element.surfaceScale
’ on the given <feSpecularLighting>
element.specularConstant
’ on the given <feSpecularLighting>
element.specularExponent
’ on the given <feSpecularLighting>
element.kernelUnitLength
’ on the given <feSpecularLighting>
element.kernelUnitLength
’ on the given <feSpecularLighting>
element. The SVGFETileElement
interface corresponds to the <feTile>
element.
interface SVGFETileElement : SVGElement { readonly attribute SVGAnimatedString in1; }; SVGFETileElement implements SVGFilterPrimitiveStandardAttributes;
filter primitive/in
’ on the given <feTile>
element. The SVGFETurbulenceElement
interface corresponds to the <feTurbulence>
element.
interface SVGFETurbulenceElement : SVGElement { // Turbulence Types const unsigned short SVG_TURBULENCE_TYPE_UNKNOWN = 0; const unsigned short SVG_TURBULENCE_TYPE_FRACTALNOISE = 1; const unsigned short SVG_TURBULENCE_TYPE_TURBULENCE = 2; // Stitch Options const unsigned short SVG_STITCHTYPE_UNKNOWN = 0; const unsigned short SVG_STITCHTYPE_STITCH = 1; const unsigned short SVG_STITCHTYPE_NOSTITCH = 2; readonly attribute SVGAnimatedNumber baseFrequencyX; readonly attribute SVGAnimatedNumber baseFrequencyY; readonly attribute SVGAnimatedInteger numOctaves; readonly attribute SVGAnimatedNumber seed; readonly attribute SVGAnimatedEnumeration stitchTiles; readonly attribute SVGAnimatedEnumeration type; }; SVGFETurbulenceElement implements SVGFilterPrimitiveStandardAttributes;
fractalNoise
’.turbulence
’.stitch
’.noStitch
’.baseFrequency
’ on the given <feTurbulence>
element. Contains
the X component of the ‘baseFrequency
’ attribute.baseFrequency
’ on the given <feTurbulence>
element. Contains
the Y component of the (possibly computed automatically) ‘baseFrequency
’ attribute.numOctaves
’ on the given <feTurbulence>
element.seed
’ on the given <feTurbulence>
element.stitchTiles
’ on the given <feTurbulence>
element. Takes one
of the SVG_STITCHTYPE_* constants defined on this interface.type
’ on the given <feTurbulence>
element. Takes one
of the SVG_TURBULENCE_TYPE_* constants defined on this interface.Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words “for
example” or are set apart from the normative text with
class="example"
, like this:
This is an example of an informative example.
Informative notes begin with the word “Note” and are set apart
from the normative text with class="note"
, like this:
Note, this is an informative note.
Conformance to this is defined for three conformance classes:
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
To avoid clashes with future CSS features, the CSS 2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.
Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.
Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
Further information on submitting testcases and implementation reports can be found from on the CSS Working Group's website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.
The following significant changes were made since the 25 October 2012 Working Draft.
See more detailed and longterm changes in the ChangeLog.
Property | Values | Initial | Applies to | Inh. | Percentages | Media |
---|---|---|---|---|---|---|
color-interpolation-filters | auto | sRGB | linearRGB | linearRGB | filter primitives | yes | N/A | visual |
enable-background | accumulate | new | accumulate | Typically elements that can contain renderable elements. language is responsible for defining the applicable set of elements. For SVG: container elements | no | N/A | visual |
feBlend | ||||||
feColorMatrix | ||||||
feComponentTransfer | ||||||
feComposite | ||||||
feConvolveMatrix | ||||||
feCustom | ||||||
feCustomParam | ||||||
feCustomSource | ||||||
feDiffuseLighting | ||||||
feDisplacementMap | ||||||
feDistantLight | ||||||
feDropShadow | ||||||
feFlood | ||||||
feFuncA | ||||||
feFuncB | ||||||
feFuncG | ||||||
feFuncR | ||||||
feGaussianBlur | ||||||
feImage | ||||||
feMerge | ||||||
feMergeNode | ||||||
feMorphology | ||||||
feOffset | ||||||
fePointLight | ||||||
feSpecularLighting | ||||||
feSpotLight | ||||||
feTile | ||||||
feTurbulence | ||||||
filter | none | <filter-function>+ | none | All elements In SVG 1.1 it applies only to "container elements (except ‘mask’) and graphics elements" | no | N/A | visual |
filter | ||||||
flood-color | currentColor | <color> <icccolor>? | black | <feFlood> and <feDropShadow> elements | no | N/A | visual |
flood-opacity | <number> | <percentage> | 1 | <feFlood> and <feDropShadow> elements | no | N/A | visual |
lighting-color | currentColor | <color> <icccolor>? | white | <feDiffuseLighting> and <feSpecularLighting> elements | no | N/A | visual |
attached
’, 11.5.
detached
’, 11.5.