My end goal is to flip a ppm image upside down, that's what the r, g, b 2d arrays are representing.
My thinking is, if I can have temp 2 as the rows reversed, I could set the first half of the image rows to the first half of temp2, then the second half of image to the first half of temp.
Giving me a 2d array where the rows have been flipped upside down.
You are bound by rules that forbid you to use a function?
I find that very hard to accept.
Also, you deleted your first post. That is exceedingly rude, and makes this thread useless to anyone but you...
...and I cannot review what you had posted originally, nor compare it to what you have now.
So... have you tested your current code? Does it do what you want? When you look at the flipped image, do you see where something goes wrong?
The solution I have demonstrated for you does not use another, temporary image. Again, it works very much like the standard “reverse a string” homeworks.
The solution you are currently proposing is:
• create a temporary image
• flip the content of the original into the temporary
• copy the (now flipped) content of the temporary straight back into the original
This is a workable solution. Again, compile it, give it a run, and see how the modified image looks. Then look at your loop bounds.
Sorry, my brain is fried right now, so... here you go.
I don't know what your pixel/RGB struct is called, so in the following I'm just calling it "Pixel".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int ytop = 0;
int ybottom = image_height - 1;
while (ytop < ybottom)
{
// swap two scan lines
for (int x = 0; x < image_width; x++)
{
Pixel pixel = im.pic[ytop][x];
im.pic[ytop][x] = im.pic[ybottom][x];
im.pic[ybottom][x] = pixel;
}
// next
ytop++;
ybottom--;
}
This works by swapping the top and bottom rows, then the next two, and so on, until you meet in the middle, at which point the image will be upside-down.