OSDN Git Service

Add Bluray support
[handbrake-jp/handbrake-jp-git.git] / gtk / src / icon_tools.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * icon_tools.c
4  * Copyright (C) John Stebbins 2008 <stebbins@stebbins>
5  * 
6  * icon_tools.c is free software.
7  * 
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)
11  * any later version.
12  * 
13  */
14 #include <glib.h>
15 #include <gdk-pixbuf/gdk-pixbuf.h>
16 #include <gdk-pixbuf/gdk-pixdata.h>
17 #include "icon_tools.h"
18
19 GdkPixbuf*
20 icon_deserialize(const guint8 *sd, guint len)
21 {
22         GdkPixdata pd;
23         GdkPixbuf *pb;
24         GError *err = NULL;
25
26         gdk_pixdata_deserialize(&pd, len, sd, &err);
27         pb = gdk_pixbuf_from_pixdata(&pd, TRUE, &err);
28         return pb;
29 }
30
31 guint8*
32 icon_serialize(const GdkPixbuf *pixbuf, guint *len)
33 {
34         GdkPixdata pd;
35         guint8 *sd;
36
37         gdk_pixdata_from_pixbuf(&pd, pixbuf, FALSE);
38         sd = gdk_pixdata_serialize(&pd, len);
39         return sd;
40 }
41
42 guint8*
43 icon_file_serialize(const gchar *filename, guint *len)
44 {
45         GdkPixbuf *pb;
46         GError *err = NULL;
47
48         pb = gdk_pixbuf_new_from_file(filename, &err);
49         if (pb == NULL)
50         {
51                 g_warning("Failed to open icon file %s: %s", filename, err->message);
52                 return NULL;
53         }
54         return icon_serialize(pb, len);
55 }
56
57 GdkPixbuf*
58 base64_to_icon(const gchar *bd)
59 {
60         guchar *sd;
61         gsize len;
62         GdkPixdata pd;
63         GdkPixbuf *pb;
64         GError *err = NULL;
65
66         sd = g_base64_decode(bd, &len);
67         gdk_pixdata_deserialize(&pd, len, sd, &err);
68         pb = gdk_pixbuf_from_pixdata(&pd, TRUE, &err);
69         g_free(sd);
70         return pb;
71 }
72
73 gchar*
74 icon_to_base64(const GdkPixbuf *pixbuf)
75 {
76         GdkPixdata pd;
77         guint len;
78         guint8 *sd;
79         gchar *bd;
80
81         gdk_pixdata_from_pixbuf(&pd, pixbuf, FALSE);
82         sd = gdk_pixdata_serialize(&pd, &len);
83         bd = g_base64_encode(sd, len);
84         g_free(sd);
85         return bd;
86 }
87
88 gchar*
89 icon_file_to_base64(const gchar *filename)
90 {
91         GdkPixbuf *pb;
92         GError *err = NULL;
93
94         pb = gdk_pixbuf_new_from_file(filename, &err);
95         if (pb == NULL)
96         {
97                 g_warning("Failed to open icon file %s: %s", filename, err->message);
98                 return NULL;
99         }
100         return icon_to_base64(pb);
101 }
102