/* 加算重ねあわせ ImageFilter Ver 0.00 */ /* */ /* */ /* by Atsushi 98/4/16 */ package net.antun.lib.awt.image; import java.awt.*; import java.awt.image.PixelGrabber; import java.awt.image.RGBImageFilter; public class AdditionImageFilter extends RGBImageFilter { /* --- Field --- */ private Image image; private int ox,oy; private PixelGrabber grabber; private Dimension imageSize; private int pixels[]; /* --- Constructor --- */ public AdditionImageFilter(Image image,int x,int y) { this.image=image; this.ox =x; this.oy =y; } /* --- 準備 --- */ public void setDimensions(int width,int height) { super.setDimensions(width,height); imageSize=new Dimension(image.getWidth(null),image.getHeight(null)); pixels=new int[imageSize.width*imageSize.height]; grabber=new PixelGrabber(image,0,0,imageSize.width,imageSize.height, pixels,0, imageSize.width); try { grabber.grabPixels(); } catch (InterruptedException e) {} } /* --- フィルタリング --- */ public int filterRGB(int x,int y,int rgb) { int rgb2,r,g,b; int xx,yy; xx=x-ox; yy=y-oy; if (0<=xx && xx<=imageSize.width-1 && 0<=yy && yy<=imageSize.height-1) { rgb2=pixels[xx+yy*imageSize.width]; r=Math.min(((rgb >>16) & 0xff)+((rgb2>>16) & 0xff),255); g=Math.min(((rgb >> 8) & 0xff)+((rgb2>> 8) & 0xff),255); b=Math.min(((rgb >> 0) & 0xff)+((rgb2>> 0) & 0xff),255); return (0xff000000 | (r<<16) | (g<<8) | (b<<0)); } else { return rgb; } } /* --- 文字列化 --- */ public String toString() { return getClass().getName()+"[x="+ox+",y="+oy+"]"; } }