"Todd C. Klaus" wrote:
> I have written the following method that iterates through all of the
> pixels of a BufferedImage, setting the color of each one based on the
> output of a procedural texture algorithm. When I run it on a 1280x1024
> image on my 1.2GHz AMD machine, it takes about 5 seconds to render.
The fastest way to get pixels into a BufferedImage is to access
the internal data array directly:
int[] pix = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
int width = image.getWidth();
int height = image.getHeight();
int p = 0;
for( int y = 0; y < height; y++ ){
for( int x = 0; x < width; x++ ){
pix[p++] = f(x,y);
}
}
Note that the loops are switched (pixels are stored by row).
Also, don't use getWidth/Height in the loop since the compiler
probably can't optimize them.
-- Kevin
---------------------------------------------------------------------
Kevin Weiner FM Software 610-997-3930 http://www.fmsware.com
===========================================================================
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".