I'm trying to create a fast, animated, Photoshop-like marquis that needs
to be drawn over a potentially large area of my component.
I start with a greyscale image that represents a mask. The marquis
needs to be generated by:
Mask Image -> AffineTransform -> Mask to Marquis filter -> Blit to
screen with animated TexturePaint
The Mask to Marquis filter works like a kernel filter. It is
initialized with a threshold value. For every pixel that is greater
than the threshold value and which has at least one neighbor that is
less than or equal to it, it outputs an opaque pixel. Otherwise it
outputs a transparent pixel. The result is a one-pixel opaque line that
runs along the mask at the threshold value.
To handle animation, I have a javax.swing.Timer that calls repaint() on
my component every 100 milliseconds. I apply an animated texture to my
marquis image by drawing a filled rectangle over the whole thing using
an AlphaComposite.SRC_ATOP and a TexturePaint for the current animation
frame. I then redraw my component and blit my marquis.
One problem with this is that the Mask to Marquis filter is very
expensive to calculate. At the moment, I am regenerating and caching a
new marquis every time the onscreen area is resized or the
AffineTransform changes and storing it in a BufferedImage. Calculating
every output pixel requires checking at least 5 input pixels.
Another problem is the large amount of memory required. I need a buffer
as big as my screen to store just my marquis. Also, I either need
another screen sized buffer to hold the transformed mask, or I need to
invert my AffineTransform and lookup each source pixel in the original
mask (in which case I'm creating a Point2D and calling a transform() at
least 5 times per pixel).
I'm also not certain if I'm updating the animated paint in the most
efficient manner.
One thing I'm considering is breaking my marquis into tiles which can be
updated in a separate thread just to keep things responsive. I could
also better cache pixels when applying the Mask to Marquis filter by
breaking it into separate horizontal and vertical passes.
Are there any good ways to optimize the above? Am I on the right
track? Is there a way to do this without buffering so much data? Is
there a way to draw my opaque marquis directly to the screen with a
texture rather than having to apply the texture to it in a separate
step? Would using a VolatileImage help?
Thanks,
Mark McKay
===========================================================================
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
lists...@java.sun.com and include in the body of the message "help".