[whatwg] Canvas operators (was Re: several messages)

Philip Taylor excors+whatwg at gmail.com
Sun May 20 18:10:01 PDT 2007

On 21/05/07, ddailey <ddailey at zoominternet.net> wrote:
> On Sunday, May 20, 2007 6:30 PML. David Baron wrote:
> "...This is the cairo 'saturate' operator..."
> The above reminded me: using SVG suggested to me a couple of questions*
> about SVG that would seem to be just as relevant to the <canvas> tag:
> 1. Is there a way, using filters, to take an image A and produce its
> photographic negative A', such that 255-C(A)=C(A') for each channel C in
> {R,G,B)?

I would have thought that
  <feComposite ... operator="arithmetic" k1="0" k2="0" k3="-1" k4="1"/>
would have done that, except it doesn't seem to work in Opera. But
  <feColorMatrix type="matrix" in="SourceGraphic"
       values="-1  0  0  0  1
                0 -1  0  0  1
                0  0 -1  0  1
                0  0  0  1  0"/>
does seem to work and gives the negative effect, and is probably
easier to understand than the feComponentTransfer thing.

(As far as I can tell, there's no way at all to do this with <canvas>.
(...except for via getImageData --
http://canvex.lazyilluminati.com/misc/filter.html isn't too dreadfully
slow (if you ignore the fillRects bit), and would be faster if you're
only doing a 1x1 filter.))

> 2. On a related theme, <feBlend/> has modes including "screen", "multiply"
> etc. Is there a way to create the "difference" between two images (as with
> the Photoshop difference filter) in SVG?

I'd have thought something like <feComposite in="SourceGraphic"
in2="BackgroundImage" operator="arithmetic" k1="0" k2="-0.5" k3="0.5"
k4="0.5" result="comp"/> except negative values still don't seem to
work and I'm not sure why...

(Also not possible with <canvas>.)

> Another question arises in my mind in this context: is there any reason that
> any of the treatments of these effects (like the Porter-Duff operators,
> darken, saturate etc.) should be any different than they are in the SVG
> spec? So many things that I see in the treatment of canvas remind me of
> something so similar to what is in SVG that it makes me wonder why not just
> reference say http://www.w3.org/TR/SVG/filters.html ?

The P-D operators should be the same in <canvas> and SVG and the rest
of the world now, all just referring to the original paper. I don't
see anything specific in SVG (not counting the arithmetic/matrix
modes) that matches the <canvas> 'lighter' (P-D 'plus') or any
implementation's 'darker', though I've not looked hard.

The arithmetic/matrix SVG operators couldn't be done in <canvas>
without making a much more complex API, and its blending modes
(normal/multiply/screen/darken/lighten) seem like a fairly arbitrary
selection and wouldn't be particularly easy to implement -- the choice
of the current <canvas> operators matches what most standard graphic
libraries (Cairo, Quartz, Java 2D, etc) already provide, and it would
take more work to extend beyond their boundaries to match SVG, and
there doesn't seem to be much justification for doing that work, hence
the disparity with SVG.

> David

Philip Taylor
excors at gmail.com

More information about the whatwg mailing list