diff options
author | Matthias Clasen <mclasen@redhat.com> | 2007-07-02 14:47:45 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2007-07-02 14:47:45 +0000 |
commit | b863097016027b191945b48acfb229c2e8656f3a (patch) | |
tree | 2c55db2839c5c3f74dba2be7fedda6aa36f54f5f /gdk-pixbuf/gdk-pixbuf-util.c | |
parent | f34766b21d70ff439079dbf6a1471ebd65b45b49 (diff) | |
download | gtk+-b863097016027b191945b48acfb229c2e8656f3a.tar.gz |
Document the "orientation" option.
2007-07-02 Matthias Clasen <mclasen@redhat.com>
* gdk-pixbuf.c (gdk_pixbuf_get_option): Document the
"orientation" option.
* gdk-pixbuf.symbols:
* gdk-pixbuf-core.h:
* gdk-pixbuf-util.c (gdk_pixbuf_apply_embedded_orientation):
New function to handle Exif orientation information in
tiff and jpeg images. (#439567, Michael Chudobiak)
svn path=/trunk/; revision=18340
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf-util.c')
-rw-r--r-- | gdk-pixbuf/gdk-pixbuf-util.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-util.c b/gdk-pixbuf/gdk-pixbuf-util.c index c25576546c..aeee33dbee 100644 --- a/gdk-pixbuf/gdk-pixbuf-util.c +++ b/gdk-pixbuf/gdk-pixbuf-util.c @@ -245,6 +245,88 @@ gdk_pixbuf_saturate_and_pixelate(const GdkPixbuf *src, } } + +/** + * gdk_pixbuf_apply_embedded_orientation: + * @src: A #GdkPixbuf. + * + * Takes an existing pixbuf and checks for the presence of an + * associated "orientation" option, which may be provided by the + * jpeg loader (which reads the exif orientation tag) or the + * tiff loader (which reads the tiff orientation tag, and + * compensates it for the partial transforms performed by + * libtiff). If an orientation option/tag is present, the + * appropriate transform will be performed so that the pixbuf + * is oriented correctly. + * + * Return value: A newly-created pixbuf, or a reference to the + * input pixbuf (with an increased reference count). + * + * Since 2.12 + **/ +GdkPixbuf * +gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src) +{ + const gchar *orientation_string; + int transform = 0; + GdkPixbuf *temp; + GdkPixbuf *dest; + + g_return_val_if_fail (src != NULL, NULL); + + /* Read the orientation option associated with the pixbuf */ + orientation_string = gdk_pixbuf_get_option (src, "orientation"); + + if (orientation_string) { + /* If an orientation option was found, convert the + orientation string into an integer. */ + transform = (int) g_ascii_strtoll (orientation_string, NULL, 10); + } + + /* Apply the actual transforms, which involve rotations and flips. + The meaning of orientation values 1-8 and the required transforms + are defined by the TIFF and EXIF (for JPEGs) standards. */ + switch (transform) { + case 1: + dest = src; + g_object_ref (dest); + break; + case 2: + dest = gdk_pixbuf_flip (src, TRUE); + break; + case 3: + dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_UPSIDEDOWN); + break; + case 4: + dest = gdk_pixbuf_flip (src, FALSE); + break; + case 5: + temp = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE); + dest = gdk_pixbuf_flip (temp, TRUE); + g_object_unref (temp); + break; + case 6: + dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE); + break; + case 7: + temp = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE); + dest = gdk_pixbuf_flip (temp, FALSE); + g_object_unref (temp); + break; + case 8: + dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); + break; + default: + /* if no orientation tag was present */ + dest = src; + g_object_ref (dest); + break; + } + + return dest; +} + + #define __GDK_PIXBUF_UTIL_C__ #include "gdk-pixbuf-aliasdef.c" |