I need help rotating a PPM image in C. The rotate function is supposed to rotate the image of a previously read in PPM image 90 degrees to the right. The code will be posted below. I need help with the rotate() function.
The signature of the function is:
void rotate(pixel_t *image, int x, int y)
X is the width of the image and Y is the height.
Here is a look at how I accomplished some other PPM manipulations in this program:
void grayscale(pixel_t *image, int x, int y)
{
int i, average = 0;
for (i = 0; i < x*y; i++)
{
average = (image[i].r + image[i].g + image[i].b) / 3;
printf("%c%c%c", average, average, average);
}
}
void flipImage(pixel_t *image, int x, int y)
{
int r, c, i;
for (c = y-1; c >= 0; c--)
{
for (r = 0; r < x; r++)
{
i = (c * x) + r;
printf("%c%c%c", image[i].r, image[i].g, image[i].b);
}
}
}
This is what I have so far:
void rotate(pixel_t *image, int x, int y)
{
int r, c;
for (r = 0; r < x; r++)
{
for (c = 0; c < y; r++)
{
printf("%c%c%c", image[c].r, image[c].g, image[c].b);
}
}
}