JoshuaForYou

Code

Jun 22nd, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | Source Code | 0 0
  1. void blur(int height, int width, RGBTRIPLE image[height][width])
  2. {
  3.     RGBTRIPLE *address;
  4.     RGBTRIPLE *start = &image[0][0];
  5.     RGBTRIPLE *end = &image[height][width];
  6.  
  7.     //temp num to count
  8.     int numRed = 0;
  9.     int numGreen = 0;
  10.     int numBlue = 0;
  11.  
  12.     //create duplicate image so values of original image isnt lost.
  13.     int tempSize = sizeof(RGBTRIPLE)*height*width;
  14.     RGBTRIPLE *temp;
  15.     memcpy(temp, image, tempSize);
  16.  
  17.     for(int i = 0; i < height; i++)
  18.     {
  19.         for(int j = 0; j < width; j++)
  20.         {
  21.              //sum of numbers
  22.             int sumRed = 0;
  23.             int sumbGreen = 0;
  24.             int sumBlue = 0;
  25.  
  26.             //check in 3x3 grids through entire image
  27.             for(int x = i - 1; x < x + 1; x++)
  28.             {
  29.                 for(int y = j - 1; y < j + 1; y++)
  30.                 {
  31.                     //check if I am not accessing outside array bounds by checkng if the position is between where the array starts and ends
  32.                     *address = image[x][y];
  33.                     if(!(address > end || address < start))
  34.                     {
  35.                         sumRed += temp[i][j].rgbtRed;
  36.                         sumBlue += temp[i][j].rgbtBlue;
  37.                         sumGreen += temp[i][j].rgbtGreen;
  38.                     }
  39.                 }
  40.             }
  41.  
  42.             //initialise new image
  43.             sumRed = sumRed/9.0;
  44.             sumGreen = sumGreen/9.0;
  45.             sumBlue = sumBlue/9.0;
  46.  
  47.             image[i][j].rgbtRed = sumRed;
  48.             image[i][j].rgbtGreen = sumGreen;
  49.             image[i][j].rgbtBlue = sumBlue;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment