Heya all,
I thought I was going crazy. I upgraded my simple Imaging app from Java2D
to JAI and suddenly, everything fell apart. After breaking it down to its
simplest components, I have determined that the PlanarImage used by Java
Advanced Imaging appears to be flawed when drawing with a scale factor.
Below is a simple code snippet that repeatably shows an outrageous speed
difference.
1) I have memory set to 32M and 128M.
2) I have called
JAI.getDefaultInstance().getTileCache().setMemoryCapacity(0L);
3) I have preloaded byte[] imageData with the appropriate image data.
// Draw with Java2D's standard Image
if (drawNormal == 0) {
logMessage(" Loading Java2D Image", time);
java.awt.Image oldImage =
Toolkit.getDefaultToolkit().createImage(imageData);
// Wait for the whole image to load.
try {
Component placeHolder = new Label();
MediaTracker tracker = new MediaTracker(placeHolder);
tracker.addImage(oldImage, 0);
tracker.waitForID(0);
} catch (Exception e) {
e.printStackTrace();
}
// Do the draw old school.
logMessage(" Starting with Java2D Image Draw", time);
g2.drawImage(oldImage, offsetX, offsetY, curImgWidth, curImgHeight, null);
logMessage(" Finished Java2D Image Draw", time);
}
// Draw using JAI's PlanarImage
else {
try {
logMessage(" Loading PlanarImage", time);
ByteArraySeekableStream byteStream = new
ByteArraySeekableStream(imageData);
RenderedImage renderedImage = JAI.create("stream", byteStream);
PlanarImage planar = PlanarImage.wrapRenderedImage(renderedImage);
// Do the draw new school.
logMessage(" Starting with JAI PlanarImage Draw", time);
g2.drawImage(image.getAsBufferedImage(), offsetX, offsetY, curImgWidth,
curImgHeight, null);
logMessage(" Finished JAI PlanarImage Draw", time);
} catch (Exception e) {
e.printStackTrace();
}
}
Test results were performed on 2 GIF images (a small 85x250, 8 bit image and
a large 2048x1536, 24 bit).
** Test Results for GIF 85x250, 8 bit Image - JAVA2D METHOD.
** Loading Java2D Image - time[00:00.010]
** Starting with Java2D Image Draw - time[00:00.090]
** Finished Java2D Image Draw - time[00:00.090] - draw took
[00:00.000]
** Test Results for GIF 85x250, 8 bit Image - JAI PlanarImage METHOD.
** Loading PlanarImage - time[00:00.000]
** Starting with JAI PlanarImage Draw - time[00:00.000]
** Finished JAI PlanarImage Draw - time[00:00.111] - draw took
[00:00.111]
** Test Results for GIF 2048x1536, 24 bit Image - JAVA2D METHOD.
** Loading Java2D Image - time[00:00.000]
** Starting with Java2D Image Draw - time[00:02.283]
** Finished Java2D Image Draw - time[00:02.733] - draw took
[00:00.450]
** Test Results for GIF 2048x1536, 24 bit Image - JAI PlanarImage
METHOD.
** Loading PlanarImage - time[00:00.010]
** Starting with JAI PlanarImage Draw - time[00:00.010]
** Finished JAI PlanarImage Draw - time[01:14.167] - draw took
[01:14.157]
On the large image, the time to draw went from .45 seconds to 1 min 14
seconds...
Someone please enlighten me! What am I doing wrong?
Curtiss Murphy
Senior Consultant - OOP
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".