/** * CircularImageFilter2.java * Copyright (c) 1998 Yoon Kyung Koo. All rights reserved. * * First release date 1998/07/07 * * @version 1.0 1998/07/07 * @author Yoon Kyung Koo */ import java.awt.image.ColorModel; import java.awt.image.ImageFilter; import java.util.Hashtable; import java.awt.*; public class CircularImageFilter2 extends ImageFilter { private static ColorModel defaultRGB = ColorModel.getRGBdefault(); private Point center=null; private double radius=0.0; private int nodes=0; private int phase=0; private int frames=0; private int amplitude=0; private int width, height; private int raster[]; CircularImageFilter2 ( Point center, double radius, int nodes, int amplitude, int phase, int frames) { this.center=center; this.radius=radius; this.nodes=nodes; this.amplitude=amplitude; this.phase=phase; this.frames=frames; } private Point getDepthPoint(int x, int y) { double distance= Math.sqrt((double) (center.x-x)*(center.x-x)+ (double) (center.y-y)*(center.y-y)); /* a simple sine curve equation about variable distance */ double depth = amplitude *Math.sin(2.0*Math.PI*nodes/radius*distance + (double)phase*2.0*Math.PI/(double)frames ); return new Point ( (int) ((center.x-x)*depth/distance) + x, (int) ((center.y-y)*depth/distance) + y ); } public void setDimensions(int width, int height) { raster = new int[width * height]; super.setDimensions(this.width=width, this.height=height); } /* public void setHints(int hintflags) { consumer.setHints(TOPDOWNLEFTRIGHT | COMPLETESCANLINES | SINGLEPASS | (hintflags & SINGLEFRAME)); } */ public void setPixels(int x, int y, int w, int h, ColorModel model, byte pixels[], int off, int scansize) { int srcoff = off; int dstoff = y * width + x; for (int yc = 0; yc < h; yc++) { for (int xc = 0; xc < w; xc++) { raster[dstoff++] = model.getRGB(pixels[srcoff++] & 0xff); } srcoff += (scansize - w); dstoff += (width - w); } } public void setPixels(int x, int y, int w, int h, ColorModel model, int pixels[], int off, int scansize) { int srcoff = off; int dstoff = y * width + x; if (model == defaultRGB) { for (int yc = 0; yc < h; yc++) { System.arraycopy(pixels, srcoff, raster, dstoff, w); srcoff += scansize; dstoff += width; } } else { for (int yc = 0; yc < h; yc++) { for (int xc = 0; xc < w; xc++) { try { raster[dstoff++] = model.getRGB(pixels[srcoff++]); } catch (Exception e) { e.printStackTrace(); } } srcoff += (scansize - w); dstoff += (width - w); } } } public void imageComplete(int status) { if (status == IMAGEERROR || status == IMAGEABORTED) { consumer.imageComplete(status); return; } int pixels[] = new int[width]; for (int dy = 0; dy < height; dy++) { for (int dx = 0; dx < width; dx++) { Point newPoint=getDepthPoint(dx, dy); if (newPoint.x <0 || newPoint.x >=width || newPoint.y <0 || newPoint.y >=height) continue; pixels[dx] = raster[newPoint.y * width + newPoint.x]; } consumer.setPixels(0, dy, width, 1, defaultRGB, pixels, 0, width); } consumer.imageComplete(status); } }