Class PaintOpImage

  • All Implemented Interfaces:
    RenderedImage, javax.media.jai.ImageJAI, javax.media.jai.PropertyChangeEmitter, javax.media.jai.PropertySource, javax.media.jai.WritablePropertySource

    public final class PaintOpImage
    extends javax.media.jai.PointOpImage
    An OpImage class to perform convolution on a source image.

    This class implements a convolution operation. Convolution is a spatial operation that computes each output sample by multiplying elements of a kernel with the samples surrounding a particular source sample.

    For each destination sample, the kernel is rotated 180 degrees and its "key element" is placed over the source pixel corresponding with the destination pixel. The kernel elements are multiplied with the source pixels under them, and the resulting products are summed together to produce the destination sample value.

    Example code for the convolution operation on a single sample dst[x][y] is as follows. First your original kernel is rotated by 180 degrees, then the following - assuming the kernel is of size M rows x N columns and the rotated kernel's key element is at position (xKey, yKey):

     dst[x][y] = 0;
     for (int i = -xKey; i < M - xKey; i++) {
         for (int j = -yKey; j < N - yKey; j++) {
             dst[x][y] += src[x + i][y + j] * kernel[xKey + i][yKey + j];
         }
     }
     

    Convolution, or any neighborhood operation, leaves a band of pixels around the edges undefined, i.e., for a 3x3 kernel, only four kernel elements and four source pixels contribute to the destination pixel located at (0,0). Such pixels are not includined in the destination image. A BorderOpImage may be used to add an appropriate border to the source image in order to avoid shrinkage of the image boundaries.

    The Kernel cannot be bigger in any dimension than the image data.

    See Also:
    KernelJAI
    • Field Summary

      • Fields inherited from class javax.media.jai.OpImage

        cache, cobbleSources, OP_COMPUTE_BOUND, OP_IO_BOUND, OP_NETWORK_BOUND, tileCacheMetric, tileRecycler
      • Fields inherited from class javax.media.jai.PlanarImage

        colorModel, eventManager, height, minX, minY, properties, sampleModel, tileFactory, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, width
    • Constructor Summary

      Constructors 
      Constructor Description
      PaintOpImage​(RenderedImage source0, RenderedImage source1, Map config, javax.media.jai.ImageLayout layout, Color paintColor, boolean alphaIsFirst)
      Creates a ConvolveOpImage given a ParameterBlock containing the image source and pre-rotated convolution kernel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void computeRect​(Raster[] sources, WritableRaster dest, Rectangle destRect)
      Performs convolution on a specified rectangle.
      • Methods inherited from class javax.media.jai.PointOpImage

        computeTile, dispose, isColormapOperation, mapDestRect, mapSourceRect, permitInPlaceOperation
      • Methods inherited from class javax.media.jai.OpImage

        addTileToCache, cancelTiles, computeRect, computesUniqueTiles, createTile, getExpandedNumBands, getFormatTags, getOperationComputeType, getTile, getTileCache, getTileCacheMetric, getTileDependencies, getTileFromCache, getTileRecycler, getTiles, hasExtender, mapDestPoint, mapSourcePoint, prefetchTiles, queueTiles, recycleTile, setTileCache, vectorize, vectorize, vectorize
      • Methods inherited from class javax.media.jai.PlanarImage

        addPropertyChangeListener, addPropertyChangeListener, addSink, addSink, addSource, addTileComputationListener, copyData, copyData, copyExtendedData, createColorModel, createSnapshot, createWritableRaster, finalize, getAsBufferedImage, getAsBufferedImage, getBounds, getColorModel, getData, getData, getDefaultColorModel, getExtendedData, getGraphics, getHeight, getImageID, getMaxTileX, getMaxTileY, getMaxX, getMaxY, getMinTileX, getMinTileY, getMinX, getMinY, getNumBands, getNumSources, getNumXTiles, getNumYTiles, getProperties, getProperty, getPropertyClass, getPropertyNames, getPropertyNames, getSampleModel, getSinks, getSource, getSourceImage, getSourceObject, getSources, getSplits, getTileComputationListeners, getTileFactory, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileIndices, getTileRect, getTiles, getTileWidth, getWidth, overlapsMultipleTiles, removeProperty, removePropertyChangeListener, removePropertyChangeListener, removeSink, removeSink, removeSinks, removeSource, removeSources, removeTileComputationListener, setImageLayout, setProperties, setProperty, setSource, setSources, tileXToX, tileXToX, tileYToY, tileYToY, toString, wrapRenderedImage, XToTileX, XToTileX, YToTileY, YToTileY
    • Constructor Detail

      • PaintOpImage

        public PaintOpImage​(RenderedImage source0,
                            RenderedImage source1,
                            Map config,
                            javax.media.jai.ImageLayout layout,
                            Color paintColor,
                            boolean alphaIsFirst)
        Creates a ConvolveOpImage given a ParameterBlock containing the image source and pre-rotated convolution kernel. The image dimensions are derived from the source image. The tile grid layout, SampleModel, and ColorModel may optionally be specified by an ImageLayout object.
        Parameters:
        source0 - a source
        source1 - a alpha mask for painting
        config - the image configuration.
        layout - an ImageLayout optionally containing the tile grid layout, SampleModel, and ColorModel, or null.
        paintColor - The paint color.
        alphaIsFirst - Whether alpha is the first band
    • Method Detail

      • computeRect

        protected void computeRect​(Raster[] sources,
                                   WritableRaster dest,
                                   Rectangle destRect)
        Performs convolution on a specified rectangle. The sources are cobbled.
        Overrides:
        computeRect in class javax.media.jai.OpImage
        Parameters:
        sources - an array of source Rasters, guaranteed to provide all necessary source data for computing the output.
        dest - a WritableRaster tile containing the area to be computed.
        destRect - the rectangle within dest to be processed.