11#include "helpers.h"
2-
2+ #include <stdint.h>
3+ #include <stdlib.h>
4+ #include "bmp.h"
35int min (int a ,int b ){
46 if (a < b ) return a ;
57 return b ;
@@ -66,12 +68,63 @@ void sepia(int height, int width, RGBTRIPLE image[height][width]){
6668
6769void reflect (int height , int width , RGBTRIPLE image [height ][width ]){
6870
69- // Reflect image horizontally
71+ // Loop over each row
72+ for (int i = 0 ; i < height ; i ++ )
73+ {
74+ // Swap pixels horizontally (mirror)
75+ for (int j = 0 ; j < width / 2 ; j ++ )
76+ {
77+ // Swap left pixel with right pixel
78+ RGBTRIPLE temp = image [i ][j ];
79+ image [i ][j ] = image [i ][width - 1 - j ];
80+ image [i ][width - 1 - j ] = temp ;
81+ }
82+ }
7083
7184}
7285
7386
7487void blur (int height , int width , RGBTRIPLE image [height ][width ]){
88+ // Allocate temporary array on heap
89+ RGBTRIPLE * * temp = malloc (height * sizeof (RGBTRIPLE * ));
90+ for (int i = 0 ; i < height ; i ++ )
91+ temp [i ] = malloc (width * sizeof (RGBTRIPLE ));
92+
93+ int kernelSize = 21 ; // large kernel for heavy blur
94+ int offset = kernelSize / 2 ;
95+ // Repeating blur 2-3 times for ultra blur effect
96+ //because in single time effect not much visible
97+ for (int repeat = 0 ; repeat < 3 ; repeat ++ ){
98+ for (int i = 0 ; i < height ; i ++ ){
99+ for (int j = 0 ; j < width ; j ++ ){
100+ int sumRed = 0 , sumGreen = 0 , sumBlue = 0 ;
101+ int count = 0 ;
102+ for (int ki = - offset ; ki <= offset ; ki ++ ){
103+ for (int kj = - offset ; kj <= offset ; kj ++ ){
104+ int ni = i + ki ;
105+ int nj = j + kj ;
106+ if (ni >= 0 && ni < height && nj >= 0 && nj < width ){
107+ sumRed += image [ni ][nj ].rgbtRed ;
108+ sumGreen += image [ni ][nj ].rgbtGreen ;
109+ sumBlue += image [ni ][nj ].rgbtBlue ;
110+ count ++ ;
111+ }
112+ }
113+ }
114+ temp [i ][j ].rgbtRed = (uint8_t )(sumRed / count );
115+ temp [i ][j ].rgbtGreen = (uint8_t )(sumGreen / count );
116+ temp [i ][j ].rgbtBlue = (uint8_t )(sumBlue / count );
117+ }
118+ }
119+ // Copy blurred array back to orig
120+ for (int i = 0 ; i < height ; i ++ )
121+ for (int j = 0 ; j < width ; j ++ )
122+ image [i ][j ] = temp [i ][j ];
123+ }
124+ for (int i = 0 ; i < height ; i ++ )
125+ free (temp [i ]);
126+ free (temp );
127+ }
75128
76129// Blur image
77130
@@ -94,4 +147,4 @@ void vignette(int height, int width, RGBTRIPLE image[height][width]){
94147 image [i ][j ].rgbtBlue = (int )(image [i ][j ].rgbtBlue * vig );
95148 }
96149 }
97- }
150+ }
0 commit comments