Algorithm to rotate an image 90 degrees in place? (No extra memory)

前端 未结 9 919
囚心锁ツ
囚心锁ツ 2020-11-29 06:26

In an embedded C app, I have a large image that I\'d like to rotate by 90 degrees. Currently I use the well-known simple algorithm to do this. However, this algorithm requi

9条回答
  •  佛祖请我去吃肉
    2020-11-29 06:56

    the real answer: no, u can't without allocating some memory.

    or you have to use recursion, which will fail with large images.

    however there are methods that require less memory than the image itself

    for example, you could take point A (x from 0 to width, y from 0 to height), calculate it's new location, B, copy B to it's new location (C) before replacing it with A, etc..

    but, that method would require to keep track of what bytes have already been moved. (using a bitmap of one bit per pixel in the rotated image)

    see the wikipedia article, it clearly demonstrates that this cannot be done for non square images: here is the link again: http://en.wikipedia.org/wiki/In-place_matrix_transposition

提交回复
热议问题