Search in sources :

Example 1 with DeferredProperty

use of org.apache.sis.internal.coverage.j2d.DeferredProperty in project sis by apache.

the class ImageRenderer method createImage.

/**
 * Creates an image with the data specified by the last call to a {@code setData(…)} method.
 * The image upper-left corner is located at the position given by {@link #getBounds()}.
 * The two-dimensional {@linkplain #getImageGeometry(int) image geometry} is stored as
 * a property associated to the {@value org.apache.sis.image.PlanarImage#GRID_GEOMETRY_KEY} key.
 *
 * <p>The default implementation returns an instance of {@link java.awt.image.WritableRenderedImage}
 * if the {@link #createRaster()} return value is an instance of {@link WritableRaster}, or a read-only
 * {@link RenderedImage} otherwise.</p>
 *
 * @return the image.
 * @throws IllegalStateException if no {@code setData(…)} method has been invoked before this method call.
 * @throws RasterFormatException if a call to a {@link Raster} factory method failed.
 * @throws ArithmeticException if a property of the image to construct exceeds the capacity of 32 bits integers.
 *
 * @since 1.1
 */
@SuppressWarnings("UseOfObsoleteCollectionType")
public RenderedImage createImage() {
    final Raster raster = createRaster();
    final Colorizer colorizer = new Colorizer(colors);
    final ColorModel colors;
    if (colorizer.initialize(bands[visibleBand]) || colorizer.initialize(raster.getSampleModel(), visibleBand)) {
        colors = colorizer.createColorModel(buffer.getDataType(), bands.length, visibleBand);
    } else {
        colors = Colorizer.NULL_COLOR_MODEL;
    }
    SliceGeometry supplier = null;
    if (imageGeometry == null) {
        if (isSameGeometry(GridCoverage2D.BIDIMENSIONAL)) {
            imageGeometry = geometry;
        } else {
            supplier = new SliceGeometry(geometry, sliceExtent, gridDimensions, mtFactory);
        }
    }
    final WritableRaster wr = (raster instanceof WritableRaster) ? (WritableRaster) raster : null;
    if (wr != null && colors != null && (imageX | imageY) == 0) {
        return new Untiled(colors, wr, properties, imageGeometry, supplier);
    }
    if (properties == null) {
        properties = new Hashtable<>();
    }
    properties.putIfAbsent(GRID_GEOMETRY_KEY, (supplier != null) ? new DeferredProperty(supplier) : imageGeometry);
    if (wr != null) {
        return new WritableTiledImage(properties, colors, width, height, 0, 0, wr);
    } else {
        return new TiledImage(properties, colors, width, height, 0, 0, raster);
    }
}
Also used : DeferredProperty(org.apache.sis.internal.coverage.j2d.DeferredProperty) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) WritableTiledImage(org.apache.sis.internal.coverage.j2d.WritableTiledImage) WritableTiledImage(org.apache.sis.internal.coverage.j2d.WritableTiledImage) TiledImage(org.apache.sis.internal.coverage.j2d.TiledImage) Colorizer(org.apache.sis.internal.coverage.j2d.Colorizer)

Aggregations

ColorModel (java.awt.image.ColorModel)1 Raster (java.awt.image.Raster)1 WritableRaster (java.awt.image.WritableRaster)1 Colorizer (org.apache.sis.internal.coverage.j2d.Colorizer)1 DeferredProperty (org.apache.sis.internal.coverage.j2d.DeferredProperty)1 TiledImage (org.apache.sis.internal.coverage.j2d.TiledImage)1 WritableTiledImage (org.apache.sis.internal.coverage.j2d.WritableTiledImage)1