@@ -283,4 +283,75 @@ void detect_edges(int height, int width, RGBTRIPLE image[height][width])
283283 for (int i = 0 ; i < height ; i ++ )
284284 free (copy [i ]);
285285 free (copy );
286- }
286+ }
287+ void glow (int height , int width , RGBTRIPLE image [height ][width ])
288+ {
289+ // Step 1: make a copy of the original
290+ RGBTRIPLE * * original = malloc (height * sizeof (RGBTRIPLE * ));
291+ RGBTRIPLE * * blurred = malloc (height * sizeof (RGBTRIPLE * ));
292+ for (int i = 0 ; i < height ; i ++ )
293+ {
294+ original [i ] = malloc (width * sizeof (RGBTRIPLE ));
295+ blurred [i ] = malloc (width * sizeof (RGBTRIPLE ));
296+ for (int j = 0 ; j < width ; j ++ )
297+ {
298+ original [i ][j ] = image [i ][j ];
299+ }
300+ }
301+
302+ // Step 2: apply a *mild* blur to copy (smaller kernel)
303+ int kernelSize = 11 ;
304+ int offset = kernelSize / 2 ;
305+
306+ for (int i = 0 ; i < height ; i ++ )
307+ {
308+ for (int j = 0 ; j < width ; j ++ )
309+ {
310+ int sumRed = 0 , sumGreen = 0 , sumBlue = 0 , count = 0 ;
311+
312+ for (int ki = - offset ; ki <= offset ; ki ++ )
313+ {
314+ for (int kj = - offset ; kj <= offset ; kj ++ )
315+ {
316+ int ni = i + ki , nj = j + kj ;
317+ if (ni >= 0 && ni < height && nj >= 0 && nj < width )
318+ {
319+ sumRed += original [ni ][nj ].rgbtRed ;
320+ sumGreen += original [ni ][nj ].rgbtGreen ;
321+ sumBlue += original [ni ][nj ].rgbtBlue ;
322+ count ++ ;
323+ }
324+ }
325+ }
326+
327+ blurred [i ][j ].rgbtRed = sumRed / count ;
328+ blurred [i ][j ].rgbtGreen = sumGreen / count ;
329+ blurred [i ][j ].rgbtBlue = sumBlue / count ;
330+ }
331+ }
332+
333+ // Step 3: blend original + blurred to produce glow
334+ for (int i = 0 ; i < height ; i ++ )
335+ {
336+ for (int j = 0 ; j < width ; j ++ )
337+ {
338+ float blend = 0.4 ; // glow intensity
339+ int newRed = (1 - blend ) * original [i ][j ].rgbtRed + blend * blurred [i ][j ].rgbtRed ;
340+ int newGreen = (1 - blend ) * original [i ][j ].rgbtGreen + blend * blurred [i ][j ].rgbtGreen ;
341+ int newBlue = (1 - blend ) * original [i ][j ].rgbtBlue + blend * blurred [i ][j ].rgbtBlue ;
342+
343+ image [i ][j ].rgbtRed = min (255 , newRed );
344+ image [i ][j ].rgbtGreen = min (255 , newGreen );
345+ image [i ][j ].rgbtBlue = min (255 , newBlue );
346+ }
347+ }
348+
349+ // Step 4: cleanup
350+ for (int i = 0 ; i < height ; i ++ )
351+ {
352+ free (original [i ]);
353+ free (blurred [i ]);
354+ }
355+ free (original );
356+ free (blurred );
357+ }
0 commit comments