0

currently I use the next algorithm to rotate a 2d pixel array to 90 degrees, but it requires I do an memory extra buffer allocation. Is there another way to do this without allocating a new entire buffer? And with a simple way to specify if it needs to be 90 and -90?

 unsigned int *output = (unsigned int*)malloc(inputBufferSize);

 for (int pixel = 0, x = width - 1; x > -1; --x)
 {
     for (int y = 0; y < height; ++y)
     {
         output[pixel++] = input[width * y + x];
     }
 }
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
  • possible duplicate of [Algorithm to rotate an image 90 degrees in place? (No extra memory)](http://stackoverflow.com/questions/2968397/algorithm-to-rotate-an-image-90-degrees-in-place-no-extra-memory) – unwind May 15 '13 at 07:38
  • 1
    This is not a simple problem, because in-place rotation of non-square matrices induces complicated permutations in the elements. Although there is a [duplicate question](http://stackoverflow.com/questions/2968397/algorithm-to-rotate-an-image-90-degrees-in-place-no-extra-memory), it does not have good answers except for the link to [the Wikipedia page on in-place matrix transposition](http://en.wikipedia.org/wiki/In-place_matrix_transposition), which is similar. If you are looking for a quick fix, there is none. If you are looking for a proper solution, it may require study and research. – Eric Postpischil May 15 '13 at 13:52

0 Answers0