Class BrightnessContrastFilter
- java.lang.Object
-
- java.awt.image.ImageFilter
-
- java.awt.image.RGBImageFilter
-
- com.twelvemonkeys.image.BrightnessContrastFilter
-
- All Implemented Interfaces:
java.awt.image.ImageConsumer
,java.lang.Cloneable
public class BrightnessContrastFilter extends java.awt.image.RGBImageFilter
Adjusts the contrast and brightness of an image.For brightness, the valid range is
-2.0,..,0.0,..,2.0
. A value of0.0
means no change. Negative values will make the pixels darker. Maximum negative value (-2
) will make all filtered pixels black. Positive values will make the pixels brighter. Maximum positive value (2
) will make all filtered pixels white.For contrast, the valid range is
-1.0,..,0.0,..,1.0
. A value of0.0
means no change. Negative values will reduce contrast. Maximum negative value (-1
) will make all filtered pixels grey (no contrast). Positive values will increase contrast. Maximum positive value (1
) will make all filtered pixels primary colors (either black, white, cyan, magenta, yellow, red, blue or green).- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/BrightnessContrastFilter.java#1 $
-
-
Field Summary
Fields Modifier and Type Field Description private int[]
LUT
-
Constructor Summary
Constructors Constructor Description BrightnessContrastFilter()
Creates a BrightnessContrastFilter with default values (brightness=0.3, contrast=0.3
).BrightnessContrastFilter(float pBrightness, float pContrast)
Creates a BrightnessContrastFilter with the given values for brightness and contrast.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
clamp(int i)
private static int[]
createLUT(float pBrightness, float pContrast)
int
filterRGB(int pX, int pY, int pARGB)
Filters one pixel, adjusting brightness and contrast according to this filter.-
Methods inherited from class java.awt.image.RGBImageFilter
filterIndexColorModel, filterRGBPixels, setColorModel, setPixels, setPixels, substituteColorModel
-
-
-
-
Constructor Detail
-
BrightnessContrastFilter
public BrightnessContrastFilter()
Creates a BrightnessContrastFilter with default values (brightness=0.3, contrast=0.3
).This will slightly increase both brightness and contrast.
-
BrightnessContrastFilter
public BrightnessContrastFilter(float pBrightness, float pContrast)
Creates a BrightnessContrastFilter with the given values for brightness and contrast.For brightness, the valid range is
-2.0,..,0.0,..,2.0
. A value of0.0
means no change. Negative values will make the pixels darker. Maximum negative value (-2
) will make all filtered pixels black. Positive values will make the pixels brighter. Maximum positive value (2
) will make all filtered pixels white.For contrast, the valid range is
-1.0,..,0.0,..,1.0
. A value of0.0
means no change. Negative values will reduce contrast. Maximum negative value (-1
) will make all filtered pixels grey (no contrast). Positive values will increase contrast. Maximum positive value (1
) will make all filtered pixels primary colors (either black, white, cyan, magenta, yellow, red, blue or green).- Parameters:
pBrightness
- adjust the brightness of the image, in the range-2.0,..,0.0,..,2.0
.pContrast
- adjust the contrast of the image, in the range-1.0,..,0.0,..,1.0
.
-
-
Method Detail
-
createLUT
private static int[] createLUT(float pBrightness, float pContrast)
-
clamp
private static int clamp(int i)
-
filterRGB
public int filterRGB(int pX, int pY, int pARGB)
Filters one pixel, adjusting brightness and contrast according to this filter.- Specified by:
filterRGB
in classjava.awt.image.RGBImageFilter
- Parameters:
pX
- xpY
- ypARGB
- pixel value in default color space- Returns:
- the filtered pixel value in the default color space
-
-