summaryrefslogtreecommitdiff
path: root/java/ImageProcessing/filters/DissolveFilter.java
blob: 0225aad6ad17dbd147b94c65923ac799f45a36dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package imaging.filters;

import java.awt.image.*;

/**
 * A derivation of RGBImageFilter that partially or wholly
 * dissolves an image.<p>
 *
 * Extent of dissolving is set by the setOpacity(int) method,
 * which is passed an integer between 0 and 255 (inclusive).
 * The integer represents the alpha value to be applied to
 * every color in the image.<p>
 *
 * An alpha value of 255 signifies an opaque color, while an
 * alpha value of 0 signifies a translucent color.<p>
 *
 * @version 1.0, Apr 1 1996
 * @author  David Geary
 * @see     RGBImageFilter
 */
public class DissolveFilter extends RGBImageFilter implements MedFilter
{
  private int opacity;

  public DissolveFilter() {
        this(0);
    }
    public DissolveFilter(int opacity) {
        canFilterIndexColorModel = true;
        setOpacity(opacity);
    }
  public String info ()
  {
    return "Dissolves an image";
  }  
  public void setOpacity(int opacity) {
        Assert.notFalse(opacity >= 0 && opacity <= 255);
        this.opacity = opacity;
    }
    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);

        alpha = opacity;

        return alpha << 24 | red << 16 | green << 8 | blue;
    }
}