Skip to content

Commit 5cffbd2

Browse files
committed
feat: add vignette filter with CLI tag and update documentation
1 parent 18b2111 commit 5cffbd2

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,39 @@ For a pixel along the edge or corner, like pixel 15, we would still look for all
113113

114114
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.
115115

116+
### 5.) The Vignette Algorithm
117+
118+
The vignette filter gives an image a cinematic look by gradually darkening its corners.
119+
120+
**Algorithm:**
121+
1. Compute the center of the image (cx, cy).
122+
2. Calculate the maximum distance from the center to any corner (max_dis).
123+
3. For each pixel at (i, j):
124+
- Calculate the Euclidean distance from this pixel to the center: dist = sqrt((j - cx)^2 + (i - cy)^2)
125+
- Compute a vignette factor: vig = 1.0 - (dist / max_dis)
126+
- Clamp vig between 0.0 (fully dark) and 1.0 (original color).
127+
- Multiply the pixel's R, G, B values by vig to darken farther-away pixels more thoroughly.
128+
129+
If you apply this algorithm, your resulting image will have gently darkened corners and an undisturbed/sunnier center.
130+
131+
---
132+
133+
### Usage
134+
135+
To apply a filter via command-line:
136+
- `g`: grayscale
137+
- `s`: sepia
138+
- `r`: reflect
139+
- `b`: blur
140+
- `i`: invert
141+
- `v`: vignette
142+
143+
For vignette:
144+
```
145+
./filter v input.bmp output.bmp
146+
```
147+
You can also chain multiple filters by supplying multiple tags (e.g., `./filter vg input.bmp output.bmp` for vignette then grayscale).
148+
116149
You should not modify any of the function signatures, nor should you modify any other files other than helpers.c.
117150

118151
Consider the following grid of pixels, where we’ve numbered each pixel.

filter.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int main(int argc, char *argv[])
88
{
99
// Define allowable filters
10-
char *filters = "bgrsi";
10+
char *filters = "bgrsiv";
1111

1212

1313
char filterArr[argc-3];
@@ -120,11 +120,14 @@ int main(int argc, char *argv[])
120120
case 's':
121121
sepia(height, width, image);
122122
break;
123-
124123
//invert
125124
case 'i':
126125
invert(height,width,image);
127126
break;
127+
// Vignette
128+
case 'v':
129+
vignette(height, width, image);
130+
break;
128131
default:
129132
printf("%c", &filterArr[i]);
130133
break;

helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ void reflect(int height, int width, RGBTRIPLE image[height][width]);
1414

1515
// Blur image
1616
void blur(int height, int width, RGBTRIPLE image[height][width]);
17+
//
18+
void vignette(int height, int width, RGBTRIPLE image[height][width]);

0 commit comments

Comments
 (0)