News for hackers. Stuff that matters.
Re:Rotating Images by pwg on Monday August 19, 2013 @12:33AM (#6235635)
The solution to making a one pass algorithm from the paper is to realize that each pixel moves a fixed amount. First it moves horizontally, then vertically, then horizontally, to arrive at its final location.

The way the algorithm works, for each pixel, the amount of shear horizontally and vertically can be calculated up front, before "moving" the pixel.

So to make a one pass algorithm, allocate a second image of sufficient size to hold the rotated original (the size of this second image can also be calculated before any pixel "movement"). Then, for each pixel, calculate its horizontal shift, followed by its vertical shift, followed by its final horizontal shift. You now have its destination coordinates, so store it into the second image buffer at the destination coordinates.

The algorithm becomes essentially:

    foreach pixel source_coord do
        dest_coord = transform(source_coord)
        dest_image(dest_coord) = source_image(source_coord)
    done
where

    transform()
performs the Horiz/Vert/Horz transformation of the input coordinate.

There are no comments on this comment yet.