1 From de2f3edd669f00160c3584149f4ba871970704e3 Mon Sep 17 00:00:00 2001
2 From: Leonardo Sobral Cunha <leonardo.cunha@openbossa.org>
3 Date: Wed, 28 May 2008 18:30:52 -0300
4 Subject: [PATCH] Add support for custom size thumbnails
6 The width or height of the custom size may be negative,
7 indicating that this orientation has no size limit.
8 You must also set the dir name relative to $HOME/.thumbnails .
10 src/lib/Epsilon.c | 59 ++++++++++++++++++++++++++++++++++++++++++++--------
11 src/lib/Epsilon.h | 6 +++++
12 2 files changed, 56 insertions(+), 9 deletions(-)
14 diff --git a/src/lib/Epsilon.c b/src/lib/Epsilon.c
15 index e293a9e..cf1969e 100644
16 --- a/src/lib/Epsilon.c
17 +++ b/src/lib/Epsilon.c
20 #define THUMB_SIZE_NORMAL 128
21 #define THUMB_SIZE_LARGE 256
22 +#define THUMB_SIZE_CUSTOM 0
23 #define THUMB_SIZE_FAIL -1
24 #include "exiftags/exif.h"
28 static char *PATH_DIR_LARGE = NULL;
29 static char *PATH_DIR_NORMAL = NULL;
30 +static char *PATH_DIR_CUSTOM = NULL;
31 static char *PATH_DIR_FAIL = NULL;
32 static unsigned LEN_DIR_LARGE = 0;
33 static unsigned LEN_DIR_NORMAL = 0;
34 +static unsigned LEN_DIR_CUSTOM = 0;
35 static unsigned LEN_DIR_FAIL = 0;
38 @@ -446,6 +449,11 @@ _epsilon_file_name(unsigned thumb_size, const char *hash, const char *ext, char
39 dir = PATH_DIR_NORMAL;
40 dir_len = LEN_DIR_NORMAL;
42 + else if (thumb_size == THUMB_SIZE_CUSTOM)
44 + dir = PATH_DIR_CUSTOM;
45 + dir_len = LEN_DIR_CUSTOM;
50 @@ -474,7 +482,7 @@ _epsilon_exists_ext_int(unsigned thumb_size, const char *hash, const char *ext,
52 _epsilon_exists_ext(Epsilon *e, const char *ext, char *path, int path_size, time_t *mtime)
54 - if (_epsilon_exists_ext_int(e->tw, e->hash, ext, path, path_size, mtime))
55 + if (_epsilon_exists_ext_int(e->tsize, e->hash, ext, path, path_size, mtime))
58 return _epsilon_exists_ext_int(THUMB_SIZE_FAIL, e->hash, ext, path, path_size, mtime);
59 @@ -601,9 +609,12 @@ epsilon_generate (Epsilon * e)
60 evas_object_image_data_update_add(im, 0, 0, iw, ih);
61 if ((iw > 0) && (ih > 0))
64 - hh = (e->tw * ih) / iw;
66 + if ((iw > ih && e->tw > 0) || e->th <= 0)
69 + hh = (e->tw * ih) / iw;
74 ww = (e->th * iw) / ih;
75 @@ -647,9 +658,12 @@ epsilon_generate (Epsilon * e)
76 alpha = evas_object_image_alpha_get(im);
77 if ((iw > 0) && (ih > 0))
80 - hh = (e->tw * ih) / iw;
82 + if ((iw > ih && e->tw > 0) || e->th <= 0)
85 + hh = (e->tw * ih) / iw;
90 ww = (e->th * iw) / ih;
91 @@ -667,7 +681,7 @@ epsilon_generate (Epsilon * e)
94 snprintf(buf, sizeof(buf), "file://%s", e->src);
95 - _epsilon_file_name(e->tw, e->hash, "png", buf2, sizeof(buf2));
96 + _epsilon_file_name(e->tsize, e->hash, "png", buf2, sizeof(buf2));
97 /* this is wrong - but hey! good enough? */
98 if (ext) snprintf(buf3, sizeof(buf3), "image/%s", ext);
99 else snprintf(buf3, sizeof(buf3), "image/png");
100 @@ -706,14 +720,41 @@ epsilon_thumb_size(Epsilon *e, Epsilon_Thumb_Size size)
101 case EPSILON_THUMB_NORMAL:
102 e->tw = THUMB_SIZE_NORMAL;
103 e->th = THUMB_SIZE_NORMAL;
104 + e->tsize = THUMB_SIZE_NORMAL;
106 case EPSILON_THUMB_LARGE:
107 e->tw = THUMB_SIZE_LARGE;
108 e->th = THUMB_SIZE_LARGE;
109 + e->tsize = THUMB_SIZE_LARGE;
116 +epsilon_custom_thumb_size (Epsilon * e, int w, int h, const char *dir)
118 + char buf[PATH_MAX];
122 + if (e && (w > 0 || h > 0))
126 + e->tsize = THUMB_SIZE_CUSTOM;
128 + home = getenv("HOME");
129 + base_len = snprintf(buf, sizeof(buf), "%s/.thumbnails/", home);
130 + strncpy(buf + base_len, dir, PATH_MAX - base_len);
132 + if (PATH_DIR_CUSTOM)
133 + free(PATH_DIR_CUSTOM);
135 + PATH_DIR_CUSTOM = strdup(buf);
136 + LEN_DIR_CUSTOM = strlen(buf);
137 + ecore_file_mkpath(PATH_DIR_CUSTOM);
143 diff --git a/src/lib/Epsilon.h b/src/lib/Epsilon.h
144 index 90a51b3..166f78c 100644
145 --- a/src/lib/Epsilon.h
146 +++ b/src/lib/Epsilon.h
147 @@ -42,6 +42,7 @@ struct _Epsilon
153 typedef struct _Epsilon Epsilon;
155 @@ -96,6 +97,11 @@ EAPI int epsilon_generate (Epsilon * e);
156 EAPI void epsilon_thumb_size(Epsilon *e, Epsilon_Thumb_Size size);
159 + * set a custom thumb size
161 +EAPI void epsilon_custom_thumb_size(Epsilon *e, int w, int h, const char *dir);
164 * get the meta information associated with the epsilon
166 EAPI Epsilon_Info *epsilon_info_get (Epsilon * e);