1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008-2011 <stebbins@stebbins>
6 * icon_tools.c is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
15 #include <gdk-pixbuf/gdk-pixbuf.h>
16 #include <gdk-pixbuf/gdk-pixdata.h>
17 #include "icon_tools.h"
20 icon_deserialize(const guint8 *sd, guint len)
26 gdk_pixdata_deserialize(&pd, len, sd, &err);
27 pb = gdk_pixbuf_from_pixdata(&pd, TRUE, &err);
32 icon_serialize(const GdkPixbuf *pixbuf, guint *len)
37 gdk_pixdata_from_pixbuf(&pd, pixbuf, FALSE);
38 sd = gdk_pixdata_serialize(&pd, len);
43 icon_file_serialize(const gchar *filename, guint *len)
48 pb = gdk_pixbuf_new_from_file(filename, &err);
51 g_warning("Failed to open icon file %s: %s", filename, err->message);
54 return icon_serialize(pb, len);
58 base64_to_icon(const gchar *bd)
66 sd = g_base64_decode(bd, &len);
67 gdk_pixdata_deserialize(&pd, len, sd, &err);
68 pb = gdk_pixbuf_from_pixdata(&pd, TRUE, &err);
74 icon_to_base64(const GdkPixbuf *pixbuf)
81 gdk_pixdata_from_pixbuf(&pd, pixbuf, FALSE);
82 sd = gdk_pixdata_serialize(&pd, &len);
83 bd = g_base64_encode(sd, len);
89 icon_file_to_base64(const gchar *filename)
94 pb = gdk_pixbuf_new_from_file(filename, &err);
97 g_warning("Failed to open icon file %s: %s", filename, err->message);
100 return icon_to_base64(pb);