[maemo-commits] [maemo-commits] r18703 - in projects/haf/trunk/hildon-thumbnail: . daemon/plugins

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Jun 11 15:01:54 EEST 2009
Author: pvanhoof
Date: 2009-06-11 15:01:37 +0300 (Thu, 11 Jun 2009)
New Revision: 18703

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
Log:
2009-06-11  Philip Van Hoof  <philip at codeminded.be>

        * daemon/plugins/gdkpixbuf-plugin.c: Detect animated GIF, and block support
        for it




Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2009-06-11 10:51:38 UTC (rev 18702)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2009-06-11 12:01:37 UTC (rev 18703)
@@ -1,5 +1,10 @@
 2009-06-11  Philip Van Hoof  <philip at codeminded.be>
 
+	* daemon/plugins/gdkpixbuf-plugin.c: Detect animated GIF, and block support
+	for it
+
+2009-06-11  Philip Van Hoof  <philip at codeminded.be>
+
 	* thumbs/hildon-thumbnail-obj.c
 	* daemon/plugins/gdkpixbuf-plugin.c
 	* daemon/plugins/pixbuf-io-loader.c: Sanity checks

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2009-06-11 10:51:38 UTC (rev 18702)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2009-06-11 12:01:37 UTC (rev 18703)
@@ -110,6 +110,38 @@
 	return hildon_thumbnail_crop_resize (src, width, height);
 }
 
+static gboolean
+is_animated_gif (const gchar *filename)
+{
+	guint frame_count = 0;
+	FILE *gif_file = fopen (filename, "r");
+
+	if (gif_file) {
+		while (!feof (gif_file) && frame_count < 2) {
+			gchar buffer[1024];
+			size_t read;
+			size_t t;
+
+			read = fread (buffer, 1, 1024, gif_file);
+			for (t = 0; t < read; t++) {
+//				if (buffer[t]   == 0x00 && buffer[t+1] == 0x21 &&
+//				    buffer[t+2] == 0xF9 && buffer[t+3] == 0x04) {
+//					    frame_count++;
+//				}
+				if (buffer[t]   == 0x00 && buffer[t+1] == 0x2C) {
+					    frame_count++;
+				}
+
+			}
+		}
+
+		fclose (gif_file);
+	}
+
+	return (frame_count > 1);
+}
+
+
 void
 hildon_thumbnail_plugin_create (GStrv uris, gchar *mime_hint, GStrv *failed_uris, GError **error)
 {
@@ -131,33 +163,25 @@
 		guint width; guint height;
 		guint rowstride; 
 		gboolean err_file = FALSE;
-/*		gchar *path; */
+		gchar *path; 
 
 		file = g_file_new_for_uri (uri);
-/*
+
 		path = g_file_get_path (file);
 
 		if (path) {
 			gchar *up = g_utf8_strup (path, -1);
 			if (g_str_has_suffix (up, "GIF")) {
-				gchar buffer[16];
-				FILE *f = fopen (path, "r");
-				if (f) {
-					if (fread (buffer, 16, 1, f) == 1) {
-						guint w = 0, h = 0;
-						w |= buffer[6];
-						w |= buffer[7];
-						h |= buffer[8];
-						h |= buffer[9];
-						printf ("%dx%d\n", w, h);
-					}
-					fclose (f);
+				if (is_animated_gif (path)) {
+					g_set_error (&nerror, DEFAULT_ERROR, 0,
+						     "Animated GIF (%s) is not supported",
+						     uri);
 				}
 			}
+			g_free (path);
 			g_free (up);
-			g_free (path);
 		}
-*/
+		
 		info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED ","
 					        G_FILE_ATTRIBUTE_STANDARD_SIZE,
 					  G_FILE_QUERY_INFO_NONE,

More information about the maemo-commits mailing list