Class AbstractImagewiseFilter

  • All Implemented Interfaces:
    java.awt.image.BufferedImageOp
    Direct Known Subclasses:
    AbstractConvolver, OilPaintingFilter

    public abstract class AbstractImagewiseFilter
    extends AbstractImageFilter
    An abstract base class for image filters that require access to the entire image at once when processing. Filters of this type produce images of the same dimensions as the original.

    It is assumed that pixels will only be read from the source image and written to the destination image. That is, that pixel values depend only on combinations of the source pixels and not on previously computed destination pixels. This allows filtering to be accelerated automatically by generating blocks of destination pixels in parallel. A filter that does not meet these criteria may return a value of 0 from workFactor() to disable the automatic acceleration mechanism.

    Author:
    Chris Jennings
    • Constructor Detail

      • AbstractImagewiseFilter

        public AbstractImagewiseFilter()
    • Method Detail

      • filter

        public java.awt.image.BufferedImage filter​(java.awt.image.BufferedImage source,
                                                   java.awt.image.BufferedImage destination)

        This implementation will call filterPixels(int[], int[], int, int, int, int) to perform the actual filtering.

        Parameters:
        source - the source image
        destination - the destination image (may be null)
        Returns:
        the destination image
      • filter

        public int[] filter​(int[] source,
                            int[] destination,
                            int width,
                            int height)
        Applies the filter to ARGB pixel data stored in an array. This method can be used during the internal processing of other filters.
        Parameters:
        source - the source pixel data in ARGB format
        destination - the destination in which the filtered should be stored, may be null
        width - the width of the source image
        height - the height of the source image
        Returns:
        the array that holds the destination pixels
      • filterPixels

        protected abstract void filterPixels​(int[] srcPixels,
                                             int[] dstPixels,
                                             int width,
                                             int height,
                                             int y0,
                                             int rows)
        Filters a block of rows in the source image, placing the result in the corresponding rows in the destination image. The block of rows to be filtered runs from y0 to y0 + rows-1 (inclusive).
        Parameters:
        srcPixels - the pixel data for the source image
        dstPixels - the destination for output pixels
        width - the width of the image
        height - the height of the image
        y0 - the index of the first row to filter
        rows - the number of rows to filter
      • workFactor

        protected float workFactor()
        Returns a factor representing the amount of work performed by this filter relative to a filter that simply copies the source image by reading and writing each pixel. For example, a filter that implemented a 3x3 convolution might return the value 9. The work factor value helps determine when an image should be processed in parallel. (There is significant overhead involved in running a filter in parallel, so it is only worth doing if the image is relatively large or the amount of processing per pixel is relatively high.)

        Note: The work factor may vary depending on the current filter settings.

        Returns:
        the approximate amount of work per pixel, relative to simply copying the pixel values