/* 光がキラン ImageFilter Ver 0.10 */ /* */ /* */ /* by Atsushi 98/4/9 */ package net.antun.lib.awt.image; import java.awt.Point; import java.awt.image.*; public class LightImageFilter extends RGBImageFilter { /* --- 定数 --- */ public final static int DEFAULT=0; public final static int CIRCLE =1; public final static int SPHERE =2; /* --- Field --- */ private int type; private int brightness,ox,oy; /* --- Constructor --- */ public LightImageFilter(int type,int brightness,int x,int y) { this.type=type; this.brightness=brightness; this.ox=x; this.oy=y; } /* --- フィルタリング --- */ public int filterRGB(int x,int y,int rgb) { int r,g,b,d=0; switch (type) { case CIRCLE: d=Math.max(0,(int)(brightness -Math.sqrt((x-ox)*(x-ox)+(y-oy)*(y-oy))*4.0)); break; case SPHERE: d=Math.max(0,(int)(brightness-((x-ox)*(x-ox)+(y-oy)*(y-oy)))); break; } r=Math.min(Math.max(((rgb>>16) & 0xff)+d,0),255); g=Math.min(Math.max(((rgb>> 8) & 0xff)+d,0),255); b=Math.min(Math.max(((rgb>> 0) & 0xff)+d,0),255); return ((rgb & 0xff000000) | (r<<16) | (g<<8) | (b<<0)); } /* --- 文字列化 --- */ public String toString() { return getClass().getName()+"[x="+ox+",y="+oy+"]"; } }