//
// Implementation of 'Two Smoothing 1D'
//
// The following code first calculates averages along the rows
// and then along the columns.
//


public class smooth1D extends Object
{
  public smooth1D() {};
  public int[] smoothen(int inPixels[], int windowSize,
                            int width, int height)
  {
        int outPixels[] = new int[inPixels.length];
	int offset = (windowSize-1)/2;

	
	// Smooth along the rows

	for (int x = offset; x < inPixels.length - offset; x++)
	{
		for (int i = x - offset; i <= x+offset; i++)
			outPixels[x] += inPixels[i];
		outPixels[x] /= windowSize;
	}
	
	
	// Smooth along the columns

	for (int x = 0; x < width; x++)
	{
		for(int y=offset; y<height-offset; y++)
		{	
			inPixels[y*width+x] = 0;
			for (int j = y-offset; j <= y+offset; j++)
				inPixels[y*width+x] += outPixels[j*width+x];
			inPixels[y*width+x] /= windowSize;
		}
	}
        return inPixels;
  }
}