ppm image flipping c++

I have been having trouble with my code to flip an image vertically in c++. My code as of now just gives me the exact copy of the image I started with. Any ideas? Thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void ppmFlipVertical(int image[MAXROWS][MAXCOLS], int numRows, int numCols)
{
	int temp, N,L,c;
	N=3*numRows;
	L=3*numCols;
	c=0;
	
		for(int r=0; r<(N/2); r++)
		{
			temp=image[r][c];
			image[r][c] = image[N-1-r][c]; 
			image[N-1-r][c] = temp;
		}
}
I don't understand why you use the N and L values that you use. You just loop over c=0, so only one column is inverted. You need to have a nested loop, something like
1
2
3
4
5
6
7
8
9
       for(c=0;c<L;c++)
      {
		for(int r=0; r<(N/2); r++)
		{
			temp=image[r][c];
			image[r][c] = image[N-1-r][c]; 
			image[N-1-r][c] = temp;
		}
      }
When i try the code above, I only get an output of about a third of the image from the right side.. I've tried this way, but I deleted to for(int c=0;c<L;c++) loop because it was giving me only part of the image as the output. Any ideas from here?
Using two dimensional array syntactic sugar and feeding the function the number of rows and columns (which suggests the syntactic sugar will be incorrect) seems a wee bit off.









Topic archived. No new replies allowed.