Skip to content

Commit 9f34e2d

Browse files
Merge pull request #16 from saumya1317/feature/implement-grayscale
Implement grayscale filter function
2 parents 2516172 + 7a69c47 commit 9f34e2d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

helpers.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ int max(int a,int b){
99
return b;
1010
}
1111
void grayscale(int height, int width, RGBTRIPLE image[height][width]){
12-
return;
13-
14-
// Convert image to grayscale
15-
12+
13+
for(int i = 0; i < height; i++){
14+
for(int j = 0; j < width; j++){
15+
int red = image[i][j].rgbtRed;
16+
int green = image[i][j].rgbtGreen;
17+
int blue = image[i][j].rgbtBlue;
18+
int avg = (red + green + blue) / 3;
19+
image[i][j].rgbtRed = avg;
20+
image[i][j].rgbtGreen = avg;
21+
image[i][j].rgbtBlue = avg;
22+
}
23+
}
1624
}
1725

26+
1827
void invert(int height, int width, RGBTRIPLE image[height][width]){
1928
for(int i = 0; i<height; i++){
2029
for(int j = 0; j<width; j++){

0 commit comments

Comments
 (0)