2009-03-30 14:22:52 -07:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 by ProFUSION embedded systems
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* @author Rafael Antognolli <antognolli@profusion.mobi>
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-11-01 13:55:15 -08:00
|
|
|
|
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
# include <alloca.h>
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
#elif defined _AIX
|
|
|
|
# define alloca __alloca
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# include <malloc.h>
|
|
|
|
# define alloca _alloca
|
|
|
|
#else
|
|
|
|
# include <stddef.h>
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
# endif
|
|
|
|
void *alloca (size_t);
|
|
|
|
#endif
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2009-04-17 16:33:45 -07:00
|
|
|
#include <sys/types.h>
|
2009-04-21 16:11:37 -07:00
|
|
|
#include <sys/stat.h>
|
2009-04-17 16:33:45 -07:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <dlfcn.h>
|
2009-11-06 14:17:55 -08:00
|
|
|
#include <ctype.h>
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
#ifndef PATH_MAX
|
2009-11-01 13:55:15 -08:00
|
|
|
# define PATH_MAX 4096
|
2009-03-30 14:22:52 -07:00
|
|
|
#endif
|
|
|
|
|
2009-11-01 13:55:15 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
#include <eina_safety_checks.h>
|
2009-03-30 14:22:52 -07:00
|
|
|
#include <Evas.h>
|
2009-11-01 13:55:15 -08:00
|
|
|
#include <Ecore.h>
|
2009-03-30 14:22:52 -07:00
|
|
|
#include <Ecore_Evas.h>
|
|
|
|
#include <Ecore_File.h>
|
|
|
|
#include <Edje.h>
|
|
|
|
|
2009-11-01 13:55:15 -08:00
|
|
|
#include "Ethumb.h"
|
|
|
|
#include "ethumb_private.h"
|
|
|
|
#include "Ethumb_Plugin.h"
|
|
|
|
#include "md5.h"
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
static int _log_dom = -1;
|
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_log_dom, __VA_ARGS__)
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
|
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(_log_dom, __VA_ARGS__)
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__)
|
2009-04-13 15:26:23 -07:00
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
static int initcount = 0;
|
2009-04-13 15:34:13 -07:00
|
|
|
static const char *_home_thumb_dir = NULL;
|
|
|
|
static const char *_thumb_category_normal = NULL;
|
|
|
|
static const char *_thumb_category_large = NULL;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
static const int THUMB_SIZE_NORMAL = 128;
|
|
|
|
static const int THUMB_SIZE_LARGE = 256;
|
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
static Eina_Hash *_plugins_ext = NULL;
|
2009-04-25 14:48:49 -07:00
|
|
|
static Eina_Array *_plugins = NULL;
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-25 14:48:49 -07:00
|
|
|
static Eina_Bool
|
2009-07-16 14:49:14 -07:00
|
|
|
_ethumb_plugin_list_cb(Eina_Module *m, void *data __UNUSED__)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-04-25 14:48:49 -07:00
|
|
|
const char *file;
|
|
|
|
const char **ext;
|
|
|
|
Ethumb_Plugin *plugin;
|
|
|
|
Ethumb_Plugin *(*plugin_get)(void);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-07-16 15:53:38 -07:00
|
|
|
file = eina_module_file_get(m);
|
2009-04-25 14:48:49 -07:00
|
|
|
if (!eina_module_load(m))
|
2009-07-16 15:53:38 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not load module \"%s\": %s",
|
2009-07-16 15:53:38 -07:00
|
|
|
file, eina_error_msg_get(eina_error_get()));
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-25 14:48:49 -07:00
|
|
|
plugin_get = eina_module_symbol_get(m, "ethumb_plugin_get");
|
|
|
|
if (!plugin_get)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not find ethumb_plugin_get() in module \"%s\": %s",
|
2009-07-16 15:53:38 -07:00
|
|
|
file, eina_error_msg_get(eina_error_get()));
|
2009-04-25 14:48:49 -07:00
|
|
|
eina_module_unload(m);
|
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-04-25 14:48:49 -07:00
|
|
|
plugin = plugin_get();
|
|
|
|
if (!plugin)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("plugin \"%s\" failed to init.", file);
|
2009-04-25 14:48:49 -07:00
|
|
|
eina_module_unload(m);
|
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 07:31:29 -07:00
|
|
|
DBG("loaded plugin \"%s\" (%p) with extensions:", file, plugin);
|
2009-04-25 14:48:49 -07:00
|
|
|
for (ext = plugin->extensions; *ext; ext++)
|
2009-07-16 15:53:38 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
DBG(" extension \"%s\"", *ext);
|
2009-07-16 15:53:38 -07:00
|
|
|
eina_hash_add(_plugins_ext, *ext, plugin);
|
|
|
|
}
|
2009-04-25 14:48:49 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_plugins_load(void)
|
|
|
|
{
|
|
|
|
_plugins_ext = eina_hash_string_small_new(NULL);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(_plugins_ext);
|
|
|
|
|
2009-04-25 14:48:49 -07:00
|
|
|
_plugins = eina_module_list_get(_plugins, PLUGINSDIR, 1,
|
|
|
|
&_ethumb_plugin_list_cb, NULL);
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_plugins_unload(void)
|
|
|
|
{
|
|
|
|
eina_hash_free(_plugins_ext);
|
|
|
|
_plugins_ext = NULL;
|
2009-04-25 14:48:49 -07:00
|
|
|
eina_module_list_unload(_plugins);
|
2010-01-08 04:22:23 -08:00
|
|
|
eina_module_list_free(_plugins);
|
2009-05-18 14:37:09 -07:00
|
|
|
eina_array_free(_plugins);
|
2009-04-25 14:48:49 -07:00
|
|
|
_plugins = NULL;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
EAPI int
|
|
|
|
ethumb_init(void)
|
|
|
|
{
|
2009-04-13 15:34:13 -07:00
|
|
|
const char *home;
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
if (initcount)
|
|
|
|
return ++initcount;
|
|
|
|
|
2009-09-06 15:23:04 -07:00
|
|
|
if (!eina_init())
|
2009-09-04 12:27:12 -07:00
|
|
|
{
|
2009-09-06 15:23:04 -07:00
|
|
|
fprintf(stderr, "ERROR: Could not initialize eina.\n");
|
2009-09-04 12:27:12 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
_log_dom = eina_log_domain_register("ethumb", EINA_COLOR_GREEN);
|
|
|
|
if (_log_dom < 0)
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not register log domain: ethumb");
|
2009-09-06 15:23:04 -07:00
|
|
|
eina_shutdown();
|
2009-09-04 12:27:12 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
evas_init();
|
|
|
|
ecore_init();
|
|
|
|
ecore_evas_init();
|
|
|
|
edje_init();
|
|
|
|
|
2009-04-13 15:34:13 -07:00
|
|
|
home = getenv("HOME");
|
|
|
|
snprintf(buf, sizeof(buf), "%s/.thumbnails", home);
|
|
|
|
|
|
|
|
_home_thumb_dir = eina_stringshare_add(buf);
|
|
|
|
_thumb_category_normal = eina_stringshare_add("normal");
|
|
|
|
_thumb_category_large = eina_stringshare_add("large");
|
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
_ethumb_plugins_load();
|
2009-03-30 14:22:52 -07:00
|
|
|
return ++initcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
ethumb_shutdown(void)
|
|
|
|
{
|
|
|
|
initcount--;
|
|
|
|
if (initcount == 0)
|
|
|
|
{
|
2009-04-17 16:33:45 -07:00
|
|
|
_ethumb_plugins_unload();
|
2009-04-13 15:34:13 -07:00
|
|
|
eina_stringshare_del(_home_thumb_dir);
|
|
|
|
eina_stringshare_del(_thumb_category_normal);
|
|
|
|
eina_stringshare_del(_thumb_category_large);
|
2009-04-13 15:32:49 -07:00
|
|
|
evas_shutdown();
|
|
|
|
ecore_shutdown();
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
edje_shutdown();
|
2009-09-04 12:27:12 -07:00
|
|
|
eina_log_domain_unregister(_log_dom);
|
|
|
|
_log_dom = -1;
|
2009-09-06 15:23:04 -07:00
|
|
|
eina_shutdown();
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return initcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Ethumb *
|
|
|
|
ethumb_new(void)
|
|
|
|
{
|
|
|
|
Ethumb *ethumb;
|
|
|
|
Ecore_Evas *ee, *sub_ee;
|
|
|
|
Evas *e, *sub_e;
|
|
|
|
Evas_Object *o, *img;
|
|
|
|
|
|
|
|
ethumb = calloc(1, sizeof(Ethumb));
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(ethumb, NULL);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-09-17 07:05:04 -07:00
|
|
|
/* IF CHANGED, UPDATE DOCS in (Ethumb.c, Ethumb_Client.c, python...)!!! */
|
2009-03-30 14:22:52 -07:00
|
|
|
ethumb->tw = THUMB_SIZE_NORMAL;
|
|
|
|
ethumb->th = THUMB_SIZE_NORMAL;
|
|
|
|
ethumb->crop_x = 0.5;
|
|
|
|
ethumb->crop_y = 0.5;
|
2009-07-09 12:16:02 -07:00
|
|
|
ethumb->quality = 80;
|
|
|
|
ethumb->compress = 9;
|
2009-07-13 12:38:17 -07:00
|
|
|
ethumb->video.start = 0.1;
|
|
|
|
ethumb->video.time = 3;
|
|
|
|
ethumb->video.interval = 0.05;
|
|
|
|
ethumb->video.ntimes = 3;
|
|
|
|
ethumb->video.fps = 10;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
ee = ecore_evas_buffer_new(1, 1);
|
|
|
|
e = ecore_evas_get(ee);
|
|
|
|
if (!e)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not create ecore evas buffer");
|
2009-03-30 14:22:52 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
evas_image_cache_set(e, 0);
|
|
|
|
evas_font_cache_set(e, 0);
|
|
|
|
|
|
|
|
o = ecore_evas_object_image_new(ee);
|
|
|
|
if (!o)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not create sub ecore evas buffer");
|
2009-03-30 14:22:52 -07:00
|
|
|
ecore_evas_free(ee);
|
|
|
|
free(ethumb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_ee = evas_object_data_get(o, "Ecore_Evas");
|
|
|
|
sub_e = ecore_evas_get(sub_ee);
|
|
|
|
|
|
|
|
evas_image_cache_set(sub_e, 0);
|
|
|
|
evas_font_cache_set(sub_e, 0);
|
|
|
|
|
|
|
|
img = evas_object_image_add(sub_e);
|
|
|
|
if (!img)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not create source objects.");
|
2009-03-30 14:22:52 -07:00
|
|
|
ecore_evas_free(ee);
|
|
|
|
free(ethumb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ethumb->ee = ee;
|
|
|
|
ethumb->e = e;
|
|
|
|
ethumb->sub_ee = sub_ee;
|
|
|
|
ethumb->sub_e = sub_e;
|
|
|
|
ethumb->o = o;
|
|
|
|
ethumb->img = img;
|
|
|
|
|
2009-09-17 07:31:29 -07:00
|
|
|
DBG("ethumb=%p", ethumb);
|
2009-09-04 12:27:12 -07:00
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
return ethumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_frame_free(Ethumb_Frame *frame)
|
|
|
|
{
|
|
|
|
Evas_Object *o;
|
|
|
|
|
|
|
|
if (!frame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (frame->swallow && frame->edje)
|
2009-05-18 14:37:09 -07:00
|
|
|
{
|
2009-03-30 14:22:52 -07:00
|
|
|
o = edje_object_part_swallow_get(frame->edje, frame->swallow);
|
2009-05-18 14:37:09 -07:00
|
|
|
if (o)
|
|
|
|
edje_object_part_unswallow(frame->edje, o);
|
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
eina_stringshare_del(frame->file);
|
|
|
|
eina_stringshare_del(frame->group);
|
|
|
|
eina_stringshare_del(frame->swallow);
|
|
|
|
|
|
|
|
if (frame->edje)
|
|
|
|
evas_object_del(frame->edje);
|
|
|
|
|
|
|
|
free(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_free(Ethumb *ethumb)
|
|
|
|
{
|
2009-04-24 11:53:11 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(ethumb);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p", ethumb);
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
if (ethumb->frame)
|
|
|
|
_ethumb_frame_free(ethumb->frame);
|
2009-04-24 11:53:11 -07:00
|
|
|
ethumb_file_free(ethumb);
|
2010-07-02 22:29:31 -07:00
|
|
|
ecore_evas_free(ethumb->o);
|
2009-03-30 14:22:52 -07:00
|
|
|
ecore_evas_free(ethumb->ee);
|
2010-07-02 22:29:31 -07:00
|
|
|
ecore_evas_free(ethumb->sub_ee);
|
2009-03-30 14:22:52 -07:00
|
|
|
eina_stringshare_del(ethumb->thumb_dir);
|
|
|
|
eina_stringshare_del(ethumb->category);
|
2009-04-17 16:33:45 -07:00
|
|
|
if (ethumb->finished_idler)
|
|
|
|
ecore_idler_del(ethumb->finished_idler);
|
2009-03-30 14:22:52 -07:00
|
|
|
free(ethumb);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
2009-04-21 16:10:04 -07:00
|
|
|
ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_FDO_Size s)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(s == ETHUMB_THUMB_NORMAL ||
|
|
|
|
s == ETHUMB_THUMB_LARGE);
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, size=%d", e, s);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
if (s == ETHUMB_THUMB_NORMAL)
|
|
|
|
{
|
|
|
|
e->tw = THUMB_SIZE_NORMAL;
|
|
|
|
e->th = THUMB_SIZE_NORMAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->tw = THUMB_SIZE_LARGE;
|
|
|
|
e->th = THUMB_SIZE_LARGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
e->format = ETHUMB_THUMB_FDO;
|
|
|
|
e->aspect = ETHUMB_THUMB_KEEP_ASPECT;
|
|
|
|
_ethumb_frame_free(e->frame);
|
|
|
|
e->frame = NULL;
|
|
|
|
eina_stringshare_del(e->thumb_dir);
|
|
|
|
eina_stringshare_del(e->category);
|
|
|
|
e->thumb_dir = NULL;
|
|
|
|
e->category = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_size_set(Ethumb *e, int tw, int th)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(tw > 0);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(th > 0);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, w=%d, h=%d", e, tw, th);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->tw = tw;
|
|
|
|
e->th = th;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_size_get(const Ethumb *e, int *tw, int *th)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
if (tw) *tw = e->tw;
|
|
|
|
if (th) *th = e->th;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_format_set(Ethumb *e, Ethumb_Thumb_Format f)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(f == ETHUMB_THUMB_FDO ||
|
2009-07-09 12:47:51 -07:00
|
|
|
f == ETHUMB_THUMB_JPEG ||
|
|
|
|
f == ETHUMB_THUMB_EET);
|
2009-04-13 15:29:39 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, format=%d", e, f);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->format = f;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Ethumb_Thumb_Format
|
|
|
|
ethumb_thumb_format_get(const Ethumb *e)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
return e->format;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_aspect_set(Ethumb *e, Ethumb_Thumb_Aspect a)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(a == ETHUMB_THUMB_KEEP_ASPECT ||
|
|
|
|
a == ETHUMB_THUMB_IGNORE_ASPECT ||
|
|
|
|
a == ETHUMB_THUMB_CROP);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, aspect=%d", e, a);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->aspect = a;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Ethumb_Thumb_Aspect
|
|
|
|
ethumb_thumb_aspect_get(const Ethumb *e)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
return e->aspect;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_crop_align_set(Ethumb *e, float x, float y)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, x=%f, y=%f", e, x, y);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->crop_x = x;
|
|
|
|
e->crop_y = y;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
2009-05-19 04:54:35 -07:00
|
|
|
ethumb_thumb_crop_align_get(const Ethumb *e, float *x, float *y)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
if (x) *x = e->crop_x;
|
|
|
|
if (y) *y = e->crop_y;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-07-09 12:16:02 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_quality_set(Ethumb *e, int quality)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, quality=%d", e, quality);
|
2009-07-09 12:16:02 -07:00
|
|
|
e->quality = quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
ethumb_thumb_quality_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
return e->quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_compress_set(Ethumb *e, int compress)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, compress=%d", e, compress);
|
2009-07-09 12:16:02 -07:00
|
|
|
e->compress = compress;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
ethumb_thumb_compress_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
return e->compress;
|
|
|
|
}
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
EAPI Eina_Bool
|
2009-03-30 14:22:52 -07:00
|
|
|
ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const char *swallow)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
Ethumb_Frame *frame;
|
|
|
|
frame = e->frame;
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, theme_file=%s, group=%s, swallow=%s",
|
|
|
|
e, theme_file ? theme_file : "", group ? group : "",
|
|
|
|
swallow ? swallow : "");
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
if (frame)
|
2009-05-18 14:38:20 -07:00
|
|
|
{
|
|
|
|
edje_object_part_unswallow(frame->edje, e->img);
|
|
|
|
if (!theme_file)
|
|
|
|
_ethumb_frame_free(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!theme_file)
|
|
|
|
{
|
|
|
|
e->frame = NULL;
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-05-18 14:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
|
|
|
frame = calloc(1, sizeof(Ethumb_Frame));
|
|
|
|
if (!frame)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not allocate Ethumb_Frame structure.");
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
frame->edje = edje_object_add(e->sub_e);
|
|
|
|
if (!frame->edje)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not create edje frame object.");
|
2009-03-30 14:22:52 -07:00
|
|
|
_ethumb_frame_free(frame);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->frame = NULL;
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!edje_object_file_set(frame->edje, theme_file, group))
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not load frame theme.");
|
2009-03-30 14:22:52 -07:00
|
|
|
_ethumb_frame_free(frame);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->frame = NULL;
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
edje_object_part_swallow(frame->edje, swallow, e->img);
|
|
|
|
if (!edje_object_part_swallow_get(frame->edje, swallow))
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not swallow image to edje frame.");
|
2009-03-30 14:22:52 -07:00
|
|
|
_ethumb_frame_free(frame);
|
2009-04-13 15:29:39 -07:00
|
|
|
e->frame = NULL;
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-04-13 15:30:32 -07:00
|
|
|
eina_stringshare_replace(&frame->file, theme_file);
|
|
|
|
eina_stringshare_replace(&frame->group, group);
|
|
|
|
eina_stringshare_replace(&frame->swallow, swallow);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
e->frame = frame;
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-05-18 14:26:56 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_frame_get(const Ethumb *e, const char **theme_file, const char **group, const char **swallow)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
if (e->frame)
|
|
|
|
{
|
|
|
|
if (theme_file) *theme_file = e->frame->file;
|
|
|
|
if (group) *group = e->frame->group;
|
|
|
|
if (swallow) *swallow = e->frame->swallow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (theme_file) *theme_file = NULL;
|
|
|
|
if (group) *group = NULL;
|
|
|
|
if (swallow) *swallow = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-26 13:33:58 -07:00
|
|
|
static const char *
|
2009-09-17 07:05:04 -07:00
|
|
|
_ethumb_build_absolute_path(const char *path, char buf[PATH_MAX])
|
2009-05-26 13:33:58 -07:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
|
|
|
|
if (path[0] == '/')
|
|
|
|
strcpy(p, path);
|
|
|
|
else if (path[0] == '~')
|
|
|
|
{
|
2009-09-17 07:05:04 -07:00
|
|
|
const char *home = getenv("HOME");
|
|
|
|
if (!home)
|
|
|
|
return NULL;
|
|
|
|
strcpy(p, home);
|
2009-05-26 13:33:58 -07:00
|
|
|
len = strlen(p);
|
|
|
|
p += len;
|
|
|
|
p[0] = '/';
|
|
|
|
p++;
|
|
|
|
strcpy(p, path + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-17 07:05:04 -07:00
|
|
|
if (!getcwd(p, PATH_MAX))
|
|
|
|
return NULL;
|
2009-05-26 13:33:58 -07:00
|
|
|
len = strlen(p);
|
|
|
|
p += len;
|
|
|
|
p[0] = '/';
|
|
|
|
p++;
|
|
|
|
strcpy(p, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_dir_path_set(Ethumb *e, const char *path)
|
|
|
|
{
|
2009-05-26 13:33:58 -07:00
|
|
|
char buf[PATH_MAX];
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, path=%s", e, path ? path : "");
|
2009-05-26 13:33:58 -07:00
|
|
|
path = _ethumb_build_absolute_path(path, buf);
|
2009-04-13 15:30:32 -07:00
|
|
|
eina_stringshare_replace(&e->thumb_dir, path);
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const char *
|
2009-05-19 04:54:35 -07:00
|
|
|
ethumb_thumb_dir_path_get(const Ethumb *e)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
return e->thumb_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_category_set(Ethumb *e, const char *category)
|
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, category=%s", e, category ? category : "");
|
2009-04-13 15:30:32 -07:00
|
|
|
eina_stringshare_replace(&e->category, category);
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const char *
|
2009-05-19 04:54:35 -07:00
|
|
|
ethumb_thumb_category_get(const Ethumb *e)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
return e->category;
|
|
|
|
}
|
|
|
|
|
2009-07-13 12:38:17 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_video_start_set(Ethumb *e, float start)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-09-17 07:05:04 -07:00
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(start >= 0.0);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(start <= 1.0);
|
2009-07-13 12:38:17 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, video_start=%f", e, start);
|
2009-07-13 12:38:17 -07:00
|
|
|
e->video.start = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI float
|
|
|
|
ethumb_video_start_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
|
|
|
|
return e->video.start;
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_video_time_set(Ethumb *e, float time)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, video_start=%f", e, time);
|
2009-04-17 16:33:45 -07:00
|
|
|
e->video.time = time;
|
|
|
|
}
|
|
|
|
|
2009-05-18 14:26:56 -07:00
|
|
|
EAPI float
|
|
|
|
ethumb_video_time_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
|
|
|
|
return e->video.time;
|
|
|
|
}
|
|
|
|
|
2009-07-13 12:38:17 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_video_interval_set(Ethumb *e, float interval)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, video_interval=%f", e, interval);
|
2009-07-13 12:38:17 -07:00
|
|
|
e->video.interval = interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI float
|
|
|
|
ethumb_video_interval_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
|
|
|
|
return e->video.interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
2009-09-17 07:05:04 -07:00
|
|
|
ethumb_video_ntimes_set(Ethumb *e, unsigned int ntimes)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-09-17 07:05:04 -07:00
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(ntimes > 0);
|
2009-07-13 12:38:17 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, video_ntimes=%d", e, ntimes);
|
2009-07-13 12:38:17 -07:00
|
|
|
e->video.ntimes = ntimes;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:05:04 -07:00
|
|
|
EAPI unsigned int
|
2009-07-13 12:38:17 -07:00
|
|
|
ethumb_video_ntimes_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
|
|
|
|
return e->video.ntimes;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
2009-09-17 07:05:04 -07:00
|
|
|
ethumb_video_fps_set(Ethumb *e, unsigned int fps)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-09-17 07:05:04 -07:00
|
|
|
EINA_SAFETY_ON_FALSE_RETURN(fps > 0);
|
2009-07-13 12:38:17 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, video_fps=%d", e, fps);
|
2009-07-13 12:38:17 -07:00
|
|
|
e->video.fps = fps;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:05:04 -07:00
|
|
|
EAPI unsigned int
|
2009-07-13 12:38:17 -07:00
|
|
|
ethumb_video_fps_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
|
|
|
|
return e->video.fps;
|
|
|
|
}
|
|
|
|
|
2009-04-21 16:03:50 -07:00
|
|
|
EAPI void
|
2009-09-17 07:05:04 -07:00
|
|
|
ethumb_document_page_set(Ethumb *e, unsigned int page)
|
2009-04-21 16:03:50 -07:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, document_page=%d", e, page);
|
2009-04-21 16:03:50 -07:00
|
|
|
e->document.page = page;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:05:04 -07:00
|
|
|
EAPI unsigned int
|
2009-05-18 14:26:56 -07:00
|
|
|
ethumb_document_page_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
|
|
|
|
return e->document.page;
|
|
|
|
}
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
EAPI Eina_Bool
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_file_set(Ethumb *e, const char *path, const char *key)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-05-26 13:33:58 -07:00
|
|
|
char buf[PATH_MAX];
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, path=%s, key=%s", e, path ? path : "", key ? key : "");
|
2009-04-21 16:11:37 -07:00
|
|
|
if (path && access(path, R_OK))
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("couldn't access file \"%s\"", path);
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-05-26 13:33:58 -07:00
|
|
|
path = _ethumb_build_absolute_path(path, buf);
|
2009-04-21 16:11:37 -07:00
|
|
|
eina_stringshare_replace(&e->src_path, path);
|
|
|
|
eina_stringshare_replace(&e->src_key, key);
|
|
|
|
eina_stringshare_replace(&e->thumb_path, NULL);
|
|
|
|
eina_stringshare_replace(&e->thumb_key, NULL);
|
2009-04-14 12:14:08 -07:00
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-04-24 11:53:11 -07:00
|
|
|
EAPI void
|
2009-05-19 04:54:35 -07:00
|
|
|
ethumb_file_get(const Ethumb *e, const char **path, const char **key)
|
2009-04-24 11:53:11 -07:00
|
|
|
{
|
2009-04-24 14:02:40 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-04-24 11:53:11 -07:00
|
|
|
|
|
|
|
if (path) *path = e->src_path;
|
|
|
|
if (key) *key = e->src_key;
|
|
|
|
}
|
|
|
|
|
2009-07-14 21:18:05 -07:00
|
|
|
static const char ACCEPTABLE_URI_CHARS[96] = {
|
|
|
|
/* ! " # $ % & ' ( ) * + , - . / */
|
|
|
|
0x00,0x3F,0x20,0x20,0x28,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x2A,0x28,0x3F,0x3F,0x1C,
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
|
|
|
|
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x20,
|
|
|
|
/* @ A B C D E F G H I J K L M N O */
|
|
|
|
0x38,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
|
|
|
|
/* P Q R S T U V W X Y Z [ \ ] ^ _ */
|
|
|
|
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
|
|
|
|
/* ` a b c d e f g h i j k l m n o */
|
|
|
|
0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
|
|
|
|
/* p q r s t u v w x y z { | } ~ DEL */
|
|
|
|
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20
|
|
|
|
};
|
2009-04-24 11:53:11 -07:00
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
static const char *
|
|
|
|
_ethumb_generate_hash(const char *file)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
MD5_CTX ctx;
|
|
|
|
char md5out[(2 * MD5_HASHBYTES) + 1];
|
|
|
|
unsigned char hash[MD5_HASHBYTES];
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
|
|
|
|
2009-07-14 21:18:05 -07:00
|
|
|
char *uri;
|
|
|
|
char *t;
|
2009-07-16 14:49:14 -07:00
|
|
|
const unsigned char *c;
|
2009-07-14 21:18:05 -07:00
|
|
|
|
|
|
|
#define _check_uri_char(c) \
|
|
|
|
((c) >= 32 && (c) < 128 && (ACCEPTABLE_URI_CHARS[(c) - 32] & 0x08))
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:29:39 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
2009-07-14 21:18:05 -07:00
|
|
|
|
|
|
|
uri = alloca(3 * strlen(file) + 9);
|
2009-09-17 11:37:22 -07:00
|
|
|
memcpy(uri, "file://", sizeof("file://") - 1);
|
|
|
|
t = uri + sizeof("file://") - 1;
|
2009-07-14 21:18:05 -07:00
|
|
|
|
2009-07-16 14:49:14 -07:00
|
|
|
for (c = (const unsigned char *)file; *c != '\0'; c++)
|
2009-07-14 21:18:05 -07:00
|
|
|
{
|
|
|
|
if (!_check_uri_char(*c))
|
|
|
|
{
|
|
|
|
*t++ = '%';
|
|
|
|
*t++ = hex[*c >> 4];
|
|
|
|
*t++ = hex[*c & 15];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*t++ = *c;
|
|
|
|
}
|
|
|
|
*t = '\0';
|
|
|
|
|
|
|
|
#undef _check_uri_char
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
MD5Init (&ctx);
|
|
|
|
MD5Update (&ctx, (unsigned char const*)uri, (unsigned)strlen (uri));
|
|
|
|
MD5Final (hash, &ctx);
|
|
|
|
|
|
|
|
for (n = 0; n < MD5_HASHBYTES; n++)
|
|
|
|
{
|
|
|
|
md5out[2 * n] = hex[hash[n] >> 4];
|
|
|
|
md5out[2 * n + 1] = hex[hash[n] & 0x0f];
|
|
|
|
}
|
|
|
|
md5out[2 * n] = '\0';
|
2009-09-04 12:27:12 -07:00
|
|
|
|
2009-09-17 07:31:29 -07:00
|
|
|
DBG("md5=%s, file=%s", md5out, file);
|
2009-03-30 14:22:52 -07:00
|
|
|
return eina_stringshare_add(md5out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_ethumb_file_check_fdo(Ethumb *e)
|
|
|
|
{
|
|
|
|
if (!((e->tw == THUMB_SIZE_NORMAL && e->th == THUMB_SIZE_NORMAL) ||
|
|
|
|
(e->tw == THUMB_SIZE_LARGE && e->th == THUMB_SIZE_LARGE)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (e->format != ETHUMB_THUMB_FDO)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (e->aspect != ETHUMB_THUMB_KEEP_ASPECT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (e->frame)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2009-04-21 16:08:17 -07:00
|
|
|
_ethumb_file_generate_custom_category(Ethumb *e)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
const char *aspect, *format;
|
|
|
|
const char *frame;
|
|
|
|
|
|
|
|
if (e->aspect == ETHUMB_THUMB_KEEP_ASPECT)
|
2009-04-13 15:34:13 -07:00
|
|
|
aspect = "keep_aspect";
|
2009-03-30 14:22:52 -07:00
|
|
|
else if (e->aspect == ETHUMB_THUMB_IGNORE_ASPECT)
|
2009-04-13 15:34:13 -07:00
|
|
|
aspect = "ignore_aspect";
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
2009-04-13 15:34:13 -07:00
|
|
|
aspect = "crop";
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
if (e->format == ETHUMB_THUMB_FDO)
|
2009-04-13 15:34:13 -07:00
|
|
|
format = "png";
|
2009-07-09 12:47:51 -07:00
|
|
|
else if (e->format == ETHUMB_THUMB_JPEG)
|
2009-04-13 15:34:13 -07:00
|
|
|
format = "jpg";
|
2009-07-09 12:47:51 -07:00
|
|
|
else
|
|
|
|
format = "eet";
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
if (e->frame)
|
2009-04-13 15:34:13 -07:00
|
|
|
frame = "-framed";
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
2009-04-13 15:34:13 -07:00
|
|
|
frame = "";
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%dx%d-%s%s-%s",
|
|
|
|
e->tw, e->th, aspect, frame, format);
|
|
|
|
|
|
|
|
return eina_stringshare_add(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-21 16:08:17 -07:00
|
|
|
_ethumb_file_generate_path(Ethumb *e)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
char *fullname;
|
|
|
|
const char *hash;
|
|
|
|
const char *thumb_dir, *category;
|
|
|
|
const char *ext;
|
|
|
|
int fdo_format;
|
|
|
|
|
|
|
|
|
|
|
|
fdo_format = _ethumb_file_check_fdo(e);
|
|
|
|
|
|
|
|
if (e->thumb_dir)
|
2009-04-13 15:34:13 -07:00
|
|
|
thumb_dir = eina_stringshare_ref(e->thumb_dir);
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
2009-04-13 15:34:13 -07:00
|
|
|
thumb_dir = eina_stringshare_ref(_home_thumb_dir);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
if (e->category)
|
2009-04-13 15:34:13 -07:00
|
|
|
category = eina_stringshare_ref(e->category);
|
2009-03-30 14:22:52 -07:00
|
|
|
else if (!fdo_format)
|
2009-04-21 16:08:17 -07:00
|
|
|
category = _ethumb_file_generate_custom_category(e);
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e->tw == THUMB_SIZE_NORMAL)
|
2009-04-13 15:34:13 -07:00
|
|
|
category = eina_stringshare_ref(_thumb_category_normal);
|
2009-03-30 14:22:52 -07:00
|
|
|
else if (e->tw == THUMB_SIZE_LARGE)
|
2009-04-13 15:34:13 -07:00
|
|
|
category = eina_stringshare_ref(_thumb_category_large);
|
2010-03-01 16:34:40 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("fdo_format but size %d is not NORMAL (%d) or LARGE (%d)?",
|
|
|
|
e->tw, THUMB_SIZE_NORMAL, THUMB_SIZE_LARGE);
|
|
|
|
category = "unknown";
|
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e->format == ETHUMB_THUMB_FDO)
|
2009-04-13 15:34:13 -07:00
|
|
|
ext = "png";
|
2009-07-09 12:47:51 -07:00
|
|
|
else if (e->format == ETHUMB_THUMB_JPEG)
|
2009-04-13 15:34:13 -07:00
|
|
|
ext = "jpg";
|
2009-07-09 12:47:51 -07:00
|
|
|
else
|
|
|
|
ext = "eet";
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
fullname = ecore_file_realpath(e->src_path);
|
2009-03-30 14:22:52 -07:00
|
|
|
hash = _ethumb_generate_hash(fullname);
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s.%s", thumb_dir, category, hash, ext);
|
|
|
|
free(fullname);
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, path=%s", e, buf);
|
2009-04-21 16:08:17 -07:00
|
|
|
eina_stringshare_replace(&e->thumb_path, buf);
|
2009-07-09 12:47:51 -07:00
|
|
|
if (e->format == ETHUMB_THUMB_EET)
|
|
|
|
eina_stringshare_replace(&e->thumb_key, "thumbnail");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eina_stringshare_del(e->thumb_key);
|
|
|
|
e->thumb_key = NULL;
|
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
eina_stringshare_del(thumb_dir);
|
|
|
|
eina_stringshare_del(category);
|
|
|
|
eina_stringshare_del(hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_file_free(Ethumb *e)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-21 16:08:17 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p", e);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
eina_stringshare_replace(&e->src_path, NULL);
|
|
|
|
eina_stringshare_replace(&e->src_key, NULL);
|
|
|
|
eina_stringshare_replace(&e->thumb_path, NULL);
|
|
|
|
eina_stringshare_replace(&e->thumb_key, NULL);
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
2009-04-21 16:11:37 -07:00
|
|
|
ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, path=%s, key=%s", e, path ? path : "", key ? key : "");
|
2009-04-13 15:29:39 -07:00
|
|
|
|
2009-04-14 12:14:08 -07:00
|
|
|
if (!path)
|
|
|
|
{
|
2009-04-21 16:08:17 -07:00
|
|
|
eina_stringshare_replace(&e->thumb_path, NULL);
|
|
|
|
eina_stringshare_replace(&e->thumb_key, NULL);
|
2009-04-14 12:14:08 -07:00
|
|
|
}
|
2009-05-18 14:37:09 -07:00
|
|
|
else
|
2009-04-14 12:14:08 -07:00
|
|
|
{
|
2009-05-26 13:33:58 -07:00
|
|
|
path = _ethumb_build_absolute_path(path, buf);
|
|
|
|
eina_stringshare_replace(&e->thumb_path, path);
|
2009-04-21 16:08:17 -07:00
|
|
|
eina_stringshare_replace(&e->thumb_key, key);
|
2009-04-14 12:14:08 -07:00
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-05-19 04:54:35 -07:00
|
|
|
EAPI void
|
|
|
|
ethumb_thumb_path_get(Ethumb *e, const char **path, const char **key)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-05-26 13:33:58 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-04-21 16:08:17 -07:00
|
|
|
if (!e->thumb_path)
|
|
|
|
_ethumb_file_generate_path(e);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-05-19 06:57:48 -07:00
|
|
|
if (path) *path = e->thumb_path;
|
|
|
|
if (key) *key = e->thumb_key;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
void
|
2009-07-09 12:42:18 -07:00
|
|
|
ethumb_calculate_aspect_from_ratio(Ethumb *e, float ia, int *w, int *h)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-07-09 12:42:18 -07:00
|
|
|
float a;
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
*w = e->tw;
|
|
|
|
*h = e->th;
|
|
|
|
|
2009-07-09 12:42:18 -07:00
|
|
|
if (ia == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
a = e->tw / (float)e->th;
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
if (e->aspect == ETHUMB_THUMB_KEEP_ASPECT)
|
|
|
|
{
|
2009-07-09 12:42:18 -07:00
|
|
|
if ((ia > a && e->tw > 0) || e->th <= 0)
|
|
|
|
*h = e->tw / ia;
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
2009-07-09 12:42:18 -07:00
|
|
|
*w = e->th * ia;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
void
|
2009-07-09 12:42:18 -07:00
|
|
|
ethumb_calculate_aspect(Ethumb *e, int iw, int ih, int *w, int *h)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-07-09 12:42:18 -07:00
|
|
|
float ia;
|
|
|
|
|
|
|
|
ia = iw / (float)ih;
|
|
|
|
|
|
|
|
ethumb_calculate_aspect_from_ratio(e, ia, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ethumb_calculate_fill_from_ratio(Ethumb *e, float ia, int *fx, int *fy, int *fw, int *fh)
|
|
|
|
{
|
|
|
|
float a;
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
*fw = e->tw;
|
|
|
|
*fh = e->th;
|
|
|
|
*fx = 0;
|
|
|
|
*fy = 0;
|
2009-10-30 07:30:15 -07:00
|
|
|
|
|
|
|
if (ia == 0)
|
|
|
|
return;
|
|
|
|
|
2009-07-09 12:42:18 -07:00
|
|
|
a = e->tw / (float)e->th;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
if (e->aspect == ETHUMB_THUMB_CROP)
|
|
|
|
{
|
2009-07-09 12:42:18 -07:00
|
|
|
if ((ia > a && e->tw > 0) || e->th <= 0)
|
|
|
|
*fw = e->th * ia;
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
2009-07-09 12:42:18 -07:00
|
|
|
*fh = e->tw / ia;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:23:49 -07:00
|
|
|
*fx = - e->crop_x * (*fw - e->tw);
|
|
|
|
*fy = - e->crop_y * (*fh - e->th);
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
else if (e->aspect == ETHUMB_THUMB_KEEP_ASPECT)
|
|
|
|
{
|
2009-07-09 12:42:18 -07:00
|
|
|
if ((ia > a && e->tw > 0) || e->th <= 0)
|
|
|
|
*fh = e->tw / ia;
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
2009-07-09 12:42:18 -07:00
|
|
|
*fw = e->th * ia;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 12:42:18 -07:00
|
|
|
void
|
|
|
|
ethumb_calculate_fill(Ethumb *e, int iw, int ih, int *fx, int *fy, int *fw, int *fh)
|
|
|
|
{
|
|
|
|
float ia;
|
|
|
|
ia = iw / (float)ih;
|
|
|
|
|
|
|
|
ethumb_calculate_fill_from_ratio(e, ia, fx, fy, fw, fh);
|
|
|
|
}
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
static Eina_Bool
|
2009-04-21 16:08:17 -07:00
|
|
|
_ethumb_plugin_generate(Ethumb *e)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-11-06 14:17:55 -08:00
|
|
|
const char *extp;
|
|
|
|
char ext[PATH_MAX];
|
2009-04-17 16:33:45 -07:00
|
|
|
Ethumb_Plugin *plugin;
|
2009-11-06 14:17:55 -08:00
|
|
|
int i;
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-11-06 14:17:55 -08:00
|
|
|
extp = strrchr(e->src_path, '.');
|
|
|
|
if (!extp)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not get extension for file \"%s\"", e->src_path);
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-11-06 14:17:55 -08:00
|
|
|
for (i = 0; extp[i] != '\0'; i++)
|
|
|
|
ext[i] = tolower(extp[i + 1]);
|
|
|
|
|
|
|
|
plugin = eina_hash_find(_plugins_ext, ext);
|
2009-04-17 16:33:45 -07:00
|
|
|
if (!plugin)
|
|
|
|
{
|
2009-11-06 14:17:55 -08:00
|
|
|
DBG("no plugin for extension: \"%s\"", ext);
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e->frame)
|
|
|
|
evas_object_hide(e->frame->edje);
|
|
|
|
else
|
|
|
|
evas_object_hide(e->img);
|
|
|
|
|
2009-05-19 04:58:29 -07:00
|
|
|
plugin->generate_thumb(e);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
Eina_Bool
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_plugin_image_resize(Ethumb *e, int w, int h)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
|
|
|
Evas_Object *img;
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
img = e->img;
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (e->frame)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
|
|
|
edje_extern_object_min_size_set(img, w, h);
|
|
|
|
edje_extern_object_max_size_set(img, w, h);
|
2009-04-21 16:08:17 -07:00
|
|
|
edje_object_calc_force(e->frame->edje);
|
|
|
|
evas_object_move(e->frame->edje, 0, 0);
|
|
|
|
evas_object_resize(e->frame->edje, w, h);
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_move(img, 0, 0);
|
|
|
|
evas_object_resize(img, w, h);
|
|
|
|
}
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
evas_object_image_size_set(e->o, w, h);
|
|
|
|
ecore_evas_resize(e->sub_ee, w, h);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
e->rw = w;
|
|
|
|
e->rh = h;
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
Eina_Bool
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_image_save(Ethumb *e)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-05-19 05:26:31 -07:00
|
|
|
Eina_Bool r;
|
2009-04-17 16:33:45 -07:00
|
|
|
char *dname;
|
2009-07-09 12:16:02 -07:00
|
|
|
char flags[256];
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
evas_damage_rectangle_add(e->sub_e, 0, 0, e->rw, e->rh);
|
|
|
|
evas_render(e->sub_e);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (!e->thumb_path)
|
|
|
|
_ethumb_file_generate_path(e);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (!e->thumb_path)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not create file path...");
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
dname = ecore_file_dir_get(e->thumb_path);
|
2009-04-17 16:33:45 -07:00
|
|
|
r = ecore_file_mkpath(dname);
|
|
|
|
free(dname);
|
|
|
|
if (!r)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not create directory '%s'", dname);
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-07-09 12:16:02 -07:00
|
|
|
snprintf(flags, sizeof(flags), "quality=%d compress=%d",
|
|
|
|
e->quality, e->compress);
|
|
|
|
r = evas_object_image_save(e->o, e->thumb_path, e->thumb_key, flags);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
|
|
|
if (!r)
|
|
|
|
{
|
2009-11-06 14:17:55 -08:00
|
|
|
ERR("could not save image: path=%s, key=%s", e->thumb_path,
|
|
|
|
e->thumb_key);
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
static int
|
2009-04-21 16:08:17 -07:00
|
|
|
_ethumb_image_load(Ethumb *e)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
Evas_Coord w, h, ww, hh, fx, fy, fw, fh;
|
|
|
|
Evas_Object *img;
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
img = e->img;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (e->frame)
|
|
|
|
evas_object_hide(e->frame->edje);
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
|
|
|
evas_object_hide(img);
|
|
|
|
evas_object_image_file_set(img, NULL, NULL);
|
2009-04-21 16:08:17 -07:00
|
|
|
evas_object_image_load_size_set(img, e->tw, e->th);
|
|
|
|
evas_object_image_file_set(img, e->src_path, e->src_key);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (e->frame)
|
|
|
|
evas_object_show(e->frame->edje);
|
2009-03-30 14:22:52 -07:00
|
|
|
else
|
|
|
|
evas_object_show(img);
|
|
|
|
|
|
|
|
error = evas_object_image_load_error_get(img);
|
|
|
|
if (error != EVAS_LOAD_ERROR_NONE)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not load image '%s': %d", e->src_path, error);
|
2009-03-30 14:22:52 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
evas_object_image_size_get(img, &w, &h);
|
|
|
|
if ((w <= 0) || (h <= 0))
|
|
|
|
return 0;
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_calculate_aspect(e, w, h, &ww, &hh);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (e->frame)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
|
|
|
edje_extern_object_min_size_set(img, ww, hh);
|
|
|
|
edje_extern_object_max_size_set(img, ww, hh);
|
2009-04-21 16:08:17 -07:00
|
|
|
edje_object_calc_force(e->frame->edje);
|
|
|
|
evas_object_move(e->frame->edje, 0, 0);
|
|
|
|
evas_object_resize(e->frame->edje, ww, hh);
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_move(img, 0, 0);
|
|
|
|
evas_object_resize(img, ww, hh);
|
|
|
|
}
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_calculate_fill(e, w, h, &fx, &fy, &fw, &fh);
|
2009-03-30 14:22:52 -07:00
|
|
|
evas_object_image_fill_set(img, fx, fy, fw, fh);
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
evas_object_image_size_set(e->o, ww, hh);
|
|
|
|
ecore_evas_resize(e->sub_ee, ww, hh);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
e->rw = ww;
|
|
|
|
e->rh = hh;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-07-07 18:00:48 -07:00
|
|
|
static Eina_Bool
|
2009-04-17 16:33:45 -07:00
|
|
|
_ethumb_finished_idler_cb(void *data)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-21 16:08:17 -07:00
|
|
|
Ethumb *e = data;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-09-12 11:23:05 -07:00
|
|
|
e->finished_cb(e->cb_data, e, e->cb_result);
|
2009-07-09 12:14:29 -07:00
|
|
|
if (e->cb_data_free)
|
|
|
|
e->cb_data_free(e->cb_data);
|
2009-04-17 16:33:45 -07:00
|
|
|
e->finished_idler = NULL;
|
|
|
|
e->finished_cb = NULL;
|
|
|
|
e->cb_data = NULL;
|
2009-07-09 12:14:29 -07:00
|
|
|
e->cb_data_free = NULL;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2010-07-07 18:00:48 -07:00
|
|
|
return EINA_FALSE;
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
void
|
2009-05-19 04:58:29 -07:00
|
|
|
ethumb_finished_callback_call(Ethumb *e, int result)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
2009-04-21 16:08:17 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-05-19 04:58:29 -07:00
|
|
|
e->cb_result = result;
|
2009-04-17 16:33:45 -07:00
|
|
|
if (e->finished_idler)
|
|
|
|
ecore_idler_del(e->finished_idler);
|
2009-04-21 16:08:17 -07:00
|
|
|
e->finished_idler = ecore_idler_add(_ethumb_finished_idler_cb, e);
|
2009-04-17 16:33:45 -07:00
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
EAPI Eina_Bool
|
2009-09-12 11:23:05 -07:00
|
|
|
ethumb_generate(Ethumb *e, Ethumb_Generate_Cb finished_cb, const void *data, Eina_Free_Cb free_data)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
|
|
|
int r;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
2009-04-17 16:33:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(finished_cb, 0);
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, finished_cb=%p, data=%p, free_data=%p, path=%s, key=%s",
|
|
|
|
e, finished_cb, data, free_data,
|
|
|
|
e->src_path ? e->src_path : "", e->src_key ? e->src_key : "");
|
2009-05-26 13:33:58 -07:00
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
if (e->finished_idler)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("thumbnail generation already in progress.");
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_FALSE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
2009-04-17 16:33:45 -07:00
|
|
|
e->finished_cb = finished_cb;
|
2009-09-12 11:23:05 -07:00
|
|
|
e->cb_data = (void *)data;
|
2009-07-09 12:14:29 -07:00
|
|
|
e->cb_data_free = free_data;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-05-26 13:33:58 -07:00
|
|
|
if (!e->src_path)
|
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("no file set.");
|
2009-05-26 13:33:58 -07:00
|
|
|
ethumb_finished_callback_call(e, 0);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
r = _ethumb_plugin_generate(e);
|
2009-04-17 16:33:45 -07:00
|
|
|
if (r)
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (!_ethumb_image_load(e))
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not load input image.");
|
2009-05-19 04:58:29 -07:00
|
|
|
ethumb_finished_callback_call(e, 0);
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
r = ethumb_image_save(e);
|
2009-04-17 16:33:45 -07:00
|
|
|
|
2009-05-19 04:58:29 -07:00
|
|
|
ethumb_finished_callback_call(e, r);
|
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
return EINA_TRUE;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|
2009-04-21 16:11:37 -07:00
|
|
|
|
2009-05-19 05:26:31 -07:00
|
|
|
EAPI Eina_Bool
|
2009-04-21 16:11:37 -07:00
|
|
|
ethumb_exists(Ethumb *e)
|
|
|
|
{
|
|
|
|
struct stat thumb, src;
|
2009-05-19 05:26:31 -07:00
|
|
|
int r_thumb, r_src;
|
|
|
|
Eina_Bool r = EINA_FALSE;
|
|
|
|
|
2009-04-21 16:11:37 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e->src_path, 0);
|
2009-09-04 12:27:12 -07:00
|
|
|
DBG("ethumb=%p, path=%s", e, e->src_path ? e->src_path : "");
|
2009-04-21 16:11:37 -07:00
|
|
|
|
|
|
|
if (!e->thumb_path)
|
|
|
|
_ethumb_file_generate_path(e);
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e->thumb_path, 0);
|
|
|
|
|
|
|
|
r_thumb = stat(e->thumb_path, &thumb);
|
|
|
|
r_src = stat(e->src_path, &src);
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(r_src, 0);
|
|
|
|
|
|
|
|
if (r_thumb && errno != ENOENT)
|
2009-09-17 07:31:29 -07:00
|
|
|
ERR("could not access file \"%s\": %s", e->thumb_path, strerror(errno));
|
2009-04-21 16:11:37 -07:00
|
|
|
else if (!r_thumb && thumb.st_mtime > src.st_mtime)
|
2009-05-19 05:26:31 -07:00
|
|
|
r = EINA_TRUE;
|
2009-04-21 16:11:37 -07:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2009-05-18 14:26:56 -07:00
|
|
|
|
|
|
|
Evas *
|
2009-05-19 04:54:35 -07:00
|
|
|
ethumb_evas_get(const Ethumb *e)
|
2009-05-18 14:26:56 -07:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
|
|
|
|
|
|
|
return e->sub_e;
|
|
|
|
}
|
2009-07-09 12:42:18 -07:00
|
|
|
|
|
|
|
Ecore_Evas *
|
|
|
|
ethumb_ecore_evas_get(const Ethumb *e)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
|
|
|
|
|
|
|
return e->sub_ee;
|
|
|
|
}
|