2

バッファを反転しようとしていますが、バッファが完全に処理されません。ピクセルのバッファであり、基本的に垂直方向に反転する必要があります。誰かが私が間違っていることを見つけることができますか?前もって感謝します。

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);
}
4

1 に答える 1

7

これは機能しますか?

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);
}
于 2013-02-10T14:32:21.340 に答える