Hi,
as an exercise in learning how to write a plugin for the Gimp I am
writing a rotation plugin using GTK+. In this process I encounter some
problems: I have no knowledge about graphics algorithms so I'm building
a brute-force algorithm.
Question: Do you know of some good graphics-algorithm books focussing on
2D algorithms?
Then the algorithm:
- get a rectangular area containing image data.
- use upperleft corner as origin.
- get the user defined angle.
example: angle is 30 degrees.
- compute the size of the new image using simple Pythagoras.
new width becomes ( cos(angle) * oldwidth ) + ( sin(angle) *
oldheight ).
- compute the coordinates of the rotated image in the new grid.
0 1 2 3 -> x
0----------------------------------------------
| | /|\ | | | | | | |
| | / | /\ | | | | | |
1| | / | / | /\| |
|
v
y
as can be seen in this very primitive view the coordinates will be
floats. The origin of the old image is translate to (2,0). The following
coordinate is translated to something like ( 2.7, 0.5). The coordinates
represent the corners of the pixels.
- compute the surfaces of the several pixels which are inside a new
pixel. As can be seen in the view above, the pixel starting at (2,0)
contains at least two old pixels and a piece, which was not part of the
old image.
Question: How do I compute how much the percentages of how much of the
new pixel is covered by the parts of the old pixels?
- For each new pixel compute the new color using the computed
percentages.
- paint the new image.
Question: Am I being totally stupid in using this ad-hoc approach? Are
there smarter approaches?
Lo van den Berg