1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
Author: Goedson Teixeira Paixao <goedson@debian.org>
Description: Fix crash when saving in unsupported format
Check if the format chosen by the user is supported before trying to save.
Bug-Ubuntu: https://bugs.edge.launchpad.net/ubuntu/+source/gpaint/+bug/386234
Bug: https://savannah.gnu.org/bugs/?25334
Forwarded: https://savannah.gnu.org/patch/?7052
Index: b/src/drawing.c
===================================================================
--- a/src/drawing.c 2009-12-19 17:12:11.000000000 -0200
+++ b/src/drawing.c 2009-12-19 17:12:12.000000000 -0200
@@ -262,7 +262,7 @@
(error && error->message) ? error->message : "");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
- g_free(error); /* allocated by gdk-pixbuf library */
+ g_error_free(error); /* allocated by gdk-pixbuf library */
}
return saved;
}
Index: b/src/image.c
===================================================================
--- a/src/image.c 2009-12-19 17:12:11.000000000 -0200
+++ b/src/image.c 2009-12-19 17:12:12.000000000 -0200
@@ -32,6 +32,7 @@
#include <gdk/gdkx.h> /* for gdk_root_parent */
#include <gdk-pixbuf/gdk-pixbuf.h>
+#define _(String) gettext (String)
static int cmp_int(const void *a, const void *b);
static void fill_polygon(
@@ -191,13 +192,48 @@
return image;
}
+
+gboolean
+is_writable (GSList *formats, gchar *type)
+{
+ gboolean writable = FALSE;
+
+ while (!writable && formats != NULL)
+ {
+ gchar** extensions = gdk_pixbuf_format_get_extensions((GdkPixbufFormat *)(formats->data));
+ gchar** e = NULL;
+ for (e = extensions; *e; ++e)
+ {
+ if (!strcmp(*e, type))
+ {
+ writable = TRUE;
+ break;
+ }
+ }
+ g_strfreev (extensions);
+ formats = g_slist_next (formats);
+ }
+ return writable;
+}
+
+void add_if_writable (GdkPixbufFormat *data, GSList **list)
+{
+ if (gdk_pixbuf_format_is_writable (data))
+ *list = g_slist_prepend (*list, data);
+}
+
int
image_write(gpaint_image* image, const gchar* filename, GError **perror)
{
gboolean saved = FALSE;
gchar *ext = NULL;
gchar *type = NULL;
-
+
+ GSList *formats = gdk_pixbuf_get_formats ();
+ GSList *writable_formats = NULL;
+ g_slist_foreach (formats, add_if_writable, &writable_formats);
+ g_slist_free (formats);
+
ext = g_strrstr(filename, ".");
if (!ext)
{
@@ -214,13 +250,20 @@
{
type = g_ascii_strdown(ext+1,-1);
debug1("type=[%s]",type);
- saved = gdk_pixbuf_save(image->pixbuf, filename, type, perror, NULL);
+ if (is_writable (writable_formats, type))
+ {
+ saved = gdk_pixbuf_save(image->pixbuf, filename, type, perror, NULL);
+ } else {
+ saved = FALSE;
+ *perror = g_error_new (GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_BAD_OPTION, _("Saving in the '%s' format is not supported by gdk_pixbuf"), type);
+ }
g_free(type);
}
if (!saved && *perror)
{
g_warning("Could not save image %s: %s\n", filename, (*perror)->message);
- }
+ }
+ g_slist_free (writable_formats);
return saved;
}
|