I've followed you all down the garden path :) and it appears to be the right path.
I've rewritten the PanelMap code using VolatileImage[1] but I can't test
it with the big map until tomorrow morning, then I'll send a report :)
P.S.- When I was doing a test with the big map in a single GeoTiff file
I've found another "problem". The image is so big (92336x146887) that I
get the following error:
java.lang.NegativeArraySizeException
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
I suppose that it's an unsigned int overflow in the DataBufferByte code
because:
map: 92336*146887 = 13562958032
uint: 2^32 = 4294967296
it's only a supposition and it isn't a problem because I'll be using
the ImageMosaic plugin.
[1]
-- start code
private class PanelMap extends JPanel {
VolatileImage vImg;
public PanelMap() {
super();
setDoubleBuffered(false);
vImg = createVolatileImage(getWidth(), getHeight());
if(vImg == null) {
System.err.println("vImage null");
}
}
/*
* OffScreen image render
*/
void renderOffscreen() {
do {
if (vImg.validate(getGraphicsConfiguration()) ==
VolatileImage.IMAGE_INCOMPATIBLE) {
// old vImg doesn't work with new GraphicsConfig;
re-create it
vImg = createVolatileImage(getWidth(), getHeight());
}
Graphics2D g = vImg.createGraphics();
/*
* Do rendering operations
*/
try {
Rectangle rectangle = new Rectangle(getSize());
System.out.println("Tamano del mapa (pixels): " +
rectangle.height + "x" + rectangle.width);
renderer.paint(g, rectangle,
mapContext.getLayerBounds());
} catch (IOException ex) {
Logger.getLogger(PanelGeoMap.class.getName()).log(Level.SEVERE, null,
ex);
}
g.dispose();
} while (vImg.contentsLost());
}
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if(vImg == null) {
System.err.println("paint :: vImg null");
//vImg = createVolatileImage(getWidth(), getHeight());
vImg =
g2.getDeviceConfiguration().createCompatibleVolatileImage(
getWidth(), getHeight());
}
/*
* Write image on the screen
*/
do {
int returnCode =
vImg.validate(getGraphicsConfiguration());
if (returnCode == VolatileImage.IMAGE_RESTORED) {
// Contents need to be restored
renderOffscreen(); // restore contents
} else if (returnCode ==
VolatileImage.IMAGE_INCOMPATIBLE) {
// old vImg doesn't work with new GraphicsConfig;
re-create it
vImg = createVolatileImage(getWidth(), getHeight());
renderOffscreen();
}
g.drawImage(vImg, 0, 0, this);
} while (vImg.contentsLost());
}
}
-- end code
On mar, 2007-12-11 at 13:50 -0800, Jody Garnett wrote:
> Okay; so JPanel does double buffering by default (so your paint method
> is being passed a Graphics object that is backed onto a BuferedImage -
> check it out in a debugger). Needless to say this is not what you want
> for performance...
>
> Have a read of this:
> - http://www.exampledepot.com/egs/java.awt.image/VolImage.html
>
> Now there is a good chance I am leading you down the garden path here;
> performance tuning is a difficult balance. Please try rendering to a
> VolatileImage and let it me know if it works in your situation. I know
> it does wonders for doing the usual range of JAI activities; but
> resampling down onto disk may stretch the limits.
>
> The source code for JAI is online; you may want to look exactly at what
> DisplayJAI is doing.
> Cheers,
> Jody
> > I append the full source code[1] but the painting part is:
> >
> > private class PanelMap extends JPanel {
> >
> > @Override
> > public void paint(Graphics g) {
> > try {
> > Graphics2D g2d = (Graphics2D) g;
> > Rectangle rectangle = new Rectangle(getSize());
> >
> > //System.out.println("Map size (px): "+ rectangle.height
> > + "x" + rectangle.width);
> >
> > renderer.paint(g2d, rectangle,
> > mapContext.getLayerBounds());
> > } catch (IOException ex) {
> >
> > Logger.getLogger(PanelGeoMap.class.getName()).log(Level.SEVERE,
> > null, ex);
> > }
> > }
> > }
> >
> > I override the JPanel's paint method. PanelMap is inside a JScrollPane
> > and the renderer, in theory, only have to draw the visible viewport.
> >
>
--
Diego Fdez. Durán <[EMAIL PROTECTED]> | http://www.goedi.net
GPG : 925C 9A21 7A11 3B13 6E43 50DB F579 D119 90D2 66BB
signature.asc
Description: Esta parte del mensaje está firmada digitalmente
------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php
_______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
