W3C home > Mailing lists > Public > www-svg@w3.org > January 2006

[SVGMobile12] Gradient color interpolation

From: Tero Karras <tero.karras@hybrid.fi>
Date: Wed, 18 Jan 2006 21:15:20 +0200
To: <www-svg@w3.org>
Message-Id: <20060118191610.42078E88441@narikka.hybrid.fi>

Hi SVG Working Group,

What is the intended way of interpolating the colors of gradient stops, if
opacities are also defined? The specification is being very vague about
this. Consider the following linear gradient, for example:

<linearGradient id="MyGradient" x1="0" y1="0" x2="1" y2="0">
  <stop offset="0" stop-color="rgb(255, 0, 0)" stop-opacity="0"/>
  <stop offset="1" stop-color="rgb(0, 255, 0)" stop-opacity="1"/>

We can think of the colors and opacities as independent quantities, and thus
interpolate them independently. This way, for the point at (0.5, 0), we get
color="rgb(127.5, 127.5, 0)" and opacity="0.5". We cannot really say that
the first stop is transparent red and the other one is opaque green. Rather,
we have a separate color ramp going from red to green, being applied through
an opacity ramp going from fully transparent to fully opaque.

On the other hand, we can think of the color and opacity as being expressed
as a single pre-multiplied RGBA color. We can interpolate the components of
these colors linearly. For our example gradient, the color of first stop
would be rgba_pre(0, 0, 0, 0), and the second one would be rgba_pre(0, 255,
0, 255). For the middle-point, we would get rgba_pre(0, 127.5, 0, 127.5),
corresponding to color="rgb(0, 255, 0)" and opacity="0.5".

The latter method has many favorable properties. For example, if our
gradient is painted on a solid background color, it will result in a linear
color slide. The former method, however, will produce a quadratic slide.

Adobe's SVG plugin seems to do the interpolation using the former method,
while OpenVG (http://www.khronos.org/openvg/) currently supports only the
latter one.

Is there a certain correct interpolation method, or is it intentionally
being left unspecified to allow SVG implementations to choose whichever
method they prefer?

  o Tero Karras, Programmer
  o Hybrid Graphics, Ltd.
  o Email: tero@hybrid.fi
  o Web: www.hybrid.fi
Received on Friday, 20 January 2006 08:56:45 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:47:06 UTC