diff --git a/README.md b/README.md index 030528e..08d2921 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,18 @@ The result is clamped between 0 and 255 and replaces the original pixel value. T --- +### 8.) The Glow Algorithm + +The “Glow” filter gives bright regions of an image a soft, luminous halo, similar to a cinematic bloom effect. This filter works by blending the original image with a blurred version of itself. + +The algorithm first creates a copy of the image and applies a mild box blur (using a smaller kernel than the main blur filter) to it. Then, for each pixel, the final color values are calculated by combining the original pixel's color with the new blurred pixel's color using a weighted average: + +- `finalRed = 0.7 * originalRed + 0.3 * blurredRed` +- `finalGreen = 0.7 * originalGreen + 0.3 * blurredGreen` +- `finalBlue = 0.7 * originalBlue + 0.3 * blurredBlue` + +The resulting values are rounded to the nearest integer and capped at 255. This process brightens the image and causes the light to "bleed" from bright areas into darker ones, creating a soft, luminous effect. + ### Usage To apply a filter via command-line: @@ -186,6 +198,13 @@ To apply a filter via command-line: - `b`: blur - `i`: invert - `v`: vignette +- `G`: glow +- `t`: threshold +- `d`: edge detection +- `B `: brightness + +Example for glow: +./filter -G input.bmp output.bmp For vignette: ``` diff --git a/filter.c b/filter.c index e3fac2c..cb1c565 100644 --- a/filter.c +++ b/filter.c @@ -7,7 +7,7 @@ int main(int argc, char *argv[]) { // Define allowable filters - char *filters = "bgrsivtdB:"; + char *filters = "bgrsivtdGB:"; char filterArr[argc-3]; @@ -133,7 +133,6 @@ int main(int argc, char *argv[]) case 't': threshold(height, width, image); break; - case 'd': // Edge Detection detect_edges(height, width, image); break; @@ -144,6 +143,9 @@ int main(int argc, char *argv[]) brightness(height, width, image, brightness_value); break; } + case 'G': + glow(height, width, image); + break; default: printf("Unknown filter: %c\n", filterArr[i]); free(image); @@ -179,4 +181,4 @@ int main(int argc, char *argv[]) fclose(inptr); fclose(outptr); return 0; -} \ No newline at end of file +} diff --git a/filter.exe b/filter.exe deleted file mode 100644 index 505744c..0000000 Binary files a/filter.exe and /dev/null differ diff --git a/helpers.c b/helpers.c index ee56bf1..5a7d2ef 100644 --- a/helpers.c +++ b/helpers.c @@ -1,6 +1,7 @@ #include "helpers.h" #include #include +#include #include "bmp.h" int min(int a,int b){ if(a= 0 && ni < height && nj >= 0 && nj < width) + { + sumRed += original[ni][nj].rgbtRed; + sumGreen += original[ni][nj].rgbtGreen; + sumBlue += original[ni][nj].rgbtBlue; + count++; + } + } + } + + blurred[i][j].rgbtRed = sumRed / count; + blurred[i][j].rgbtGreen = sumGreen / count; + blurred[i][j].rgbtBlue = sumBlue / count; + } + } + + // Step 3: blend original + blurred to produce glow + for (int i = 0; i < height; i++) + { + for (int j = 0; j < width; j++) + { + float blend = 0.3; // glow intensity + int newRed = (1 - blend) * original[i][j].rgbtRed + blend * blurred[i][j].rgbtRed; + int newGreen = (1 - blend) * original[i][j].rgbtGreen + blend * blurred[i][j].rgbtGreen; + int newBlue = (1 - blend) * original[i][j].rgbtBlue + blend * blurred[i][j].rgbtBlue; + + image[i][j].rgbtRed = min(255, newRed); + image[i][j].rgbtGreen = min(255, newGreen); + image[i][j].rgbtBlue = min(255, newBlue); + } + } + + // Step 4: cleanup + for (int i = 0; i < height; i++) + { + free(original[i]); + free(blurred[i]); + } + free(original); + free(blurred); +} diff --git a/helpers.h b/helpers.h index 770ab49..0acb499 100644 --- a/helpers.h +++ b/helpers.h @@ -33,5 +33,6 @@ void brightness(int height, int width, RGBTRIPLE image[height][width], int value // Vignette filter void vignette(int height, int width, RGBTRIPLE image[height][width]); - +// Glow filter +void glow(int height, int width, RGBTRIPLE image[height][width]); #endif