Advertisement
Theo107

blur v1

Apr 9th, 2024
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. void blur(int height, int width, RGBTRIPLE image[height][width])
  2. {
  3.     // Create a copy of image
  4.     RGBTRIPLE copy[height][width];
  5.     for (int i = 0; i < height; i++)
  6.     {
  7.         for (int j = 0; j < width; j++)
  8.         {
  9.             copy[i][j] = image[i][j];
  10.         }
  11.     }
  12.  
  13.     for (int i = 0; i < height; i++)
  14.     {
  15.         for (int j = 0; j < width; j++)
  16.         {
  17.             int newRed = 0;
  18.             int newGreen = 0;
  19.             int newBlue = 0;
  20.             float avgCount = 0.0;
  21.  
  22.             for (int k = -1; k <= 1; k++)
  23.             {
  24.                 for (int l = -1; l <= -1; l++)
  25.                 {
  26.                     if (!(i + k == -1) && !(i + k == height) && !(j + l == -1) && !(j + l == width))
  27.                     {
  28.                         newRed += copy[(i+k)][(j+l)].rgbtRed;
  29.                         newGreen += copy[(i+k)][(j+l)].rgbtGreen;
  30.                         newBlue += copy[(i+k)][(j+l)].rgbtBlue;
  31.                         avgCount += 1.0;
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             image[i][j].rgbtRed = round(newRed / avgCount);
  37.             image[i][j].rgbtGreen = round(newGreen / avgCount);
  38.             image[i][j].rgbtBlue = round(newBlue / avgCount);
  39.         }
  40.     }
  41.     return;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement