Enabling pixel grabbing in SVG just like Canvas

View: New views
4 Messages — Rating Filter:   Alert me  

Enabling pixel grabbing in SVG just like Canvas

by Jon Ferraiolo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At SVG Open, there was discussion today about adding Canvas's pixel grabbing APIs to SVG, with claims that SVG implementations don't necessarily retain a rendering surface. It now occurs to me that there is a CSS property ('enable-background') in the SVG 1.1 spec just for this purpose:

* http://www.w3.org/TR/SVG/filters.html#AccessingBackgroundImage

Pixel grabbing APIs in SVG could require that 'enable-background' is placed on the outermost <svg> element as a hint to the implementation that it needs to retrievable retain pixel values for image.

Note that implementations pretty much have to implement saved rendering surfaces to do group opacity even if they haven't implemented filter effects yet.

Jon Ferraiolo
IBM






Re: Enabling pixel grabbing in SVG just like Canvas

by Robert O'Callahan-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Oct 4, 2009 at 2:17 PM, Jon Ferraiolo <jferrai@...> wrote:

At SVG Open, there was discussion today about adding Canvas's pixel grabbing APIs to SVG, with claims that SVG implementations don't necessarily retain a rendering surface. It now occurs to me that there is a CSS property ('enable-background') in the SVG 1.1 spec just for this purpose:

* http://www.w3.org/TR/SVG/filters.html#AccessingBackgroundImage

Pixel grabbing APIs in SVG could require that 'enable-background' is placed on the outermost <svg> element as a hint to the implementation that it needs to retrievable retain pixel values for image.

Note that implementations pretty much have to implement saved rendering surfaces to do group opacity even if they haven't implemented filter effects yet.

 
Why don't we just make it more convenient to render SVG to <canvas> and then use canvas's getImageData?

Rob
--
"He was pierced for our transgressions, he was crushed for our iniquities; the punishment that brought us peace was upon him, and by his wounds we are healed. We all, like sheep, have gone astray, each of us has turned to his own way; and the LORD has laid on him the iniquity of us all." [Isaiah 53:5-6]

Re: Enabling pixel grabbing in SVG just like Canvas

by Jon Ferraiolo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Rob,
Sounds intriguing to me. Maybe:

<svg id="aaa" canvas="true">...</svg>

In the DOM, you could get the canvas object via

var canvas = document.getElementById("aaa").canvas;

This markup approach would allow you to make canvases out of subtrees of SVG objects and allow reference via <use>, which would use the saved raster rather than render the content from the DOM:

<svg>
<g id="bbb" canvas="true">
<!-- Complicated graphics -->
</g>
<!-- reference the saved canvas --->
<use href="#bbb"/>
</svg>

Something in this space could provide huge performance gains for certain types of complicated graphics.

Jon



Inactive hide details for "Robert O'Callahan" ---10/03/2009 06:36:21 PM---On Sun, Oct 4, 2009 at 2:17 PM, Jon Ferraiolo <jferra"Robert O'Callahan" ---10/03/2009 06:36:21 PM---On Sun, Oct 4, 2009 at 2:17 PM, Jon Ferraiolo <jferrai@...> wrote: > At SVG Open, there was d


From:

"Robert O'Callahan" <robert@...>

To:

Jon Ferraiolo/Menlo Park/IBM@IBMUS

Cc:

www-svg@...

Date:

10/03/2009 06:36 PM

Subject:

Re: Enabling pixel grabbing in SVG just like Canvas

Sent by:

rocallahan@...





On Sun, Oct 4, 2009 at 2:17 PM, Jon Ferraiolo <jferrai@...> wrote:
    At SVG Open, there was discussion today about adding Canvas's pixel grabbing APIs to SVG, with claims that SVG implementations don't necessarily retain a rendering surface. It now occurs to me that there is a CSS property ('enable-background') in the SVG 1.1 spec just for this purpose:

    *
    http://www.w3.org/TR/SVG/filters.html#AccessingBackgroundImage

    Pixel grabbing APIs in SVG could require that 'enable-background' is placed on the outermost <svg> element as a hint to the implementation that it needs to retrievable retain pixel values for image.

    Note that implementations pretty much have to implement saved rendering surfaces to do group opacity even if they haven't implemented filter effects yet.

 
Why don't we just make it more convenient to render SVG to <canvas> and then use canvas's getImageData?

Rob
--
"He was pierced for our transgressions, he was crushed for our iniquities; the punishment that brought us peace was upon him, and by his wounds we are healed. We all, like sheep, have gone astray, each of us has turned to his own way; and the LORD has laid on him the iniquity of us all." [Isaiah 53:5-6]





Re: Enabling pixel grabbing in SVG just like Canvas

by Robert O'Callahan-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 5, 2009 at 2:21 AM, Jon Ferraiolo <jferrai@...> wrote:

Sounds intriguing to me. Maybe:

<svg id="aaa" canvas="true">...</svg>


Sorry, that wasn't what I meant. What I meant was
var canvas = document.createElement("canvas");
canvas.drawImage(svgElement);
var data = canvas.getImageData(...);

Rob
--
"He was pierced for our transgressions, he was crushed for our iniquities; the punishment that brought us peace was upon him, and by his wounds we are healed. We all, like sheep, have gone astray, each of us has turned to his own way; and the LORD has laid on him the iniquity of us all." [Isaiah 53:5-6]