From: Juanjo Marín Date: Sun, 29 Nov 2009 14:30:48 +0000 (+0100) Subject: [libdocument] Add a function to invert colors of a GdkPibuf X-Git-Tag: EVINCE_2_29_3~17 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=d461d1ef4316a8f4320e38415af50ab80666703d;p=evince.git [libdocument] Add a function to invert colors of a GdkPibuf See bgo#321823. --- diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index 889e4a88..ced1ca11 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009 Juanjo Marín * Copyright (c) 2007 Carlos Garcia Campos * 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 5a2ea035..47e3c417 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