forked from enlightenment/enlightenment
generate thumbs vaguely efficiently withotu eating up all ram and generating
billions of processes :) SVN revision: 17708
This commit is contained in:
parent
61e8c0d0c4
commit
621a0fdd30
|
@ -42,7 +42,7 @@ static void _e_fm_icon_smart_clip_unset (Evas_Object *obj);
|
||||||
/* Create icons */
|
/* Create icons */
|
||||||
static void _e_fm_icon_icon_mime_get(E_Smart_Data *sd);
|
static void _e_fm_icon_icon_mime_get(E_Smart_Data *sd);
|
||||||
|
|
||||||
static void _e_fm_icon_thumb_job_generate(void *data);
|
static void _e_fm_icon_thumb_generate(void);
|
||||||
static int _e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event);
|
static int _e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event);
|
||||||
|
|
||||||
/* local subsystem globals */
|
/* local subsystem globals */
|
||||||
|
@ -50,7 +50,6 @@ static Evas_Smart *e_smart = NULL;
|
||||||
|
|
||||||
static pid_t pid = -1;
|
static pid_t pid = -1;
|
||||||
static Evas_List *thumb_files = NULL;
|
static Evas_List *thumb_files = NULL;
|
||||||
static Ecore_Job *thumb_job = NULL;
|
|
||||||
|
|
||||||
static Evas_List *event_handlers = NULL;
|
static Evas_List *event_handlers = NULL;
|
||||||
|
|
||||||
|
@ -345,8 +344,7 @@ _e_fm_icon_smart_show(Evas_Object *obj)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
thumb_files = evas_list_append(thumb_files, sd);
|
thumb_files = evas_list_append(thumb_files, sd);
|
||||||
if (thumb_job) ecore_job_del(thumb_job);
|
if (pid == -1) _e_fm_icon_thumb_generate();
|
||||||
thumb_job = ecore_job_add(_e_fm_icon_thumb_job_generate, NULL);
|
|
||||||
_e_fm_icon_icon_mime_get(sd);
|
_e_fm_icon_icon_mime_get(sd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -460,67 +458,46 @@ _e_fm_icon_icon_mime_get(E_Smart_Data *sd)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_e_fm_icon_thumb_job_generate(void *data)
|
_e_fm_icon_thumb_generate(void)
|
||||||
{
|
{
|
||||||
if ((!thumb_files) || (pid != -1))return;
|
E_Smart_Data *sd;
|
||||||
|
|
||||||
|
if ((!thumb_files) || (pid != -1)) return;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
thumb_job = NULL;
|
|
||||||
|
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
/* child */
|
sd = thumb_files->data;
|
||||||
Evas_List *l;
|
if (!e_thumb_exists(sd->file->path))
|
||||||
for (l = thumb_files; l; l = l->next)
|
e_thumb_create(sd->file->path, 48, 48); // thumbnail size
|
||||||
{
|
|
||||||
E_Smart_Data *sd;
|
|
||||||
sd = l->data;
|
|
||||||
if(!e_thumb_exists(sd->file->path))
|
|
||||||
e_thumb_create(sd->file->path, sd->w, sd->h);
|
|
||||||
}
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event)
|
_e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event)
|
||||||
{
|
{
|
||||||
Ecore_Event_Exe_Exit *ev;
|
Ecore_Event_Exe_Exit *ev;
|
||||||
Evas_List *l;
|
E_Smart_Data *sd;
|
||||||
|
|
||||||
ev = event;
|
ev = event;
|
||||||
if (ev->pid != pid) return 1;
|
if (ev->pid != pid) return 1;
|
||||||
for (l = thumb_files; l;)
|
if (!thumb_files) return 1;
|
||||||
{
|
|
||||||
E_Smart_Data *sd;
|
|
||||||
|
|
||||||
sd = l->data;
|
sd = thumb_files->data;
|
||||||
if (ecore_file_exists(sd->thumb_path))
|
thumb_files = evas_list_remove_list(thumb_files, thumb_files);
|
||||||
{
|
|
||||||
Evas_List *tmp;
|
if (ecore_file_exists(sd->thumb_path))
|
||||||
if (sd->image_object) evas_object_del(sd->image_object);
|
{
|
||||||
sd->image_object = NULL;
|
if (sd->image_object) evas_object_del(sd->image_object);
|
||||||
sd->image_object = e_thumb_evas_object_get(sd->file->path,
|
sd->image_object = e_thumb_evas_object_get(sd->file->path,
|
||||||
sd->evas,
|
sd->evas,
|
||||||
sd->w, sd->h);
|
sd->w, sd->h);
|
||||||
edje_object_part_swallow(sd->icon_object, "icon_swallow",
|
edje_object_part_swallow(sd->icon_object, "icon_swallow",
|
||||||
sd->image_object);
|
sd->image_object);
|
||||||
tmp = l;
|
|
||||||
l = l->next;
|
|
||||||
thumb_files = evas_list_remove_list(thumb_files, tmp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
l = l->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = -1;
|
pid = -1;
|
||||||
if (thumb_files)
|
_e_fm_icon_thumb_generate();
|
||||||
{
|
|
||||||
if (thumb_job) ecore_job_del(thumb_job);
|
|
||||||
thumb_job = ecore_job_add(_e_fm_icon_thumb_job_generate, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,17 @@ e_icon_file_set(Evas_Object *obj, const char *file)
|
||||||
_e_icon_smart_reconfigure(sd);
|
_e_icon_smart_reconfigure(sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
e_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
|
||||||
|
{
|
||||||
|
E_Smart_Data *sd;
|
||||||
|
|
||||||
|
sd = evas_object_smart_data_get(obj);
|
||||||
|
/* smart code here */
|
||||||
|
evas_object_image_file_set(sd->obj, file, key);
|
||||||
|
_e_icon_smart_reconfigure(sd);
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
e_icon_file_get(Evas_Object *obj)
|
e_icon_file_get(Evas_Object *obj)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
EAPI Evas_Object *e_icon_add (Evas *evas);
|
EAPI Evas_Object *e_icon_add (Evas *evas);
|
||||||
EAPI void e_icon_file_set (Evas_Object *obj, const char *file);
|
EAPI void e_icon_file_set (Evas_Object *obj, const char *file);
|
||||||
|
EAPI void e_icon_file_key_set (Evas_Object *obj, const char *file, const char *key);
|
||||||
EAPI const char *e_icon_file_get (Evas_Object *obj);
|
EAPI const char *e_icon_file_get (Evas_Object *obj);
|
||||||
EAPI void e_icon_smooth_scale_set (Evas_Object *obj, int smooth);
|
EAPI void e_icon_smooth_scale_set (Evas_Object *obj, int smooth);
|
||||||
EAPI int e_icon_smooth_scale_get (Evas_Object *obj);
|
EAPI int e_icon_smooth_scale_get (Evas_Object *obj);
|
||||||
|
|
|
@ -78,19 +78,24 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h)
|
||||||
char *thumbpath;
|
char *thumbpath;
|
||||||
Evas_Object *im;
|
Evas_Object *im;
|
||||||
const int *data;
|
const int *data;
|
||||||
int size;
|
int size, iw, ih, ww, hh;
|
||||||
Ecore_Evas *buf;
|
Ecore_Evas *buf;
|
||||||
Evas *evasbuf;
|
Evas *evasbuf;
|
||||||
|
int alpha;
|
||||||
|
|
||||||
thumbpath = e_thumb_file_get(file);
|
thumbpath = e_thumb_file_get(file);
|
||||||
if(!thumbpath) { free(thumbpath); return -1; }
|
if (!thumbpath)
|
||||||
|
{
|
||||||
|
free(thumbpath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ef = eet_open(thumbpath, EET_FILE_MODE_WRITE);
|
ef = eet_open(thumbpath, EET_FILE_MODE_WRITE);
|
||||||
if (!ef)
|
if (!ef)
|
||||||
{
|
{
|
||||||
free(thumbpath);
|
free(thumbpath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(thumbpath);
|
free(thumbpath);
|
||||||
|
|
||||||
|
@ -98,20 +103,32 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h)
|
||||||
evasbuf = ecore_evas_get(buf);
|
evasbuf = ecore_evas_get(buf);
|
||||||
im = evas_object_image_add(evasbuf);
|
im = evas_object_image_add(evasbuf);
|
||||||
evas_object_image_file_set(im, file, NULL);
|
evas_object_image_file_set(im, file, NULL);
|
||||||
evas_object_image_fill_set(im, 0, 0, w, h);
|
iw = 0; ih = 0;
|
||||||
evas_object_resize(im, w, h);
|
evas_object_image_size_get(im, &iw, &ih);
|
||||||
|
alpha = evas_object_image_alpha_get(im);
|
||||||
|
ww = w;
|
||||||
|
hh = (w * ih) / iw;
|
||||||
|
if (hh > h)
|
||||||
|
{
|
||||||
|
hh = h;
|
||||||
|
ww = (h * iw) / ih;
|
||||||
|
}
|
||||||
|
ecore_evas_resize(buf, ww, hh);
|
||||||
|
evas_object_image_fill_set(im, 0, 0, ww, hh);
|
||||||
|
evas_object_resize(im, ww, hh);
|
||||||
evas_object_show(im);
|
evas_object_show(im);
|
||||||
data = ecore_evas_buffer_pixels_get(buf);
|
data = ecore_evas_buffer_pixels_get(buf);
|
||||||
|
|
||||||
if ((size = eet_data_image_write(ef, "/thumbnail/data", (void *)data, w, h, 1, 0, 70, 1)) < 0)
|
eet_write(ef, "/thumbnail/orig_path", file, strlen(file), 1);
|
||||||
|
if ((size = eet_data_image_write(ef, "/thumbnail/data",
|
||||||
|
(void *)data, ww, hh, alpha,
|
||||||
|
0, 91, 1)) <= 0)
|
||||||
{
|
{
|
||||||
printf("e_thumb: BUG: Couldn't write thumb db\n");
|
|
||||||
eet_close(ef);
|
eet_close(ef);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
evas_object_del(im);
|
||||||
eet_close(ef);
|
eet_close(ef);
|
||||||
|
|
||||||
ecore_evas_free(buf);
|
ecore_evas_free(buf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -159,47 +176,32 @@ e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord hei
|
||||||
/* saved thumb */
|
/* saved thumb */
|
||||||
/* TODO: add ability to fetch thumbs from freedesktop dirs */
|
/* TODO: add ability to fetch thumbs from freedesktop dirs */
|
||||||
if (!e_thumb_exists(file))
|
if (!e_thumb_exists(file))
|
||||||
{
|
{
|
||||||
if(!e_thumb_create(file, width, height))
|
if (!e_thumb_create(file, width, height))
|
||||||
{
|
{
|
||||||
DEF_THUMB_RETURN;
|
DEF_THUMB_RETURN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thumb = e_thumb_file_get(file);
|
thumb = e_thumb_file_get(file);
|
||||||
if(!thumb)
|
if (!thumb)
|
||||||
{
|
{
|
||||||
DEF_THUMB_RETURN;
|
DEF_THUMB_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
ef = eet_open(thumb, EET_FILE_MODE_READ);
|
ef = eet_open(thumb, EET_FILE_MODE_READ);
|
||||||
if (!ef)
|
if (!ef)
|
||||||
{
|
{
|
||||||
free(thumb);
|
eet_close(ef);
|
||||||
DEF_THUMB_RETURN;
|
free(thumb);
|
||||||
}
|
DEF_THUMB_RETURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
im = e_icon_add(evas);
|
||||||
|
e_icon_file_key_set(im, thumb, "/thumbnail/data");
|
||||||
|
e_icon_fill_inside_set(im, 1);
|
||||||
free(thumb);
|
free(thumb);
|
||||||
|
|
||||||
data = eet_data_image_read(ef, "/thumbnail/data", &w, &h, &a, &c, &q, &l);
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
im = evas_object_image_add(evas);
|
|
||||||
evas_object_image_alpha_set(im, 1);
|
|
||||||
evas_object_image_size_set(im, w, h);
|
|
||||||
evas_object_image_smooth_scale_set(im, 0);
|
|
||||||
evas_object_image_data_copy_set(im, data);
|
|
||||||
evas_object_image_data_update_add(im, 0, 0, w, h);
|
|
||||||
evas_object_image_fill_set(im, 0, 0, w, h);
|
|
||||||
evas_object_resize(im, w, h);
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DEF_THUMB_RETURN;
|
|
||||||
}
|
|
||||||
|
|
||||||
eet_close(ef);
|
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,10 +209,13 @@ e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord hei
|
||||||
static char *
|
static char *
|
||||||
_e_thumb_file_id(char *file)
|
_e_thumb_file_id(char *file)
|
||||||
{
|
{
|
||||||
char s[256];
|
char s[256], *sp;
|
||||||
const char *chmap =
|
const char *chmap =
|
||||||
"0123456789abcdefghijklmnopqrstuvwxyz€<EFBFBD>‚ƒ„…†‡ˆŠ‹Œ<EFBFBD>Ž<EFBFBD><EFBFBD>‘’“<EFBFBD>-_";
|
"0123456789abcdef"
|
||||||
int id[2];
|
"ghijklmnopqrstuv"
|
||||||
|
"wxyz`~!@#$%^&*()"
|
||||||
|
"[];',.{}<>?-=_+|";
|
||||||
|
unsigned int id[6], i;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (stat(file, &st) < 0)
|
if (stat(file, &st) < 0)
|
||||||
|
@ -218,21 +223,28 @@ _e_thumb_file_id(char *file)
|
||||||
|
|
||||||
id[0] = (int)st.st_ino;
|
id[0] = (int)st.st_ino;
|
||||||
id[1] = (int)st.st_dev;
|
id[1] = (int)st.st_dev;
|
||||||
|
id[2] = (int)(st.st_size & 0xffffffff);
|
||||||
|
id[3] = (int)((st.st_size >> 32) & 0xffffffff);
|
||||||
|
id[4] = (int)(st.st_mtime & 0xffffffff);
|
||||||
|
id[5] = (int)((st.st_mtime >> 32) & 0xffffffff);
|
||||||
|
|
||||||
sprintf(s,
|
sp = s;
|
||||||
"%c%c%c%c%c%c"
|
for (i = 0; i < 6; i++)
|
||||||
"%c%c%c%c%c%c",
|
{
|
||||||
chmap[(id[0] >> 0) & 0x3f],
|
unsigned int t, tt;
|
||||||
chmap[(id[0] >> 6) & 0x3f],
|
int j;
|
||||||
chmap[(id[0] >> 12) & 0x3f],
|
|
||||||
chmap[(id[0] >> 18) & 0x3f],
|
|
||||||
chmap[(id[0] >> 24) & 0x3f],
|
|
||||||
chmap[(id[0] >> 28) & 0x3f],
|
|
||||||
chmap[(id[1] >> 0) & 0x3f],
|
|
||||||
chmap[(id[1] >> 6) & 0x3f],
|
|
||||||
chmap[(id[1] >> 12) & 0x3f],
|
|
||||||
chmap[(id[1] >> 18) & 0x3f],
|
|
||||||
chmap[(id[1] >> 24) & 0x3f], chmap[(id[1] >> 28) & 0x3f]);
|
|
||||||
|
|
||||||
|
t = id[i];
|
||||||
|
j = 32;
|
||||||
|
while (j > 0)
|
||||||
|
{
|
||||||
|
tt = t & ((1 << 6) - 1);
|
||||||
|
*sp = chmap[tt];
|
||||||
|
t >>= 6;
|
||||||
|
j -= 6;
|
||||||
|
sp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*sp = 0;
|
||||||
return strdup(s);
|
return strdup(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue