I am not sure why I am having issues with my code. I know I can store the rgb values for the left pixels in 3 temporary variables then assign the right values to the left and the temp values to the right but I feel that is just writing out the swap function we learned in the lesson and that is how I saw most people do it but I would like to incorporate the swap function. Can someone help me figure out why it isn't working properly? Here is my code:
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
void swap(int *a, int *b);
int s = 1;
int red = 0;
int green = 0;
int blue = 0;
int Red = 0;
int Green = 0;
int Blue = 0;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width / 2; j++)
{
red = image[i][j].rgbtRed;
green = image[i][j].rgbtGreen;
blue = image[i][j].rgbtBlue;
Red = image[i][width - s].rgbtRed;
Green = image[i][width - s].rgbtGreen;
Blue = image[i][width - s].rgbtBlue;
swap(&red, &Red);
swap(&blue, &Blue);
swap(&green, &Green);
s++;
}
}
return;
}
void swap(int *a, int *b)
{
int tempB = *a;
*a = *b;
*b = tempB;
}
Here are the errors:
:( reflect correctly filters 1x2 image expected "0 0 255\n255 0...", not "255 0 0\n0 0 2..."
:( reflect correctly filters 1x3 image expected "0 0 255\n0 255...", not "255 0 0\n0 255..."
:) reflect correctly filters image that is its own mirror image
:( reflect correctly filters 3x3 image expected "70 80 90\n40 5...", not "10 20 30\n40 5..."
:( reflect correctly filters 4x4 image expected "100 110 120\n7...", not "10 20 30\n40 5..."