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

前端 未结 9 895
囚心锁ツ
囚心锁ツ 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 07:09

    Not sure what processing you will do after the rotation, but you can leave it alone and use another function to read rotated pixel from the original memory.

    uint16_t getPixel90(Image *img, int x, int y) 
    {
        return img->data[(img->height - x) * img->width + y];
    }
    

    Where input parameter x and y has swapped dimension from original

提交回复
热议问题