Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void blur(int height, int width, RGBTRIPLE image[height][width])
- {
- RGBTRIPLE *address;
- RGBTRIPLE *start = &image[0][0];
- RGBTRIPLE *end = &image[height][width];
- //temp num to count
- int numRed = 0;
- int numGreen = 0;
- int numBlue = 0;
- //create duplicate image so values of original image isnt lost.
- int tempSize = sizeof(RGBTRIPLE)*height*width;
- RGBTRIPLE *temp;
- memcpy(temp, image, tempSize);
- for(int i = 0; i < height; i++)
- {
- for(int j = 0; j < width; j++)
- {
- //sum of numbers
- int sumRed = 0;
- int sumbGreen = 0;
- int sumBlue = 0;
- //check in 3x3 grids through entire image
- for(int x = i - 1; x < x + 1; x++)
- {
- for(int y = j - 1; y < j + 1; y++)
- {
- //check if I am not accessing outside array bounds by checkng if the position is between where the array starts and ends
- *address = image[x][y];
- if(!(address > end || address < start))
- {
- sumRed += temp[i][j].rgbtRed;
- sumBlue += temp[i][j].rgbtBlue;
- sumGreen += temp[i][j].rgbtGreen;
- }
- }
- }
- //initialise new image
- sumRed = sumRed/9.0;
- sumGreen = sumGreen/9.0;
- sumBlue = sumBlue/9.0;
- image[i][j].rgbtRed = sumRed;
- image[i][j].rgbtGreen = sumGreen;
- image[i][j].rgbtBlue = sumBlue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment