OK, so here's the problem. You load the data into XBuffer, then you store a pointer to that bffer into InBuff, you load the next set of data into XBuffer and store the same pointer into the next element of inBuff, and so on. One way to fix it would be to move the new of XBuffer into the loop. As in:
for (Y = 0; Y < Ymax; Y++) { Xbuffer = new byte[Xmax]; for (X = 0; X < Xmax; X++) { XBuffer[X] = buffer[X + Y * 4]; } InBuff[Y] = XBuffer; }
The down side of this is that this will use up twice the amount of memory. If you use the data from the initial buffer it would save the memory.