From 7a69c477a2a4704aee37cd81aa97a6e19125204b Mon Sep 17 00:00:00 2001 From: saumya1317 Date: Tue, 21 Oct 2025 23:01:42 +0530 Subject: [PATCH] feat: implement grayscale filter function Add grayscale function in helpers.c --- helpers.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/helpers.c b/helpers.c index 8275ef6..c3201bb 100644 --- a/helpers.c +++ b/helpers.c @@ -9,12 +9,21 @@ int max(int a,int b){ return b; } void grayscale(int height, int width, RGBTRIPLE image[height][width]){ - return; - -// Convert image to grayscale - + + for(int i = 0; i < height; i++){ + for(int j = 0; j < width; j++){ + int red = image[i][j].rgbtRed; + int green = image[i][j].rgbtGreen; + int blue = image[i][j].rgbtBlue; + int avg = (red + green + blue) / 3; + image[i][j].rgbtRed = avg; + image[i][j].rgbtGreen = avg; + image[i][j].rgbtBlue = avg; + } + } } + void invert(int height, int width, RGBTRIPLE image[height][width]){ for(int i = 0; i