Skip to content

Commit cf84b3a

Browse files
authored
Merge branch 'main' into feature/brightness-adjust
2 parents 7e99a6a + eba8e70 commit cf84b3a

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"C_Cpp.errorSquiggles": "disabled"
2+
"C_Cpp.errorSquiggles": "disabled",
3+
"files.associations": {
4+
"helpers.h": "c"
5+
}
36
}

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,38 @@ If you apply the above algorithm to each pixel in the image, the result should l
129129
```sh
130130
./filter -v input.bmp output.bmp
131131
```
132+
### 5.) The Vignette Algorithm
133+
134+
The vignette filter gives an image a cinematic look by gradually darkening its corners.
135+
136+
**Algorithm:**
137+
1. Compute the center of the image (cx, cy).
138+
2. Calculate the maximum distance from the center to any corner (max_dis).
139+
3. For each pixel at (i, j):
140+
- Calculate the Euclidean distance from this pixel to the center: dist = sqrt((j - cx)^2 + (i - cy)^2)
141+
- Compute a vignette factor: vig = 1.0 - (dist / max_dis)
142+
- Clamp vig between 0.0 (fully dark) and 1.0 (original color).
143+
- Multiply the pixel's R, G, B values by vig to darken farther-away pixels more thoroughly.
144+
145+
If you apply this algorithm, your resulting image will have gently darkened corners and an undisturbed/sunnier center.
146+
147+
---
148+
149+
### Usage
150+
151+
To apply a filter via command-line:
152+
- `g`: grayscale
153+
- `s`: sepia
154+
- `r`: reflect
155+
- `b`: blur
156+
- `i`: invert
157+
- `v`: vignette
158+
159+
For vignette:
160+
```
161+
./filter v input.bmp output.bmp
162+
```
163+
You can also chain multiple filters by supplying multiple tags (e.g., `./filter vg input.bmp output.bmp` for vignette then grayscale).
132164

133165
You should not modify any of the function signatures, nor should you modify any other files other than helpers.c.
134166

filter.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ 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);

filter.exe

-98.8 KB
Binary file not shown.

helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ void vignette(int height, int width, RGBTRIPLE image[height][width]) {
138138
image[i][j].rgbtBlue = (int)(image[i][j].rgbtBlue * vig);
139139
}
140140
}
141-
}
141+
}

helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ void reflect(int height, int width, RGBTRIPLE image[height][width]);
1616
void blur(int height, int width, RGBTRIPLE image[height][width]);
1717

1818
// Brightness adjustment filter
19-
void brightness(int height, int width, RGBTRIPLE image[height][width], int value);
19+
void brightness(int height, int width, RGBTRIPLE image[height][width], int value);
68.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)