package yi.iu.processor.morph;

import java.awt.*;

public class Erosion extends Morph
{
	public Erosion(int st, int s)
	{
		super(st, s);
	}
    
    public int[] getProcessed(int source[], Dimension d)
    {
        int width=d.width, height=d.height;
        int[] result= new int[width*height];
        
	    boolean[] stct= getStruct();
	    int r=(size-1)/2;
	    
	    for (int i=0;i<height;i++)
		    for (int j=0;j<width;j++)
		    {
		        boolean gotColor=true;
			    for (int m=0;m<size;m++)
				    for (int n=0;n<size;n++) {
        			    if (!stct[m*size+n]) continue;
					    int y=i+m-r;
					    int x=j+n-r;
					    if (x<0 || x>=width) continue;
					    if (y<0 || y>=height) continue;
					    if (source[y*width+x]==0) {m=n=size;gotColor=false;break;}
				    }
				if (gotColor) result[i*width+j]=source[i*width+j];
		    }
	    return result;			        
    }
    
}