Smoothing, which is just a type of blurring is based on a concept called convolution. How this works is that you take a square section of pixels, often 3x3 but can be any size, although the larger you make the grid, the less pixels that will get affected by the effect around the edges.
The centre pixel of the grid is the main pixel we are interested in. To use convolution, what we do is assign weightings to each pixel in the grid, depending on what effect we are trying to achieve, and then assign the result to the centre pixel.
The basic data structure we use for the convolution is a class which contains the 2D array, as well as a weighting factor, and an offset.
Now, having this class, we can implement the convolution algorithm
Finally, after all that, we are ready to implement a smoothing function. To smooth an image, we assign a particular value to the centre pixel, and then add 1 to all the surrounding pixels, so the array would look something like this
1
1
1
1
8
1
1
1
1
The factor parameter is set to the sum of each pixel in the grid, which in this case would be 16, and the offset is set to 0. The offset shifts all the values of the colour components by the specified amount.
Now all that is left is calling the convolution function.