Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
// Define allowable filters
char *filters = "bgrsi";
char *filters = "bgrsiv";


char filterArr[argc-3];
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,25 @@ void blur(int height, int width, RGBTRIPLE image[height][width]){
free(temp);
}

// Blur image

}
void vignette(int height, int width, RGBTRIPLE image[height][width]){
float cx = width / 2.0; // center of the image
float cy= height / 2.0;
float max_dis= sqrt(cx * cx + cy * cy);
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
float disx = j - cx;
float disy = i - cy;
float dist= sqrt(disx * disx + disy * disy);
// (0.0 = dark, 1.0 = og)
float vig = 1.0 - (dist/ max_dis);
if(vig< 0.0) vig = 0.0;
if(vig > 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);
}
}
}
2 changes: 2 additions & 0 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
// Vignette image
void vignette(int height, int width, RGBTRIPLE image[height][width]);
Loading