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
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,14 @@ 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.
### 6.) Brightness Adjustment Filter
- **Flag:** `-B <value>`
- **Description:** Increases or decreases the brightness of the image by adding a fixed value to each pixel's R, G, and B channels. The value should be an integer—positive to increase, negative to decrease.
- **Usage examples:**
```sh
./filter -B 40 input.bmp output.bmp # Increase brightness by 40
./filter -B -30 input.bmp output.bmp # Decrease brightness by 30
```

### 6.) The Threshold Algorithm

Expand Down
27 changes: 16 additions & 11 deletions filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
int main(int argc, char *argv[])
{
// Define allowable filters
char *filters = "bgrsivt";
char *filters = "bgrsivB:";


char filterArr[argc-3];
int filterCount = 0;

// gets all filter flags and checks validity
for(int i=0; i<argc; i++){
char temp = getopt(argc,argv,filters);
if(temp == -1) break;
filterArr[i]= temp;
if(filterArr[i] == '?') {
printf("Invalid filter option");
int opt;
while ((opt = getopt(argc, argv, filters)) != -1) {
if (opt == '?') {
printf("Invalid filter option\n");
return 1;
}
filterArr[filterCount++] = opt;
}


Expand Down Expand Up @@ -98,7 +98,7 @@ int main(int argc, char *argv[])
}

// Filter image
for(int i=0; i<argc-3; i++){
for(int i=0; i<filterCount; i++){
switch (filterArr[i])
{
// Blur
Expand All @@ -124,15 +124,20 @@ int main(int argc, char *argv[])
case 'i':
invert(height,width,image);
break;

// Vignette
case 'v':
vignette(height, width, image);
break;
case 't':
threshold(height, width, image);

// Brightness Adjust
case 'B': {
int brightness_value = atoi(optarg);
brightness(height, width, image, brightness_value);
break;
}
default:
printf("%c", &filterArr[i]);
printf("Unknown filter: %c\n", filterArr[i]);
break;

}
Expand Down
20 changes: 18 additions & 2 deletions helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,24 @@ void blur(int height, int width, RGBTRIPLE image[height][width]){
free(temp);
}

// Blur image

void brightness(int height, int width, RGBTRIPLE image[height][width], int value) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int r = image[i][j].rgbtRed + value;
int g = image[i][j].rgbtGreen + value;
int b = image[i][j].rgbtBlue + value;
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
image[i][j].rgbtRed = r;
image[i][j].rgbtGreen = g;
image[i][j].rgbtBlue = b;
}
}
}

void vignette(int height, int width, RGBTRIPLE image[height][width]){
float cx = width / 2.0; // center of the image
Expand Down
9 changes: 5 additions & 4 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ 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]);

//Threshold Filter(Black & White)
void threshold(int height, int width, RGBTRIPLE image[height][width]);
// Brightness adjustment filter
void brightness(int height, int width, RGBTRIPLE image[height][width], int value);

// Vignette filter
void vignette(int height, int width, RGBTRIPLE image[height][width]);
Loading