]> www.fi.muni.cz Git - evince.git/commitdiff
[libdocument] Add a function to invert colors of a GdkPibuf
authorJuanjo Marín <juanj.marin@juntadeandalucia.es>
Sun, 29 Nov 2009 14:30:48 +0000 (15:30 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 29 Nov 2009 14:30:48 +0000 (15:30 +0100)
See bgo#321823.

libdocument/ev-document-misc.c
libdocument/ev-document-misc.h

index 889e4a88d0a08e51e1d3c2b92530ea1469bbb3df..ced1ca11cb30b256ef4ac8da8048fb67cddc6eec 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ *  Copyright (C) 2009 Juanjo Marín <juanj.marin@juntadeandalucia.es>
  *  Copyright (c) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
  *  Copyright (C) 2000-2003 Marco Pesenti Gritti
  *
@@ -294,4 +295,33 @@ ev_document_misc_surface_rotate_and_scale (cairo_surface_t *surface,
 
        return new_surface;
 }
-       
+
+void
+ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf)
+{
+       guchar *data, *p;
+       guint   width, height, x, y, rowstride, n_channels;
+
+       n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+       g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
+       g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
+
+       /* First grab a pointer to the raw pixel data. */
+       data = gdk_pixbuf_get_pixels (pixbuf);
+
+       /* Find the number of bytes per row (could be padded). */
+       rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+
+       width = gdk_pixbuf_get_width (pixbuf);
+       height = gdk_pixbuf_get_height (pixbuf);
+       for (x = 0; x < width; x++) {
+               for (y = 0; y < height; y++) {
+                       /* Calculate pixel's offset into the data array. */
+                       p = data + x * n_channels + y * rowstride;
+                       /* Change the RGB values*/
+                       p[0] = 255 - p[0];
+                       p[1] = 255 - p[1];
+                       p[2] = 255 - p[2];
+               }
+       }
+}
index 5a2ea035d8d209cb8d19bea5872b8bd3256fd71e..47e3c41794180cf8f18953bb0f435ca754b42753 100644 (file)
@@ -51,6 +51,7 @@ cairo_surface_t *ev_document_misc_surface_rotate_and_scale (cairo_surface_t *sur
                                                            gint             dest_width,
                                                            gint             dest_height,
                                                            gint             dest_rotation);
+void            ev_document_misc_invert_pixbuf  (GdkPixbuf       *pixbuf);
 
 G_END_DECLS