import java.awt.image.*; /*********************************************************************** * * 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. * *

* Home page: www.source-code.biz
* Copyright 1997-2003: Christian d'Heureuse, Inventec Informatik AG, Switzerland.
* License: This is "Open Source" software and released under the GNU/GPL license. * It is provided "as is" without warranty of any kind. Please contact the author for other licensing arrangements.
* *

* Version history:
* 1997-07-01 Christian d'Heureuse (chdh): Module created.
* 2003-06-30 chdh: Revision.
* ***********************************************************************/ 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 fatalError (String msg) { throw new RuntimeException(getClass().getName()+": "+msg); } 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>>= 8; accu[p+1] += rgb & 0xff; rgb >>>= 8; accu[p] += rgb & 0xff; } p += 3; } if (yMod == scalingFactor-1) { genOutputLine(); sendOutputLine (srcY/scalingFactor); }} private void procSetPixels (int x, int y, int w, int h, ColorModel model, byte pixelsB[], int pixelsI[], int offs0, int scansize) { if (x != 0 || w != srcWidth) fatalError ("Invalid x or w in setPixels."); if (y != expectedSrcY) fatalError ("ExpectedSrcY does not match."); int offs = offs0; for (int srcY=y; srcY