//
// Implementation of 'One Smoothing 2D'
//
// the following code calculates the averages of squares 
// of pixels specified by windowSize and replaces the original 
// pixel with this new value
//


public class smooth2D extends Object
{
  public smooth2D() {};
  public int[] smoothen(int inPixels[], int windowSize,
                            int width, int height)
  {
    int outPixels[] = new int[inPixels.length];
    int offset = (windowSize-1)/2;

    for (int x = offset; x < width - offset; x++)
    {
      for (int y = offset; y < height - offset; y++)
      {
        for (int i = x - offset; i <= x + offset; i++)
        {
          for (int j = y - offset; j <= y + offset; j++)
          {
            outPixels[y*width+x] += inPixels[j*width+i];
          }
        }
        outPixels[y*width+x] /= windowSize * windowSize;
      }
    }
    return outPixels;
  }
}
