   Flipping an image around the X axis
  I'm trying flip an image loaded into a one-dimension linear array upside-down. he code for doing this so far is:for(unsigned int i = 0; i < Width; ++i){for(unsigned int j = 0; j < Height; ++j){for(unsigned int k = 0; k < BPP; ++k){Data[i+(Width*j) + (Width*Height*k)] = gtl::getData(Texture)[<what shoud go here??>];}}}now, I've been tryint to figure out the what goes here part for the past hour, and i've failed. any ideas?   
  Here's some pseudocode, I think this should do the trick:HalfHeight = Height / 2for y = 0, y < HalfHeight{for x = 0, x < Width{Data(x, y) = Texture(x, Height-y-1)}};  It should be something along these lines:Data[i+(Width*j) + (Width*Height*k)] = gtl::getData(Texture)[(Heigh * Width * BPP) - (i+(Width*j) + (Width*Height*k))];This way you are reading from the back of one buffer to the front of the other.EDIT: D'oh, this will flip and reverse the image. Nevermind if you are just going for an X reversal.   ;  i+(Width*(Height - j - 1)) + (Width*Height*k)   ;Quote:Original post by ChaosPhoenixIt should be something along these lines:Data[i+(Width*j) + (Width*Height*k)] = gtl::getData(Texture)[(Heigh * Width * BPP) - (i+(Width*j) + (Width*Height*k))];This way you are reading from the back of one buffer to the front of the other.EDIT: D'oh, this will flip and reverse the image. Nevermind if you are just going for an X reversal.this is too-correct. it flipped it in x, y AND rgb->bgr! I tried messing around with this, but I failed. any ideas on geting an X flip, anyone?   ;  Do you mean like this?before   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15 0 <--> 12 4 <-->  8 1 <--> 13 5 <-->  9 2 <--> 14 6 <--> 10 3 <--> 15 7 <--> 11after  12  13  14  15   8   9  10  11   4   5   6   7   0   1   2   3In which case this will do it. Make an array of struct { uint r, uint g, uint b } and then you dont have to worry about complicating the flip function to factor in the bpp cells of the array.// define array//const int width = 5;//int myArray[width*width] = { 0,1,2,3,4, 5,6,7,8,9, 10,11,12,13,14, 15,16,17,18,19, 20,21,22,23,24 };const int width = 4;int myArray[width*width] = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15 };//const int width = 3;//int myArray[width*width] = { 0,1,2, 3,4,5, 6,7,8 };//const int width = 2;//int myArray[width*width] = { 0,1, 2,3 };// print arraycout << "before" << endl;for (int i=0; i < width; i++){for (int j=0; j < width; j++){cout << setw(4) << myArray[(i*width)+j];}cout << endl;}cout << endl;int tmp = 0;for (int i=0; i < width; i++){for (int j=0; j < (width/2); j++){// demo the elements swappingcout << setw(2) << i+(j*width) << " <--> " << setw(2) << (((width-j)-1)*width)+i;// do the swaptmp = myArray[i+(j*width)];myArray[i+(j*width)] = myArray[(((width-j)-1)*width)+i];myArray[(((width-j)-1)*width)+i] = tmp;}cout << endl;}cout << endl;// print arraycout << "after" << endl;for (int i=0; i < width; i++){for (int j=0; j < width; j++){cout << setw(4) << myArray[(i*width)+j];}cout << endl;}cout << endl;hthF451   ;  performance wise, I need the straight projection equation...   ;Quote:performance wise, I need the straight projection equation...Why not just do this in-place?const int row_pitch= Width*BPP;for( int row= 0; row< Height/2; ++row )  memswap( Data+row*row_pitch, Data+(Height-row)*row_pitch, row_pitch );Slow implementation of memswap is straight-forward:  void memswap( char* /*restrict*/ a, char* /*restrict*/ b, const int size )  {    for( int i= 0; i!= size; ++i ) std::swap( a++, b++ );  }