home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
DarkenFilter.java
< prev
next >
Wrap
Text File
|
1998-08-21
|
3KB
|
118 lines
package symantec.itools.awt.image;
import java.awt.image.RGBImageFilter;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
import java.lang.IllegalArgumentException;
import java.util.ResourceBundle;
import java.text.MessageFormat;
// Written by Levi Brown and Micheal Hopkins 1.1, July 8, 1997.
/**
* An Image filter to use for darkening an Image a specified percentage.
* @version 1.1, July 8, 1997
* @author Symantec
*/
public class DarkenFilter extends RGBImageFilter
{
/**
* Constructs a default DarkenFilter.
* By default the Image is darkened 50%.
* @see DarkenFilter#DarkenFilter(double)
* @see #setPercent
*/
public DarkenFilter()
{
this(0.50);
}
/**
* Constructs a DarkenFilter.
* @param percent the percent to darken the image when filtering.
* @see DarkenFilter#DarkenFilter()
* @see #setPercent
*/
public DarkenFilter(double percent)
{
errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
canFilterIndexColorModel = true;
try
{
setPercent(percent);
}
catch (IllegalArgumentException exc)
{
Object[] args = { new Double(percent) };
System.err.println("DarkenFilter: " + errors.getString("InvalidPercent1"));
System.err.println(" " + errors.getString("InvalidPercent2"));
System.err.println(" " + errors.getString("InvalidPercent3"));
try { setPercent(0.50); } catch (IllegalArgumentException exc2) {}
}
}
/**
* Sets the percentage to fade when filtering.
* @param percent the percentage to fade.
* @exception IllegalArgumentException
* if the specified percentage value is unacceptable
* @see #getPercent
*/
public void setPercent(double percent) throws IllegalArgumentException
{
symantec.itools.util.GeneralUtils.checkValidPercent(percent);
this.percent = percent;
}
/**
* Gets the percentage to fade when filtering.
* @return the percentage to fade.
* @see #setPercent
*/
public double getPercent()
{
return percent;
}
/**
* Filters an RGB value by the current fade percentage.
* @param x unused
* @param y unused
* @param rgb the rgb value to fade
* @return the faded rgb value
*/
public int filterRGB( int x, int y, int rgb )
{
DirectColorModel cm = (DirectColorModel)ColorModel.getRGBdefault();
int alpha = cm.getAlpha(rgb);
int red = cm.getRed(rgb);
int green = cm.getGreen(rgb);
int blue = cm.getBlue(rgb);
red = Math.max((int)(red * (1 - percent)), 0);
green = Math.max((int)(green * (1 - percent)), 0);
blue = Math.max((int)(blue * (1 - percent)), 0);
alpha = alpha << 24;
red = red << 16;
green = green << 8;
return alpha | red | green | blue;
}
/**
* The percentage to fade when filtering.
* @see #getPercent
* @see #setPercent
*/
protected double percent;
/**
* Error strings.
*/
transient protected ResourceBundle errors;
}