Class ImageUtils


  • public class ImageUtils
    extends Object
    A utility class providing a set of static functions frequently used when working with images.

    All functions have been implemented with extreme caution in order to provide a maximum performance.

    Version:
    $Revision$ $Date$
    • Constructor Detail

      • ImageUtils

        public ImageUtils()
    • Method Detail

      • buildImageLayout

        public static javax.media.jai.ImageLayout buildImageLayout​(Integer dataBufferType,
                                                                   int imageWidth,
                                                                   int imageHeight,
                                                                   int level,
                                                                   Dimension defaultJAIReadTileSize)
        Creates a new image layout for the specified level.
        Parameters:
        dataBufferType - the buffer type of the sample model or null if no the sample model to create
        imageWidth - the width of the image
        imageHeight - the height of the image
        level - the level for which the image layout is created
        defaultJAIReadTileSize - the default JAI tile size
        Returns:
        the image layout
      • buildImageLayout

        public static javax.media.jai.ImageLayout buildImageLayout​(Integer dataBufferType,
                                                                   int imageWidth,
                                                                   int imageHeight,
                                                                   int level,
                                                                   Dimension defaultJAIReadTileSize,
                                                                   int topLeftTileWidth,
                                                                   int topLeftTileHeight)
        Creates a new image layout for the specified level. The level tile size is the minimum size between the default JAI tile size and the size of the first tile from the left top corner.
        Parameters:
        dataBufferType - the buffer type of the sample model or null if no the sample model to create
        imageWidth - the width of the image
        imageHeight - the height of the image
        level - the level for which the image layout is created
        defaultJAIReadTileSize - the default JAI tile size
        topLeftTileWidth - the tile width from the left top corner of the final image
        topLeftTileHeight - the tile height from the left top corner of the final image
        Returns:
        the image layout
      • buildTileImageLayout

        public static javax.media.jai.ImageLayout buildTileImageLayout​(int dataBufferType,
                                                                       int imageWidth,
                                                                       int imageHeight,
                                                                       int level,
                                                                       Dimension defaultJAIReadTileSize)
        Creates the image layout of a tile image for the specified level. The level tile size is smaller than the level image size.
        Parameters:
        dataBufferType - the buffer type of the sample model
        imageWidth - the width of the image
        imageHeight - the height of the image
        level - the level for which the image layout is created
        defaultJAIReadTileSize - the default JAI tile size
        Returns:
        the image layout
      • buildCrsGeoCoding

        public static CrsGeoCoding buildCrsGeoCoding​(Point2D.Double coordinateUpperLeft,
                                                     Point2D.Double resolution,
                                                     Dimension defaultSize,
                                                     org.opengis.referencing.crs.CoordinateReferenceSystem mapCRS,
                                                     Rectangle subsetBounds)
                                              throws org.opengis.referencing.FactoryException,
                                                     org.opengis.referencing.operation.TransformException
        Throws:
        org.opengis.referencing.FactoryException
        org.opengis.referencing.operation.TransformException
      • buildCrsGeoCoding

        public static CrsGeoCoding buildCrsGeoCoding​(double coordinateUpperLeftX,
                                                     double coordinateUpperLeftY,
                                                     double resolutionX,
                                                     double resolutionY,
                                                     Dimension defaultSize,
                                                     org.opengis.referencing.crs.CoordinateReferenceSystem mapCRS,
                                                     Rectangle subsetBounds)
                                              throws org.opengis.referencing.FactoryException,
                                                     org.opengis.referencing.operation.TransformException
        Throws:
        org.opengis.referencing.FactoryException
        org.opengis.referencing.operation.TransformException
      • buildCrsGeoCoding

        public static CrsGeoCoding buildCrsGeoCoding​(double coordinateUpperLeftX,
                                                     double coordinateUpperLeftY,
                                                     double resolutionX,
                                                     double resolutionY,
                                                     int defaultWidth,
                                                     int defaultHeight,
                                                     org.opengis.referencing.crs.CoordinateReferenceSystem mapCRS,
                                                     Rectangle subsetBounds)
                                              throws org.opengis.referencing.FactoryException,
                                                     org.opengis.referencing.operation.TransformException
        Throws:
        org.opengis.referencing.FactoryException
        org.opengis.referencing.operation.TransformException
      • buildCrsGeoCoding

        public static CrsGeoCoding buildCrsGeoCoding​(double coordinateUpperLeftX,
                                                     double coordinateUpperLeftY,
                                                     double resolutionX,
                                                     double resolutionY,
                                                     int defaultWidth,
                                                     int defaultHeight,
                                                     org.opengis.referencing.crs.CoordinateReferenceSystem mapCRS,
                                                     Rectangle subsetBounds,
                                                     double referencePixelX,
                                                     double referencePixelY)
                                              throws org.opengis.referencing.FactoryException,
                                                     org.opengis.referencing.operation.TransformException
        Throws:
        org.opengis.referencing.FactoryException
        org.opengis.referencing.operation.TransformException
      • computeSceneRasterSize

        public static Dimension computeSceneRasterSize​(int defaultSceneRasterWidth,
                                                       int defaultSceneRasterHeight,
                                                       Dimension regionRasterSize)
      • computeTileCount

        public static int computeTileCount​(int imageSize,
                                           int tileSize)
      • computeLevelSizeAsDouble

        public static double computeLevelSizeAsDouble​(int sourceSize,
                                                      int level)
      • computeLevelSize

        public static int computeLevelSize​(int sourceSize,
                                           int level)
      • convertImage

        public static BufferedImage convertImage​(RenderedImage image,
                                                 int imageType)
        Converts the given rendered image into an image of the given {#link java.awt.image.BufferedImage} type.
        Parameters:
        image - the source image
        imageType - the {#link java.awt.image.BufferedImage} type
        Returns:
        the buffered image of the given type
      • getDataTypeMinMax

        public static double[] getDataTypeMinMax​(int dataType,
                                                 double[] minmax)
        Returns an array containing the minimum and maximum value of the native data type used to store pixel values in the given image.
        Parameters:
        dataType - a data type as defined in DataBuffer
        See Also:
        DataBuffer
      • getDataTypeName

        public static String getDataTypeName​(int dataType)
        Gets a textual representation of the supplied raster data type
        Parameters:
        dataType - a data type as defined in DataBuffer
        Returns:
        a textual representation of the supplied raster data type
        See Also:
        DataBuffer
      • getColorSpaceName

        public static String getColorSpaceName​(int spaceType)
        Gets a textual representation of the supplied color space type
        Parameters:
        spaceType - a dcolor space type as defined in ColorSpace
        Returns:
        a textual representation of the color space
        See Also:
        ColorSpace
      • createGreyscaleColorModelImage

        public static BufferedImage createGreyscaleColorModelImage​(int width,
                                                                   int height,
                                                                   byte[] data)
      • create8BitGreyscaleColorModel

        public static ColorModel create8BitGreyscaleColorModel()
      • getPrimitiveArray

        public static Object getPrimitiveArray​(DataBuffer dataBuffer)
      • createDataBufferArray

        public static Object createDataBufferArray​(int dataBufferType,
                                                   int size)
      • createSingleBandedSampleModel

        public static SampleModel createSingleBandedSampleModel​(int dataBufferType,
                                                                int width,
                                                                int height)