Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void blur(int height, int width, RGBTRIPLE image[height][width])
- {
- // Create a copy of image
- RGBTRIPLE copy[height][width];
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- copy[i][j] = image[i][j];
- }
- }
- for (int i = 0, n = height; i < n; i++)
- {
- for (int j = 0, o = width; j < o; j++)
- {
- int startx = 0;
- int endx = 0;
- int starty = 0;
- int endy = 0;
- if (j == 0)
- {
- startx = 0;
- endx = 1;
- }
- else if (j == (width - 1))
- {
- startx = (width - 2);
- endx = (width - 1);
- }
- else
- {
- startx = (j - 1);
- endx = (j + 1);
- }
- if (i == 0)
- {
- starty = 0;
- endy = 1;
- }
- else if (i == (height - 1))
- {
- starty = (height - 2);
- endy = (height - 1);
- }
- else
- {
- starty = (i - 1);
- endy = (i + 1);
- }
- long newRed = 0;
- long newGreen = 0;
- long newBlue = 0;
- float avgCount = 0.0;
- for (int x = startx; x <= endx; x++)
- {
- for (int y = starty; y <= endy; y++)
- {
- newRed += copy[x][y].rgbtRed;
- newGreen += copy[x][y].rgbtGreen;
- newBlue += copy[x][y].rgbtBlue;
- avgCount += 1.0;
- }
- }
- image[i][j].rgbtRed = round( newRed / avgCount);
- image[i][j].rgbtGreen = round( newGreen / avgCount);
- image[i][j].rgbtBlue = round( newBlue / avgCount);
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement