Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/epsilon

Dir     : e17/libs/epsilon/src/lib


Modified Files:
        Epsilon.c Epsilon_Plugin.h Makefile.am 


Log Message:


doesnt need imlib2 anymore - uses evas directly for thumbnailing (and remove
epeg - evas can do this too with load options).

===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/Epsilon.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -3 -r1.46 -r1.47
--- Epsilon.c   10 May 2008 04:53:20 -0000      1.46
+++ Epsilon.c   22 May 2008 03:36:25 -0000      1.47
@@ -60,7 +60,7 @@
 static char *epsilon_hash (const char *file);
 #ifdef HAVE_PNG_H
 static FILE *_epsilon_open_png_file_reading (const char *filename);
-static int _epsilon_png_write (const char *file, DATA32 * ptr,
+static int _epsilon_png_write (const char *file, unsigned int * ptr,
                               int tw, int th, int sw, int sh, char *imformat,
                               int mtime, char *uri);
 #endif
@@ -137,7 +137,7 @@
   char* type;
   DIR *dir;
   Epsilon_Plugin *plugin;
-  char plugin_path[1024];
+  char plugin_path[PATH_MAX];
 
   if (epsilon_init_count) return ++epsilon_init_count;
 
@@ -549,189 +549,151 @@
 int
 epsilon_generate (Epsilon * e)
 {
-  int iw, ih;
-  int tw, th;
-  char outfile[PATH_MAX];
-  const char* mime;
-  Epsilon_Plugin* plugin;
-
-#ifdef HAVE_EPEG_H
-  Epeg_Image *im;
-  Epeg_Thumbnail_Info info;
-  int len;
-#endif
-
-  if (!e || !e->src || !e->hash)
-    return (EPSILON_FAIL);
+   char buf[PATH_MAX], buf2[PATH_MAX], buf3[256], *ext = NULL;
+   Evas *evas = NULL, *evas_im = NULL;
+   Ecore_Evas *ee = NULL, *ee_im = NULL;
+   Evas_Object *im = NULL, *edje = NULL;
+   int ret = EPSILON_FAIL;
+   int iw, ih, alpha, ww, hh;
+   int *data = NULL;
+   struct stat filestatus;
+   time_t mtime = 0;
+   const char *mime = NULL;
+   Epsilon_Image *img_thm = NULL;
+   Epsilon_Plugin *plugin = NULL;
    
-  tw = e->tw;
-  th = e->th;
+   if (stat(e->src, &filestatus) != 0)
+     return ret;
    
-#ifdef HAVE_EPEG_H
-  len = strlen (e->src);
-  if ((len > 4) &&
-      !strcasecmp (&e->src[len - 3], "jpg") && (im = epeg_file_open (e->src)))
-    {
-      _epsilon_file_name(e->tw, e->hash, "jpg", outfile, sizeof(outfile));
-      epeg_thumbnail_comments_get (im, &info);
-      epeg_size_get (im, &iw, &ih);
-      if (iw > ih)
-       {
-         th = ((unsigned long) e->tw * ih) / iw;
-         if (th < 1) th = 1;
-       }
-      else
-       {
-         tw = ((unsigned long) e->th *  iw) / ih;
-         if (tw < 1) tw = 1;
-       }
-      epeg_decode_size_set (im, tw, th);
-      epeg_quality_set (im, 100);
-      epeg_thumbnail_comments_enable (im, 1);
-      epeg_file_output_set (im, outfile);
-      if (!epeg_encode (im))
-       {
-         epeg_close (im);
-         return (EPSILON_OK);
-       }
-      epeg_close (im);
-    }
-#endif
-  {
-    int mtime;
-    char uri[PATH_MAX];
-    char format[32];
-    struct stat filestatus;
-    int isedje = 0, len=0;
-    Imlib_Image tmp = NULL;
-    Imlib_Image src = NULL;
-    Ecore_Evas *ee = NULL;
-
-    if (stat (e->src, &filestatus) != 0)
-      return (EPSILON_FAIL);
-
-    mtime = filestatus.st_mtime;
-
-    len = strlen (e->src);
-
-   if (!evas_init()) return -1;
-   if (!ecore_init()) {
-     evas_shutdown ();
-     return -1;
-   }
-
-   if (!ecore_evas_init()) {
-     evas_shutdown ();
-     ecore_shutdown ();
-     return -1;
-    }
-
-    if ((len > 4) && (!strcmp (&e->src[len - 3], "edj")))
-      {
-       Evas *evas = NULL;
-       Evas_Object *edje = NULL;
-       const int *pixels;
-       int w, h;
-       edje_init ();
-       if (!e->key)
-         {
-           fprintf (stderr, "Key required for this file type! ERROR!!\n");
-           return (EPSILON_FAIL);
-         }
-
-       isedje = 1;
-       if (e->w > 0)
-         w = e->w;
-       else
-         w = e->tw;
-
-       if (e->h > 0)
-         h = e->h;
-       else
-         h = e->tw;
-
-       ee = ecore_evas_buffer_new (w, h);
-       if (ee)
+   mtime = filestatus.st_mtime;
+   evas_init();
+   ecore_init();
+   ecore_evas_init();
+   edje_init();
+   
+   edje_file_cache_set(0);
+   edje_collection_cache_set(0);
+   ee = ecore_evas_buffer_new(1, 1);
+   evas = ecore_evas_get(ee);
+   evas_image_cache_set(evas, 0);
+   evas_font_cache_set(evas, 0);
+   ww = 0;
+   hh = 0;
+   alpha = 1;
+   
+   ext = strrchr(e->src, '.');
+   if (ext)
+     {
+       mime = epsilon_mime_for_extension_get(ext + 1);
+       if ((plugin = ecore_hash_get(plugins_mime, mime)))
+         img_thm = (plugin->epsilon_generate_thumb)(e);
+     }
+   
+   if (img_thm)
+     {
+       iw = img_thm->w;
+       ih = img_thm->h;
+       im = evas_object_image_add(evas);
+       alpha = img_thm->alpha;
+       evas_object_image_alpha_set(im, alpha);
+       evas_object_image_size_set(im, iw, ih);
+       evas_object_image_data_set(im, img_thm->data);
+       evas_object_image_data_update_add(im, 0, 0, iw, ih);
+       if ((iw > 0) && (ih > 0))
          {
-           evas = ecore_evas_get (ee);
-           edje = edje_object_add (evas);
-           if (edje_object_file_set (edje, e->src, e->key))
-             {
-               evas_object_move (edje, 0, 0);
-               evas_object_resize (edje, w, h);
-               evas_object_show (edje);
-               edje_message_signal_process ();
-
-               pixels = ecore_evas_buffer_pixels_get (ee);
-               tmp = imlib_create_image_using_data (w, h, (DATA32 *) pixels);
-
-               imlib_context_set_image (tmp);
-               snprintf (format, sizeof(format), "image/edje");
-             }
-           else
-             {
-               ecore_evas_free(ee);
-               printf ("Cannot load file %s, group %s\n", e->src, e->key);
-               return (EPSILON_FAIL);
-             }
+            ww = e->tw;
+            hh = (e->tw * ih) / iw;
+            if (hh > e->th)
+              {
+                 hh = e->th;
+                 ww = (e->th * iw) / ih;
+              }
+            evas_object_image_fill_set(im, 0, 0, ww, hh);
          }
-       else
+       ret = EPSILON_OK;
+     }
+   else if ((ext) &&
+       (!strcasecmp(ext, ".edj")))
+     {
+       ww = e->tw;
+       hh = e->th;
+       im = ecore_evas_object_image_new(ee);
+       ee_im = evas_object_data_get(im, "Ecore_Evas");
+       evas_im = ecore_evas_get(ee_im);
+       evas_image_cache_set(evas_im, 0);
+       evas_font_cache_set(evas_im, 0);
+       evas_object_image_size_set(im, ww * 2, hh * 2);
+       evas_object_image_fill_set(im, 0, 0, ww, hh);
+       edje = edje_object_add(evas_im);
+       if ((edje_object_file_set(edje, e->src, "e/desktop/background")) ||
+           (edje_object_file_set(edje, e->src, "e/init/splash")) ||
+           (edje_object_file_set(edje, e->src, "icon")))
          {
-           fprintf (stderr, "Cannot create buffer canvas! ERROR!\n");
-           return (EPSILON_FAIL);
+            ret = EPSILON_OK;
+            evas_object_move(edje, 0, 0);
+            evas_object_resize(edje, ww * 2, hh * 2);
+            evas_object_show(edje);
          }
-      }
-
-   mime = epsilon_mime_for_extension_get( strrchr(e->src, '.')+1);  
-   if (  (plugin = ecore_hash_get(plugins_mime, mime)) ) {
-       tmp = (*plugin->epsilon_generate_thumb)(e);
-   } else {
-        if(!tmp)
-           tmp = imlib_load_image_immediately_without_cache (e->src);
-       imlib_context_set_image (tmp);
-       snprintf (format, sizeof(format), "image/%s", imlib_image_format ());
-      }
-
-#ifdef HAVE_PNG_H
-    if (tmp)
-      {
-       iw = imlib_image_get_width ();
-       ih = imlib_image_get_height ();
-       if (iw > ih)
+     }
+   else
+     {
+       im = evas_object_image_add(evas);
+       evas_object_image_load_size_set(im, e->tw, e->th);
+       evas_object_image_file_set(im, e->src, NULL);
+       if (evas_object_image_load_error_get(im) == EVAS_LOAD_ERROR_NONE)
+         ret = EPSILON_OK;
+       iw = 0; ih = 0;
+       evas_object_image_size_get(im, &iw, &ih);
+       alpha = evas_object_image_alpha_get(im);
+       if ((iw > 0) && (ih > 0))
          {
-            th = ((unsigned long) e->tw * ih) / iw;
-            if (th < 1) th = 1;
+            ww = e->tw;
+            hh = (e->tw * ih) / iw;
+            if (hh > e->th)
+              {
+                 hh = e->th;
+                 ww = (e->th * iw) / ih;
+              }
+            evas_object_image_fill_set(im, 0, 0, ww, hh);
          }
-       else
+     }
+   evas_object_move(im, 0, 0);
+   evas_object_resize(im, ww, hh);
+   ecore_evas_resize(ee, ww, hh);
+   evas_object_show(im);
+   if ((ret == EPSILON_OK) && (ww > 0))
+     {
+       data = (int *)ecore_evas_buffer_pixels_get(ee);
+       if (data)
          {
-            tw = ((unsigned long) e->th *  iw) / ih;
-            if (tw < 1) tw = 1;
+            snprintf(buf, sizeof(buf), "file://%s", e->src);
+            _epsilon_file_name(e->tw, 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;
+              }
          }
-       imlib_context_set_cliprect (0, 0, tw, th);
-       if ((src = imlib_create_cropped_scaled_image (0, 0, iw, ih, tw, th)))
-         {
-           imlib_free_image_and_decache ();
-           imlib_context_set_image (src);
-           imlib_image_set_has_alpha (1);
-           imlib_image_set_format ("argb");
-           snprintf (uri, sizeof(uri), "file://%s", e->src);
-           _epsilon_file_name(e->tw, e->hash, "png", outfile, sizeof(outfile));
-           if (!_epsilon_png_write (outfile,
-                                    imlib_image_get_data (), tw, th, iw, ih,
-                                    format, mtime, uri))
-             {
-               imlib_free_image_and_decache ();
-               if (ee) ecore_evas_free(ee);
-               return (EPSILON_OK);
-             }
-           imlib_free_image_and_decache ();
-         } 
-
-      } 
-#endif
-    if (ee) ecore_evas_free(ee);
-  }
-  return (EPSILON_FAIL);
+     }
+   if (edje) evas_object_del(edje);
+   if (ee_im) ecore_evas_free(ee_im);
+   else if (im) evas_object_del(im);
+   
+   if (img_thm)
+     {
+       free(img_thm->data);
+       free(img_thm);
+     }
+   
+   edje_shutdown();
+   ecore_evas_shutdown();
+   ecore_shutdown();
+   evas_shutdown();
+   return ret;
 }
 
 void
@@ -793,7 +755,7 @@
   strncpy(&tmpfile[_l-35],_buf,_ll+1); }
 
 static int
-_epsilon_png_write (const char *file, DATA32 * ptr, int tw, int th, int sw,
+_epsilon_png_write (const char *file, unsigned int * ptr, int tw, int th, int 
sw,
                    int sh, char *imformat, int mtime, char *uri)
 {
   FILE *fp = NULL;
@@ -801,7 +763,7 @@
   int i, j, k, has_alpha = 1, ret = 0;
 
 /*
-  DATA32      *ptr=NULL;
+  unsigned int      *ptr=NULL;
 */
   png_infop info_ptr;
   png_color_8 sig_bit;
===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/Epsilon_Plugin.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- Epsilon_Plugin.h    9 Jul 2007 16:10:36 -0000       1.1
+++ Epsilon_Plugin.h    22 May 2008 03:36:25 -0000      1.2
@@ -1,15 +1,22 @@
 #ifndef _EPSILON_PLUGIN_H_
 #define _EPSILON_PLUGIN_H_
 
-#include "Imlib2.h"
 #include "Ecore_Data.h"
 
+typedef struct _Epsilon_Image Epsilon_Image;
 typedef struct _Epsilon_Plugin Epsilon_Plugin;
 
+struct _Epsilon_Image
+{
+   int w, h;
+   int alpha;
+   void *data;
+};
+
 struct _Epsilon_Plugin
 {
   Ecore_List* mime_types;
-  Imlib_Image (*epsilon_generate_thumb)(Epsilon*);
+  Epsilon_Image *(*epsilon_generate_thumb)(Epsilon*);
 };
 
 #endif /* _EPSILON_PLUGIN_H_ */
===================================================================
RCS file: /cvs/e/e17/libs/epsilon/src/lib/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- Makefile.am 11 Nov 2007 10:11:19 -0000      1.14
+++ Makefile.am 22 May 2008 03:36:25 -0000      1.15
@@ -7,11 +7,9 @@
 -I$(top_srcdir)/src/include \
 -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
 -DPACKAGE_LIB_DIR=\""$(libdir)"\" \
[EMAIL PROTECTED]@ \
 @EVAS_CFLAGS@ \
 @ECORE_CFLAGS@ \
 @EDJE_CFLAGS@ \
[EMAIL PROTECTED]@ \
 @PNG_CFLAGS@
 
 lib_LTLIBRARIES      = libepsilon.la
@@ -23,6 +21,6 @@
 epsilon_thumb.c \
 $(top_srcdir)/src/common/epsilon_thumb_common.c
 
-libepsilon_la_LIBADD   = exiftags/libepsilon_exiftags.la @PNG_LIBS@ 
@EPEG_LIBS@ @EDJE_LIBS@ @ECORE_LIBS@ @EVAS_LIBS@ @IMLIB2_LIBS@
+libepsilon_la_LIBADD   = exiftags/libepsilon_exiftags.la @PNG_LIBS@ 
@EDJE_LIBS@ @ECORE_LIBS@ @EVAS_LIBS@
 libepsilon_la_DEPENDENCIES = ../config.h
 libepsilon_la_LDFLAGS      = -version-info @version_info@



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to