Author: danieleromagnoli
Date: 2012-01-11 07:14:01 -0800 (Wed, 11 Jan 2012)
New Revision: 38476
Modified:
branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerRequest.java
branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerResponse.java
branches/2.7.x/modules/plugin/jp2k/src/main/java/org/geotools/coverageio/jp2k/Utils.java
branches/2.7.x/pom.xml
Log:
GEOT-3931 Align gt 2.7.x to imageio-ext 1.1.x series
Modified: branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerRequest.java
===================================================================
--- branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerRequest.java 2012-01-11 05:39:32 UTC (rev 38475)
+++ branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerRequest.java 2012-01-11 15:14:01 UTC (rev 38476)
@@ -16,7 +16,7 @@
*/
package org.geotools.coverageio;
-import it.geosolutions.imageio.imageioimpl.imagereadmt.DefaultCloneableImageReadParam;
+import it.geosolutions.imageio.imageioimpl.EnhancedImageReadParam;
import java.awt.Rectangle;
import java.awt.RenderingHints;
@@ -71,6 +71,7 @@
* @author Simone Giannecchini, GeoSolutions
*/
class RasterLayerRequest {
+ static boolean useDestinationRegion = /*Boolean.getBoolean("org.geotools.destination")*/true;
/** Logger. */
private final static Logger LOGGER = org.geotools.util.logging.Logging
@@ -145,7 +146,7 @@
* subsampling factors) which will be used by a coverageResponse to read
* data.
*/
- private ImageReadParam imageReadParam = null;
+ private EnhancedImageReadParam imageReadParam = null;
/** The source */
private Rectangle coverageRequestedRasterArea;
@@ -343,12 +344,8 @@
//
// //
useJAI = requestUsesJaiImageread();
- if (useMultithreading) {
- imageReadParam = new DefaultCloneableImageReadParam();
- } else {
- imageReadParam = new ImageReadParam();
- }
-
+ imageReadParam = new EnhancedImageReadParam();
+
// //
//
// Set the read parameters
@@ -505,28 +502,6 @@
return;
}
- // //
- //
- // Resolution requested. I am here computing the resolution required
- // by the user.
- //
- // //
-// if (requestedEnvelope != null) {
-// final GridToEnvelopeMapper geMapper = new GridToEnvelopeMapper();
-// geMapper.setEnvelope(requestedEnvelope);
-// geMapper.setGridRange(new GridEnvelope2D(requestedDim));
-//
-// // CELL_CORNER comes from GDAL based reader.
-// geMapper.setPixelAnchor(PixelInCell.CELL_CORNER);
-// AffineTransform transform = geMapper.createAffineTransform();
-// requestedRes = CoverageUtilities.getResolution(transform);
-//
-// if (LOGGER.isLoggable(Level.FINE)) {
-// LOGGER.log(Level.FINE, "requested resolution: ("
-// + requestedRes[0] + "," + requestedRes[1] + ")");
-// }
-// }
-
// ////////////////////////////////////////////////////////////////////
//
// DECIMATION ON READING since GDAL will automatically use the
@@ -724,32 +699,26 @@
if (requestedRes == null) {
imageReadParam.setSourceSubsampling(1, 1, 0, 0);
} else {
- int subSamplingFactorX = (int) Math.floor(requestedRes[0]
- / fullResolution[0]);
- subSamplingFactorX = (subSamplingFactorX == 0) ? 1
- : subSamplingFactorX;
+ if (useDestinationRegion && !useJAI){
+ final double xRatio = fullResolution[0]/requestedRes[0];
+ final double yRatio = fullResolution[1]/requestedRes[1];
+ imageReadParam.setDestinationRegion(new Rectangle(0,0,
+ (int)Math.floor(coverageRequestedRasterArea.width*xRatio),
+ (int)Math.floor(coverageRequestedRasterArea.height*yRatio)));
+ } else {
+ int subSamplingFactorX = (int) Math.floor(requestedRes[0] / fullResolution[0]);
+ subSamplingFactorX = (subSamplingFactorX == 0) ? 1 : subSamplingFactorX;
+ while (((w / subSamplingFactorX) <= 0) && (subSamplingFactorX >= 0))
+ subSamplingFactorX--;
+ subSamplingFactorX = (subSamplingFactorX == 0) ? 1 : subSamplingFactorX;
- while (((w / subSamplingFactorX) <= 0)
- && (subSamplingFactorX >= 0))
- subSamplingFactorX--;
-
- subSamplingFactorX = (subSamplingFactorX == 0) ? 1
- : subSamplingFactorX;
-
- int subSamplingFactorY = (int) Math.floor(requestedRes[1]
- / fullResolution[1]);
- subSamplingFactorY = (subSamplingFactorY == 0) ? 1
- : subSamplingFactorY;
-
- while (((h / subSamplingFactorY) <= 0)
- && (subSamplingFactorY >= 0))
- subSamplingFactorY--;
-
- subSamplingFactorY = (subSamplingFactorY == 0) ? 1
- : subSamplingFactorY;
-
- imageReadParam.setSourceSubsampling(subSamplingFactorX,
- subSamplingFactorY, 0, 0);
+ int subSamplingFactorY = (int) Math.floor(requestedRes[1] / fullResolution[1]);
+ subSamplingFactorY = (subSamplingFactorY == 0) ? 1 : subSamplingFactorY;
+ while (((h / subSamplingFactorY) <= 0) && (subSamplingFactorY >= 0))
+ subSamplingFactorY--;
+ subSamplingFactorY = (subSamplingFactorY == 0) ? 1 : subSamplingFactorY;
+ imageReadParam.setSourceSubsampling(subSamplingFactorX, subSamplingFactorY, 0, 0);
+ }
}
}
}
@@ -833,29 +802,6 @@
final GridToEnvelopeMapper geMapper= new GridToEnvelopeMapper(new GridEnvelope2D(requestedRasterArea),requestedBBox);
requestedResolution=CoverageUtilities.getResolution(geMapper.createAffineTransform());
-// ////
-// //
-// // STEP 3: Go back to destination space with the nevelope
-// //
-// ////
-// // transform the intersection envelope from the destination world
-// // space to the requested raster space
-// if (destinationToSourceTransform != null&& !destinationToSourceTransform.isIdentity() )
-// {
-// final GeneralEnvelope temp =CRS.transform(destinationToSourceTransform.inverse(),requestedBBoxInSourceCRS2D) ;
-// temp.setCoordinateReferenceSystem(requestedBBoxCRS2D);
-// requestedBBox = new ReferencedEnvelope(temp);
-//
-// }
-// else
-// //we do not need to do anything
-// requestedBBox=new ReferencedEnvelope(
-// requestedBBoxInSourceCRS2D.getMinX(),
-// requestedBBoxInSourceCRS2D.getMaxX(),
-// requestedBBoxInSourceCRS2D.getMinY(),
-// requestedBBoxInSourceCRS2D.getMaxY(),
-// coverageCRS2D);
-//
return;
} catch (TransformException te) {
Modified: branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerResponse.java
===================================================================
--- branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerResponse.java 2012-01-11 05:39:32 UTC (rev 38475)
+++ branches/2.7.x/modules/plugin/imageio-ext-gdal/src/main/java/org/geotools/coverageio/RasterLayerResponse.java 2012-01-11 15:14:01 UTC (rev 38476)
@@ -291,9 +291,8 @@
* Returns a {@code PlanarImage} given a set of parameter specifying the
* type of read operation to be performed.
*
- * @param new
- * FileImageInputStreamExtImplinput the input
- * {@code ImageInputStream} to be used for reading the image.
+ * @param input
+ * a File input to be used for reading the image.
* @param useJAI
* {@code true} if we need to use a JAI ImageRead operation,
* {@code false} if we need a simple direct
@@ -311,9 +310,14 @@
final ImageReadParam imageReadParam, final boolean useMultithreading)
throws IOException {
PlanarImage raster;
+ final ImageReader reader;
+ FileImageInputStreamExtImpl fiis = null;
if (useJAI) {
+ fiis = new FileImageInputStreamExtImpl(input);
+ reader = readerSpi.createReaderInstance();
+
final ParameterBlock pbjImageRead = new ParameterBlock();
- pbjImageRead.add(new FileImageInputStreamExtImpl(input));
+ pbjImageRead.add(fiis);
pbjImageRead.add(0);
pbjImageRead.add(Boolean.FALSE);
pbjImageRead.add(Boolean.FALSE);
@@ -321,28 +325,40 @@
pbjImageRead.add(null);
pbjImageRead.add(null);
pbjImageRead.add(imageReadParam);
- pbjImageRead.add(readerSpi.createReaderInstance());
+ pbjImageRead.add(reader);
// Check if to use a simple JAI ImageRead operation or a
// multithreaded one
final String jaiOperation = useMultithreading ? GridCoverageUtilities.IMAGEREADMT: GridCoverageUtilities.IMAGEREAD;
raster = JAI.create(jaiOperation, pbjImageRead, hints);
} else {
- final ImageReader reader = readerSpi.createReaderInstance();
+ reader = readerSpi.createReaderInstance();
+ fiis = new FileImageInputStreamExtImpl(input);
try {
- reader.setInput(new FileImageInputStreamExtImpl(input), true, true);
+ reader.setInput(fiis, true, true);
raster = PlanarImage.wrapRenderedImage(reader.read(0,imageReadParam));
}
finally {
- if(reader!=null)
- try {
- reader.dispose();
- }catch (Exception e) {
- if(LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE,e.getLocalizedMessage(),e);
- }
+
+ if (fiis != null) {
+ try {
+ fiis.close();
+ } catch (Exception e) {
+ if (LOGGER.isLoggable(Level.FINE)){
+ LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
+ }
+ }
+ }
+
+ if (reader != null)
+ try {
+ reader.dispose();
+ } catch (Exception e) {
+ if (LOGGER.isLoggable(Level.FINE)){
+ LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
+ }
+ }
}
-
}
return raster;
Modified: branches/2.7.x/modules/plugin/jp2k/src/main/java/org/geotools/coverageio/jp2k/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/jp2k/src/main/java/org/geotools/coverageio/jp2k/Utils.java 2012-01-11 05:39:32 UTC (rev 38475)
+++ branches/2.7.x/modules/plugin/jp2k/src/main/java/org/geotools/coverageio/jp2k/Utils.java 2012-01-11 15:14:01 UTC (rev 38476)
@@ -16,8 +16,7 @@
*/
package org.geotools.coverageio.jp2k;
-import it.geosolutions.imageio.imageioimpl.imagereadmt.CloneableImageReadParam;
-import it.geosolutions.imageio.imageioimpl.imagereadmt.DefaultCloneableImageReadParam;
+import it.geosolutions.imageio.imageioimpl.EnhancedImageReadParam;
import it.geosolutions.imageio.stream.input.FileImageInputStreamExt;
import java.awt.Rectangle;
@@ -161,7 +160,7 @@
// in which there is not a special ImageReadparam used.
// Create a new ImageReadParam instance.
- CloneableImageReadParam newParam = new DefaultCloneableImageReadParam();
+ EnhancedImageReadParam newParam = new EnhancedImageReadParam();
// Set all fields which need to be set.
Modified: branches/2.7.x/pom.xml
===================================================================
--- branches/2.7.x/pom.xml 2012-01-11 05:39:32 UTC (rev 38475)
+++ branches/2.7.x/pom.xml 2012-01-11 15:14:01 UTC (rev 38476)
@@ -73,7 +73,7 @@
<stress.skip.pattern>**/*StressTest.java</stress.skip.pattern>
<test.maxHeapSize>512M</test.maxHeapSize>
<src.output>${basedir}/target</src.output>
- <imageio.ext.version>1.0.8</imageio.ext.version>
+ <imageio.ext.version>1.1.2</imageio.ext.version>
<jt.version>1.1.1</jt.version>
<jvm.opts></jvm.opts>
<maven.build.timestamp.format>dd-MMM-yyyy HH:mm</maven.build.timestamp.format>
|