Skip to content

Commit c7cdffd

Browse files
feat: add glow filter
1 parent 3f74b7c commit c7cdffd

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ The result is clamped between 0 and 255 and replaces the original pixel value. T
177177

178178
---
179179

180+
### 8.) The Glow Algorithm
181+
182+
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.
183+
184+
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:
185+
186+
- `finalRed = 0.7 * originalRed + 0.3 * blurredRed`
187+
- `finalGreen = 0.7 * originalGreen + 0.3 * blurredGreen`
188+
- `finalBlue = 0.7 * originalBlue + 0.3 * blurredBlue`
189+
190+
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.
191+
180192
### Usage
181193

182194
To apply a filter via command-line:
@@ -186,6 +198,13 @@ To apply a filter via command-line:
186198
- `b`: blur
187199
- `i`: invert
188200
- `v`: vignette
201+
- `G`: glow
202+
- `t`: threshold
203+
- `d`: edge detection
204+
- `B <value>`: brightness
205+
206+
Example for glow:
207+
./filter -G input.bmp output.bmp
189208

190209
For vignette:
191210
```

filter.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int main(int argc, char *argv[])
88
{
99
// Define allowable filters
10-
char *filters = "bgrsivtdB:";
10+
char *filters = "bgrsivtdB:G";
1111

1212

1313
char filterArr[argc-3];
@@ -133,10 +133,6 @@ int main(int argc, char *argv[])
133133
case 't':
134134
threshold(height, width, image);
135135
break;
136-
case 'w':
137-
glow(height, width, image);
138-
break;
139-
140136
case 'd': // Edge Detection
141137
detect_edges(height, width, image);
142138
break;
@@ -147,10 +143,9 @@ int main(int argc, char *argv[])
147143
brightness(height, width, image, brightness_value);
148144
break;
149145
}
150-
case 'w':{
146+
case 'G':
151147
glow(height, width, image);
152148
break;
153-
}
154149
default:
155150
printf("Unknown filter: %c\n", filterArr[i]);
156151
free(image);

filter.exe

-54.7 KB
Binary file not shown.

helpers.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "helpers.h"
22
#include <stdint.h>
33
#include <stdlib.h>
4+
#include <math.h>
45
#include "bmp.h"
56
int min(int a,int b){
67
if(a<b) return a;
@@ -335,7 +336,7 @@ void glow(int height, int width, RGBTRIPLE image[height][width])
335336
{
336337
for (int j = 0; j < width; j++)
337338
{
338-
float blend = 0.4; // glow intensity
339+
float blend = 0.3; // glow intensity
339340
int newRed = (1 - blend) * original[i][j].rgbtRed + blend * blurred[i][j].rgbtRed;
340341
int newGreen = (1 - blend) * original[i][j].rgbtGreen + blend * blurred[i][j].rgbtGreen;
341342
int newBlue = (1 - blend) * original[i][j].rgbtBlue + blend * blurred[i][j].rgbtBlue;

helpers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ void brightness(int height, int width, RGBTRIPLE image[height][width], int value
3333
// Vignette filter
3434
void vignette(int height, int width, RGBTRIPLE image[height][width]);
3535

36-
36+
// Glow filter
37+
void glow(int height, int width, RGBTRIPLE image[height][width]);
3738
#endif

0 commit comments

Comments
 (0)