Updated epsilon patches.
[maemo-efl] / trunk / epsilon / debian / patches / 02_epsilon_thumb_canola.diff
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
5
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 .
9 ---
10  src/lib/Epsilon.c |   59 ++++++++++++++++++++++++++++++++++++++++++++--------
11  src/lib/Epsilon.h |    6 +++++
12  2 files changed, 56 insertions(+), 9 deletions(-)
13
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
18 @@ -25,6 +25,7 @@
19  #endif
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"
25  
26 @@ -38,9 +39,11 @@
27  
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;
36  
37  
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;
41       }
42 +   else if (thumb_size == THUMB_SIZE_CUSTOM)
43 +     {
44 +       dir = PATH_DIR_CUSTOM;
45 +       dir_len = LEN_DIR_CUSTOM;
46 +     }
47     else
48       {
49         dir = PATH_DIR_FAIL;
50 @@ -474,7 +482,7 @@ _epsilon_exists_ext_int(unsigned thumb_size, const char *hash, const char *ext,
51  static int
52  _epsilon_exists_ext(Epsilon *e, const char *ext, char *path, int path_size, time_t *mtime)
53  {
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))
56       return 1;
57  
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))
62           {
63 -            ww = e->tw;
64 -            hh = (e->tw * ih) / iw;
65 -            if (hh > e->th)
66 +            if ((iw > ih && e->tw > 0) || e->th <= 0)
67 +              {
68 +                 ww = e->tw;
69 +                 hh = (e->tw * ih) / iw;
70 +              }
71 +            else
72                {
73                   hh = e->th;
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))
78           {
79 -            ww = e->tw;
80 -            hh = (e->tw * ih) / iw;
81 -            if (hh > e->th)
82 +            if ((iw > ih && e->tw > 0) || e->th <= 0)
83 +              {
84 +                 ww = e->tw;
85 +                 hh = (e->tw * ih) / iw;
86 +              }
87 +            else
88                {
89                   hh = e->th;
90                   ww = (e->th * iw) / ih;
91 @@ -667,7 +681,7 @@ epsilon_generate (Epsilon * e)
92         if (data)
93           {
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;
105         break;
106        case EPSILON_THUMB_LARGE:
107         e->tw = THUMB_SIZE_LARGE;
108         e->th = THUMB_SIZE_LARGE;
109 +       e->tsize = THUMB_SIZE_LARGE;
110         break;
111 -     }   
112 +     }
113  }
114  
115 +void
116 +epsilon_custom_thumb_size (Epsilon * e, int w, int h, const char *dir)
117 +{
118 +  char buf[PATH_MAX];
119 +  int base_len;
120 +  char *home;
121 +
122 +  if (e && (w > 0 || h > 0))
123 +    {
124 +      e->tw = w;
125 +      e->th = h;
126 +      e->tsize = THUMB_SIZE_CUSTOM;
127 +
128 +      home = getenv("HOME");
129 +      base_len = snprintf(buf, sizeof(buf), "%s/.thumbnails/", home);
130 +      strncpy(buf + base_len, dir, PATH_MAX - base_len);
131 +
132 +      if (PATH_DIR_CUSTOM)
133 +        free(PATH_DIR_CUSTOM);
134 +
135 +      PATH_DIR_CUSTOM = strdup(buf);
136 +      LEN_DIR_CUSTOM = strlen(buf);
137 +      ecore_file_mkpath(PATH_DIR_CUSTOM);
138 +    }
139 +}
140  
141  #ifdef HAVE_PNG_H
142  static FILE *
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
148    char *key;
149    int w, h;
150    int tw, th;
151 +  int tsize;
152  };
153  typedef struct _Epsilon Epsilon;
154  
155 @@ -96,6 +97,11 @@ EAPI int epsilon_generate (Epsilon * e);
156  EAPI void epsilon_thumb_size(Epsilon *e, Epsilon_Thumb_Size size);
157  
158  /*
159 + * set a custom thumb size
160 + */
161 +EAPI void epsilon_custom_thumb_size(Epsilon *e, int w, int h, const char *dir);
162 +
163 +/*
164   * get the meta information associated with the epsilon
165   */
166  EAPI Epsilon_Info *epsilon_info_get (Epsilon * e);
167 -- 
168 1.5.4.3
169