// Copyright 1997-2015 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland // www.source-code.biz, www.inventec.ch/chdh // // This module is multi-licensed and may be used under the terms of any of the following licenses: // // LGPL, GNU Lesser General Public License, V2.1 or later, http://www.gnu.org/licenses/lgpl.html // EPL, Eclipse Public License, V1.0 or later, http://www.eclipse.org/legal // // Please contact the author if you need another license. // This module is provided "as is", without warranties of any kind. // // Home page: http://www.source-code.biz/snippets/java/1.htm import java.awt.image.ImageFilter; import java.awt.image.ColorModel; /** * An anti-aliasing image filter. * *
* This is an image filter class that can be used for anti-aliasing.
* The input image is scaled down by the factor ScalingFactor
.
* The color value of an output pixel is computed by averaging the
* color values of the corresponding input pixels.
*/
public class AntiAliasingFilter extends ImageFilter {
private static final ColorModel rgbModel = ColorModel.getRGBdefault();
private int scalingFactor;
private int scalingFactorSqr;
private int srcWidth;
private int srcHeight;
private int destWidth;
private int destHeight;
private int expectedSrcY;
private int accu[];
private int outLine[];
private void sendOutputLine (int destY) {
consumer.setPixels(0, destY, destWidth, 1, rgbModel, outLine, 0, destWidth); }
private void genOutputLine() {
int p = 0;
for (int i = 0; i