Skip to content

Commit 2516172

Browse files
Merge pull request #15 from ekanshgupta2046/added-reflect-function
feat(image-filtering): add reflect function
2 parents 18b2111 + f6b8141 commit 2516172

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

helpers.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ void sepia(int height, int width, RGBTRIPLE image[height][width]){
5757

5858
void reflect(int height, int width, RGBTRIPLE image[height][width]){
5959

60-
// Reflect image horizontally
60+
// Loop over each row
61+
for (int i = 0; i < height; i++)
62+
{
63+
// Swap pixels horizontally (mirror)
64+
for (int j = 0; j < width / 2; j++)
65+
{
66+
// Swap left pixel with right pixel
67+
RGBTRIPLE temp = image[i][j];
68+
image[i][j] = image[i][width - 1 - j];
69+
image[i][width - 1 - j] = temp;
70+
}
71+
}
6172

6273
}
6374

0 commit comments

Comments
 (0)