/* Date: 10/05/96 File is: AlphaFilter.java Release: 1.0 * Last Modified: 12/19/96 by: abb@nuccard.eushc.org * Copyright (c) Andrew B. Barclay 1996. All rights reserved. */ import java.awt.image.RGBImageFilter ; class AlphaFilter extends RGBImageFilter { int alphaval ; int threshold ; public AlphaFilter( int alpha ) { this( alpha, 0 ) ; } public AlphaFilter( int alpha, int threshold ) { canFilterIndexColorModel = true ; alphaval = alpha ; this.threshold = 3*threshold ; System.out.println( "AlphaFilter: threshold="+threshold ) ; } public int filterRGB( int x, int y, int rgba ) { if( threshold > 0 ) { int r = (rgba >> 16) & 0xff ; int g = (rgba >> 8) & 0xff ; int b = rgba & 0xff ; //System.out.println( "AlphaFilter: checking "+r+","+g+","+b ) ; if( (r+g+b) < threshold ) { // Make anything below threshold transparent. //System.out.println( "AlphaFilter: thresholding "+r+","+g+","+b ) ; return (rgba & 0x00ffffff) ; } } int alpha = (rgba >> 24) & 0xff ; alpha = alpha * alphaval / 255 ; return ((rgba & 0x00ffffff) | (alpha << 24)) ; } }