svn - r34370 - in branches/2.6.x/modules/unsupported/jp2kakadu: . src/main/java/org/geotools/coverageio/jp2kak

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34370 - in branches/2.6.x/modules/unsupported/jp2kakadu: . src/main/java/org/geotools/coverageio/jp2kak

Reply Threaded More More options
Print post
Permalink
Author: danieleromagnoli
Date: 2009-11-12 10:42:41 -0500 (Thu, 12 Nov 2009)
New Revision: 34370

Modified:
   branches/2.6.x/modules/unsupported/jp2kakadu/pom.xml
   branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/Granule.java
   branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/JP2KReader.java
   branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterLayerResponse.java
   branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterManager.java
   branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/ReadType.java
Log:
Improving CRS management and data loading

Modified: branches/2.6.x/modules/unsupported/jp2kakadu/pom.xml
===================================================================
--- branches/2.6.x/modules/unsupported/jp2kakadu/pom.xml 2009-11-12 15:02:56 UTC (rev 34369)
+++ branches/2.6.x/modules/unsupported/jp2kakadu/pom.xml 2009-11-12 15:42:41 UTC (rev 34370)
@@ -95,7 +95,7 @@
      <dependency>
       <groupId>it.geosolutions.imageio-ext</groupId>
       <artifactId>imageio-ext-utilities</artifactId>
-      <version>${imageio.ext.version}</version>
+      <version>1.0-SNAPSHOT</version>
     </dependency>
   
     <!-- Test dependencies -->

Modified: branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/Granule.java
===================================================================
--- branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/Granule.java 2009-11-12 15:02:56 UTC (rev 34369)
+++ branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/Granule.java 2009-11-12 15:42:41 UTC (rev 34370)
@@ -1,6 +1,8 @@
 package org.geotools.coverageio.jp2kak;
 
 
+import it.geosolutions.imageio.utilities.Utilities;
+
 import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.RenderingHints;
@@ -335,8 +337,8 @@
  this.granuleFile = granuleFile;
 
  // create the base grid to world transformation
- ImageInputStream inStream=null;
- ImageReader reader=null;
+ ImageInputStream inStream = null;
+ ImageReader reader = null;
  try {
  //
  //get info about the raster we have to read
@@ -344,18 +346,18 @@
 
  // get a stream
  inStream = Utils.getInputStream(granuleFile);
- if(inStream==null)
+ if(inStream == null)
  throw new IllegalArgumentException("Unable to get an input stream for the provided file "+granuleFile.getAbsolutePath());
 
  // get a reader and try to cache the relevant SPI
- if(cachedSPI==null){
+ if(cachedSPI == null){
  reader = Utils.getReader( inStream);
- if(reader!=null)
- cachedSPI=reader.getOriginatingProvider();
+ if(reader != null)
+ cachedSPI = reader.getOriginatingProvider();
  }
  else
- reader=cachedSPI.createReaderInstance();
- if(reader==null)
+ reader = cachedSPI.createReaderInstance();
+ if(reader == null)
  throw new IllegalArgumentException("Unable to get an ImageReader for the provided file "+granuleFile.getAbsolutePath());
 
  //get selected level and base level dimensions
@@ -366,15 +368,12 @@
  // we do not have such info, hence we assume that it is a simple
  // scale and translate
  final GridToEnvelopeMapper geMapper= new GridToEnvelopeMapper(
- new GridEnvelope2D(originalDimension),
- granuleBBOX
- );
+ new GridEnvelope2D(originalDimension), granuleBBOX);
  geMapper.setPixelAnchor(PixelInCell.CELL_CENTER);//this is the default behavior but it is nice to write it down anyway
- this.baseGridToWorld=geMapper.createAffineTransform();
+ this.baseGridToWorld = geMapper.createAffineTransform();
 
-
  // add the base level
- this.granuleLevels.put(Integer.valueOf(0),new Level(1,1,originalDimension.width,originalDimension.height));
+ this.granuleLevels.put(Integer.valueOf(0), new Level(1, 1, originalDimension.width, originalDimension.height));
 
  } catch (IllegalStateException e) {
  throw new IllegalArgumentException(e);
@@ -384,14 +383,14 @@
  }
  finally{
  try{
- if(inStream!=null)
+ if(inStream != null)
  inStream.close();
  }
  catch (Throwable e) {
  throw new IllegalArgumentException(e);
  }
  finally{
- if(reader!=null)
+ if(reader != null)
  reader.dispose();
  }
  }
@@ -467,15 +466,21 @@
  LOGGER.fine((new StringBuffer("Loading level ").append(
  imageIndex).append(" with source region ").append(
  sourceArea).toString()));
+ final int ssx = readParameters.getSourceXSubsampling();
+ final int ssy = readParameters.getSourceYSubsampling();
+ final int newSubSamplingFactor = Utilities.getSubSamplingFactor2(ssx,ssy);
+ if (newSubSamplingFactor != 0){
+ readParameters.setSourceSubsampling(newSubSamplingFactor, newSubSamplingFactor,0,0);
+ }
+
  // set the source region
  readParameters.setSourceRegion(sourceArea);
-
- // read
- final RenderedImage raster = request.getReadType().read(readParameters,imageIndex, granuleFile, selectedlevel.rasterDimensions,tileDimension);
- if (raster == null)
- return null;
+ final RenderedImage raster;
  try{
- raster.getWidth();
+ // read
+ raster= request.getReadType().read(readParameters,imageIndex, granuleFile, selectedlevel.rasterDimensions,tileDimension,cachedSPI);
+ if (raster == null)
+ return null;
  }
  catch (Throwable e) {
  if(LOGGER.isLoggable(java.util.logging.Level.FINE))
@@ -497,18 +502,16 @@
  // image sizes.
  //
  // place it in the mosaic using the coords created above;
- double decimationScaleX =  ((1.0 * sourceArea.width) / raster.getWidth());
- double decimationScaleY =  ((1.0 * sourceArea.height) / raster.getHeight());
+ double decimationScaleX = ((1.0 * sourceArea.width) / raster.getWidth());
+ double decimationScaleY = ((1.0 * sourceArea.height) / raster.getHeight());
  final AffineTransform decimationScaleTranform = XAffineTransform.getScaleInstance(decimationScaleX, decimationScaleY);
 
  // keep into account translation  to work into the selected level raster space
- final AffineTransform afterDecimationTranslateTranform =XAffineTransform.getTranslateInstance(sourceArea.x, sourceArea.y);
-
+ final AffineTransform afterDecimationTranslateTranform = XAffineTransform.getTranslateInstance(sourceArea.x, sourceArea.y);
 
  // now we need to go back to the base level raster space
- final AffineTransform backToBaseLevelScaleTransform =selectedlevel.baseToLevelTransform;
+ final AffineTransform backToBaseLevelScaleTransform = selectedlevel.baseToLevelTransform;
 
-
  // now create the overall transform
  final AffineTransform finalRaster2Model = new AffineTransform(baseGridToWorld);
  finalRaster2Model.concatenate(Utils.CENTER_TO_CORNER);
@@ -531,10 +534,9 @@
  (float)finalRaster2Model.getTranslateX(),
  (float)finalRaster2Model.getTranslateY(),
  nearest);
- if(finalLayout.isEmpty())
- {
+ if(finalLayout.isEmpty()){
  if(LOGGER.isLoggable(java.util.logging.Level.FINE))
- LOGGER.fine("Unable to create a granule "+this.toString()+ " due to jai scale bug");
+ LOGGER.fine("Unable to create a granule " + this.toString()+ " due to jai scale bug");
  return null;
  }
 
@@ -586,10 +588,8 @@
  reader.dispose();
  }
  }
-
  }
 
-
  public Level getLevel(final int index) {
  synchronized (granuleLevels) {
  if(granuleLevels.containsKey(Integer.valueOf(index)))
@@ -660,7 +660,6 @@
  }
  }
 
-
  @Override
  public String toString() {
  // build a decent representation for this level

Modified: branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/JP2KReader.java
===================================================================
--- branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/JP2KReader.java 2009-11-12 15:02:56 UTC (rev 34369)
+++ branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/JP2KReader.java 2009-11-12 15:42:41 UTC (rev 34370)
@@ -23,7 +23,6 @@
 
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
-import java.awt.image.DataBufferByte;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -92,12 +91,14 @@
  /** The system-dependent default name-separator character. */
     private final static char SEPARATOR = File.separatorChar;
 
-    private final static short[] geoJp2UUID = new short[] { 0xb1, 0x4b, 0xf8, 0xbd, 0x08,
+    private final static short[] GEOJP2_UUID = new short[] { 0xb1, 0x4b, 0xf8, 0xbd, 0x08,
         0x3d, 0x4b, 0x43, 0xa5, 0xae, 0x8c, 0xd7, 0xd5, 0xa6, 0xce, 0x03 };
     
-    private final static short[] msigWorldFileBoxUUID = new short[] { 0x96, 0xa9, 0xf1, 0xf1,
+    private final static short[] MSIG_WORLDFILEBOX_UUID = new short[] { 0x96, 0xa9, 0xf1, 0xf1,
         0xdc, 0x98, 0x40, 0x2d, 0xa7, 0xae, 0xd6, 0x8e, 0x34, 0x45, 0x18, 0x09 };
 
+    private final static int WORLD_FILE_INTERPRETATION_PIXEL_CORNER = 1;
+    
     /**
      * The base {@link GridRange} for the {@link GridCoverage2D} of this reader.
      */
@@ -134,8 +135,7 @@
         final IIOMetadata metadata = reader.getStreamMetadata();
         int hrWidth = reader.getWidth(0);
         int hrHeight = reader.getHeight(0);
-        final Rectangle actualDim = new Rectangle(0, 0, hrWidth,
-                hrHeight);
+        final Rectangle actualDim = new Rectangle(0, 0, hrWidth, hrHeight);
         this.nativeGridRange = new GridEnvelope2D(actualDim);
         if (this.crs == null) {
             parsePRJFile();
@@ -195,11 +195,11 @@
     }
     
     private boolean isGeoJP2(final byte[] id) {
-     return isSameUUID(id, geoJp2UUID);
+     return isSameUUID(id, GEOJP2_UUID);
     }
     
     private boolean isWorldBox(final byte[] id) {
-     return isSameUUID(id, msigWorldFileBoxUUID);
+     return isSameUUID(id, MSIG_WORLDFILEBOX_UUID);
     }
     
     private boolean isSameUUID(final byte[] id, final short[] uuid) {
@@ -210,6 +210,11 @@
         return true;
     }
     
+    /**
+     * Look for UUID boxes containing GeoJP2 Boxes / MSIG World Box
+     * @param metadata
+     * @throws IOException
+     */
     private void checkUUIDBoxes(final IIOMetadata metadata) throws IOException{
      if (!(metadata instanceof JP2KStreamMetadata)) {
             if (LOGGER.isLoggable(Level.WARNING))
@@ -223,34 +228,45 @@
         // //
         final List<IIOMetadataNode> uuidBoxMetadataNodes = ((JP2KStreamMetadata) metadata)
                 .searchOccurrencesNode(UUIDBox.BOX_TYPE);
+        UUIDBoxMetadataNode geoJP2uuid = null;
+        UUIDBoxMetadataNode worldBoxuuid = null;
         if (uuidBoxMetadataNodes != null && !uuidBoxMetadataNodes.isEmpty()){
          for (IIOMetadataNode node: uuidBoxMetadataNodes){
          if (node instanceof UUIDBoxMetadataNode) {
                     final UUIDBoxMetadataNode uuid = (UUIDBoxMetadataNode) node;
                     final byte[] id = uuid.getUuid();
                     if (isGeoJP2(id)) {
-                       getGeoJP2(uuid);
+                       geoJP2uuid = uuid;
                        continue;
                     }
                     
-                    // //
-                    //
-                    // Without a proper crs, the World Box is useless
-                    //
-                    // //
-                    if (crs != null)
-                     if (isWorldBox(id)){
-                     getWorldBox(uuid);
-                    }
+                 if (isWorldBox(id)){
+                     worldBoxuuid = uuid;
+                    }
                 }
          }
         }
+
+        if (geoJP2uuid!=null)
+         getGeoJP2(geoJP2uuid);
+        
+        // //
+        //
+        // Without a proper crs, the World Box is useless
+        //
+        // //
+        if (worldBoxuuid!=null && crs != null){
+         getWorldBox(worldBoxuuid);
+        }
+        
     }
     
     private void getWorldBox(final UUIDBoxMetadataNode uuid) throws IOException {
 
      // //
+     //
      // Parsing Header
+     //
      // //
      final byte[] bb = uuid.getData();
         if (bb[0]!='M'||bb[1]!='S'||bb[2]!='I'||bb[3]!='G')
@@ -273,6 +289,10 @@
         
         if (chunkIndex!=0 && chunkLength!=48)
          return;
+        
+        // //
+        // Parsing the Grid to World transformation
+        // //
         final double xScale = Utils.bytes2double(bb,ckIndex+6);
         final double xRotation = Utils.bytes2double(bb,ckIndex+14);
         final double yRotation = Utils.bytes2double(bb,ckIndex+22);
@@ -281,63 +301,76 @@
         final double yUpperLeft = Utils.bytes2double(bb,ckIndex+46);
         
         final boolean footerOk = (bb[ckIndex + 54] == (byte)0xFF) && (bb[ckIndex + 55] == (byte)0x00);
-
+
+        // //
+        // Setting up the grid to world transformation
+        // //
         final AffineTransform tempTransform = new AffineTransform(
          xScale, yRotation, xRotation,
          yScale, xUpperLeft, yUpperLeft);
         this.raster2Model = ProjectiveTransform.create(tempTransform);
-        tempTransform.translate(-0.5, -0.5);
+
+        // ////////////////////////////////////////////////////////////////////
+        //
+        // Quoting from 3.2.2.1 at:
+        // http://www.lizardtech.com/support/kb/docs/geotiff_box.txt
+        //
+        // "This was instituted with version 1.03.11 (May 15, 2003) to signify that we
+        // clarified the definition of the georeferencing data and found out that that
+        // data represents the upper left corner of the upper left pixel, not the
+        // center as we had thought, so the [world chunk values are] not equal to the
+        // geotiff data, but is shifted by 0.5*scale to the center of the pixel."
+        //
+        // Finally note that:
+        // If the world chunk is present, these values should override
+        // the corresponding values in the GeoTIFF box.
+        //
+        // ////////////////////////////////////////////////////////////////////
+        if (worldFileInterpretation == WORLD_FILE_INTERPRETATION_PIXEL_CORNER)
+         tempTransform.translate(-0.5, -0.5);
       
         try {
-         GeneralEnvelope envelope = CRS.transform(
-            ProjectiveTransform.create(tempTransform),
-            new GeneralEnvelope(nativeGridRange));
+         final GeneralEnvelope envelope = CRS.transform(ProjectiveTransform.create(tempTransform),
+         new GeneralEnvelope(nativeGridRange));
          envelope.setCoordinateReferenceSystem(crs);
          this.nativeEnvelope = envelope;
         } catch (TransformException e) {
             if (LOGGER.isLoggable(Level.FINE))
-                LOGGER.log(Level.FINE,
-                        "Unable to parse CRS from underlying TIFF", e);
+                LOGGER.log(Level.FINE,"Unable to parse CRS from underlying TIFF", e);
         } catch (UnsupportedOperationException e) {
             if (LOGGER.isLoggable(Level.FINE))
-                LOGGER.log(Level.FINE,
-                        "Unable to parse CRS from underlying TIFF due to an unsupported CRS", e);
+                LOGGER.log(Level.FINE,"Unable to parse CRS from underlying TIFF due to an unsupported CRS", e);
         }
         
     }
 
+    /**
+     * Get the degenerate GeoTIFF to obtain the related CoordinateReferenceSystem tags
+     * @param uuid
+     * @throws IOException
+     */
  private void getGeoJP2(final UUIDBoxMetadataNode uuid) throws IOException {
 
  CoordinateReferenceSystem coordinateReferenceSystem = null;
- final ByteArrayInputStream inputStream = new ByteArrayInputStream(
-                 uuid.getData());
-         final TIFFImageReader tiffreader = (TIFFImageReader) new TIFFImageReaderSpi()
-                 .createReaderInstance();
-         tiffreader
-                 .setInput(ImageIO.createImageInputStream(inputStream));
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(uuid.getData());
+         final TIFFImageReader tiffreader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
+         tiffreader.setInput(ImageIO.createImageInputStream(inputStream));
          final IIOMetadata tiffmetadata = tiffreader.getImageMetadata(0);
-         final GeoTiffIIOMetadataDecoder metadataDecoder = new GeoTiffIIOMetadataDecoder(
-                 tiffmetadata);
-         final GeoTiffMetadata2CRSAdapter adapter = new GeoTiffMetadata2CRSAdapter(
-                 null);
          try {
-             coordinateReferenceSystem = adapter
-                     .createCoordinateSystem(metadataDecoder);
+         final GeoTiffIIOMetadataDecoder metadataDecoder = new GeoTiffIIOMetadataDecoder(tiffmetadata);
+         final GeoTiffMetadata2CRSAdapter adapter = new GeoTiffMetadata2CRSAdapter(null);
+             coordinateReferenceSystem = adapter.createCoordinateSystem(metadataDecoder);
              if (coordinateReferenceSystem != null) {
              if (this.crs == null)
              this.crs = coordinateReferenceSystem;
              }
              if (this.raster2Model == null){
-                 this.raster2Model = adapter
-                         .getRasterToModel(metadataDecoder);
-                 final AffineTransform tempTransform = new AffineTransform(
-                         (AffineTransform) raster2Model);
+                 this.raster2Model = adapter.getRasterToModel(metadataDecoder);
+                 final AffineTransform tempTransform = new AffineTransform((AffineTransform) raster2Model);
                  tempTransform.translate(-0.5, -0.5);
-                 GeneralEnvelope envelope = CRS.transform(
-                         ProjectiveTransform.create(tempTransform),
+                 GeneralEnvelope envelope = CRS.transform(ProjectiveTransform.create(tempTransform),
                          new GeneralEnvelope(nativeGridRange));
-                 envelope
-                         .setCoordinateReferenceSystem(crs);
+                 envelope.setCoordinateReferenceSystem(crs);
                  this.nativeEnvelope = envelope;
              }
 
@@ -354,8 +387,13 @@
          } catch (UnsupportedOperationException e) {
              if (LOGGER.isLoggable(Level.FINE))
                  LOGGER.log(Level.FINE,
-                         "Unable to parse CRS from underlying TIFF due to an unsupported CRS", e);
+                         "Unable to parse CRS from underlying TIFF", e);
              coordinateReferenceSystem = null;
+         } catch (IllegalArgumentException e) {
+             if (LOGGER.isLoggable(Level.FINE))
+                 LOGGER.log(Level.FINE,
+                         "Unable to parse CRS from underlying TIFF", e);
+             coordinateReferenceSystem = null;
          } finally {
              if (inputStream != null)
                  try {
@@ -499,7 +537,7 @@
 
  final Collection<GridCoverage2D> response = rasterManager.read(params);
  if(response.isEmpty())
- throw new DataSourceException("Unable to create a coverage for this request ");
+ return null;
  else
  return response.iterator().next();
  }

Modified: branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterLayerResponse.java
===================================================================
--- branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterLayerResponse.java 2009-11-12 15:02:56 UTC (rev 34369)
+++ branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterLayerResponse.java 2009-11-12 15:42:41 UTC (rev 34370)
@@ -195,10 +195,7 @@
  //
  //create a granule loader
  final GranuleLoader loader = new GranuleLoader(baseReadParameters, imageChoice, bbox, finalWorldToGridCorner,granule,request.getTileDimensions());
-// if(!multithreadingAllowed)
- tasks.add(new FutureTask<RenderedImage>(loader));
-// else
-// tasks.add(JP2KReader.multiThreadedLoader.submit(loader));
+ tasks.add(new FutureTask<RenderedImage>(loader));
 
  granulesNumber++;
  }
@@ -479,6 +476,7 @@
  // level dimension and envelope. The grid to world transforms for
  // the other levels can be computed accordingly knowning the scale
  // factors.
+
  if (request.getRequestedBBox() != null&& request.getRequestedRasterArea() != null)
  imageChoice = setReadParams(request.getOverviewPolicy(), baseReadParameters,request);
  else
@@ -497,7 +495,6 @@
  else
  bbox = new ReferencedEnvelope(coverageEnvelope);
 
-
  //compute final world to grid
  // base grid to world for the center of pixels
  final AffineTransform g2w = new AffineTransform((AffineTransform) baseGridToWorld);
@@ -520,14 +517,14 @@
  rasterBounds=new GeneralGridEnvelope(CRS.transform(finalWorldToGridCorner, bbox),PixelInCell.CELL_CORNER,false).toRectangle();
 
 
- // create the index visitor and visit the feature
+ // create Init the granuleWorker
  final GranuleWorker worker = new GranuleWorker();
  worker.init(new ReferencedEnvelope(coverageEnvelope));
  worker.produce();
 
  //
  // Did we actually load anything?? Notice that it might happen that
- // either we have wholes inside the definition area for the mosaic
+ // either we have holes inside the definition area for the mosaic
  // or we had some problem with missing tiles, therefore it might
  // happen that for some bboxes we don't have anything to load.
  //
@@ -673,6 +670,7 @@
  * @param readParams
  *            an instance of {@link ImageReadParam} for setting the
  *            subsampling factors.
+ * @param rescalingF
  * @param requestedEnvelope
  *            the {@link GeneralEnvelope} we are requesting.
  * @param requestedDim

Modified: branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterManager.java
===================================================================
--- branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterManager.java 2009-11-12 15:02:56 UTC (rev 34369)
+++ branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/RasterManager.java 2009-11-12 15:42:41 UTC (rev 34370)
@@ -78,7 +78,6 @@
         return "OverviewLevel[Choice=" + imageChoice + ",scaleFactor=" + scaleFactor + "]";
     }
     
-
  @Override
  public int hashCode() {
  int hash= Utilities.hash(imageChoice, 31);
@@ -87,8 +86,6 @@
  hash=Utilities.hash(scaleFactor, hash);
  return hash;
  }    
-    
-    
  }
 
  class OverviewsController  {
@@ -223,70 +220,64 @@
  * @param requestedRes
  */
  void performDecimation(
- final int imageIndex,
- final ImageReadParam readParameters,
- final RasterLayerRequest request) {
+ final int imageIndex,
+ final ImageReadParam readParameters,
+ final RasterLayerRequest request) {
+
+ // the read parameters cannot be null
+ Utils.ensureNonNull("readParameters", readParameters);
+ Utils.ensureNonNull("request", request);
+
+ //get the requested resolution
+ final double[] requestedRes=request.getRequestedResolution();
+ if(requestedRes==null)
  {
-
- // the read parameters cannot be null
- Utils.ensureNonNull("readParameters", readParameters);
- Utils.ensureNonNull("request", request);
-
- //get the requested resolution
- final double[] requestedRes=request.getRequestedResolution();
- if(requestedRes==null)
- {
- // if there is no requested resolution we don't do any subsampling
- readParameters.setSourceSubsampling(1, 1, 0, 0);
- return;
- }
+ // if there is no requested resolution we don't do any subsampling
+ readParameters.setSourceSubsampling(1, 1, 0, 0);
+ return;
+ }
 
- double selectedRes[] = new double[2];
- final OverviewLevel level=overviewsController.resolutionsLevels.get(imageIndex);
- selectedRes[0] = level.resolutionX;
- selectedRes[1] = level.resolutionY;
-
- final int rasterWidth, rasterHeight;
- if (imageIndex == 0) {
- // highest resolution
- rasterWidth = spatialDomainManager.coverageRasterArea.width;
- rasterHeight = spatialDomainManager.coverageRasterArea.height;
- } else {
- // work on overviews
- //TODO this is bad side effect of how the Overviews are managed right now. There are two problems here,
- // first we are assuming that we are working with LON/LAT, second is that we are getting just an approximation of
- // raster dimensions. The solution is to have the rater dimensions on each level and to confront raster dimensions,
- //which means working
- rasterWidth = (int) Math.round(spatialDomainManager.coverageBBox.getSpan(0)/ selectedRes[0]);
- rasterHeight = (int) Math.round(spatialDomainManager.coverageBBox.getSpan(1)/ selectedRes[1]);
-
- }
- // /////////////////////////////////////////////////////////////////////
- // DECIMATION ON READING
- // Setting subsampling factors with some checks
- // 1) the subsampling factors cannot be zero
- // 2) the subsampling factors cannot be such that the w or h are
- // zero
- // /////////////////////////////////////////////////////////////////////
- int subSamplingFactorX = (int) Math.floor(requestedRes[0]/ selectedRes[0]);
- subSamplingFactorX = subSamplingFactorX == 0 ? 1: subSamplingFactorX;
+ double selectedRes[] = new double[2];
+ final OverviewLevel level=overviewsController.resolutionsLevels.get(imageIndex);
+ selectedRes[0] = level.resolutionX;
+ selectedRes[1] = level.resolutionY;
+
+ final int rasterWidth, rasterHeight;
+ if (imageIndex == 0) {
+ // highest resolution
+ rasterWidth = spatialDomainManager.coverageRasterArea.width;
+ rasterHeight = spatialDomainManager.coverageRasterArea.height;
+ } else {
+ // work on overviews
+ //TODO this is bad side effect of how the Overviews are managed right now. There are two problems here,
+ // first we are assuming that we are working with LON/LAT, second is that we are getting just an approximation of
+ // raster dimensions. The solution is to have the rater dimensions on each level and to confront raster dimensions,
+ //which means working
+ rasterWidth = (int) Math.round(spatialDomainManager.coverageBBox.getSpan(0)/ selectedRes[0]);
+ rasterHeight = (int) Math.round(spatialDomainManager.coverageBBox.getSpan(1)/ selectedRes[1]);
 
- while (rasterWidth / subSamplingFactorX <= 0 && subSamplingFactorX >= 0)
- subSamplingFactorX--;
- subSamplingFactorX = subSamplingFactorX <= 0 ? 1: subSamplingFactorX;
-
- int subSamplingFactorY = (int) Math.floor(requestedRes[1]/ selectedRes[1]);
- subSamplingFactorY = subSamplingFactorY == 0 ? 1: subSamplingFactorY;
-
- while (rasterHeight / subSamplingFactorY <= 0 && subSamplingFactorY >= 0)subSamplingFactorY--;
- subSamplingFactorY = subSamplingFactorY <= 0 ? 1: subSamplingFactorY;
-
- readParameters.setSourceSubsampling(subSamplingFactorX,subSamplingFactorY, 0, 0);
-
-
  }
+ // /////////////////////////////////////////////////////////////////////
+ // DECIMATION ON READING
+ // Setting subsampling factors with some checks
+ // 1) the subsampling factors cannot be zero
+ // 2) the subsampling factors cannot be such that the w or h are zero
+ // /////////////////////////////////////////////////////////////////////
+ int subSamplingFactorX = (int) Math.floor(requestedRes[0]/ selectedRes[0]);
+ subSamplingFactorX = subSamplingFactorX == 0 ? 1: subSamplingFactorX;
+
+ while (rasterWidth / subSamplingFactorX <= 0 && subSamplingFactorX >= 0)
+ subSamplingFactorX--;
+ subSamplingFactorX = subSamplingFactorX <= 0 ? 1: subSamplingFactorX;
+
+ int subSamplingFactorY = (int) Math.floor(requestedRes[1]/ selectedRes[1]);
+ subSamplingFactorY = subSamplingFactorY == 0 ? 1: subSamplingFactorY;
+
+ while (rasterHeight / subSamplingFactorY <= 0 && subSamplingFactorY >= 0)subSamplingFactorY--;
+ subSamplingFactorY = subSamplingFactorY <= 0 ? 1: subSamplingFactorY;
+
+ readParameters.setSourceSubsampling(subSamplingFactorX, subSamplingFactorY, 0, 0);
  }
-
  }
 
  /**
@@ -455,7 +446,6 @@
  *         {@link Hints#VALUE_OVERVIEW_POLICY_SPEED}, {@link Hints#VALUE_OVERVIEW_POLICY_QUALITY}.
  *         Default is {@link Hints#VALUE_OVERVIEW_POLICY_NEAREST}.
  */
- @SuppressWarnings("deprecation")
  private OverviewPolicy extractOverviewPolicy() {
 
  if (this.hints != null)

Modified: branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/ReadType.java
===================================================================
--- branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/ReadType.java 2009-11-12 15:02:56 UTC (rev 34369)
+++ branches/2.6.x/modules/unsupported/jp2kakadu/src/main/java/org/geotools/coverageio/jp2kak/ReadType.java 2009-11-12 15:42:41 UTC (rev 34370)
@@ -15,6 +15,7 @@
 
 import javax.imageio.ImageReadParam;
 import javax.imageio.ImageReader;
+import javax.imageio.spi.ImageReaderSpi;
 import javax.imageio.stream.ImageInputStream;
 import javax.media.jai.ImageLayout;
 import javax.media.jai.JAI;
@@ -38,7 +39,8 @@
      final int imageIndex,
      final File rasterFile,
      final Rectangle readDimension,
-     final Dimension tileDimension // we just ignore in this case
+     final Dimension tileDimension, // we just ignore in this case
+     final ImageReaderSpi spi
      )throws IOException{
      //
      // Using ImageReader to load the data directly
@@ -50,7 +52,7 @@
      if(inStream==null)
      return null;
     
-     reader=Utils.getReader( inStream);
+     reader=spi.createReaderInstance();
      if(reader==null)
      {
      if (LOGGER.isLoggable(Level.WARNING))
@@ -103,7 +105,8 @@
      final int imageIndex,
      final File rasterFile,
      final Rectangle readDimension,
-     final Dimension tileDimension
+     final Dimension tileDimension,
+     final ImageReaderSpi spi
      ) throws IOException{
     
        ///
@@ -117,7 +120,7 @@
      if(inStream==null)
      return null;
      // get a reader
-     reader = Utils.getReader(inStream);
+     reader=spi.createReaderInstance();
      if(reader==null)
      {
      if (LOGGER.isLoggable(Level.WARNING))
@@ -169,7 +172,7 @@
  pbjImageRead.add(null);
  pbjImageRead.add(null);
  pbjImageRead.add(readP);
- pbjImageRead.add(null);
+ pbjImageRead.add(spi.createReaderInstance());
  final RenderedOp raster;
  if(tileDimension!=null){
  //build a proper layout
@@ -193,7 +196,8 @@
      final int imageIndex,
      final File rasterFile,
      final Rectangle readDimension,
-     final Dimension tileDimension
+     final Dimension tileDimension,
+     final ImageReaderSpi spi
      ) throws IOException{
     
        ///
@@ -207,7 +211,7 @@
      if(inStream==null)
      return null;
      // get a reader
-     reader = Utils.getReader(inStream);
+     reader=spi.createReaderInstance();
      if(reader==null)
      {
      if (LOGGER.isLoggable(Level.WARNING))
@@ -259,7 +263,7 @@
  pbjImageRead.add(null);
  pbjImageRead.add(null);
  pbjImageRead.add(readP);
- pbjImageRead.add(null);
+ pbjImageRead.add(spi.createReaderInstance());
  final RenderedOp raster;
  if(tileDimension!=null){
  //build a proper layout
@@ -284,7 +288,8 @@
      final int imageIndex,
      final File rasterFile,
      final Rectangle readDimension,
-     final Dimension tileDimension
+     final Dimension tileDimension,
+     final ImageReaderSpi spi
      )throws IOException{
      throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1,"read"));
      }
@@ -329,7 +334,8 @@
  final int imageIndex,
  final File rasterFile,
  final Rectangle readDimension,
- final Dimension tileDimension
+ final Dimension tileDimension,
+ final ImageReaderSpi spi
  ) throws IOException;
 
 };


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
GeoTools-commits mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-commits