gdk-pixbuf external conversion?



There are lots of image formats not handled by gdk-pixbuf at the moment,
many of which are handled by other things like imlib. IMVHO, there should be
the ability to call an external program to convert a file, then load the new
(temporary) file.

I have attached a patch for gdk-pixbuf-io.c that enable
that, with an example for the apple PICT format (using picttoppm), and a
pseudo image format that always loads a certain picture (ok, probably
useless, but it works anyway :)

I would *very* much like for this kind of ability (not neccesarily my
implementation) to be added, it would be very useful IMHO.

(Constructive) criticism of the patch is most welcome.
(but not my spelling :)

(the attached patch is also @ http://users.bigpond.com/mibus/gdk-pixbuf.patch
incase the patch doesnt 'stick' when its posted to the list.)

I would *really* like feedback on this.

mibus
-- 
Robert Mibus <mibus@bigpond.com>
Fast, cheap, reliable. Pick two.
--- gdk-pixbuf-io.c.orig	Thu Apr 13 10:10:28 2000
+++ gdk-pixbuf-io.c	Fri Jun 16 19:10:49 2000
@@ -29,6 +29,19 @@
 
 
 
+static char *pixbuf_conv_ext[] = 
+{
+".pic",
+".mib",
+0
+};
+static char *pixbuf_conv_cmd[] = 
+{
+"picttoppm",
+"cat /dose/pics/tux-large.jpg",
+0
+};
+
 static gboolean
 pixbuf_check_png (guchar *buffer, int size)
 {
@@ -412,15 +425,37 @@
 {
 	GdkPixbuf *pixbuf;
 	int size;
+	int i=0;
 	FILE *f;
 	guchar buffer [128];
 	GdkPixbufModule *image_module;
+	char *cmd=NULL;
+	char *temp_fn=NULL;
+	char *ext=NULL;
 
 	g_return_val_if_fail (filename != NULL, NULL);
 
 	f = fopen (filename, "r");
 	if (!f)
 		return NULL;
+	ext = strrchr(filename, '.');
+	if (ext)
+		while (pixbuf_conv_ext[i]) {
+		        if (!strcasecmp (ext, pixbuf_conv_ext[i])) {
+				temp_fn = strdup ("/tmp/gdk-pixbuf.XXXXXX");
+				mkstemp (temp_fn);
+		                cmd = (char *) malloc (sizeof(char) * (strlen ("(cat  |  >  ) >& /dev/null") + strlen (filename) + strlen (temp_fn) + strlen(pixbuf_conv_cmd[i])));
+		                sprintf (cmd, "(cat %s | %s > %s) >& /dev/null", filename, pixbuf_conv_cmd[i], temp_fn);
+		                system (cmd);
+		                fclose (f);
+		                f = fopen (temp_fn, "r");
+		                if (!f) {
+					unlink (temp_fn);
+		                        return NULL;
+				}
+	        	}
+			i++;
+		}
 
 	size = fread (&buffer, 1, sizeof (buffer), f);
 	if (size == 0) {
@@ -449,6 +484,9 @@
 
 	if (pixbuf)
 		g_assert (pixbuf->ref_count > 0);
+
+	if (temp_fn)
+		unlink (temp_fn);
 
 	return pixbuf;
 }

PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]