GNOME Bugzilla – Bug 95865
gdk_pixbuf_rotate_simple
Last modified: 2010-07-10 04:07:38 UTC
I have written a function to rotate GdkPixbufs in 90 degree angles. The code is available at http://liw.iki.fi/liw/gdk-pixbuf-rotate/ (sorry, no patch, but it's one new file, plus a few lines to be inserted into gdk-pixbuf.h).
Haven't really looked at the implementation or the API , but a few thoughts: - A _simple() function without having the normal variant is a little odd. - It might be better to actually use a double angle parameter in degrees and say that only 90 degree increments work than to have the enum.
I discussed the interface on #gtk+ before implementing it. My first proposal was GdkPixbuf *gdk_pixbuf_rotate(GdkPixbuf *src, gdouble angle); However, the interface in the implementation was suggested to me to make it painfully clear to the caller that the function is not a general rotation function. The implicit goal is to have the general function call one of the internal rotate_NN functions for the special cases and maybe even remove the _simple function after a general one is written. I can, of course, live with either interface and would be happy to change it to whatever is deemed best. (I'll even take a stab at the general function once I find a clear description of a good algorithm for it, but that may take a while.)
I like the enum better since it makes things absolutely clear. I'd also add CLOCKWISE and COUNTERCLOCKWISE aliases.
I also prefer the enum interface. Additionally I'd prefer a different name, since I would expect a general gdk_pixbuf_rotate () function to do filtering and it would be strange to have it return an unfiltered result for 90 degrees and a filtered one for 90.0005. Maybe a different name, like gdk_pixbuf_turn() or gdk_pixbuf_flip() would help to clarify the difference.
I don't have a good name suggestion, though if we are going to go with the enum approach, we might as well add FLIP_HORIZONTAL/FLIP_VERTICAL, though that makes the naming even a bit worse, I don't like the idea of CW/CCW aliases ... I think having multiple names confuses things.
Might also throw in the two flip-and-rotate combinations. How about gdk_pixbuf_reorient() ?
I have since written an arbitrary rotation function, which I've now added to the page, as rotate-new.c. The new function special cases normalized angles 0.0, 90.0, 180.0, and 270.0 and uses a generic one for the other cases. Thus, there is only one exported function: GdkPixbuf * gdk_pixbuf_rotate(const GdkPixbuf *src, gdouble degrees, guint32 fill_pixel, gint algorithm) I've been told that the fill_pixel should be done in a better way, but I have since forgotten how.
I like rotate_simple. It's also easier for people looking at the header or API reference to find a rotation operation, rather than strange nonstandard terminology. If we want to have flip functionality, that should be a separate function.
*** Bug 140830 has been marked as a duplicate of this bug. ***