diff options
author | Juanjo Marín <juanj.marin@juntadeandalucia.es> | 2009-11-29 14:30:48 (GMT) |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2009-11-29 14:30:48 (GMT) |
commit | d461d1ef4316a8f4320e38415af50ab80666703d (patch) | |
tree | 13eb98b437d8020e120e9d634f603cf198644f86 | |
parent | 033f94dd47cb9f3fdcc26b5464391cdef7790b18 (diff) |
[libdocument] Add a function to invert colors of a GdkPibuf
See bgo#321823.
-rw-r--r-- | libdocument/ev-document-misc.c | 32 | ||||
-rw-r--r-- | libdocument/ev-document-misc.h | 1 |
2 files changed, 32 insertions, 1 deletions
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index 889e4a8..ced1ca1 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -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]; + } + } +} diff --git a/libdocument/ev-document-misc.h b/libdocument/ev-document-misc.h index 5a2ea03..47e3c41 100644 --- a/libdocument/ev-document-misc.h +++ b/libdocument/ev-document-misc.h @@ -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 |