Example usage for java.awt.image RenderedImage getProperty

List of usage examples for java.awt.image RenderedImage getProperty

Introduction

In this page you can find the example usage for java.awt.image RenderedImage getProperty.

Prototype

Object getProperty(String name);

Source Link

Document

Gets a property from the property set of this image.

Usage

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetilerAction.java

/**
 * @deprecated replaced by {@link #GeoTiffRetilerUtils.reTile(...)}
 *///  w  w  w  .j  av a2 s.co  m
@Deprecated
public static void reTile(File inFile, File tiledTiffFile, double compressionRatio, String compressionType,
        int tileW, int tileH, boolean forceBigTiff) throws IOException {
    //
    // look for a valid file that we can read
    //

    AbstractGridFormat format = null;
    AbstractGridCoverage2DReader reader = null;
    GridCoverage2D inCoverage = null;
    AbstractGridCoverageWriter writer = null;
    final Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);

    // getting a format for the given input
    format = (AbstractGridFormat) GridFormatFinder.findFormat(inFile, hints);
    if (format == null || (format instanceof UnknownFormat)) {
        throw new IllegalArgumentException("Unable to find the GridFormat for the provided file: " + inFile);
    }

    try {
        //
        // ACQUIRING A READER
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Acquiring a reader for the provided file...");
        }

        // can throw UnsupportedOperationsException
        reader = (AbstractGridCoverage2DReader) format.getReader(inFile, hints);

        if (reader == null) {
            final IOException ioe = new IOException("Unable to find a reader for the provided file: " + inFile);
            throw ioe;
        }

        //
        // ACQUIRING A COVERAGE
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Acquiring a coverage provided file...");
        }
        inCoverage = (GridCoverage2D) reader.read(null);
        if (inCoverage == null) {
            final IOException ioe = new IOException("inCoverage == null");
            throw ioe;
        }

        //
        // PREPARING A WRITE
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Writing down the file in the decoded directory...");
        }

        final GeoTiffFormat wformat = new GeoTiffFormat();
        final GeoTiffWriteParams wp = new GeoTiffWriteParams();
        if (!Double.isNaN(compressionRatio) && compressionType != null) {
            wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
            wp.setCompressionType(compressionType);
            wp.setCompressionQuality((float) compressionRatio);
        }
        wp.setForceToBigTIFF(forceBigTiff);
        wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT);
        wp.setTiling(tileW, tileH);
        final ParameterValueGroup wparams = wformat.getWriteParameters();
        wparams.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);

        //
        // ACQUIRING A WRITER AND PERFORMING A WRITE
        //
        writer = (AbstractGridCoverageWriter) new GeoTiffWriter(tiledTiffFile);
        writer.write(inCoverage,
                (GeneralParameterValue[]) wparams.values().toArray(new GeneralParameterValue[1]));

    } finally {
        //
        // PERFORMING FINAL CLEAN UP AFTER THE WRITE PROCESS
        //
        if (reader != null) {
            try {
                reader.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(e.getLocalizedMessage(), e);
            }

        }

        if (writer != null) {
            try {
                writer.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(e.getLocalizedMessage(), e);
            }

        }

        if (inCoverage != null) {
            final RenderedImage initImage = inCoverage.getRenderedImage();
            ImageReader r = (ImageReader) initImage.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
            try {
                r.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("GeotiffRetiler::reTile(): " + e.getLocalizedMessage(), e);
            }

            // dispose
            ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(initImage));

        }
    }

}

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetiler.java

public static void reTile(File inFile, File tiledTiffFile, double compressionRatio, String compressionType,
        int tileW, int tileH, boolean forceBigTiff) throws IOException {
    ////from w  w w.  ja  v a  2  s  .  com
    // look for a valid file that we can read
    //

    AbstractGridFormat format = null;
    AbstractGridCoverage2DReader reader = null;
    GridCoverage2D inCoverage = null;
    AbstractGridCoverageWriter writer = null;
    final Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);

    // getting a format for the given input
    format = (AbstractGridFormat) GridFormatFinder.findFormat(inFile, hints);
    if (format == null || (format instanceof UnknownFormat)) {
        throw new IllegalArgumentException("Unable to find the GridFormat for the provided file: " + inFile);
    }

    try {
        //
        // ACQUIRING A READER
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Acquiring a reader for the provided file...");
        }

        // can throw UnsupportedOperationsException
        reader = (AbstractGridCoverage2DReader) format.getReader(inFile, hints);

        if (reader == null) {
            final IOException ioe = new IOException("Unable to find a reader for the provided file: " + inFile);
            throw ioe;
        }

        //
        // ACQUIRING A COVERAGE
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Acquiring a coverage provided file...");
        }
        inCoverage = (GridCoverage2D) reader.read(null);
        if (inCoverage == null) {
            final IOException ioe = new IOException("inCoverage == null");
            throw ioe;
        }

        //
        // PREPARING A WRITE
        //
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Writing down the file in the decoded directory...");
        }

        final GeoTiffFormat wformat = new GeoTiffFormat();
        final GeoTiffWriteParams wp = new GeoTiffWriteParams();
        if (!Double.isNaN(compressionRatio) && compressionType != null) {
            wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
            wp.setCompressionType(compressionType);
            wp.setCompressionQuality((float) compressionRatio);
        }
        wp.setForceToBigTIFF(forceBigTiff);
        wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT);
        wp.setTiling(tileW, tileH);
        final ParameterValueGroup wparams = wformat.getWriteParameters();
        wparams.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);

        //
        // ACQUIRING A WRITER AND PERFORMING A WRITE
        //
        writer = (AbstractGridCoverageWriter) new GeoTiffWriter(tiledTiffFile);
        writer.write(inCoverage,
                (GeneralParameterValue[]) wparams.values().toArray(new GeneralParameterValue[1]));

    } finally {
        //
        // PERFORMING FINAL CLEAN UP AFTER THE WRITE PROCESS
        //
        if (reader != null) {
            try {
                reader.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(e.getLocalizedMessage(), e);
            }

        }

        if (writer != null) {
            try {
                writer.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(e.getLocalizedMessage(), e);
            }

        }

        if (inCoverage != null) {
            final RenderedImage initImage = inCoverage.getRenderedImage();
            ImageReader r = (ImageReader) initImage.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
            try {
                r.dispose();
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("GeotiffRetiler::reTile(): " + e.getLocalizedMessage(), e);
            }

            // dispose
            ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(initImage));

        }
    }

}

From source file:org.esa.nest.gpf.GCPSelectionOp.java

private static double getMean(final RenderedImage image) {

    final ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);/*from w  ww . ja  v  a 2  s . c o m*/
    pb.add(null); // null ROI means whole image
    pb.add(1); // check every pixel horizontally
    pb.add(1); // check every pixel vertically

    // Perform the mean operation on the source image.
    final RenderedImage meanImage = JAI.create("mean", pb, null);
    // Retrieve and report the mean pixel value.
    final double[] mean = (double[]) meanImage.getProperty("mean");
    return mean[0];
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * @noinspection UseOfObsoleteCollectionType
 * @see Graphics2D#drawRenderedImage(RenderedImage, AffineTransform)
 *///from  w w w  .  j  av a2s .  com
@Override
public void drawRenderedImage(final RenderedImage img, final AffineTransform xform) {
    final BufferedImage image;
    if (img instanceof BufferedImage) {
        image = (BufferedImage) img;
    } else {
        final ColorModel cm = img.getColorModel();
        final int width = img.getWidth();
        final int height = img.getHeight();
        final WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
        final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
        final Hashtable properties = new Hashtable();
        final String[] keys = img.getPropertyNames();
        if (keys != null) {
            final int keyCount = keys.length;
            for (int i = 0; i < keyCount; i++) {
                properties.put(keys[i], img.getProperty(keys[i]));
            }
        }
        final BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
        img.copyData(raster);
        image = result;
    }
    drawImage(image, xform, null);
}

From source file:org.photovault.dcraw.AHDInterpolateOp.java

/**
 * Constructor//from   w  w  w .j  a v a2  s.co m
 * @param src Source image
 * @param rmult Red channel multiplier
 * @param gmult Green channel multiplier
 * @param bmult Blue channel multiplier
 * @param downsample Downsampling factor
 * @param hints Rendering hints
 */
public AHDInterpolateOp(RenderedImage src, double rmult, double gmult, double bmult, int downsample,
        RenderingHints hints) {
    super(sourceHelper(src), layoutHelper(src, downsample), hints, false);
    mult[0] = rmult;
    mult[1] = gmult;
    mult[2] = bmult;
    mult[3] = gmult;
    this.downSample = downsample;
    double maxMult = Math.max(gmult, Math.max(rmult, bmult));

    int rawMax = (Integer) src.getProperty("dcraw_max");
    rawBlackLevel = (Integer) src.getProperty("dcraw_black");
    double m = 0x10000 / (maxMult * (double) rawMax);
    for (int n = 0; n < mult.length; n++) {
        mult[n] *= m;
    }

    Object obj = src.getProperty("bayerfilter");
    bayerfilter = (Integer) obj;
    obj = src.getProperty("dcraw_margin_top");
    topMargin = (Short) obj;
    obj = src.getProperty("dcraw_margin_left");
    leftMargin = (Short) obj;

    camToRGB = new double[3][4];
    float[] rgb_cam = (float[]) src.getProperty("dcraw_rgb_cam");
    for (int r = 0; r < 3; r++) {
        for (int c = 0; c < 3; c++) {
            camToRGB[r][c] = rgb_cam[r * 4 + c];
        }
    }
    initCielabConv();
}

From source file:org.photovault.image.PhotovaultImage.java

/**
 Find the last cached rendering of a certain phase of image processing pipeline.
 The name is stored in JAI property "org.photovault.opname".
 <p>/*from www  . j  a va 2s.  co  m*/
 This function makes a depth-first search to the sources of given node and 
 returns the first node that has the name.
 @param op The "sink" node of the image processing graph that is searched
 @param The name
 @return First node found with given name or <code>NULL</codel> if no such 
 node is found.
 */
RenderedImage findNamedRendering(RenderedImage op, String name) {
    if (op != null) {
        Object imgName = op.getProperty("org.photovault.opname");
        if (imgName.equals(name)) {
            return op;
        }
        Vector sources = op.getSources();
        if (sources == null) {
            // Apparently we arrived at the leaf node without finding the 
            // correct rendering.
            return null;
        }
        for (Object o : sources) {
            if (o != null && o instanceof RenderedImage) {
                RenderedImage candidate = findNamedRendering((RenderedImage) o, name);
                if (candidate != null) {
                    return candidate;
                }
            }
        }
    }
    return null;
}

From source file:org.photovault.image.PhotovaultImage.java

private void debugPrintGraph(RenderedImage img, String prefix) {
    Object opName = img.getProperty("org.photovault.opname");
    if (opName != null && opName instanceof String) {
        System.out.println(prefix + opName + " (" + img.getClass().getName() + ")");
    } else {//from  w w w  . jav  a  2  s.  c  om
        System.out.println(prefix + "unnamed image" + " (" + img.getClass().getName() + ")");
    }

    System.out.println(prefix + "  " + img.toString());
    if (img instanceof RenderedOp) {
        RenderedOp op = (RenderedOp) img;
        System.out.println(prefix + "  operation name" + op.getOperationName());
        ParameterBlock pb = op.getParameterBlock();
        if (pb instanceof ParameterBlockJAI) {
            ParameterBlockJAI pbj = (ParameterBlockJAI) pb;
            String[] paramNames = pbj.getParameterListDescriptor().getParamNames();
            Vector params = pbj.getParameters();
            for (int n = 0; n < paramNames.length; n++) {
                System.out.println(prefix + "  " + paramNames[n] + params.get(n));
            }
        }
    }
    Vector<RenderedImage> sources = img.getSources();
    if (sources == null) {
        return;
    }
    for (RenderedImage parent : sources) {
        debugPrintGraph(parent, prefix + "    ");
    }
}