From: Enlightenment S. <no-...@en...> - 2008-10-06 03:25:16
|
Log: epsilon: enable selecting thumbnail format. This will make possible to generate JPEG thumbnails using Evas, before it was just done for EPEG, which is now OLD/deprecated. Patch by Hendrik Siedelmann. Author: barbieri Date: 2008-10-05 20:24:26 -0700 (Sun, 05 Oct 2008) New Revision: 36470 Modified: trunk/epsilon/src/bin/epsilon_thumb_test.c trunk/epsilon/src/bin/epsilon_thumbd.c trunk/epsilon/src/include/Epsilon_Request.h trunk/epsilon/src/include/epsilon_private.h trunk/epsilon/src/lib/Epsilon.c trunk/epsilon/src/lib/Epsilon.h trunk/epsilon/src/lib/epsilon_thumb.c Modified: trunk/epsilon/src/bin/epsilon_thumb_test.c =================================================================== --- trunk/epsilon/src/bin/epsilon_thumb_test.c 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/bin/epsilon_thumb_test.c 2008-10-06 03:24:26 UTC (rev 36470) @@ -36,9 +36,12 @@ char *file; Ecore_List *files; double start, end; + Epsilon_Thumb_Size thumb_size = EPSILON_THUMB_NORMAL; + Epsilon_Thumb_Format thumb_format = EPSILON_THUMB_FDO; + int i; if (argc < 2) { - printf ("Usage: epsilon_thumb_test <directory path>\n"); + printf ("Usage: epsilon_thumb_test [-large] [-jpg] <directory path>\n"); exit(0); } @@ -46,13 +49,17 @@ thumb_done = ecore_event_handler_add(EPSILON_EVENT_DONE, thumb_complete_cb, NULL); - if (!ecore_file_is_dir(argv[1])) { + if (!ecore_file_is_dir(argv[argc - 1])) { printf("Need a directory\n"); exit(-1); } - files = ecore_file_ls(argv[1]); + for(i=1;i<argc;i++) + if (!strcmp(argv[i], "-large")) thumb_size = EPSILON_THUMB_LARGE; + else if (!strcmp(argv[i], "-jpg")) thumb_format = EPSILON_THUMB_LARGE; + files = ecore_file_ls(argv[argc - 1]); + start = ecore_time_get(); ecore_list_first_goto(files); @@ -60,10 +67,10 @@ char *realpath; char fullpath[PATH_MAX]; - snprintf(fullpath, PATH_MAX, "%s/%s", argv[1], file); + snprintf(fullpath, PATH_MAX, "%s/%s", argv[argc - 1], file); realpath = ecore_file_realpath(fullpath); if (ecore_file_exists(realpath) && !ecore_file_is_dir(realpath)) { - epsilon_request_add(realpath, EPSILON_THUMB_NORMAL, NULL); + epsilon_request_add_advanced(realpath, thumb_size, thumb_format, NULL); incomplete_thumbs++; } free(realpath); Modified: trunk/epsilon/src/bin/epsilon_thumbd.c =================================================================== --- trunk/epsilon/src/bin/epsilon_thumbd.c 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/bin/epsilon_thumbd.c 2008-10-06 03:24:26 UTC (rev 36470) @@ -497,6 +497,7 @@ path = ((char *)msg + sizeof(Epsilon_Message)); ep = epsilon_new(path); epsilon_thumb_size(ep, msg->thumbsize); + epsilon_format_set(ep, msg->thumbformat); if (debug) printf("Thumbnailing %d: %s\n", msg->mid, path); /* Modified: trunk/epsilon/src/include/Epsilon_Request.h =================================================================== --- trunk/epsilon/src/include/Epsilon_Request.h 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/include/Epsilon_Request.h 2008-10-06 03:24:26 UTC (rev 36470) @@ -18,6 +18,7 @@ { unsigned int id; /**< Identifier for this thumbnail */ unsigned int size; /**< Thumbnail size to be generated */ + unsigned int format; /**< Thumbnail format to be generated */ unsigned int status; /**< Status code of the thumbnail generation */ char *path; /**< Path to file requiring thumbnail */ char *dest; /**< Path to generated file, NULL on error */ @@ -30,6 +31,8 @@ EAPI int epsilon_request_init(void); EAPI int epsilon_request_shutdown(void); EAPI Epsilon_Request *epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data); +EAPI Epsilon_Request *epsilon_request_add_advanced(const char *path, Epsilon_Thumb_Size size, + Epsilon_Thumb_Format format, void *data); EAPI void epsilon_request_del(Epsilon_Request *thumb); #ifdef __cplusplus Modified: trunk/epsilon/src/include/epsilon_private.h =================================================================== --- trunk/epsilon/src/include/epsilon_private.h 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/include/epsilon_private.h 2008-10-06 03:24:26 UTC (rev 36470) @@ -28,6 +28,7 @@ unsigned int status; unsigned int thumbsize; unsigned int bufsize; + unsigned int thumbformat; }; typedef struct Epsilon_Ipc_End Epsilon_Ipc_End; Modified: trunk/epsilon/src/lib/Epsilon.c =================================================================== --- trunk/epsilon/src/lib/Epsilon.c 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/lib/Epsilon.c 2008-10-06 03:24:26 UTC (rev 36470) @@ -67,6 +67,8 @@ int tw, int th, int sw, int sh, char *imformat, int mtime, char *uri); #endif +static int _epsilon_jpg_write (const char *file, unsigned int * ptr, + Evas_Object *eo, int w, int h); Epsilon * epsilon_new (const char *file) @@ -80,6 +82,7 @@ result->src = strdup (file); result->tw = THUMB_SIZE_LARGE; result->th = THUMB_SIZE_LARGE; + result->format = EPSILON_THUMB_FDO; } else { @@ -217,6 +220,13 @@ } } +void +epsilon_format_set (Epsilon * e, Epsilon_Thumb_Format f) +{ + if (e && (f == EPSILON_THUMB_FDO || f == EPSILON_THUMB_JPEG)) + e->format = f; +} + const char * epsilon_file_get (Epsilon * e) { @@ -236,13 +246,12 @@ return (NULL); if (e->thumb) return (e->thumb); -#ifdef HAVE_EPEG_H + if (_epsilon_exists_ext(e, "jpg", buf, sizeof(buf), &mtime)) { e->thumb = strdup(buf); return (e->thumb); } -#endif #ifdef HAVE_PNG_H if (_epsilon_exists_ext(e, "png", buf, sizeof(buf), &mtime)) { @@ -390,6 +399,9 @@ fclose (fp); #endif } + else + return NULL; + if ((p->eei = epsilon_exif_info_get (e))) { if (p->w == 0) @@ -527,7 +539,6 @@ if (!e->hash) return (EPSILON_FAIL); -#ifdef HAVE_EPEG_H if (!ok) { char path[PATH_MAX]; @@ -538,7 +549,6 @@ /* XXX compare with time from e->src exif tag? */ } } -#endif #ifdef HAVE_PNG_H if (!ok) { @@ -681,16 +691,28 @@ if (data) { snprintf(buf, sizeof(buf), "file://%s", e->src); - _epsilon_file_name(e->tsize, e->hash, "png", buf2, sizeof(buf2)); - /* this is wrong - but hey! good enough? */ - if (ext) snprintf(buf3, sizeof(buf3), "image/%s", ext); - else snprintf(buf3, sizeof(buf3), "image/png"); - if (_epsilon_png_write(buf2, - data, ww, hh, iw, ih, - buf3, mtime, buf)) + if (e->format == EPSILON_THUMB_FDO) { - ret = EPSILON_FAIL; - } + _epsilon_file_name(e->tsize, e->hash, "png", buf2, sizeof(buf2)); + /* this is wrong - but hey! good enough? */ + if (ext) snprintf(buf3, sizeof(buf3), "image/%s", ext); + else snprintf(buf3, sizeof(buf3), "image/png"); + if (_epsilon_png_write(buf2, + data, ww, hh, iw, ih, + buf3, mtime, buf)) + { + ret = EPSILON_FAIL; + } + } + else + { + _epsilon_file_name(e->tsize, e->hash, "jpg", buf2, sizeof(buf2)); + if (_epsilon_jpg_write(buf2, + data, im, ww, hh)) + { + ret = EPSILON_FAIL; + } + } } } if (edje) evas_object_del(edje); @@ -943,3 +965,32 @@ return (ret); } #endif + +static int +_epsilon_jpg_write (const char *file, unsigned int * ptr, Evas_Object *eo, int w, int h) +{ + char tmpfile[PATH_MAX] = ""; + + int l,ll; + char buf[21]; + l=snprintf(tmpfile,sizeof(tmpfile),"%s",file); + ll=snprintf(buf,sizeof(buf),"epsilon-%06d.jpg",(int)getpid()); + strncpy(&tmpfile[l-35], buf,ll+1); + + evas_object_image_data_set(eo, NULL); + evas_object_image_size_set(eo, w, h); + evas_object_image_data_set(eo, ptr); + + if (!evas_object_image_save(eo, tmpfile, NULL, NULL)) + return 1; + + if (!rename (tmpfile, file)) + { + if (chmod (file, S_IWUSR | S_IRUSR)) + fprintf (stderr, + "epsilon: could not set permissions on \"%s\"!?\n", + file); + } + + return 0; +} Modified: trunk/epsilon/src/lib/Epsilon.h =================================================================== --- trunk/epsilon/src/lib/Epsilon.h 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/lib/Epsilon.h 2008-10-06 03:24:26 UTC (rev 36470) @@ -43,6 +43,7 @@ int w, h; int tw, th; int tsize; + int format; }; typedef struct _Epsilon Epsilon; @@ -64,6 +65,14 @@ typedef enum _Epsilon_Thumb_Size Epsilon_Thumb_Size; +enum _Epsilon_Thumb_Format +{ + EPSILON_THUMB_FDO, + EPSILON_THUMB_JPEG +}; + +typedef enum _Epsilon_Thumb_Format Epsilon_Thumb_Format; + EAPI int epsilon_init (void); /* construct destruct */ @@ -74,6 +83,8 @@ EAPI void epsilon_key_set (Epsilon * e, const char *key); /* Set the resolution*/ EAPI void epsilon_resolution_set (Epsilon * e, int w, int h); +/* Set the thumbnail format */ +EAPI void epsilon_format_set (Epsilon * e, Epsilon_Thumb_Format f); /* * the source filename Modified: trunk/epsilon/src/lib/epsilon_thumb.c =================================================================== --- trunk/epsilon/src/lib/epsilon_thumb.c 2008-10-06 03:11:29 UTC (rev 36469) +++ trunk/epsilon/src/lib/epsilon_thumb.c 2008-10-06 03:24:26 UTC (rev 36470) @@ -306,12 +306,14 @@ /** * @param path Path to the original image that will be thumbnailed. * @param size Enum determining the scale of the thumbnail. + * @param size Enum determining the format of the thumbnail. * @param data Data associated with this thumbnail for client use. * @brief Request a thumbnail to be generated asynchronously for the specified * @a path. */ Epsilon_Request * -epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data) +epsilon_request_add_advanced(const char *path, Epsilon_Thumb_Size size, + Epsilon_Thumb_Format format, void *data) { Epsilon_Request *thumb; @@ -333,6 +335,7 @@ } thumb->size = size; thumb->data = data; + thumb->format = format; if (epsilon_request_resolve_thumb_file(thumb)) { thumb->status = 1; epsilon_event_inform_done(thumb); @@ -342,6 +345,7 @@ msg = epsilon_message_new(epsilon_mid++, path, 0); if (msg) { msg->thumbsize = size; + msg->thumbformat = format; if (debug) printf("!! requesting thumbnail for %s (request %d)!!, %d\n", path, msg->mid, sizeof(Epsilon_Message)+msg->bufsize); if (ecore_ipc_server_send(epsilon_server, 1,1,1,1,1,msg,sizeof(Epsilon_Message)+msg->bufsize)) { thumb->id = msg->mid; @@ -358,6 +362,19 @@ } /** + * @param path Path to the original image that will be thumbnailed. + * @param size Enum determining the scale of the thumbnail. + * @param data Data associated with this thumbnail for client use. + * @brief Request a thumbnail to be generated asynchronously for the specified + * @a path. + */ +Epsilon_Request * +epsilon_request_add(const char *path, Epsilon_Thumb_Size size, void *data) +{ + return epsilon_request_add_advanced(path, size, EPSILON_THUMB_FDO, data); +} + +/** * @param thumb Thumbnail request to delete. * @brief Request a thumbnail request to be cancelled. */ |