summaryrefslogtreecommitdiffstats
path: root/gtk/src/icon_tools.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2008-09-09 23:14:28 +0000
committerjstebbins <[email protected]>2008-09-09 23:14:28 +0000
commite57d4d0bf36c3b5d4691134d0fdb8171cb25f843 (patch)
treead4dddfe057558ad5cd8fd5c02eb1d156079c709 /gtk/src/icon_tools.c
parentebf4b4d663b9eeeed5d9632b5a2076355cff7145 (diff)
LinGui: consolidate all resources into one stringified plist file that gets
compiled in. icons and everyting all rolled up into one ball-o-wax. hehe, plists are cool git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1685 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/icon_tools.c')
-rw-r--r--gtk/src/icon_tools.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/gtk/src/icon_tools.c b/gtk/src/icon_tools.c
new file mode 100644
index 000000000..b63640bbe
--- /dev/null
+++ b/gtk/src/icon_tools.c
@@ -0,0 +1,102 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * icon_tools.c
+ * Copyright (C) John Stebbins 2008 <stebbins@stebbins>
+ *
+ * icon_tools.c is free software.
+ *
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk-pixbuf/gdk-pixdata.h>
+#include "icon_tools.h"
+
+GdkPixbuf*
+icon_deserialize(const guint8 *sd, guint len)
+{
+ GdkPixdata pd;
+ GdkPixbuf *pb;
+ GError *err = NULL;
+
+ gdk_pixdata_deserialize(&pd, len, sd, &err);
+ pb = gdk_pixbuf_from_pixdata(&pd, TRUE, &err);
+ return pb;
+}
+
+guint8*
+icon_serialize(const GdkPixbuf *pixbuf, guint *len)
+{
+ GdkPixdata pd;
+ guint8 *sd;
+
+ gdk_pixdata_from_pixbuf(&pd, pixbuf, FALSE);
+ sd = gdk_pixdata_serialize(&pd, len);
+ return sd;
+}
+
+guint8*
+icon_file_serialize(const gchar *filename, guint *len)
+{
+ GdkPixbuf *pb;
+ GError *err = NULL;
+
+ pb = gdk_pixbuf_new_from_file(filename, &err);
+ if (pb == NULL)
+ {
+ g_warning("Failed to open icon file %s: %s", filename, err->message);
+ return NULL;
+ }
+ return icon_serialize(pb, len);
+}
+
+GdkPixbuf*
+base64_to_icon(const gchar *bd)
+{
+ guchar *sd;
+ gsize len;
+ GdkPixdata pd;
+ GdkPixbuf *pb;
+ GError *err = NULL;
+
+ sd = g_base64_decode(bd, &len);
+ gdk_pixdata_deserialize(&pd, len, sd, &err);
+ pb = gdk_pixbuf_from_pixdata(&pd, TRUE, &err);
+ g_free(sd);
+ return pb;
+}
+
+gchar*
+icon_to_base64(const GdkPixbuf *pixbuf)
+{
+ GdkPixdata pd;
+ guint len;
+ guint8 *sd;
+ gchar *bd;
+
+ gdk_pixdata_from_pixbuf(&pd, pixbuf, FALSE);
+ sd = gdk_pixdata_serialize(&pd, &len);
+ bd = g_base64_encode(sd, len);
+ g_free(sd);
+ return bd;
+}
+
+gchar*
+icon_file_to_base64(const gchar *filename)
+{
+ GdkPixbuf *pb;
+ GError *err = NULL;
+
+ pb = gdk_pixbuf_new_from_file(filename, &err);
+ if (pb == NULL)
+ {
+ g_warning("Failed to open icon file %s: %s", filename, err->message);
+ return NULL;
+ }
+ return icon_to_base64(pb);
+}
+