Package javax.imageio

Examples of javax.imageio.ImageReadParam


    // if we get here we have something to load
     
    //
    // compute the requested resolution
    //
    final ImageReadParam readP = new ImageReadParam();
    Integer imageChoice=0;
    if (dim != null)
      imageChoice = setReadParams(overviewPolicy, readP,requestedEnvelope, dim);
   
    //
View Full Code Here


        // Load feaures from the index
        // In case there are no features under the requested bbox which is legal
        // in case the mosaic is not a real sqare, we return a fake mosaic.
        //
        // /////////////////////////////////////////////////////////////////////
        final ImageReadParam readP = new ImageReadParam();
        final Integer imageChoice;

        if (pixelDimension != null) {
            try {
                imageChoice = setReadParams(OverviewPolicy.getDefaultPolicy(), readP, state
                        .getRequestEnvelopeTransformed(), pixelDimension);
                readP.setSourceSubsampling(1, 1, 0, 0);
            } catch (TransformException e) {
                LOGGER.severe(e.getLocalizedMessage());

                return coverageFactory.create(coverageName, getEmptyImage((int) pixelDimension
                        .getWidth(), (int) pixelDimension.getHeight(), backgroundColor,outputTransparentColor),
View Full Code Here

    // Setting subsampling factors with some checkings
    // 1) the subsampling factors cannot be zero
    // 2) the subsampling factors cannot be such that the w or h are zero
    //
    // //
    final ImageReadParam readP = new ImageReadParam();
    final Integer imageChoice;
    try {
      imageChoice = setReadParams(overviewPolicy, readP,
          requestedEnvelope, requestedDim);
    } catch (IOException e) {
View Full Code Here

    }

    private void prepareParams() throws DataSourceException {

        try {
            baseReadParameters = new ImageReadParam();
            performDecimation(baseReadParameters);

            // === extract bbox
            initBBOX();
View Full Code Here

        if (LOGGER.isLoggable(java.util.logging.Level.FINER)) {
            final String name = Thread.currentThread().getName();
            LOGGER.finer("Thread:" + name + " Loading raster data for granuleDescriptor "
                    + this.toString());
        }
        ImageReadParam readParameters = null;
        int imageIndex;
        final ReferencedEnvelope bbox = request.spatialRequestHelper.getCoverageProperties().getBbox();

        // intersection of this tile bound with the current crop bbox
        final ReferencedEnvelope intersection = new ReferencedEnvelope(bbox.intersection(cropBBox),
                cropBBox.getCoordinateReferenceSystem());
        if (intersection.isEmpty()) {
            if (LOGGER.isLoggable(java.util.logging.Level.FINE)) {
                LOGGER.fine(new StringBuilder("Got empty intersection for granule ")
                        .append(this.toString()).append(" with request ")
                        .append(request.toString())
                        .append(" Resulting in no granule loaded: Empty result").toString());
            }
            return null;
        }
        try {

            // What about thread safety?
           
            imageIndex = index;
            readParameters = imageReadParameters;

            // now create the crop grid to world which can be used to decide
            // which source area we need to crop in the selected level taking
            // into account the scale factors imposed by the selection of this
            // level together with the base level grid to world transformation

            final AffineTransform gridToWorldTransform_ = new AffineTransform();
            gridToWorldTransform_.preConcatenate(CoverageUtilities.CENTER_TO_CORNER);
            gridToWorldTransform_.preConcatenate(baseGridToWorld);
            AffineTransform2D cropWorldToGrid = new AffineTransform2D(gridToWorldTransform_);
            cropWorldToGrid = (AffineTransform2D) cropWorldToGrid.inverse();
            // computing the crop source area which lives into the
            // selected level raster space, NOTICE that at the end we need to
            // take into account the fact that we might also decimate therefore
            // we cannot just use the crop grid to world but we need to correct
            // it.
            Rectangle sourceArea = CRS.transform(cropWorldToGrid, intersection)
                    .toRectangle2D().getBounds();
            // Selection of the source original area for cropping the computed source area
            // (may have negative values for the approximation)
            final Rectangle initialArea = request.source.getSpatialDomain()
                    .getRasterElements(true, null).iterator().next().toRectangle();
            sourceArea = sourceArea.intersection(initialArea);

            if (sourceArea.isEmpty()) {
                if (LOGGER.isLoggable(java.util.logging.Level.FINE)) {
                    LOGGER.fine("Got empty area for granuleDescriptor " + this.toString()
                            + " with request " + request.toString()
                            + " Resulting in no granule loaded: Empty result");

                }
                return null;

            } else if (LOGGER.isLoggable(java.util.logging.Level.FINER)) {
                LOGGER.finer("Loading level " + imageIndex + " with source region: " + sourceArea
                        + " subsampling: " + readParameters.getSourceXSubsampling() + ","
                        + readParameters.getSourceYSubsampling() + " for granule:" + datasetURL);
            }

            // set the source region
            readParameters.setSourceRegion(sourceArea);
            final RenderedImage raster;
            try {
                // read
                raster = request.readType.read(readParameters, imageIndex, datasetURL,
                        request.spatialRequestHelper.getCoverageProperties().getRasterArea(),
                        request.source.reader, hints, false);

            } catch (Throwable e) {
                if (LOGGER.isLoggable(java.util.logging.Level.FINE)) {
                    LOGGER.log(java.util.logging.Level.FINE,
                            "Unable to load raster for granuleDescriptor " + this.toString()
                                    + " with request " + request.toString()
                                    + " Resulting in no granule loaded: Empty result", e);
                }
                return null;
            }

            // use fixed source area
            sourceArea.setRect(readParameters.getSourceRegion());

            //
            // setting new coefficients to define a new affineTransformation
            // to be applied to the grid to world transformation
            // -----------------------------------------------------------------------------------
View Full Code Here

        originatingCoverageRequest.prepare();
        if (originatingCoverageRequest.isEmptyRequest())
          //something bad happened
            gridCoverage = null;
        else {
            final ImageReadParam imageReadParam = originatingCoverageRequest.getImageReadParam();
            final File input = originatingCoverageRequest.getInput();
            final boolean useMultithreading = originatingCoverageRequest.useMultithreading();
            final boolean newTransform = originatingCoverageRequest.isAdjustGridToWorldSet();
            final boolean useJAI = originatingCoverageRequest.useJAI();
            gridCoverage = createCoverage(input, imageReadParam, useJAI,useMultithreading, newTransform);
View Full Code Here

        slice.rasterDimensions=rasterLayout;
       
        //
        // get sample image
        //
        final ImageReadParam readParam = reader.getDefaultReadParam();
        readParam.setSourceRegion(new Rectangle(0, 0, 2, 2));
        final BufferedImage sampleImage = reader.read(index, readParam);
        final ImageTypeSpecifier imageType = new ImageTypeSpecifier(sampleImage);
        slice.imageType=imageType;
       
        double noDataValue;
View Full Code Here

    // Setting subsampling factors with some checkings
    // 1) the subsampling factors cannot be zero
    // 2) the subsampling factors cannot be such that the w or h are zero
    //
    // /////////////////////////////////////////////////////////////////////
    final ImageReadParam readP = new ImageReadParam();
    final Integer imageChoice;
    try {
      imageChoice = setReadParams(overviewPolicy, readP,
          requestedEnvelope, dim);
    } catch (TransformException e) {
      throw new DataSourceException(e);
    }


    // /////////////////////////////////////////////////////////////////////
    //
    // Statistics
    //
    // /////////////////////////////////////////////////////////////////////
    final int max = stats.getMax();
    final int min = stats.getMin();

    // /////////////////////////////////////////////////////////////////////
    //
    // Preparing to load
    //
    // /////////////////////////////////////////////////////////////////////
    // trying to create a channel to the file to read
    final File file = DataUtilities.urlToFile(demURL);
    final ImageInputStream iis = ImageIO.createImageInputStream(file);
    if (header.getByteOrder().compareToIgnoreCase("M") == 0) {
      iis.setByteOrder(ByteOrder.BIG_ENDIAN);
    } else {
      iis.setByteOrder(ByteOrder.LITTLE_ENDIAN);
    }

    // Prepare temporary colorModel and sample model, needed to build the
    // RawImageInputStream
    final ImageLayout layout = getImageLayout();
    final ImageTypeSpecifier its = new ImageTypeSpecifier(layout.getColorModel(null), layout.getSampleModel(null));
   
    // Finally, build the image input stream
    final RawImageInputStream raw = new RawImageInputStream(iis, its,
        new long[] { 0 }, new Dimension[] { new Dimension(hrWidth,
            hrHeight) });

    // building the final image layout
    final ImageLayout il = new ImageLayout(0, 0, hrWidth
        / readP.getSourceXSubsampling(), hrHeight
        / readP.getSourceYSubsampling(), 0, 0,
        layout.getTileWidth(null),
        layout.getTileHeight(null),
        layout.getSampleModel(null),
        layout.getColorModel(null));
View Full Code Here

    //
    // set params
    //
    Integer imageChoice = new Integer(0);
    final ImageReadParam readP = new ImageReadParam();
    try {
      imageChoice = setReadParams(overviewPolicy, readP,requestedEnvelope, dim);
    } catch (TransformException e) {
      new DataSourceException(e);
    }
View Full Code Here

   
    if (LOGGER.isLoggable(java.util.logging.Level.FINER)){
        final String name = Thread.currentThread().getName();
      LOGGER.finer("Thread:" + name + " Loading raster data for granuleDescriptor "+this.toString());
    }
    ImageReadParam readParameters = null;
    int imageIndex;
    final boolean useFootprint = roiProvider != null&&request.getFootprintBehavior()!=FootprintBehavior.None;
    Geometry inclusionGeometry = useFootprint ? roiProvider.getFootprint(): null;
    final ReferencedEnvelope bbox = useFootprint?
            new ReferencedEnvelope(granuleBBOX.intersection(inclusionGeometry.getEnvelopeInternal()), granuleBBOX.getCoordinateReferenceSystem()):
                granuleBBOX;
    boolean doFiltering = false;
                if (filterMe && useFootprint){
                    doFiltering = Utils.areaIsDifferent(inclusionGeometry, baseGridToWorld, granuleBBOX);
                }
   
   
                // intersection of this tile bound with the current crop bbox
                final ReferencedEnvelope intersection = new ReferencedEnvelope(bbox.intersection(cropBBox), cropBBox.getCoordinateReferenceSystem());
                if (intersection.isEmpty()) {
                    if (LOGGER.isLoggable(java.util.logging.Level.FINE)){
                            LOGGER.fine(new StringBuilder("Got empty intersection for granule ").append(this.toString())
                                    .append(" with request ").append(request.toString()).append(" Resulting in no granule loaded: Empty result").toString());
                    }
                    return null;
                }
               
        // check if the requested bbox intersects or overlaps the requested area
        if(useFootprint && inclusionGeometry != null && !JTS.toGeometry(cropBBox).intersects(inclusionGeometry)) {
            if (LOGGER.isLoggable(java.util.logging.Level.FINE)) {
                LOGGER.fine(new StringBuilder("Got empty intersection for granule ").append(this.toString())
                        .append(" with request ").append(request.toString()).append(" Resulting in no granule loaded: Empty result").toString());
            }
            return null;
        }
               

    ImageInputStream inStream=null;
    ImageReader reader=null;
    try {
      //
      //get info about the raster we have to read
      //
     
      // get a stream
            assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
                        inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
      if(inStream==null)
        return null;
     
 
      // get a reader and try to cache the relevant SPI
      if(cachedReaderSPI==null){
        reader = ImageIOExt.getImageioReader(inStream);
        if(reader!=null)
          cachedReaderSPI=reader.getOriginatingProvider();
      }
      else
        reader=cachedReaderSPI.createReaderInstance();
      if(reader==null) {
        if (LOGGER.isLoggable(java.util.logging.Level.WARNING)){
          LOGGER.warning(new StringBuilder("Unable to get s reader for granuleDescriptor ").append(this.toString())
                  .append(" with request ").append(request.toString()).append(" Resulting in no granule loaded: Empty result").toString());
        }
        return null;
      }
      // set input
      customizeReaderInitialization(reader, hints);
      reader.setInput(inStream);
     
            // Checking for heterogeneous granules and if the mosaic is not multidimensional
            if (request.isHeterogeneousGranules() && singleDimensionalGranule) {
          // create read parameters
          readParameters = new ImageReadParam();
         
          //override the overviews controller for the base layer
          imageIndex = ReadParamsController.setReadParams(
                  request.spatialRequestHelper.getComputedResolution(),
                  request.getOverviewPolicy(),
                  request.getDecimationPolicy(),
                  readParameters,
                  request.rasterManager,
                  overviewsController);
      } else {
          imageIndex = index;
          readParameters = imageReadParameters;
      }
     
      //get selected level and base level dimensions
      final GranuleOverviewLevelDescriptor selectedlevel= getLevel(imageIndex,reader);
 
     
      // now create the crop grid to world which can be used to decide
      // which source area we need to crop in the selected level taking
      // into account the scale factors imposed by the selection of this
      // level together with the base level grid to world transformation
            AffineTransform2D cropWorldToGrid= new AffineTransform2D(selectedlevel.gridToWorldTransformCorner);
            cropWorldToGrid=(AffineTransform2D) cropWorldToGrid.inverse();
      // computing the crop source area which lives into the
      // selected level raster space, NOTICE that at the end we need to
      // take into account the fact that we might also decimate therefore
      // we cannot just use the crop grid to world but we need to correct
      // it.
      final Rectangle sourceArea = CRS.transform(cropWorldToGrid, intersection).toRectangle2D().getBounds();
      //gutter
      if(selectedlevel.baseToLevelTransform.isIdentity()){
          sourceArea.grow(2, 2);
      }
      XRectangle2D.intersect(sourceArea, selectedlevel.rasterDimensions, sourceArea);//make sure roundings don't bother us
      // is it empty??
      if (sourceArea.isEmpty()) {
        if (LOGGER.isLoggable(java.util.logging.Level.FINE)){
          LOGGER.fine("Got empty area for granuleDescriptor "+this.toString()+
                  " with request "+request.toString()+" Resulting in no granule loaded: Empty result");
         
        }
        return null;

      } else if (LOGGER.isLoggable(java.util.logging.Level.FINER)){
        LOGGER.finer( "Loading level " + imageIndex + " with source region: "
                + sourceArea + " subsampling: "
                + readParameters.getSourceXSubsampling() + ","
                + readParameters.getSourceYSubsampling() + " for granule:"
                + granuleUrl) ;
      }

      // Setting subsampling
      int newSubSamplingFactor = 0;
      final String pluginName = cachedReaderSPI.getPluginClassName();
      if (pluginName != null && pluginName.equals(ImageUtilities.DIRECT_KAKADU_PLUGIN)){
        final int ssx = readParameters.getSourceXSubsampling();
        final int ssy = readParameters.getSourceYSubsampling();
        newSubSamplingFactor = ImageIOUtilities.getSubSamplingFactor2(ssx, ssy);
        if (newSubSamplingFactor != 0) {
            if (newSubSamplingFactor > maxDecimationFactor && maxDecimationFactor != -1){
                newSubSamplingFactor = maxDecimationFactor;
            }
            readParameters.setSourceSubsampling(newSubSamplingFactor, newSubSamplingFactor,0,0);
        }
      }
     
      // set the source region
      readParameters.setSourceRegion(sourceArea);
      RenderedImage raster;
      try {
        // read
        raster= request.getReadType().read(readParameters,imageIndex, granuleUrl, selectedlevel.rasterDimensions, reader, hints,false);
       
      } catch (Throwable e) {
        if (LOGGER.isLoggable(java.util.logging.Level.FINE)){
          LOGGER.log(java.util.logging.Level.FINE,
                  "Unable to load raster for granuleDescriptor "
                  + this.toString() + " with request "
                  + request.toString() + " Resulting in no granule loaded: Empty result",e);
        }
        return null;
      }

      // use fixed source area
      sourceArea.setRect(readParameters.getSourceRegion());
     
      //
      // setting new coefficients to define a new affineTransformation
      // to be applied to the grid to world transformation
      // -----------------------------------------------------------------------------------
View Full Code Here

TOP

Related Classes of javax.imageio.ImageReadParam

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.