I am working on reflecting this image. I think I got the logic correctly, but I am not positive about that. However, my image did not reflect. Is this because I need to use malloc? I tried to but couldn't figure out what to set malloc to... what type (it's not being an int, char, etc).. Not sure what else to try...
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE reflection[height][width];
for (int i = 0; i < height; i ++)
{
for (int j = 0; j < width; j++)
{
//need swap each pixel from left to right...
reflection[i][j] = image[i][width-j];
}
}
return;
}
I figured out how to use malloc but it's still not working. Seems to run but then the result is the same as the oringal image... any suggestions?
Thanks!
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE reflection[height][width];
struct reflection *p = malloc((height * width) + 1);
for (int i = 0; i < height; i ++)
{
for (int j = 0; j < width; j++)
{
//need swap each pixel from left to right...
reflection[i][j] = image[i][width-j];
}
}
return;
}
I changed it up a bit... now it's still not working:
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE temp[height][width];
RGBTRIPLE reflection[height][width];
struct reflection *p = malloc((height * width) + 1);
for (int i = 0; i < height; i ++)
{
for (int j = 0; j < width; j++)
{
//need swap each pixel from left to right...
temp[i][j] = image[i][j];
image[i][j] = reflection[i][width - j];
reflection[i][width - j] = temp[i][j];
}
}
return;
free(reflection);
}
Now it works! But the check50 function is still marking it red... not sure why.
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
void swap(RGBTRIPLE *a, RGBTRIPLE *b);
RGBTRIPLE temp[height][width];
for (int i = 0; i < height; i ++)
{
for (int j = 0; j < (width/2); j++)
{
//need swap each pixel from left to right...
swap(&image[i][j], &image[i][width-j]);
}
}
return;
}
void swap(RGBTRIPLE *a, RGBTRIPLE *b)
{
RGBTRIPLE temp;
temp = *a;
*a = *b;
*b = temp;
}