You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Justin Couch <ju...@vlc.com.au> on 2002/03/13 23:57:36 UTC

What's absolute minimum requires for AWT Image generation?

Confused programmer seeking Batik advice.... Before I start into asking 
for advice, I'll need to describe what we're trying to do.

The code that we're working on operates on number of levels, and we'd 
like SVG content to be available on all of those. At the core of this we 
are doing 3D graphics rendering and want to put SVG content into the 3D 
environment - either as textures or overlays, or for simpler items like 
2D text in the 3D environment. How we're doing the 3D rendering is 
probably inconsequential, but for the moment it's using Java3D, but may 
well also include GL4Java and/or custom OpenGL wrappers. Either way, we 
need a extremely precise low-level control over the texture generation 
process.

There are at least 2 open source (LGPL) projects involved in using this 
process . At the lowest level is my j3d.org code repository. This does a 
lot of very low-level 3D graphics stuff. I need to control every texture 
on every frame - up to and including syncing animation systems (eg SMIL 
animated textures). At a much higher level is the Xj3D project, which is 
taking the VRML97/X3D specifications and providing a renderer for them. 
X3D has an XML encoding, so we can also include SVG textures directly 
into the file and animate those using the X3D scripting process etc etc. 
  In this system, SVG is used as both a texture source, and for our 
implementation of the 2D text node requirements.

So, hopefully you can see where I'm going here - we're looking at Batik 
and it's rendering process and trying to work out "how low can you go?". 
  Just how much of Batik can we throw away and still get something 
rendered.

Our most basic requirement is: given our DOM parsed document, how simply 
can we get a BufferedImage instance out of it (ideally, we'd actually 
like a RenderedImage instance so that maybe we can use the JDK 1.4 
VolatileImage stuff so we can blit this stuff directly on the video card 
every frame rather than needing to transfer across the bus every frame 
when we're animating stuff).

Reading through the archives, I can see lots of suggestions about using 
ImageTranscoders to create an Image instance. For us, that is not 
appropriate because there is a lot of extra image and object creation 
going on. In addition, there is a lot of caching being done too. We 
don't want that. Object creation kills framerates (allocation time, plus 
GC afterwards). Caching is not wanted as we will be managing our own 
caching of everything. Document parsing is not wanted because we are 
doing our own stuff too (we're playing with DOM Level3 implementations 
as well as a bunch of other custom stuff for the network handling that 
doesn't involve the Java core APIs).

So, where are we at? Basically, we've taken what we think is the lowest 
level approach possible, but would like to know if there is any more 
that we can strip out. In addition, we want to include the generated 
image with texture transparency for the background colour, which we 
don't seem to be able to do.

The code looks roughly like this:

    build shared GVTBridge & builder instances

    build DOM document
    Create buffered image with our height & width. ARGB image
    Get Graphics2D with Batik GraphicsUtil
    Build GraphicsNode instance with GVTBuilder
    setup background colors etc

    while(rendering)
      make changes to DOM scene graph
      GraphicsNode.paint(graphics2d instance)
      return image and update J3D Texture2D instance.

For some reason, the GVT code seems to be ignoring our background colour 
settings and other oddities. I can't quite put my finger on it ATM as 
I'm still learning what Batik does for a few things. They aren't 
immediately obvious from the source.


For those interested, here's the two projects:

http://code.j3d.org/
http://www.web3d.org/TaskGroups/source/xj3d.html

-- 
Justin Couch                         http://www.vlc.com.au/~justin/
Java Architect & Bit Twiddler              http://www.yumetech.com/
Author, Java 3D FAQ Maintainer                  http://www.j3d.org/
-------------------------------------------------------------------
"Humanism is dead. Animals think, feel; so do machines now.
Neither man nor woman is the measure of all things. Every organism
processes data according to its domain, its environment; you, with
all your brains, would be useless in a mouse's universe..."
                                               - Greg Bear, Slant
-------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: What's absolute minimum requires for AWT Image generation?

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "JC" == Justin Couch <ju...@vlc.com.au> writes:

      This is a bit thin on details that might let us really debug
your problem (like exactly what sort of buffered image you are using
and the SVG snippit you are rendering).

JC> Vincent Hardy wrote:

>> You are saying that you cannot get the background color right or
>> that you have 'other oddities': could you tell us specifically how
>> you are trying to set the background color and what the oddities
>> are?

JC> The simplest process is creating my own custom Image instance,
JC> with default background of all alpha. With this, I then use
JC> GraphicsUtil to create a Graphics2D instance, as recommended. From
JC> this, I then call GraphicsNode.paint() on a root instance of the
JC> document. No RenderingHints are set. Visual artifacts are the
JC> background colour is being reset (I'd like just to create a
JC> straight text string printed on an image) there's aliasing effects
JC> around the edge of the text. I think some of that is to do with
JC> the way I'm creating the image, but I'm not really sure yet.

JC> In this simplest of tests I'm trying to implement an X3D Text node
JC> which is described as a "Flat two-sided item". We don't need to
JC> create polygons, so as the first step is just a simple text string
JC> on a transparent image to run as a texture. Admittedly it would be
JC> far easier to not use SVG altogether, but this was supposed to be
JC> the first step in a much larger process for the integration. It's
JC> the "get to know you" step.

    Given the amount of information I have I suspect one of two things:

    1) Your 3D engine only does masking not alpha.  Since by default
       everything we draw is anti-aliased your text will have
       semi-transparent pixels all around the edges if the 3D engine
       converts this alpha channel to a mask some of these blended
       pixels will become opaque giving bad results if the background
       is something other than black (you don't say what color the
       text is in SVG or the background in 3D).

    2) You or the JDK is messing up the alpha premultiplied state.
       There are a number of bugs in the JDK (1.2, and 1.3 haven't
       tested 1.4 yet) where it tries to divide out alpha but doesn't.
       This can also cause commonly edge effects.

    If it is #1 (which is my bet) you will need to either tell the SVG
content to use 'crisp edges'/'gemetric precision' or tell Batik not to
anti-alias (RenderingHints).

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: What's absolute minimum requires for AWT Image generation?

Posted by Justin Couch <ju...@vlc.com.au>.
Vincent Hardy wrote:
> I have read through your email and, while I understand what you are 
> trying to do, I am not sure what you are looking for exactly. 

Err... yeah, just read through what I wrote... even I can't make sense 
of what I wrote!

> You are saying that you cannot get the background color
> right or that you have 'other oddities': could you tell us specifically
> how you are trying to set the background color and what the oddities
> are? 

The simplest process is creating my own custom Image instance, with 
default background of all alpha. With this, I then use GraphicsUtil to 
create a Graphics2D instance, as recommended. From this, I then call 
GraphicsNode.paint() on a root instance of the document. No 
RenderingHints are set. Visual artifacts are the background colour is 
being reset (I'd like just to create a straight text string printed on 
an image) there's aliasing effects around the edge of the text. I think 
some of that is to do with the way I'm creating the image, but I'm not 
really sure yet.

In this simplest of tests I'm trying to implement an X3D Text node which 
is described as a "Flat two-sided item". We don't need to create 
polygons, so as the first step is just a simple text string on a 
transparent image to run as a texture. Admittedly it would be far easier 
to not use SVG altogether, but this was supposed to be the first step in 
a much larger process for the integration. It's the "get to know you" step.
-- 
Justin Couch                         http://www.vlc.com.au/~justin/
Java Architect & Bit Twiddler              http://www.yumetech.com/
Author, Java 3D FAQ Maintainer                  http://www.j3d.org/
-------------------------------------------------------------------
"Humanism is dead. Animals think, feel; so do machines now.
Neither man nor woman is the measure of all things. Every organism
processes data according to its domain, its environment; you, with
all your brains, would be useless in a mouse's universe..."
                                               - Greg Bear, Slant
-------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: What's absolute minimum requires for AWT Image generation?

Posted by Vincent Hardy <vi...@sun.com>.
Justin,

I have read through your email and, while I understand what you are 
trying to do, I am not sure what you are looking
for exactly. You are saying that you cannot get the background color
right or that you have 'other oddities': could you tell us specifically
how you are trying to set the background color and what the oddities
are? 

For your information, the ImageTranscoder does background color
and it works fine, so I think you are not using the right technique to
do it.

Regards,
Vincent Hardy.

Justin Couch wrote:
> 
> Confused programmer seeking Batik advice.... Before I start into asking
> for advice, I'll need to describe what we're trying to do.
> 
> The code that we're working on operates on number of levels, and we'd
> like SVG content to be available on all of those. At the core of this we
> are doing 3D graphics rendering and want to put SVG content into the 3D
> environment - either as textures or overlays, or for simpler items like
> 2D text in the 3D environment. How we're doing the 3D rendering is
> probably inconsequential, but for the moment it's using Java3D, but may
> well also include GL4Java and/or custom OpenGL wrappers. Either way, we
> need a extremely precise low-level control over the texture generation
> process.
> 
> There are at least 2 open source (LGPL) projects involved in using this
> process . At the lowest level is my j3d.org code repository. This does a
> lot of very low-level 3D graphics stuff. I need to control every texture
> on every frame - up to and including syncing animation systems (eg SMIL
> animated textures). At a much higher level is the Xj3D project, which is
> taking the VRML97/X3D specifications and providing a renderer for them.
> X3D has an XML encoding, so we can also include SVG textures directly
> into the file and animate those using the X3D scripting process etc etc.
>   In this system, SVG is used as both a texture source, and for our
> implementation of the 2D text node requirements.
> 
> So, hopefully you can see where I'm going here - we're looking at Batik
> and it's rendering process and trying to work out "how low can you go?".
>   Just how much of Batik can we throw away and still get something
> rendered.
> 
> Our most basic requirement is: given our DOM parsed document, how simply
> can we get a BufferedImage instance out of it (ideally, we'd actually
> like a RenderedImage instance so that maybe we can use the JDK 1.4
> VolatileImage stuff so we can blit this stuff directly on the video card
> every frame rather than needing to transfer across the bus every frame
> when we're animating stuff).
> 
> Reading through the archives, I can see lots of suggestions about using
> ImageTranscoders to create an Image instance. For us, that is not
> appropriate because there is a lot of extra image and object creation
> going on. In addition, there is a lot of caching being done too. We
> don't want that. Object creation kills framerates (allocation time, plus
> GC afterwards). Caching is not wanted as we will be managing our own
> caching of everything. Document parsing is not wanted because we are
> doing our own stuff too (we're playing with DOM Level3 implementations
> as well as a bunch of other custom stuff for the network handling that
> doesn't involve the Java core APIs).
> 
> So, where are we at? Basically, we've taken what we think is the lowest
> level approach possible, but would like to know if there is any more
> that we can strip out. In addition, we want to include the generated
> image with texture transparency for the background colour, which we
> don't seem to be able to do.
> 
> The code looks roughly like this:
> 
>     build shared GVTBridge & builder instances
> 
>     build DOM document
>     Create buffered image with our height & width. ARGB image
>     Get Graphics2D with Batik GraphicsUtil
>     Build GraphicsNode instance with GVTBuilder
>     setup background colors etc
> 
>     while(rendering)
>       make changes to DOM scene graph
>       GraphicsNode.paint(graphics2d instance)
>       return image and update J3D Texture2D instance.
> 
> For some reason, the GVT code seems to be ignoring our background colour
> settings and other oddities. I can't quite put my finger on it ATM as
> I'm still learning what Batik does for a few things. They aren't
> immediately obvious from the source.
> 
> For those interested, here's the two projects:
> 
> http://code.j3d.org/
> http://www.web3d.org/TaskGroups/source/xj3d.html
> 
> --
> Justin Couch                         http://www.vlc.com.au/~justin/
> Java Architect & Bit Twiddler              http://www.yumetech.com/
> Author, Java 3D FAQ Maintainer                  http://www.j3d.org/
> -------------------------------------------------------------------
> "Humanism is dead. Animals think, feel; so do machines now.
> Neither man nor woman is the measure of all things. Every organism
> processes data according to its domain, its environment; you, with
> all your brains, would be useless in a mouse's universe..."
>                                                - Greg Bear, Slant
> -------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org