1. fix thumb to not use preload thread - i spotted bugs. concurrency ones.

2. also write a sort id (harmless - doesnt affect anything). useful for...
sorting.




SVN revision: 40166
This commit is contained in:
Carsten Haitzler 2009-04-18 13:52:24 +00:00
parent ce2009b32b
commit b592a9176f
4 changed files with 194 additions and 7 deletions

View File

@ -344,7 +344,7 @@ e_thumb_main.c \
e_user.c \
e_sha1.c
enlightenment_thumb_LDADD = @E_THUMB_LIBS@
enlightenment_thumb_LDADD = @E_THUMB_LIBS@ -lm
enlightenment_fm_SOURCES = \
e_fm_main.c \

View File

@ -11,6 +11,7 @@ struct _E_Thumb
int w, h;
const char *file;
const char *key;
char *sort_id;
unsigned char queued : 1;
unsigned char busy : 1;
unsigned char done : 1;
@ -108,6 +109,8 @@ e_thumb_icon_file_set(Evas_Object *obj, const char *file, const char *key)
eth->file = NULL;
if (eth->key) eina_stringshare_del(eth->key);
eth->key = NULL;
if (eth->sort_id) free(eth->sort_id);
eth->sort_id = NULL;
if (file) eth->file = eina_stringshare_add(file);
if (key) eth->key = eina_stringshare_add(key);
}
@ -201,6 +204,43 @@ e_thumb_icon_rethumb(Evas_Object *obj)
e_thumb_icon_begin(obj);
}
#define A(v) (((v) >> 24) & 0xff)
#define R(v) (((v) >> 16) & 0xff)
#define G(v) (((v) >> 8 ) & 0xff)
#define B(v) (((v) ) & 0xff)
#define PIX(p, x, y) p[((y) << 2) + (x)]
#define PIX2(p, x, y) p[((y) << 1) + (x)]
static void
_e_thumb_key_load(E_Thumb *eth, const char *icon)
{
Eet_File *ef;
int size = 0;
ef = eet_open(icon, EET_FILE_MODE_READ);
if (!ef) return;
eth->sort_id = eet_read(ef, "/thumbnail/sort_id", &size);
if (eth->sort_id)
{
if (size > 0) eth->sort_id[size - 1] = 0;
else
{
free(eth->sort_id);
eth->sort_id = NULL;
}
}
eet_close(ef);
}
EAPI const char *
e_thumb_sort_id_get(Evas_Object *obj)
{
E_Thumb *eth;
eth = evas_object_data_get(obj, "e_thumbdata");
if (!eth) return "";
if (!eth->sort_id) return "";
return eth->sort_id;
}
EAPI void
e_thumb_client_data(Ecore_Ipc_Event_Client_Data *e)
@ -228,9 +268,10 @@ e_thumb_client_data(Ecore_Ipc_Event_Client_Data *e)
_pending--;
eth->done = 1;
if (_pending == 0) _e_thumb_thumbnailers_kill();
e_icon_preload_set(obj, 1);
//y// e_icon_preload_set(obj, 1);
e_icon_file_key_set(obj, icon, "/thumbnail/data");
//x// evas_object_smart_callback_call(obj, "e_thumb_gen", NULL);
_e_thumb_key_load(eth, icon);
evas_object_smart_callback_call(obj, "e_thumb_gen", NULL);
}
}
}
@ -316,6 +357,7 @@ _e_thumb_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info)
_thumb_queue = eina_list_remove(_thumb_queue, eth);
if (eth->file) eina_stringshare_del(eth->file);
if (eth->key) eina_stringshare_del(eth->key);
if (eth->sort_id) free(eth->sort_id);
free(eth);
}

View File

@ -17,7 +17,8 @@ EAPI void e_thumb_icon_size_set(Evas_Object *obj, int w, int h)
EAPI void e_thumb_icon_begin(Evas_Object *obj);
EAPI void e_thumb_icon_end(Evas_Object *obj);
EAPI void e_thumb_icon_rethumb(Evas_Object *obj);
EAPI const char *e_thumb_sort_id_get(Evas_Object *obj);
EAPI void e_thumb_client_data(Ecore_Ipc_Event_Client_Data *e);
EAPI void e_thumb_client_del(Ecore_Ipc_Event_Client_Del *e);

View File

@ -5,6 +5,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Ecore_Ipc.h>
@ -236,6 +237,23 @@ _e_cb_timer(void *data)
return 0;
}
typedef struct _Color Color;
struct _Color
{
Color *closest;
int closest_dist;
int use;
unsigned char r, g, b;
};
static int
_sort_col(const void *d1, const void *d2)
{
Color *c1 = (Color *)d1, *c2 = (Color *)d2;
return c2->use - c1->use;
}
static void
_e_thumb_generate(E_Thumb *eth)
{
@ -245,7 +263,7 @@ _e_thumb_generate(E_Thumb *eth)
Evas_Object *im = NULL, *edje = NULL;
Eet_File *ef;
int iw, ih, alpha, ww, hh;
int *data = NULL;
unsigned int *data = NULL;
time_t mtime_orig, mtime_thumb;
id = _e_thumb_file_id(eth->file, eth->key);
@ -294,7 +312,7 @@ _e_thumb_generate(E_Thumb *eth)
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 * 8, hh * 8);
evas_object_image_size_set(im, ww * 4, hh * 4);
evas_object_image_fill_set(im, 0, 0, ww, hh);
edje = edje_object_add(evas_im);
if ((eth->key) &&
@ -304,7 +322,7 @@ _e_thumb_generate(E_Thumb *eth)
if (edje_object_file_set(edje, eth->file, eth->key))
{
evas_object_move(edje, 0, 0);
evas_object_resize(edje, ww * 8, hh * 8);
evas_object_resize(edje, ww * 4, hh * 4);
evas_object_show(edje);
}
}
@ -348,10 +366,136 @@ _e_thumb_generate(E_Thumb *eth)
eet_data_image_write(ef, "/thumbnail/data",
(void *)data, ww, hh, alpha,
0, 91, 1);
ww = 4; hh = 4;
evas_object_image_fill_set(im, 0, 0, ww, hh);
evas_object_resize(im, ww, hh);
ecore_evas_resize(ee, ww, hh);
data = (int *)ecore_evas_buffer_pixels_get(ee);
if (data)
{
unsigned int *data1;
data1 = malloc(ww * hh * sizeof(unsigned int));
memcpy(data1, data, ww * hh * sizeof(unsigned int));
ww = 2; hh = 2;
evas_object_image_fill_set(im, 0, 0, ww, hh);
evas_object_resize(im, ww, hh);
ecore_evas_resize(ee, ww, hh);
data = (int *)ecore_evas_buffer_pixels_get(ee);
if (data)
{
unsigned int *data2;
data2 = malloc(ww * hh * sizeof(unsigned int));
memcpy(data2, data, ww * hh * sizeof(unsigned int));
ww = 1; hh = 1;
evas_object_image_fill_set(im, 0, 0, ww, hh);
evas_object_resize(im, ww, hh);
ecore_evas_resize(ee, ww, hh);
data = (int *)ecore_evas_buffer_pixels_get(ee);
if (data)
{
unsigned int *data3;
unsigned char id[(21 * 4) + 1];
int n, i;
int hi, si, vi;
float h, s, v;
const int pat2[4] =
{
0, 3, 1, 2
};
const int pat1[16] =
{
5, 10, 6, 9,
0, 15, 3, 12,
1, 14, 7, 8,
4, 11, 2, 13
};
data3 = malloc(ww * hh * sizeof(unsigned int));
memcpy(data3, data, ww * hh * sizeof(unsigned int));
// sort_id
n = 0;
#define A(v) (((v) >> 24) & 0xff)
#define R(v) (((v) >> 16) & 0xff)
#define G(v) (((v) >> 8 ) & 0xff)
#define B(v) (((v) ) & 0xff)
#define HSV(p) \
evas_color_rgb_to_hsv(R(p), G(p), B(p), &h, &s, &v); \
hi = 20 * (h / 360.0); \
si = 20 * s; \
vi = 20 * v; \
if (si < 2) hi = 25;
#define SAVEHSV(h, s, v) \
id[n++] = 'a' + h; \
id[n++] = 'a' + v; \
id[n++] = 'a' + s;
#define SAVEX(x) \
id[n++] = 'a' + x;
#if 0
HSV(data3[0]);
SAVEHSV(hi, si, vi);
for (i = 0; i < 4; i++)
{
HSV(data2[pat2[i]]);
SAVEHSV(hi, si, vi);
}
for (i = 0; i < 16; i++)
{
HSV(data1[pat1[i]]);
SAVEHSV(hi, si, vi);
}
#else
HSV(data3[0]);
SAVEX(hi);
for (i = 0; i < 4; i++)
{
HSV(data2[pat2[i]]);
SAVEX(hi);
}
for (i = 0; i < 16; i++)
{
HSV(data1[pat1[i]]);
SAVEX(hi);
}
HSV(data3[0]);
SAVEX(vi);
for (i = 0; i < 4; i++)
{
HSV(data2[pat2[i]]);
SAVEX(vi);
}
for (i = 0; i < 16; i++)
{
HSV(data1[pat1[i]]);
SAVEX(vi);
}
HSV(data3[0]);
SAVEX(si);
for (i = 0; i < 4; i++)
{
HSV(data2[pat2[i]]);
SAVEX(si);
}
for (i = 0; i < 16; i++)
{
HSV(data1[pat1[i]]);
SAVEX(si);
}
#endif
id[n++] = 0;
eet_write(ef, "/thumbnail/sort_id", id, n, 1);
free(data3);
}
free(data2);
}
free(data1);
}
eet_close(ef);
}
}
}
/* will free all */
if (edje) evas_object_del(edje);
if (ee_im) ecore_evas_free(ee_im);