Using Debug50, I can see that the RGB pixel values are appropriately swapped through. However the outfile is not actually reflected at all.
The last comment section for the "fix" only seem to apply a black line right in the middle of the outfile when uncommented.
Could you point me in the right direction as to why the reflection is not occurring?
I have seen code using TEMP variables but I thought I could use the pointers since I am on PSET4 now.
Thanks a lot !
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
// initialise variable at the beginning before touching i and j.
int i = 0;
int j = 0;
// Getting midle pixel value just in case width is even
int PixFixRed = image[i][width / 2].rgbtRed;
int PixFixGreen = image[i][width / 2].rgbtGreen;
int PixFixBlue = image[i][width / 2].rgbtBlue;
for (i = 0; i < height; i++)
{
for (j = 0; j < width / 2; j++)
{
// For row [j][x][x][x][x][x][x][x][x][x][x][x][x][x][width-1-j]
// Earllllyyy >>>>> Middle <<<<< Eeennndd
// Get values of the pixel j (going from the left of the array)
int EarlyPixRed = image[i][j].rgbtRed;
int EarlyPixGreen = image[i][j].rgbtGreen;
int EarlyPixBlue = image[i][j].rgbtBlue;
// Get values of the pixel width-j (going from the right of the array)
int EndPixRed = image[i][(width - 1) - j].rgbtRed;
int EndPixGreen = image[i][(width - 1) - j].rgbtGreen;
int EndPixBlue = image[i][(width - 1) - j].rgbtBlue;
// SWAP Function
// RED ONLY
int *SwapRed = malloc(4);
*SwapRed = EndPixRed;
EndPixRed = EarlyPixRed;
EarlyPixRed = *SwapRed;
free(SwapRed);
// Green ONLY
int *SwapGreen = malloc(4);
*SwapGreen = EndPixGreen;
EndPixGreen = EarlyPixGreen;
EarlyPixGreen = *SwapGreen;
free(SwapGreen);
// Blue ONLY
int *SwapBlue = malloc(4);
*SwapBlue = EndPixBlue;
EndPixBlue = EarlyPixBlue;
EarlyPixBlue = *SwapBlue;
free(SwapBlue);
}
// Fixes the middle pixel if picture has an even width
//if (width % 2 == 0)
//{
// image[i][width / 2].rgbtRed = PixFixRed;
// image[i][width / 2].rgbtGreen = PixFixGreen;
// image[i][width / 2].rgbtBlue = PixFixBlue;
//}
}
return;
}
Note that the code above gives out the following Check50 results :
:( 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..."