Untitled
unknown
plain_text
8 days ago
2.5 kB
14
Indexable
Never
// Blur image void blur(int height, int width, RGBTRIPLE image[height][width]) { // create a copy of image, so we can calculate averages and // change pixels without interfering with other pixels' blur RGBTRIPLE copy[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { copy[i][j] = image[i][j]; } } // read pixels' colors int sumRed, sumGreen, sumBlue = 0; double averageRed, averageGreen, averageBlue = 0; int lastIndexInRow = width - 1; int lastIndexInColumn = height - 1; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { // catching each corner (4 pixel grid) if ((i == 0 && j == 0) { sumRed = copy[i][j].rgbtRed + copy[i][j+1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j+1].rgbtRed; sumGreen = copy[i][j].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen; sumBlue = copy[i][j].rgbtBlue + copy[i][j+1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen; averageRed = round(sumRed / (double) 4); averageGreen = round(sumGreen / (double) 4); averageBlue = round(sumBlue / (double) 4); } else if (i == 0 && j == lastIndexInRow) { sumRed = copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i+1][j-1].rgbtRed + copy[i+1][j].rgbtRed; sumGreen = copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i+1][j-1].rgbtGreen + copy[i+1][j].rgbtGreen; sumBlue = copy[i][j].rgbtBlue + copy[i][j-1].rgbtGreen + copy[i+1][j-1].rgbtGreen + copy[i+1][j].rgbtGreen; averageRed = round(sumRed / (double) 4); averageGreen = round(sumGreen / (double) 4); averageBlue = round(sumBlue / (double) 4); } else if (i == lastIndexInColumn && j == 0) { } else if (i == lastIndexInColumn && j == lastIndexInRow) { } // catching edges (6 pixel grid) else if () { } .. .. else () // catching body (9 pixel grid) { } } } return; }
Leave a Comment