Just a small correction...
[EMAIL PROTECTED] wrote:
Can you try to modify my example code using your
suggestion, so that we can see if it produces
similiar memory leaking behavior or if it solves it?
Sorry, no ... I don't have the time.
I post a snippit which should be easy to use:
[code]
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int[] buffer = ((DataBufferInt) img.getRaster().getDataBuffer())
.getData();
[/code]
buffer is now width*height in lenght. so width-1 is the first element of the
second line.
The first element of the first line would be at index 0.
The last element of the first line would be at index width-1.
The first element of the second line would actually be at index width
(not width-1 ;-).
But, these rules of thumb make an assumption about the scan stride being
used and the offset to the first pixel. Those assumptions will be true
for a brand new BufferedImage and on the reference runtime, but there
are 2 cases where those assumptions may fail if you care about these
situations:
- If Java is ever ported to an architecture where alignment stricter
than 4-bytes for image data is desired, then the scanline stride may
need to be padded to the next 8 (or 16 or ?) byte boundary.
- If you want to work on an sub-image, such as those created by the
BufferedImage.getSubimage() call then the scanline stride may be totally
unrelated to the width of this image, and the offset to the first pixel
may not be 0 any more either (since the sub-image is talking to a subset
of the image data for the parent image).
- If you want to work on a BufferedImage that someone created using
their own Raster, it might still be tagged as TYPE_INT_[A]RGB, even
though they didn't honor those restrictions that the BufferedImage
constructor would impose and so the offset to the first pixel and the
scanline stride may be different. The only restrictions on an image
created from a Raster to be classified as TYPE_INT_* are that it use a
DirectColorModel, a SinglePixelPackedSampleModel and have a pixel stride
of 1.
If you want to be just a little bit more technically correct then the
following should cover you in the situations that require a different
scanline stride:
// one-time setup
Raster r = img.getRaster();
SinglePixelPackedSampleModel sppsm;
int buf[] = ((DataBufferInt) r.getDataBuffer()).getData();
sppsm = ((SinglePixelPackedSampleModel) r.getSampleModel());
int scan = sppsm.getScanlineStride();
// per-pixel access code
buf[y * scan + x] = /* data for x,y */
And if you want to work on a subimage, or a manually created
BufferedImage, then the following should cover all of these bases with
only a couple more lines in the setup code:
// one-time setup
Raster r = img.getRaster();
SinglePixelPackedSampleModel sppsm;
int buf[] = ((DataBufferInt) r.getDataBuffer()).getData();
sppsm = ((SinglePixelPackedSampleModel) r.getSampleModel());
int scan = sppsm.getScanlineStride();
int sampX = r.getSampleModelTranslateX();
int sampY = r.getSampleModelTranslateY();
int off = - (sampY * scan + sampX);
// per-pixel access code
buf[off + y * scan + x] = /* data for x,y */
...jim
===========================================================================
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".