XML technologies / SVG / Filters, transformations and gradients / Using and combining filters and lighting effectively / Filters and masks / The feComponentTransfer filter element

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

The filter element <feComponentTransfer> changes individual color components or the alpha channel. Insert further child elements inside it. The element <feComponentTransfer> has no attributes of its own, but each child has many additional attributes and can also use the universal attributes. Its child elements are:

All these elements have the following attributes:

Table: Color calculation for the different type values.

Value of type

Color calculation formula

Description

identity

C' = C

No change occurs because the new color C' equals the original color C.

table

k/N <= C < (k+1)/N => C' = vk + (C - k/N)*N * (vk+1 - vk)

With the value table supply a table of values named v1 through vk. N is the number of table values.

discrete

k/N <= C < (k+1)/N => C' = vk

Here too, supply table values named v1 through vk. N is the number of table values.

linear

C' = slope * C + intercept

With the value linear the color is calculated by linear interpolation. Here slope is the line’s slope, set by an attribute of the same name. Set intercept through an attribute too.

gamma

C' = amplitude * (C exponent) + offset

For type gamma values are calculated using a curve function. Specify amplitude, exponent and offset as attributes too.

<filter id="identity">
  <feComponentTransfer in="SourceGraphic">
    <feFuncR type="identity" />
    <feFuncG type="identity" />
    <feFuncB type="identity" />
    <feFuncA type="identity" />
  </feComponentTransfer>
</filter>
<filter id="table">
  <feComponentTransfer in="SourceGraphic">
    <feFuncR type="table" tableValues="0.3 -5 6" />
    <feFuncG type="table" tableValues="-0.3 5 -2" />
    <feFuncB type="table" tableValues="1 2.3" />
    <feFuncA type="identity" />
  </feComponentTransfer>
</filter>
<filter id="discrete">
  <feComponentTransfer in="SourceGraphic" >
    <feFuncR type="discrete" tableValues="0.3 -5 6"/>
    <feFuncG type="discrete" tableValues="0.3 -5 6"/>
    <feFuncB type="discrete" tableValues="0.3 -5 6"/>
    <feFuncA type="identity"/>
  </feComponentTransfer>
</filter>
<filter id="linear">
  <feComponentTransfer in="SourceGraphic" >
    <feFuncR type="linear" slope="-0.7" intercept="0.2"/>
    <feFuncG type="linear" slope="2" intercept="0.8"/>
    <feFuncB type="linear" slope="1.5" intercept="0.2"/>
    <feFuncA type="identity" />
  </feComponentTransfer>
</filter>
<filter id="gamma">
  <feComponentTransfer in="SourceGraphic" >
    <feFuncR type="gamma" amplitude="1" exponent="1.5" offset="-0.5"/>
    <feFuncG type="gamma" amplitude="3" exponent="2.5" offset="1" />
    <feFuncB type="gamma" amplitude="1" exponent="0.5" offset="0"/>
    <feFuncA type="identity"/>
  </feComponentTransfer>
</filter>

Result of the feComponentTransfer filter element

Figure: Result of the feComponentTransfer filter element.

Note:
Different methods can be chosen for the child elements’ type attribute.

   

 

 

 

back to top