Monday, 15 September 2014

Simple Flip buffer (Vertically) issue in C\C++ -



Simple Flip buffer (Vertically) issue in C\C++ -

i trying flip buffer, buffer doesn't processed. buffer of pixels , need flip vertically. can spot doing wrong? in advance.

void flipvertically(unsigned int* buffer, const unsigned int width, const unsigned int height) { const unsigned int rowwidth = width; // length of row const unsigned int rows = height / 2; // iterate half buffer total flip unsigned int* temprow = (unsigned int*)malloc(rowwidth); (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); }

will work?

void flip(unsigned* buffer, unsigned width, unsigned height) { unsigned rows = height / 2; // iterate half buffer total flip unsigned* temprow = (unsigned*)malloc(width * sizeof(unsigned)); (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 pixels memcpy flip

No comments:

Post a Comment