summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-xpm.c
diff options
context:
space:
mode:
authorMatthias Clasen <matthiasc@src.gnome.org>2002-04-11 21:18:40 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2002-04-11 21:18:40 +0000
commit693951085158842b584cfb7289e5ad75d7d6600a (patch)
treecd98c146d4acb69ddc8cb837ba04b2f6f4af386f /gdk-pixbuf/io-xpm.c
parente60568a1da1c38da1793e9eab1364d0c8ddb6fa9 (diff)
downloadgdk-pixbuf-693951085158842b584cfb7289e5ad75d7d6600a.tar.gz
More fixes for #77807:
* io-tga.c (get_contiguous_pixbuf): Helper function to create a pixbuf with a contiguous pixel array while being careful about overflow. * io-tga.c (fill_in_context, get_image_pseudocolor, get_image_truecolor, get_image_grayscale): Use get_contiguous_pixbuf instead of manually allocating image storage. * io-xpm.c (pixbuf_create_from_xpm): * io-pnm.c (gdk_pixbuf__pnm_image_load): * io-jpeg.c (gdk_pixbuf__jpeg_image_load): Use gdk_pixbuf_new instead of manually allocating image storage.
Diffstat (limited to 'gdk-pixbuf/io-xpm.c')
-rw-r--r--gdk-pixbuf/io-xpm.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/gdk-pixbuf/io-xpm.c b/gdk-pixbuf/io-xpm.c
index 2e6e33aae..3f0472989 100644
--- a/gdk-pixbuf/io-xpm.c
+++ b/gdk-pixbuf/io-xpm.c
@@ -1203,13 +1203,6 @@ mem_buffer (enum buf_op op, gpointer handle)
return NULL;
}
-/* Destroy notification function for the pixbuf */
-static void
-free_buffer (guchar *pixels, gpointer data)
-{
- g_free (pixels);
-}
-
/* This function does all the work. */
static GdkPixbuf *
pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handle), gpointer handle,
@@ -1223,7 +1216,8 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
gchar pixel_str[32];
GHashTable *color_hash;
XPMColor *colors, *color, *fallbackcolor;
- guchar *pixels, *pixtmp;
+ guchar *pixtmp;
+ GdkPixbuf *pixbuf;
fallbackcolor = NULL;
@@ -1314,12 +1308,9 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
fallbackcolor = color;
}
- if (is_trans)
- pixels = g_try_malloc (w * h * 4);
- else
- pixels = g_try_malloc (w * h * 3);
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, is_trans, 8, w, h);
- if (!pixels) {
+ if (!pixbuf) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
@@ -1331,7 +1322,7 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
}
wbytes = w * cpp;
- pixtmp = pixels;
+ pixtmp = pixbuf->pixels;
for (ycnt = 0; ycnt < h; ycnt++) {
buffer = (*get_buf) (op_body, handle);
@@ -1364,9 +1355,7 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
g_free (colors);
g_free (name_buf);
- return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, is_trans, 8,
- w, h, is_trans ? (w * 4) : (w * 3),
- free_buffer, NULL);
+ return pixbuf;
}
/* Shared library entry point for file loading */