Skip to main content

mosaic memory allocation problem

4 replies [Last post]
peterg
Offline
Joined: 2004-03-23

Hi all,
I've researched for some time now, and cannot find the solution to my problem. I'm trying to render a collection of tiles on the screen, where each tile is stored as a 500x500 pixel JPEG on disk. Here are my methods:

- loop through tiles on disk and call JAI.create("fileload",fileName) to load each one
and then JAI.create("translate",pb, null) to indicate where in the huge image this tile is located.
- set the sources to be all of the tiles and call JAI.create("mosaic", pb) to create the entire image.
- each time a user scales, perform JAI.create("scale",pb) on the mosaic
- draw the new image on the graphics object to display to the user. This is done by grabbing the visible tiles, and drawing them using their BufferedImage representation.

My problem ends up being on the draw. Any time I try to draw, the memory allocation shoots up from 15Mb to 80Mb. I know I could just up the memory size, but something here doesn't sit right. Since JAI is supposed to only load what is visible, then the memory shouldn't shoot up that much. When I was doing file loading manually without JAI, that is, loading tiles that were visible from disk and drawing them, it never went up that much. Even when I try to do a crop operation on a rectangular bound, it shoots up to over 80Mb. I've also tried to flip the scaling and mosaic operations to no avail (although it performs better) . What can I do differently that might improve the memory consumption?

A separate issue was when the user would zoom out causing a lot of tiles to be displayed. This would cause the zooming to slow tremendously. I think it is due to the fact that JAI has to load all of the different tiles when the drawing occurs. Any performance enhancements I can make?

Thanks for the help!
-peter

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jrariasf
Offline
Joined: 2005-11-02

Hi,
Can you show me your code?
I have several images of satellite and I want to assemble them in a single one. The used format is JPG.
Thanks a lot.

Brian Burkhalter

I would suggest starting by reading these:

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...

Brian

On Wed, 2 Nov 2005, jai-interest@javadesktop.org wrote:

> Hi,
> Can you show me your code?
> I have several images of satellite and I want to assemble them in a single one. The used format is JPG.
> Thanks a lot.
> ---
> [Message sent by forum member 'jrariasf' (José Ramón)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=122910&#122910
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Multimedia, 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

jrariasf
Offline
Joined: 2005-11-02

But then, to join several images of satellite, what I must do first? I must move (translate) the source images to its suitable position and then to overlap them?

The problem with my code is that the new image (dst.jpg) is equal to the first (img1a.jpg).
The code is:

[i]
import java.util.*;
import java.awt.image.renderable.*;
import javax.media.jai.*;
import javax.media.jai.operator.*;

class UsarMosaic {

public static void main (String[] args)
{
MosaicDescriptor md;
String fileName = "img.jpg";
String src1 = "img1a.jpg";
String src2 = "img2a.jpg";
RenderedOp[] misimagenes = new RenderedOp[2];

misimagenes[0] = JAI.create("fileload", src1);
misimagenes[1] = JAI.create("fileload", src2);
RenderedOp salida;

md = new MosaicDescriptor();
salida = md.create(misimagenes,
MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
null, null, null, null, null);

JAI.create("filestore", salida, "dst.jpg", "jpeg", null);

}
}
[/i]

Message was edited by: jrariasf

jrariasf
Offline
Joined: 2005-11-02

(Por fin he conseguido lo que quería, unir varias imágenes. El problema era que no había hecho el "translate".)

Finally I have what I wanted. The problem was that the second image must be translate to the adecuate position.
Here is the code:

[i]

import java.util.*;
import java.awt.image.*;
import java.awt.image.renderable.*;
import javax.media.jai.*;
import javax.media.jai.operator.*;

class UsarMosaic {

public static void main (String[] args)
{
MosaicDescriptor md;
String fileName = "img.jpg";
String src1 = "img1.jpg";
String src2 = "img2.jpg";
RenderedOp[] misimagenes = new RenderedOp[2];
RenderedOp image;
RenderedOp salida;

misimagenes[0] = JAI.create("fileload", src1);
image = JAI.create("fileload", src2);

int width = misimagenes[0].getWidth();
int height = misimagenes[0].getHeight();

BufferedImage trans = image.getAsBufferedImage();
ParameterBlockJAI transParams = new ParameterBlockJAI("Translate", "rendered");
transParams.addSource(image);
transParams.setParameter("xTrans", (float)width);
transParams.setParameter("yTrans", 0.00F);
misimagenes[1] = JAI.create("Translate", transParams);

md = new MosaicDescriptor();
salida = md.create(misimagenes, MosaicDescriptor.MOSAIC_TYPE_OVERLAY, null, null, null, null, null
);

JAI.create("filestore", salida, "dst.jpg", "jpeg", null);

}

}
[/i]