Advertisement
Theo107

blur v0

Apr 9th, 2024
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 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.     for (int i = 0, n = height; i < n; i++)
  13.     {
  14.         for (int j = 0, o = width; j < o; j++)
  15.         {
  16.             int startx = 0;
  17.             int endx = 0;
  18.             int starty = 0;
  19.             int endy = 0;
  20.  
  21.             if (j == 0)
  22.             {
  23.                 startx = 0;
  24.                 endx = 1;
  25.             }
  26.             else if (j == (width - 1))
  27.             {
  28.                 startx = (width - 2);
  29.                 endx = (width - 1);
  30.             }
  31.             else
  32.             {
  33.                 startx = (j - 1);
  34.                 endx = (j + 1);
  35.             }
  36.  
  37.             if (i == 0)
  38.             {
  39.                 starty = 0;
  40.                 endy = 1;
  41.             }
  42.             else if (i == (height - 1))
  43.             {
  44.                 starty = (height - 2);
  45.                 endy = (height - 1);
  46.             }
  47.             else
  48.             {
  49.                 starty = (i - 1);
  50.                 endy = (i + 1);
  51.             }
  52.  
  53.             long newRed = 0;
  54.             long newGreen = 0;
  55.             long newBlue = 0;
  56.  
  57.             float avgCount = 0.0;
  58.             for (int x = startx; x <= endx; x++)
  59.             {
  60.                 for (int y = starty; y <= endy; y++)
  61.                 {
  62.                     newRed += copy[x][y].rgbtRed;
  63.                     newGreen += copy[x][y].rgbtGreen;
  64.                     newBlue += copy[x][y].rgbtBlue;
  65.                     avgCount += 1.0;
  66.                 }
  67.             }
  68.             image[i][j].rgbtRed = round( newRed / avgCount);
  69.             image[i][j].rgbtGreen = round( newGreen / avgCount);
  70.             image[i][j].rgbtBlue = round( newBlue / avgCount);
  71.         }
  72.     }
  73.     return;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement