C++ C\C中的简单翻转缓冲区(垂直)问题++
我试图翻转缓冲区,但缓冲区未得到完全处理。 是一个像素缓冲区,我基本上需要垂直翻转它。 谁能看出我做错了什么?提前谢谢C++ C\C中的简单翻转缓冲区(垂直)问题++,c++,c,pixels,memcpy,flip,C++,C,Pixels,Memcpy,Flip,我试图翻转缓冲区,但缓冲区未得到完全处理。 是一个像素缓冲区,我基本上需要垂直翻转它。 谁能看出我做错了什么?提前谢谢 void flipVertically(unsigned int* buffer, const unsigned int width, const unsigned int height) { const unsigned int rowWidth = width; // Length of a row const unsigned int rows = hei
void flipVertically(unsigned int* buffer, const unsigned int width, const unsigned int height)
{
const unsigned int rowWidth = width; // Length of a row
const unsigned int rows = height / 2; // Iterate only half the buffer to get a full flip
unsigned int* tempRow = (unsigned int*)malloc(rowWidth);
for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
memcpy(tempRow, buffer + (rowIndex * rowWidth), rowWidth);
memcpy(buffer + (rowIndex * rowWidth), buffer + (height - rowIndex - 1) * rowWidth, rowWidth);
memcpy(buffer + (height - rowIndex - 1) * rowWidth, tempRow, rowWidth);
}
free(tempRow);
}
这样行吗
void flip(unsigned* buffer, unsigned width, unsigned height)
{
unsigned rows = height / 2; // Iterate only half the buffer to get a full flip
unsigned* tempRow = (unsigned*)malloc(width * sizeof(unsigned));
for (unsigned rowIndex = 0; rowIndex < rows; rowIndex++)
{
memcpy(tempRow, buffer + rowIndex * width, width * sizeof(unsigned));
memcpy(buffer + rowIndex * width, buffer + (height - rowIndex - 1) * width, width * sizeof(unsigned));
memcpy(buffer + (height - rowIndex - 1) * width, tempRow, width * sizeof(unsigned));
}
free(tempRow);
}
你能澄清一下你所说的翻转是什么意思吗?你是说反向吗?你是说转置吗?这是C还是C++?如果是C++,为什么使用指针?什么是缓冲像素?到底是什么出错了?注意:你把行宽传递给MeMcPy,而你可能想要RoWix**sieOff**。@ AlexChamberlain,我想它是一个2D数组,按顺序存储在内存中,需要垂直翻转行[0 ]行[W-1 ],行[1 ]行[W2]等。