[gnome-settings-daemon] wacom: Add gsd_wacom_oled_gdkpixbuf_to_base64 function



commit de0ba166de27b98c5da4d3b4c630bdd0727c343b
Author: Przemo Firszt <przemo firszt eu>
Date:   Sat May 18 22:53:41 2013 +0100

    wacom: Add gsd_wacom_oled_gdkpixbuf_to_base64 function
    
    Add function that encodes GdkPixbuf to base64 string. The returned
    string starts with MAGIC_BASE64 "base64:". The pixbuf has to be
    64x32 pixels otherwise function returns NULL. The function averages
    pixel value, so for grayscale GdkPixbuf there is no change and it
    should make color icons to look acceptable on wacom OLED screens.
    
    The function is not (yet) used.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700499

 plugins/wacom/gsd-wacom-oled.c |   41 ++++++++++++++++++++++++++++++++++++++++
 plugins/wacom/gsd-wacom-oled.h |    1 +
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/plugins/wacom/gsd-wacom-oled.c b/plugins/wacom/gsd-wacom-oled.c
index bdc2bcd..6b7c11c 100644
--- a/plugins/wacom/gsd-wacom-oled.c
+++ b/plugins/wacom/gsd-wacom-oled.c
@@ -174,6 +174,47 @@ oled_render_text (char   *label,
        cairo_surface_destroy (surface);
 }
 
+char *
+gsd_wacom_oled_gdkpixbuf_to_base64 (GdkPixbuf *pixbuf)
+{
+       int i, x, y, ch, rs;
+       guchar *pix, *p;
+       guchar *image;
+       guchar lo, hi;
+       char *base_string, *base64;
+
+       if (OLED_WIDTH != gdk_pixbuf_get_width (pixbuf))
+               return NULL;
+
+       if (OLED_HEIGHT != gdk_pixbuf_get_height (pixbuf))
+               return NULL;
+
+       ch = gdk_pixbuf_get_n_channels (pixbuf);
+       rs = gdk_pixbuf_get_rowstride (pixbuf);
+       pix = gdk_pixbuf_get_pixels (pixbuf);
+
+       image = g_malloc (MAX_IMAGE_SIZE);
+       i = 0;
+       for (y = 0; y < OLED_HEIGHT; y++) {
+               for (x = 0; x < (OLED_WIDTH / 2); x++) {
+                       p = pix + y * rs + 2 * x * ch;
+                       hi = 0xf0 & ((p[0] + p[1] + p[2])/ 3 * p[3] / 0xff);
+                       p = pix + y * rs + ((2 * x) + 1) * ch;
+                       lo = 0x0f & (((p[0] + p[1] + p[2])/ 3 * p[3] / 0xff) >> 4);
+                       image[i] = hi | lo;
+                       i++;
+               }
+       }
+
+       oled_scramble_icon (image);
+       base_string = g_base64_encode (image, MAX_IMAGE_SIZE);
+       base64 = g_strconcat (MAGIC_BASE64, base_string, NULL);
+       g_free (base_string);
+       g_free (image);
+
+       return base64;
+}
+
 static char *
 oled_encode_image (char *label)
 {
diff --git a/plugins/wacom/gsd-wacom-oled.h b/plugins/wacom/gsd-wacom-oled.h
index 1cdaf65..7ffa84b 100644
--- a/plugins/wacom/gsd-wacom-oled.h
+++ b/plugins/wacom/gsd-wacom-oled.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
 #define MAX_1ST_LINE_LEN       10                      /*Maximum number of characters in 1st line of OLED 
icon*/
 
 void set_oled (GsdWacomDevice *device, char *button_id, char *label);
+char *gsd_wacom_oled_gdkpixbuf_to_base64 (GdkPixbuf *pixbuf);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]