Ciao Diego, please read below...

On Dec 12, 2007 2:16 AM, Diego Fdez. Durán <[EMAIL PROTECTED]> wrote:
> 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.

The Java2D DataBuffer model is based on int hence by default you
cannot create DataBuffer bigger than Integer.MAX value, which means
width*height>Integer.MAX. Of course there are ways to work around this
limitations, but I will keep that for consultancy :-).


>
>
> [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
>

The streaming renderer was thought for streaming data in a server side
app hence using volatile images was not really an option for various
reasons.
-Volatile images are good if you know that you'll never be modifying
them, which includes writing on them, and especially good for
background images like backgrounds in games.
-Volatile images for JVM < 1.5 did not suppor transparency hence they
were not realaly an option for the streaming renderer
-Volatile images does not support the creation of complex color model
like we do (ask aaime) for improving the compression of images for gif
and jpeg. Since the main target of streaming renderer wasa geoserver
this would be a big problem

Ciao,
Simone.

>
> 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
>
>
> -------------------------------------------------------------------------
> 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
> Geotools-gt2-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>



-- 
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions S.A.S.
Via Carignoni 51
55041  Camaiore (LU)
Italy

phone: +39 0584983027
fax:      +39 0584983027
mob:    +39 333 8128928


http://www.geo-solutions.it

-------------------------------------------------------

-------------------------------------------------------------------------
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
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to