diff --git a/README.md b/README.md index 1b9bf53..b918117 100644 --- a/README.md +++ b/README.md @@ -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 ` +- **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 diff --git a/filter.c b/filter.c index ac19958..b642fd8 100644 --- a/filter.c +++ b/filter.c @@ -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 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 diff --git a/helpers.h b/helpers.h index ade29b6..88da2ff 100644 --- a/helpers.h +++ b/helpers.h @@ -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]);