Class BrightnessContrastFilter

  • All Implemented Interfaces:
    Fn, java.awt.image.BufferedImageOp

    public class BrightnessContrastFilter
    extends AbstractFunctionFilter
    An image filter that adjusts the brightness and contrast of an image. The brightness and contrast adjustments are specified as values in the range -1 to +1 (inclusive). A value of 0 indicates no change, while values greater or less than 0 increase or decrease (respectively) the brightness or contrast.

    In-place filtering: This class supports in-place filtering (the source and destination images may be the same).

    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Detail

      • BrightnessContrastFilter

        public BrightnessContrastFilter()
        Creates a new filter with default brightness and contrast settings of 0, resulting in no change.
      • BrightnessContrastFilter

        public BrightnessContrastFilter​(double brightness,
                                        double contrast)
        Creates a new filter with the requested brightness and contrast adjustments.
        Parameters:
        brightness - the brightness adjustment factor to apply
        contrast - the contrast adjustment factor to apply
        Throws:
        java.lang.IllegalArgumentException - if brightness or contrast are not in the range -1 to 1 inclusive
    • Method Detail

      • getBrightness

        public double getBrightness()
        Returns the current brightness adjustment setting, between -1 and 1 inclusive.
        Returns:
        the brightness adjustment setting
      • setBrightness

        public void setBrightness​(double brightness)
        Sets the current brightness adjustment setting, between -1 and 1 inclusive. A value of 0 results in no brightness change, while negative and positive values decrease and increase brightness, respectively.
        Parameters:
        brightness - the brightness adjustment to apply to filtered images
      • getContrast

        public double getContrast()
        Returns the current contrast adjustment setting, between -1 and 1 inclusive.
        Returns:
        the contrast adjustment setting
      • setContrast

        public void setContrast​(double contrast)
        Sets the current contrast adjustment setting, between -1 and 1 inclusive. A value of 0 results in no contrast change, while negative and positive values decrease and increase contrast, respectively.
        Parameters:
        contrast - the contrast adjustment to apply to filtered images
      • f

        public double f​(double x)
        A transfer function for the current brightness and contrast settings. See AbstractFunctionFilter.f(double).
        Specified by:
        f in interface Fn
        Specified by:
        f in class AbstractFunctionFilter
        Parameters:
        x - the input value
        Returns:
        the output value after applying the brightness and contrast adjustment