4 * A.k.a `Best web-album Of the world, Or your money back, Humerus'.
6 * The acronyn sucks, however this is a tribute to Dragon Ball by
7 * Akira Toriyama, where the last enemy beaten by heroes of Dragon
8 * Ball is named "Boo". But there was already a free software project
9 * called Boo, so this one will be it "Booh". Or whatever.
12 * Copyright (c) 2005 Guillaume Cottenceau
14 * This software may be freely redistributed under the terms of the GNU
15 * public license version 2.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define GDK_PIXBUF_ENABLE_BACKEND
26 #include <gdk-pixbuf/gdk-pixbuf.h>
27 #include <gdk-pixbuf/gdk-pixdata.h>
28 #include "rbgobject.h"
30 #define _SELF(s) GDK_PIXBUF(RVAL2GOBJ(s))
32 #include <libexif/exif-data.h>
35 whitebalance(self, level)
38 double red_filter[256], blue_filter[256];
40 guchar* pixels = gdk_pixbuf_get_pixels(_SELF(self));
41 int rowstride = gdk_pixbuf_get_rowstride(_SELF(self));
43 double factor = 1 + fabs(NUM2DBL(level))/100;
44 if (NUM2DBL(level) < 0) {
48 for (i = 0; i < 256; i++) {
49 red_filter[i] = pow(((double)i)/255, 1/factor) * 255;
50 blue_filter[i] = pow(((double)i)/255, factor) * 255;
53 for (y = 0; y < gdk_pixbuf_get_height(_SELF(self)); y++) {
54 guchar* pixline = &(pixels[rowstride*y]);
55 for (x = 0; x < gdk_pixbuf_get_width(_SELF(self)); x++) {
56 pixline[x*3] = red_filter[pixline[x*3]];
57 pixline[x*3+2] = blue_filter[pixline[x*3+2]];
65 gammacorrect(self, level)
70 guchar* pixels = gdk_pixbuf_get_pixels(_SELF(self));
71 int rowstride = gdk_pixbuf_get_rowstride(_SELF(self));
73 double factor = 1 + fabs(NUM2DBL(level))/100;
74 if (NUM2DBL(level) > 0) {
78 for (i = 0; i < 256; i++) {
79 filter[i] = pow(((double)i)/255, factor) * 255;
82 for (y = 0; y < gdk_pixbuf_get_height(_SELF(self)); y++) {
83 guchar* pixline = &(pixels[rowstride*y]);
84 for (x = 0; x < gdk_pixbuf_get_width(_SELF(self)); x++) {
85 pixline[x*3] = filter[pixline[x*3]];
86 pixline[x*3+1] = filter[pixline[x*3+1]];
87 pixline[x*3+2] = filter[pixline[x*3+2]];
94 static VALUE exif_orientation(VALUE module, VALUE filename) {
99 data = exif_data_new_from_file(StringValuePtr(filename));
101 fprintf(stderr, "libexif failed loading file '%s'\n", StringValuePtr(filename));
105 for (i = 0; i < EXIF_IFD_COUNT; i++) {
106 ExifEntry* entry = exif_content_get_entry(data->ifd[i], EXIF_TAG_ORIENTATION);
110 if (!entry || !entry->parent || !entry->parent->parent)
112 o = exif_data_get_byte_order(entry->parent->parent);
113 v_short = exif_get_short(entry->data, o);
114 ret = INT2NUM(v_short);
119 exif_data_free(data);
127 RGObjClassInfo* cinfo = (RGObjClassInfo*)rbgobj_lookup_class_by_gtype(GDK_TYPE_PIXBUF, Qnil);
128 rb_define_method(cinfo->klass, "whitebalance!", whitebalance, 1);
129 rb_define_method(cinfo->klass, "gammacorrect!", gammacorrect, 1);
131 VALUE exif = rb_define_module("Exif");
132 rb_define_module_function(exif, "orientation", exif_orientation, 1);