@@ -198,3 +198,75 @@ void threshold(int height, int width, RGBTRIPLE image[height][width])
198198 }
199199 }
200200}
201+
202+ void glow (int height , int width , RGBTRIPLE image [height ][width ])
203+ {
204+ // Step 1: make a copy of the original
205+ RGBTRIPLE * * original = malloc (height * sizeof (RGBTRIPLE * ));
206+ RGBTRIPLE * * blurred = malloc (height * sizeof (RGBTRIPLE * ));
207+ for (int i = 0 ; i < height ; i ++ )
208+ {
209+ original [i ] = malloc (width * sizeof (RGBTRIPLE ));
210+ blurred [i ] = malloc (width * sizeof (RGBTRIPLE ));
211+ for (int j = 0 ; j < width ; j ++ )
212+ {
213+ original [i ][j ] = image [i ][j ];
214+ }
215+ }
216+
217+ // Step 2: apply a *mild* blur to copy (smaller kernel)
218+ int kernelSize = 11 ;
219+ int offset = kernelSize / 2 ;
220+
221+ for (int i = 0 ; i < height ; i ++ )
222+ {
223+ for (int j = 0 ; j < width ; j ++ )
224+ {
225+ int sumRed = 0 , sumGreen = 0 , sumBlue = 0 , count = 0 ;
226+
227+ for (int ki = - offset ; ki <= offset ; ki ++ )
228+ {
229+ for (int kj = - offset ; kj <= offset ; kj ++ )
230+ {
231+ int ni = i + ki , nj = j + kj ;
232+ if (ni >= 0 && ni < height && nj >= 0 && nj < width )
233+ {
234+ sumRed += original [ni ][nj ].rgbtRed ;
235+ sumGreen += original [ni ][nj ].rgbtGreen ;
236+ sumBlue += original [ni ][nj ].rgbtBlue ;
237+ count ++ ;
238+ }
239+ }
240+ }
241+
242+ blurred [i ][j ].rgbtRed = sumRed / count ;
243+ blurred [i ][j ].rgbtGreen = sumGreen / count ;
244+ blurred [i ][j ].rgbtBlue = sumBlue / count ;
245+ }
246+ }
247+
248+ // Step 3: blend original + blurred to produce glow
249+ for (int i = 0 ; i < height ; i ++ )
250+ {
251+ for (int j = 0 ; j < width ; j ++ )
252+ {
253+ float blend = 0.4 ; // glow intensity
254+ int newRed = (1 - blend ) * original [i ][j ].rgbtRed + blend * blurred [i ][j ].rgbtRed ;
255+ int newGreen = (1 - blend ) * original [i ][j ].rgbtGreen + blend * blurred [i ][j ].rgbtGreen ;
256+ int newBlue = (1 - blend ) * original [i ][j ].rgbtBlue + blend * blurred [i ][j ].rgbtBlue ;
257+
258+ image [i ][j ].rgbtRed = min (255 , newRed );
259+ image [i ][j ].rgbtGreen = min (255 , newGreen );
260+ image [i ][j ].rgbtBlue = min (255 , newBlue );
261+ }
262+ }
263+
264+ // Step 4: cleanup
265+ for (int i = 0 ; i < height ; i ++ )
266+ {
267+ free (original [i ]);
268+ free (blurred [i ]);
269+ }
270+ free (original );
271+ free (blurred );
272+ }
0 commit comments