Package javax.imageio

Examples of javax.imageio.ImageReadParam


            crs = CRS.parseWKT(metaDataTable.get(GrassBinaryImageMetadata.CRS));
        } catch (FactoryException e) {
            throw new IOException(e.getLocalizedMessage());
        }
        // where to put the region to read and if use subSampling
        ImageReadParam imageReadParam = new ImageReadParam();

        /*
         * the envelope that was requested, i.e. what has to be given back in
         * terms of bounds and resolution.
         */
        Envelope requestedRegionEnvelope = null;
        /*
         * the read region, i.e. the requested region without the parts east and
         * south of the file region. (since they would produce negative origin)
         */
        Rectangle sourceRegion = null;

        int requestedRows = 0;
        int requestedCols = 0;
        double requestedWest = -1;
        double requestedEast = -1;
        double requestedSouth = -1;
        double requestedNorth = -1;
        double requestedXres = -1;
        double requestedYres = -1;

        int subSamplingX = 1;
        int subSamplingY = 1;
        // These variable are difference,in N-E coordinate, between the
        // requested region and the
        // image region.
        double xDeltaW = 0;
        double xDeltaE = 0;
        double yDeltaN = 0;
        double yDeltaS = 0;
        // this is a difference used to compute the exact region in the world in
        // order to transform
        // the SR.
        double tmpDxW = 0.0;
        double tmpDyS = 0.0;
        double tmpDyN = 0.0;
        double tmpDxE = 0.0;
        int xPaddingSx = 0;
        int yPaddingTop = 0;

        if (region != null) {
            /*
             * the user requested a particular read region. and that is exactly
             * the region we have to give back.
             */
            requestedRows = region.getRows();
            requestedCols = region.getCols();
            requestedWest = region.getWest();
            requestedEast = region.getEast();
            requestedSouth = region.getSouth();
            requestedNorth = region.getNorth();
            requestedXres = region.getWEResolution();
            requestedYres = region.getNSResolution();
            /*
             * define the raster space region
             */
            double scaleX = fileCols / (fileEast - fileWest);
            double scaleY = fileRows / (fileNorth - fileSouth);
            double EPS = 1E-7;

            // awt space seen in the world view (north is ymax)
            int xmin = (int) Math.floor((requestedWest - fileWest) * scaleX + EPS);
            int xmax = (int) Math.ceil((requestedEast - fileWest) * scaleX - EPS);
            int ymin = (int) Math.floor((fileNorth - requestedNorth) * scaleY + EPS);
            int ymax = (int) Math.ceil((fileNorth - requestedSouth) * scaleY - EPS);

            /*
             * clip away region that is west and south of the image bounds. This
             * is important because the imageio source region can't be < 0.
             * Later the clipped parts will be resolved by translation of the
             * image.
             */
            if (xmin < 0) {
                xPaddingSx = xmin;
                xmin = 0;
            }
            if (ymin < 0) {
                yPaddingTop = ymin;
                ymin = 0;
            }

            /*
             * the pixel space region that will be extracted. Since the origin
             * is always 0,0, we can continue to see this in world view.
             */
            sourceRegion = new Rectangle(xmin, ymin, (xmax - xmin), ymax - ymin);
            requestedRegionEnvelope = new Envelope2D(crs, requestedWest, requestedSouth, requestedEast - requestedWest,
                    requestedNorth - requestedSouth);

            /*
             * the real world deltas
             */
            xDeltaW = requestedWest - fileWest;
            yDeltaS = requestedSouth - fileSouth;
            xDeltaE = requestedEast - fileEast;
            yDeltaN = requestedNorth - fileNorth;
            // yDelta = requestedNorth - north;

            /*
             * the real world envelope covering the read map part.
             */
            tmpDxW = xDeltaW > 0.0 ? 0.0 : xDeltaW;
            tmpDyS = yDeltaS > 0.0 ? 0.0 : yDeltaS;
            tmpDyN = yDeltaN < 0.0 ? 0.0 : yDeltaN;
            tmpDxE = xDeltaE < 0.0 ? 0.0 : xDeltaE;
            // set the region to the requestedRegion, this value is passed to
            // the coverage to
            // transform the JAI space into the real space.

            /*
             * define the subsampling values. This done starting from the
             * original's image resolution.
             */
            if (!useSubSamplingAsRequestedColsRows) {
                /*
                 * in this case we respect the original subsampling contract.
                 */
                JGrassRegion tmpRegion = new JGrassRegion(region);
                tmpRegion.setWEResolution((fileEast - fileWest) / (double) fileCols);
                tmpRegion.setNSResolution((fileNorth - fileSouth) / (double) fileRows);
                subSamplingX = (int) Math.floor((double) tmpRegion.getCols() / (double) requestedCols);
                subSamplingY = (int) Math.floor((double) tmpRegion.getRows() / (double) requestedRows);
                if (subSamplingX == 0)
                    subSamplingX = 1;
                if (subSamplingY == 0)
                    subSamplingY = 1;
                if (subSamplingX != subSamplingY) {
                    if (subSamplingX < subSamplingY) {
                        subSamplingY = subSamplingX;
                    } else {
                        subSamplingX = subSamplingY;
                    }
                }
            } else {
                /*
                 * in this case the subsampling values are interpreted as
                 * columns and row numbers to be used to calculate the
                 * resolution from the given boundaries.
                 */

                double sourceCols = (requestedEast - requestedWest) / (1 + (xPaddingSx / (xmax - xmin))) / requestedXres;
                double sourceRows = (requestedNorth - requestedSouth) / (1 + (yPaddingTop / (ymax - ymin))) / requestedYres;
                /*
                 * the padding has to be removed since inside the reader
                 * the padding is ignored and non present in the sourceRegion that
                 * is passed.
                 */
                sourceCols = sourceCols + xPaddingSx;
                sourceRows = sourceRows + yPaddingTop;
                subSamplingX = (int) Math.round(sourceCols);
                subSamplingY = (int) Math.round(sourceRows);

                if (subSamplingX < 1) {
                    subSamplingX = 1;
                }
                if (subSamplingY < 1) {
                    subSamplingY = 1;
                }
            }

        } else {
            /*
             * if no region has been requested, the source and requested region
             * are the same, i.e. the whole raster is read and passed.
             */
            requestedRows = fileRows;
            requestedCols = fileCols;
            requestedWest = fileWest;
            requestedEast = fileEast;
            requestedSouth = fileSouth;
            requestedNorth = fileNorth;
            double scaleX = fileCols / (fileEast - fileWest);
            double scaleY = fileRows / (fileNorth - fileSouth);
            double EPS = 1E-6;
            int xmin = (int) Math.floor((requestedWest - fileWest) * scaleX + EPS);
            int xmax = (int) Math.ceil((requestedEast - fileWest) * scaleX - EPS);
            int ymin = (int) Math.floor((fileNorth - requestedNorth) * scaleY + EPS);
            int ymax = (int) Math.ceil((fileNorth - requestedSouth) * scaleY - EPS);
            sourceRegion = new Rectangle(xmin, ymin, (xmax - xmin), ymax - ymin);
            requestedRegionEnvelope = new Envelope2D(crs, requestedWest, requestedSouth, requestedEast - requestedWest,
                    requestedNorth - requestedSouth);

            /*
             * define the subsampling values. This done starting from the
             * original's image resolution.
             */
            if (!useSubSamplingAsRequestedColsRows) {
                /*
                 * in this case we respect the original subsampling contract.
                 */
                subSamplingX = 1;
                subSamplingY = 1;
            } else {
                subSamplingX = fileCols;
                subSamplingY = fileRows;

            }
        }
        if (sourceRegion.getWidth() <= 0 || sourceRegion.getHeight() <= 0) {
            return null;
        }

        // now we have enough info to create the ImageReadParam
        imageReadParam.setSourceRegion(sourceRegion);
        imageReadParam.setSourceSubsampling(subSamplingX, subSamplingY, 0, 0);
        RenderedImage finalImage = null;

        BufferedImage image = imageReader.read(0, imageReadParam, useSubSamplingAsRequestedColsRows, castDoubleToFloating,
                monitor);
        imageReader.dispose();
View Full Code Here


    /**
     * Tests the checkEmptySourceRegion method.
     */
    @Test
    public void testCheckEmptySourceRegion() {
        final ImageReadParam params = new ImageReadParam();
        Rectangle sourceRegion = new Rectangle(300, 300, 700, 700);
        params.setSourceRegion(sourceRegion);
        Assert.assertEquals(sourceRegion.x, 300);
        Assert.assertEquals(sourceRegion.y, 300);
        Assert.assertEquals(sourceRegion.height, 700);
        Assert.assertEquals(sourceRegion.width, 700);
       
        final Rectangle intersecting = new Rectangle(400, 400, 900, 900);
        boolean isEmpty = CoverageUtilities.checkEmptySourceRegion(params, intersecting);
       
        Assert.assertFalse(isEmpty);
        final Rectangle intersection = params.getSourceRegion();
        Assert.assertEquals(intersection.x, 400);
        Assert.assertEquals(intersection.y, 400);
        Assert.assertEquals(intersection.height, 600);
        Assert.assertEquals(intersection.width, 600);
      
View Full Code Here

        Object source = bis;
        ImageInputStream iis = ImageIO.createImageInputStream(source);
        Iterator<?> readers = ImageIO.getImageReaders(iis);
        ImageReader reader = (ImageReader) readers.next();
        reader.setInput(iis, true);
        ImageReadParam param = reader.getDefaultReadParam();
        return reader.read(0, param);
    }
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

            // //
            useJAI = requestUsesJaiImageread();
            if (useMultithreading) {
                imageReadParam = new DefaultCloneableImageReadParam();
            } else {
                imageReadParam = new ImageReadParam();
            }

            // //
            //
            // Set the read parameters
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

        final Rectangle sourceRasterRegion = new Rectangle();
        GeneralEnvelope adjustedRequestedEnvelope2D;
        final GeneralEnvelope requestedEnvelope2D = new GeneralEnvelope(requestedBoundingBox);
        final MathTransform2D grid2WorldTransform = request.getGridToWorldTransform();
        final ImageReadParam imageReadParam = new ImageReadParam();
        try {
            // //
            //
            // Set envelope and source region
            //
            // //
            adjustedRequestedEnvelope2D = Utilities.evaluateRequestedParams(
                    access.gridGeometry2DMap.get(this.name).getGridRange(),
                    access.baseEnvelope2DMap.get(this.name),
                    access.spatialReferenceSystem2DMap.get(this.name),
                    access.raster2ModelMap.get(this.name), requestedEnvelope2D,
                    sourceRasterRegion, requestedRasterArea,
                    grid2WorldTransform, access.wgs84BaseEnvelope2DMap.get(this.name));

            // //
            //
            // Set specific imageIO parameters: type of read operation,
            // imageReadParams
            //
            // //

            if (adjustedRequestedEnvelope2D != null) {
                final GeneralEnvelope req = (adjustedRequestedEnvelope2D.isEmpty()) ? requestedEnvelope2D
                        : adjustedRequestedEnvelope2D;
                Utilities.setReadParameters(null /* OverviewPolicy */,
                        imageReadParam, req, requestedRasterArea,
                        access.highestResMap.get(this.name),
                        access.gridGeometry2DMap.get(this.name).getGridRange(),
                        PixelInCell.CELL_CORNER);
            }
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
            adjustedRequestedEnvelope2D = null;
        } catch (TransformException e) {
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
            adjustedRequestedEnvelope2D = null;
        }
        if (adjustedRequestedEnvelope2D != null && sourceRasterRegion != null && !sourceRasterRegion.isEmpty()) {
            imageReadParam.setSourceRegion(sourceRasterRegion);
        }

        // A transformation is requested in case the requested envelope has been
        // adjusted
        final boolean needTransformation = (adjustedRequestedEnvelope2D != null && !adjustedRequestedEnvelope2D.isEmpty());
View Full Code Here

      {
         return;
      }

      ImageReader reader = (ImageReader) iter.next();
      ImageReadParam param = reader.getDefaultReadParam();
      reader.setInput(stream, true, true);
      String type = reader.getFormatName();
      setContentType(Type.getTypeByFormatName(type));
      bufferedImage = reader.read(0, param);
      stream.close();
View Full Code Here

    public void doTest() {
        try {
            reader.addIIOReadProgressListener(this);
            iis = ImageIO.createImageInputStream(file);
            reader.setInput(iis);
            ImageReadParam p = reader.getDefaultReadParam();
            Thread.sleep(70);
            BufferedImage res = reader.read(0, p);
            Thread.sleep(70);
        } catch (Exception e) {
            /*
 
View Full Code Here

    public void run() {
        try {
            ImageInputStream iis = ImageIO.createImageInputStream(file);
            r.setInput(iis);
            ImageReadParam p = r.getDefaultReadParam();
            Thread.sleep(70);
            BufferedImage res = r.read(0, p);
            Thread.sleep(70);
            r.reset();
        } catch (IllegalStateException e) {
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.