From 5cffbd29b403a195b5a0b7773c1825ffd8304ba2 Mon Sep 17 00:00:00 2001 From: saumya1317 Date: Wed, 22 Oct 2025 03:04:53 +0530 Subject: [PATCH 1/3] feat: add vignette filter with CLI tag and update documentation --- README.md | 33 +++++++++++++++++++++++++++++++++ filter.c | 7 +++++-- helpers.h | 2 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3c92eea..dc5f032 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,39 @@ For a pixel along the edge or corner, like pixel 15, we would still look for all If you apply the above algorithm to each pixel in the image, the result should look like a blurry, out-of-focus version of the original. +### 5.) The Vignette Algorithm + +The vignette filter gives an image a cinematic look by gradually darkening its corners. + +**Algorithm:** +1. Compute the center of the image (cx, cy). +2. Calculate the maximum distance from the center to any corner (max_dis). +3. For each pixel at (i, j): + - Calculate the Euclidean distance from this pixel to the center: dist = sqrt((j - cx)^2 + (i - cy)^2) + - Compute a vignette factor: vig = 1.0 - (dist / max_dis) + - Clamp vig between 0.0 (fully dark) and 1.0 (original color). + - Multiply the pixel's R, G, B values by vig to darken farther-away pixels more thoroughly. + +If you apply this algorithm, your resulting image will have gently darkened corners and an undisturbed/sunnier center. + +--- + +### Usage + +To apply a filter via command-line: +- `g`: grayscale +- `s`: sepia +- `r`: reflect +- `b`: blur +- `i`: invert +- `v`: vignette + +For vignette: +``` +./filter v input.bmp output.bmp +``` +You can also chain multiple filters by supplying multiple tags (e.g., `./filter vg input.bmp output.bmp` for vignette then grayscale). + You should not modify any of the function signatures, nor should you modify any other files other than helpers.c. Consider the following grid of pixels, where we’ve numbered each pixel. diff --git a/filter.c b/filter.c index f6f8115..59b1037 100644 --- a/filter.c +++ b/filter.c @@ -7,7 +7,7 @@ int main(int argc, char *argv[]) { // Define allowable filters - char *filters = "bgrsi"; + char *filters = "bgrsiv"; char filterArr[argc-3]; @@ -120,11 +120,14 @@ int main(int argc, char *argv[]) case 's': sepia(height, width, image); break; - //invert case 'i': invert(height,width,image); break; + // Vignette + case 'v': + vignette(height, width, image); + break; default: printf("%c", &filterArr[i]); break; diff --git a/helpers.h b/helpers.h index 89790e5..b38e5b4 100644 --- a/helpers.h +++ b/helpers.h @@ -14,3 +14,5 @@ void reflect(int height, int width, RGBTRIPLE image[height][width]); // Blur image void blur(int height, int width, RGBTRIPLE image[height][width]); +// +void vignette(int height, int width, RGBTRIPLE image[height][width]); \ No newline at end of file From 895d8565d537faa452b9ee59610c4e834f1f9aa3 Mon Sep 17 00:00:00 2001 From: saumya1317 Date: Wed, 22 Oct 2025 03:07:19 +0530 Subject: [PATCH 2/3] feat: add vignette filter to helpers.c and integrate with CLI and docs --- helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers.h b/helpers.h index b38e5b4..c7447c2 100644 --- a/helpers.h +++ b/helpers.h @@ -14,5 +14,5 @@ void reflect(int height, int width, RGBTRIPLE image[height][width]); // Blur image void blur(int height, int width, RGBTRIPLE image[height][width]); -// +// Vignette image void vignette(int height, int width, RGBTRIPLE image[height][width]); \ No newline at end of file From 05a2a51036dda5823108dcf6e0e3b9bec8c79933 Mon Sep 17 00:00:00 2001 From: saumya1317 Date: Wed, 22 Oct 2025 03:13:11 +0530 Subject: [PATCH 3/3] fix: add vignette and other filter logic to helpers.c --- helpers.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/helpers.c b/helpers.c index 8275ef6..5e9d03b 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 1.0) vig = 1.0; + image[i][j].rgbtRed = (int)(image[i][j].rgbtRed * vig); + image[i][j].rgbtGreen = (int)(image[i][j].rgbtGreen * vig); + image[i][j].rgbtBlue = (int)(image[i][j].rgbtBlue * vig); + } + } } \ No newline at end of file