package yi.iu.processor.morph;

import java.awt.*;

public class Dilation extends Morph
{
	public Dilation(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++)
		    {
			    if (source[i*width+j]==0) continue;
			    for (int m=0;m<size;m++)
				    for (int n=0;n<size;n++) {
					    int y=i+m-r;
					    int x=j+n-r;
					    if (x<0 || x>=width) continue;
					    if (y<0 || y>=height) continue;
					    if (stct[m*size+n]) result[y*width+x]=source[i*width+j];
				    }
		    }
	    return result;			        
    }

}