Skip to content

Commit f6b8141

Browse files
feat(image-filtering): add reflect function
1 parent 7adc431 commit f6b8141

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)