Okay here it is, this patch adds the possibility to epsilon to create
thumbnails in jpg format. The thumbnails are saved in FDO naming
convention, just with ending .jpg. Would be glad if you could give me
some feedback so this could eventually be included in svn. Patch works
for me, but there are some things to mention:

- default behaviour is like before, BUT epsilon_exists will also find
jpg thumbs, so epsilon_thumb_file_get will return the jpg and
epsilon_info_get will return nothing as the jpg contains no exif
infos.

- I don't know what happens in those HAVE_EPEG_H parts, only tested
without epeg.

- new function epsilon_format_set which allows to set format to jpeg.

- also changed epsilon_thumbd and added function
epsilon_request_add_advanced which can also set format (and in the
future hopefully custom sizes).

- changed epsilon_thumb_test to accept the arguments -large and -jpg
to request thumbnails with these options.

>From my test the jpg output is at least two times as fast on my laptop
and at least five times on the the freerunner. Also the resulting
files are 10-20% the size of png thumbnails.
Index: src/include/Epsilon_Request.h
===================================================================
--- src/include/Epsilon_Request.h	(Revision 35888)
+++ src/include/Epsilon_Request.h	(Arbeitskopie)
@@ -18,6 +18,7 @@
 {
 	unsigned int   id;       /**< Identifier for this thumbnail */
 	unsigned int   size;     /**< Thumbnail size to be generated */
+	unsigned int   format;   /**< Thumbnail format to be generated */
 	unsigned int   status;   /**< Status code of the thumbnail generation */
 	char          *path;     /**< Path to file requiring thumbnail */
 	char          *dest;     /**< Path to generated file, NULL on error */
@@ -30,6 +31,8 @@
 EAPI int              epsilon_request_init(void);
 EAPI int              epsilon_request_shutdown(void);
 EAPI Epsilon_Request *epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data);
+EAPI Epsilon_Request *epsilon_request_add_advanced(const char *path, Epsilon_Thumb_Size size,
+						   Epsilon_Thumb_Format format, void *data);
 EAPI void             epsilon_request_del(Epsilon_Request *thumb);
 
 #ifdef __cplusplus
Index: src/include/epsilon_private.h
===================================================================
--- src/include/epsilon_private.h	(Revision 35888)
+++ src/include/epsilon_private.h	(Arbeitskopie)
@@ -28,6 +28,7 @@
 	unsigned int status;
 	unsigned int thumbsize;
 	unsigned int bufsize;
+	unsigned int thumbformat;
 };
 
 typedef struct Epsilon_Ipc_End Epsilon_Ipc_End;
Index: src/lib/Epsilon.h
===================================================================
--- src/lib/Epsilon.h	(Revision 35888)
+++ src/lib/Epsilon.h	(Arbeitskopie)
@@ -43,6 +43,7 @@
   int w, h;
   int tw, th;
   int tsize;
+  int format;
 };
 typedef struct _Epsilon Epsilon;
 
@@ -64,6 +65,14 @@
 
 typedef enum _Epsilon_Thumb_Size Epsilon_Thumb_Size;
 
+enum _Epsilon_Thumb_Format
+{
+   EPSILON_THUMB_FDO,
+   EPSILON_THUMB_JPEG
+};
+
+typedef enum _Epsilon_Thumb_Format Epsilon_Thumb_Format;
+
 EAPI int epsilon_init (void);
 
 /* construct destruct */
@@ -74,6 +83,8 @@
 EAPI void epsilon_key_set (Epsilon * e, const char *key);
 /* Set the resolution*/
 EAPI void epsilon_resolution_set (Epsilon * e, int w, int h);
+/* Set the thumbnail format */
+EAPI void epsilon_format_set (Epsilon * e, Epsilon_Thumb_Format f);
 
 /*
  * the source filename
Index: src/lib/epsilon_thumb.c
===================================================================
--- src/lib/epsilon_thumb.c	(Revision 35888)
+++ src/lib/epsilon_thumb.c	(Arbeitskopie)
@@ -306,12 +306,14 @@
 /**
  * @param path Path to the original image that will be thumbnailed.
  * @param size Enum determining the scale of the thumbnail.
+ * @param size Enum determining the format of the thumbnail.
  * @param data Data associated with this thumbnail for client use.
  * @brief Request a thumbnail to be generated asynchronously for the specified
  * @a path.
  */
 Epsilon_Request *
-epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data)
+epsilon_request_add_advanced(const char *path, Epsilon_Thumb_Size size,
+			     Epsilon_Thumb_Format format, void *data)
 {
 	Epsilon_Request *thumb;
 
@@ -333,6 +335,7 @@
 	}
 	thumb->size = size;
 	thumb->data = data;
+	thumb->format = format;
 	if (epsilon_request_resolve_thumb_file(thumb)) {
 		thumb->status = 1;
 		epsilon_event_inform_done(thumb);
@@ -342,6 +345,7 @@
 		msg = epsilon_message_new(epsilon_mid++, path, 0);
 		if (msg) {
 			msg->thumbsize = size;
+			msg->thumbformat = format;
 			if (debug) printf("!! requesting thumbnail for %s (request %d)!!, %d\n", path, msg->mid, sizeof(Epsilon_Message)+msg->bufsize);
 			if (ecore_ipc_server_send(epsilon_server, 1,1,1,1,1,msg,sizeof(Epsilon_Message)+msg->bufsize)) {
 				thumb->id = msg->mid;
@@ -358,6 +362,19 @@
 }
 
 /**
+ * @param path Path to the original image that will be thumbnailed.
+ * @param size Enum determining the scale of the thumbnail.
+ * @param data Data associated with this thumbnail for client use.
+ * @brief Request a thumbnail to be generated asynchronously for the specified
+ * @a path.
+ */
+Epsilon_Request *
+epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data)
+{
+	return epsilon_request_add_advanced(path, size, EPSILON_THUMB_FDO, data);
+}
+
+/**
  * @param thumb Thumbnail request to delete.
  * @brief Request a thumbnail request to be cancelled.
  */
Index: src/lib/Epsilon.c
===================================================================
--- src/lib/Epsilon.c	(Revision 35888)
+++ src/lib/Epsilon.c	(Arbeitskopie)
@@ -67,6 +67,8 @@
 			       int tw, int th, int sw, int sh, char *imformat,
 			       int mtime, char *uri);
 #endif
+static int _epsilon_jpg_write (const char *file, unsigned int * ptr,
+			       Evas_Object *eo, int w, int h);
 
 Epsilon *
 epsilon_new (const char *file)
@@ -80,6 +82,7 @@
 	  result->src = strdup (file);
 	  result->tw = THUMB_SIZE_LARGE;
 	  result->th = THUMB_SIZE_LARGE;
+	  result->format = EPSILON_THUMB_FDO;
 	}
       else
 	{
@@ -217,6 +220,13 @@
     }
 }
 
+void
+epsilon_format_set (Epsilon * e, Epsilon_Thumb_Format f)
+{
+  if (e && (f == EPSILON_THUMB_FDO || f == EPSILON_THUMB_JPEG))
+    e->format = f;
+}
+
 const char *
 epsilon_file_get (Epsilon * e)
 {
@@ -236,13 +246,12 @@
     return (NULL);
   if (e->thumb)
     return (e->thumb);
-#ifdef HAVE_EPEG_H
+
   if (_epsilon_exists_ext(e, "jpg", buf, sizeof(buf), &mtime))
     {
        e->thumb = strdup(buf);
        return (e->thumb);
     }
-#endif
 #ifdef HAVE_PNG_H
   if (_epsilon_exists_ext(e, "png", buf, sizeof(buf), &mtime))
     {
@@ -390,6 +399,9 @@
       fclose (fp);
 #endif
     }
+  else
+     return NULL;
+
   if ((p->eei = epsilon_exif_info_get (e)))
     {
       if (p->w == 0)
@@ -527,7 +539,6 @@
   if (!e->hash)
     return (EPSILON_FAIL);
 
-#ifdef HAVE_EPEG_H
   if (!ok)
     {
        char path[PATH_MAX];
@@ -538,7 +549,6 @@
 	  /* XXX compare with time from e->src exif tag? */
        }
     }
-#endif
 #ifdef HAVE_PNG_H
   if (!ok)
     {
@@ -681,16 +691,28 @@
 	if (data)
 	  {
 	     snprintf(buf, sizeof(buf), "file://%s", e->src);
-	     _epsilon_file_name(e->tsize, e->hash, "png", buf2, sizeof(buf2));
-	     /* this is wrong - but hey! good enough? */
-	     if (ext) snprintf(buf3, sizeof(buf3), "image/%s", ext);
-	     else snprintf(buf3, sizeof(buf3), "image/png");
-	     if (_epsilon_png_write(buf2,
-				    data, ww, hh, iw, ih,
-				    buf3, mtime, buf))
+	     if (e->format == EPSILON_THUMB_FDO)
 	       {
-		  ret = EPSILON_FAIL;
-	       }
+	        _epsilon_file_name(e->tsize, e->hash, "png", buf2, sizeof(buf2));
+	        /* this is wrong - but hey! good enough? */
+	        if (ext) snprintf(buf3, sizeof(buf3), "image/%s", ext);
+	        else snprintf(buf3, sizeof(buf3), "image/png");
+	        if (_epsilon_png_write(buf2,
+				       data, ww, hh, iw, ih,
+				       buf3, mtime, buf))
+	          {
+		     ret = EPSILON_FAIL;
+	          }
+               }
+	     else
+	     {
+		  _epsilon_file_name(e->tsize, e->hash, "jpg", buf2, sizeof(buf2));
+	          if (_epsilon_jpg_write(buf2,
+					 data, im, ww, hh))
+		    {
+		       ret = EPSILON_FAIL;
+		    }
+	     }
 	  }
      }
    if (edje) evas_object_del(edje);
@@ -943,3 +965,32 @@
   return (ret);
 }
 #endif
+
+static int
+_epsilon_jpg_write (const char *file, unsigned int * ptr, Evas_Object *eo, int w, int h)
+{
+  char tmpfile[PATH_MAX] = "";
+
+  int l,ll;
+  char buf[21];
+  l=snprintf(tmpfile,sizeof(tmpfile),"%s",file);
+  ll=snprintf(buf,sizeof(buf),"epsilon-%06d.jpg",(int)getpid());
+  strncpy(&tmpfile[l-35], buf,ll+1);
+
+  evas_object_image_data_set(eo, NULL);
+  evas_object_image_size_set(eo, w, h);
+  evas_object_image_data_set(eo, ptr);
+
+  if (!evas_object_image_save(eo, tmpfile, NULL, NULL))
+    return 1;
+
+  if (!rename (tmpfile, file))
+    {
+       if (chmod (file, S_IWUSR | S_IRUSR))
+	 fprintf (stderr,
+		  "epsilon: could not set permissions on \"%s\"!?\n",
+		  file);
+    }
+
+  return 0;
+}
Index: src/bin/epsilon_thumb_test.c
===================================================================
--- src/bin/epsilon_thumb_test.c	(Revision 35888)
+++ src/bin/epsilon_thumb_test.c	(Arbeitskopie)
@@ -36,9 +36,12 @@
 	char *file;
 	Ecore_List *files;
 	double start, end;
+	Epsilon_Thumb_Size thumb_size = EPSILON_THUMB_NORMAL;
+	Epsilon_Thumb_Format thumb_format = EPSILON_THUMB_FDO;
+	int i;
 
 	if (argc < 2) {
-		printf ("Usage: epsilon_thumb_test <directory path>\n");
+		printf ("Usage: epsilon_thumb_test [-large] [-jpg] <directory path>\n");
 		exit(0);
 	}
 
@@ -46,13 +49,17 @@
 
 	thumb_done = ecore_event_handler_add(EPSILON_EVENT_DONE, thumb_complete_cb, NULL);
 
-	if (!ecore_file_is_dir(argv[1])) {
+	if (!ecore_file_is_dir(argv[argc - 1])) {
 		printf("Need a directory\n");
 		exit(-1);
 	}
 
-	files = ecore_file_ls(argv[1]);
+	for(i=1;i<argc;i++)
+		if (!strcmp(argv[i], "-large")) thumb_size = EPSILON_THUMB_LARGE;
+		else if (!strcmp(argv[i], "-jpg")) thumb_format = EPSILON_THUMB_LARGE;
 
+	files = ecore_file_ls(argv[argc - 1]);
+
 	start = ecore_time_get();
 
 	ecore_list_first_goto(files);
@@ -60,10 +67,10 @@
 		char *realpath;
 		char fullpath[PATH_MAX];
 
-		snprintf(fullpath, PATH_MAX, "%s/%s", argv[1], file);
+		snprintf(fullpath, PATH_MAX, "%s/%s", argv[argc - 1], file);
 		realpath = ecore_file_realpath(fullpath);
 		if (ecore_file_exists(realpath) && !ecore_file_is_dir(realpath)) {
-			epsilon_request_add(realpath, EPSILON_THUMB_NORMAL, NULL);
+			epsilon_request_add_advanced(realpath, thumb_size, thumb_format, NULL);
 			incomplete_thumbs++;
 		}
 		free(realpath);
Index: src/bin/epsilon_thumbd.c
===================================================================
--- src/bin/epsilon_thumbd.c	(Revision 35888)
+++ src/bin/epsilon_thumbd.c	(Arbeitskopie)
@@ -497,6 +497,7 @@
 		path = ((char *)msg + sizeof(Epsilon_Message));
 		ep = epsilon_new(path);
 		epsilon_thumb_size(ep, msg->thumbsize);
+		epsilon_format_set(ep, msg->thumbformat);
 		if (debug) printf("Thumbnailing %d: %s\n", msg->mid, path);
 
 		/*
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to