The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » JAI

Thread: renderable chain examples?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 5 - Last Post: Sep 17, 2007 3:03 PM by: Brian Burkhalter
dvucinic

Posts: 2
renderable chain examples?
Posted: Sep 13, 2007 1:12 PM
  Click to reply to this thread Reply

Greetings,

I'm writing an application that reads in large amounts of data from a
digitizer and needs to display it every once in a while as an image.
I'm using a java.nio.ByteBuffer created in native code to access the
digitized samples in shared memory--I don't want to copy the data
into a byte[] on every acquisition because this incurs a lot of JVM
overhead.

Over the past few days I've been trying without success to find
examples of JAI image processing using the "renderable" instead of
the "rendered" chain. The general idea is that the ByteBuffer would
be wrapped into something that's a RenderableImage so the bytes
would be sucked out of volatile shared memory at rendering time
without having to be copied into a byte[] first. Can anyone point
me to example code that does something like this, or explain in
broad strokes how this could be done? I'm at a loss trying to
understand how a RenderableImage implementation would be made
to appear in DisplayJAI for instance.

Thanks,

--diego

Fork Labs
Re: [JAI] renderable chain examples?
Posted: Sep 14, 2007 8:28 AM   in response to: dvucinic
  Click to reply to this thread Reply

Hello,

I would also appreciate Renderable examples, if only to be able to
make tests in my jai-operators project.

Regards,

Daniel Léonard

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net


Brian Burkhalter
Re: [JAI] renderable chain examples?
Posted: Sep 14, 2007 11:15 AM   in response to: Fork Labs
  Click to reply to this thread Reply

We'll see what we can put together.

Brian

On Fri, 14 Sep 2007, Fork Labs wrote:

> Hello,
>
> I would also appreciate Renderable examples, if only to be able to
> make tests in my jai-operators project.
>
> Regards,
>
> Daniel Léonard
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>


>^..^^..^<

Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net


Brian Burkhalter
Re: [JAI] renderable chain examples?
Posted: Sep 14, 2007 1:48 PM   in response to: Brian Burkhalter
  Click to reply to this thread Reply

These aren't all that extensive as demo code goes but there are a couple of
classes in the tutorial demo at

https://jai-demos.dev.java.net/source/browse/jai-demos/jai-apps/src/TutorialDemo/demos/

namely

https://jai-demos.dev.java.net/source/browse/jai-demos/jai-apps/src/TutorialDemo/demos/RenderableDemo.java?rev=1.1&view=markup
https://jai-demos.dev.java.net/source/browse/jai-demos/jai-apps/src/TutorialDemo/demos/RenderableScale.java?rev=1.1&view=markup

Hopefully we can come up with something better ...

>^..^^..^<

Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net


dvucinic

Posts: 2
Re: [JAI] renderable chain examples?
Posted: Sep 15, 2007 12:27 PM   in response to: Brian Burkhalter
  Click to reply to this thread Reply

Hi Brian,

I looked at the examples you kindly provided. Then I looked at the sources and documentation some more, and things are looking much worse. It appears as if the whole "renderable" idea was a use case that was discussed during the design phase of Java2D and carried over into JAI but never actually implemented.

For instance: I create a JComponent, get its Graphics2D and call Graphics2D.drawRenderableImage(new RenderableImage() { ... }); The one and only method that ever gets called on the interface is createRendering(RenderContext), in other words RenderableImage interface doesn't seem to serve any purpose other than a very cumbersome way to get back at the RenderedImage.

Things get even stranger once in JAI, since anything 2D must be converted to a PlanarImage which can then be put as a source in a ParameterBlock that can be told to become "renderable" (why this is a command is completely beyond me). But the javadoc for PlanarImage states:

"All non-JAI RenderedImage instances must be converted into PlanarImages by means of the RenderedImageAdapter and WritableRenderedImageAdapter classes. The wrapRenderedImage method provides a convenient interface to both add a wrapper and take a snapshot if the image is writable. All of the PlanarImage constructors perform this wrapping automatically."

Note the "take a snapshot". In other words, any conversion from, say, a BufferedImage into JAI entails a memory-to-memory copy! This makes 2D and JAI fundamentally unsuitable for any kind of video display.

Perhaps I'm missing a very big and obvious chunk of the solution here? All I'm trying to do is something that was trivial in first-generation java.awt: I could take a byte[], wrap it in a MemoryImageSource, call setAnimated(), put it in a JLabel, and every time I called newPixels() any changes I made to the underlying byte[] would show up on screen. This is how the now abandoned JMF renderer worked. Surely there must be a way to accomplish this in Java2D/JAI?

Thanks,

--diego



Brian Burkhalter
Re: [JAI] renderable chain examples?
Posted: Sep 17, 2007 3:03 PM   in response to: dvucinic
  Click to reply to this thread Reply

[nobr]On Sat, 15 Sep 2007, jai-interest@javadesktop.org wrote:

>

I looked at the examples you kindly provided. Then I looked at the
> sources and documentation some more, and things are looking much worse.
> It appears as if the
> whole "renderable" idea was a use case that was discussed during
> the design phase of Java2D and carried over into JAI but never actually
> implemented.



Well you are partly correct. The RenderableImage interface is in fact defined
in Java 2D which does not itself implement support for it. JAI however *does*
implement the renderable layer.

>

For instance: I create a JComponent, get its Graphics2D and call
> Graphics2D.drawRenderableImage(new RenderableImage() { ... });
> The one and only method that ever gets called on the interface is
> createRendering(RenderContext), in other words RenderableImage
> interface doesn't seem to serve any purpose other than a very
> cumbersome way to get back at the RenderedImage.



That's all it is supposed to do. An image after all must be convered into
pixel coordinates before it can be drawn.

>

Things get even stranger once in JAI, since anything 2D must be
> converted to a PlanarImage which can then be put as a source in a
> ParameterBlock that can be told to become "renderable" (why this
> is a command is completely beyond me). But the javadoc for
> PlanarImage states:


>
>

"All non-JAI RenderedImage instances must be converted into
> PlanarImages by means of the RenderedImageAdapter and
> WritableRenderedImageAdapter classes. The wrapRenderedImage
> method provides a convenient interface to both add a wrapper and
> take a snapshot
if the image is writable. All of the PlanarImage

As it turns out this javadoc is incorrect: no snapshot is taken although it
should be. I have filed issue #115 for this:

https://jai-core.dev.java.net/issues/show_bug.cgi?id=115

> constructors perform this wrapping automatically."


>
>

Note the "take a snapshot". In other words, any conversion from, say,
> a BufferedImage into JAI entails a memory-to-memory copy!

Unfortunately there is a tiny little gap in your logic here: the snapshot
mechanism doesn't copy anything unless it detects that the source
WritableRenderdImage has changed. Please see

http://download.java.net/media/jai/javadoc/1.1.3/jai-apidocs/javax/media/jai/SnapshotImage.html

to rectify your lack of knowledge on this point.

> This makes 2D and JAI fundamentally unsuitable for any kind of video display.


>
>

Perhaps I'm missing a very big and obvious chunk of the solution here?
> All I'm trying to do is something that was trivial in first-generation java.awt:
> I could take a byte[], wrap it in a MemoryImageSource, call setAnimated(),
> put it in a JLabel, and every time I called newPixels() any changes I made
> to the underlying byte[] would show up on screen. This is how the now
> abandoned JMF renderer worked. Surely there must be a way to
> accomplish this in Java2D/JAI?



Well this is not really a JAI issue at all and you might get a better answer
on the Java 2D or Swing mailing lists but why can't you register a
TileObserver

http://java.sun.com/javase/6/docs/api/java/awt/image/TileObserver.html

with your BufferedImage and have the TileObserver repaint your component?


>^..^^..^<

Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net
[/nobr]




 XML java.net RSS