4 * Copyright (C) 2009 by ProFUSION embedded systems
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library;
18 * if not, see <http://www.gnu.org/licenses/>.
20 * @author Rafael Antognolli <antognolli@profusion.mobi>
33 #include <Ecore_Getopt.h>
36 const char *aspect_opt[] = { "keep", "ignore", "crop", NULL };
37 const char *format_opt[] = { "png", "jpg", "eet", NULL };
46 _ethumb_getopt_callback_frame_parse(const Ecore_Getopt *parser __UNUSED__, const Ecore_Getopt_Desc *desc __UNUSED__, const char *str, void *data __UNUSED__, Ecore_Getopt_Value *storage)
48 struct frame *f = (struct frame *)storage->ptrp;
49 const char *tfile, *tgroup, *tswallow, *base, *sep;
52 sep = strchr(base, ':');
55 tfile = eina_stringshare_add_length(base, sep - base);
58 sep = strchr(base, ':');
61 eina_stringshare_del(tfile);
64 tgroup = eina_stringshare_add_length(base, sep - base);
68 eina_stringshare_del(tfile);
69 eina_stringshare_del(tgroup);
72 tswallow = eina_stringshare_add(base);
76 f->swallow = tswallow;
81 "ERROR: invalid theme, not in format "
82 "'file:group:swallow_part': '%s'\n",
87 const Ecore_Getopt optdesc = {
91 "(C) 2009 - ProFUSION embedded systems",
92 "LGPL v3 - GNU Lesser General Public License",
93 "Thumbnails generator.\n"
95 "This program uses ethumb to create thumbnails from pictures. "
96 "It's an example of use and a test for ethumb.\n",
99 ECORE_GETOPT_CALLBACK_ARGS
100 ('s', "size", "thumbnail size expected.",
101 "WxH", ecore_getopt_callback_size_parse, NULL),
103 ('f', "format", "file format to save.", format_opt),
105 ('a', "aspect", "original image aspect ratio.", aspect_opt),
106 ECORE_GETOPT_STORE_STR
107 ('d', "directory", "directory to save thumbnails."),
108 ECORE_GETOPT_STORE_STR
109 ('c', "category", "thumbnails category."),
110 ECORE_GETOPT_CALLBACK_ARGS
111 ('t', "theme", "path to theme file, group and swallow part.",
112 "file:group:swallow_part", _ethumb_getopt_callback_frame_parse, NULL),
113 ECORE_GETOPT_STORE_STR
114 ('k', "key", "key inside eet file to read image from."),
115 ECORE_GETOPT_STORE_DOUBLE
116 ('v', "video_time", "time of video frame to use as thumbnail."),
117 ECORE_GETOPT_STORE_INT
118 ('p', "document_page", "document page to use as thumbnail."),
119 ECORE_GETOPT_LICENSE('L', "license"),
120 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
121 ECORE_GETOPT_VERSION('V', "version"),
122 ECORE_GETOPT_HELP('h', "help"),
123 ECORE_GETOPT_SENTINEL
128 _thumb_report(const char *mode, Ethumb *e)
130 const char *ap, *ak, *gp, *gk;
131 ethumb_file_get(e, &ap, &ak);
132 ethumb_thumb_path_get(e, &gp, &gk);
133 printf("%s '%s' '%s' => '%s' '%s'\n",
134 mode, ap, ak ? ak : "", gp, gk ? gk : "");
138 _finished_thumb( void *data __UNUSED__, Ethumb *e, Eina_Bool success)
140 const char *mode = success ? "GENERATED" : "FAILED";
141 _thumb_report(mode, e);
142 ecore_main_loop_quit();
146 main(int argc, char *argv[])
149 Eina_Bool quit_option = 0;
150 Eina_Rectangle geometry = {-1, -1, -1, -1};
151 unsigned int format = 0, aspect = 0;
152 char *format_str = NULL;
153 char *aspect_str = NULL;
154 char *directory = NULL;
155 char *category = NULL;
156 char *src_key = NULL;
157 struct frame frame = {NULL, NULL, NULL};
158 const char *thumb_path = NULL;
159 const char *thumb_key = NULL;
160 double video_time = 0;
170 Ecore_Getopt_Value values[] = {
171 ECORE_GETOPT_VALUE_PTR_CAST(geometry),
172 ECORE_GETOPT_VALUE_PTR_CAST(format_str),
173 ECORE_GETOPT_VALUE_PTR_CAST(aspect_str),
174 ECORE_GETOPT_VALUE_STR(directory),
175 ECORE_GETOPT_VALUE_STR(category),
176 ECORE_GETOPT_VALUE_PTR_CAST(frame),
177 ECORE_GETOPT_VALUE_STR(src_key),
178 ECORE_GETOPT_VALUE_DOUBLE(video_time),
179 ECORE_GETOPT_VALUE_INT(page),
180 ECORE_GETOPT_VALUE_BOOL(quit_option),
181 ECORE_GETOPT_VALUE_BOOL(quit_option),
182 ECORE_GETOPT_VALUE_BOOL(quit_option),
183 ECORE_GETOPT_VALUE_BOOL(quit_option),
184 ECORE_GETOPT_VALUE_NONE
187 arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
190 fprintf(stderr, "Could not parse arguments.\n");
193 eina_stringshare_del(frame.file);
194 eina_stringshare_del(frame.group);
195 eina_stringshare_del(frame.swallow);
206 eina_stringshare_del(frame.file);
207 eina_stringshare_del(frame.group);
208 eina_stringshare_del(frame.swallow);
215 for (i = 0; i < 3; i++)
216 if (format_opt[i] == format_str)
222 for (i = 0; i < 3; i++)
223 if (aspect_opt[i] == aspect_str)
231 ethumb_thumb_format_set(e, format);
232 ethumb_thumb_aspect_set(e, aspect);
233 if (directory) ethumb_thumb_dir_path_set(e, directory);
234 if (category) ethumb_thumb_category_set(e, category);
235 if (geometry.w > 0 && geometry.h > 0)
236 ethumb_thumb_size_set(e, geometry.w, geometry.h);
239 ethumb_frame_set(e, frame.file, frame.group, frame.swallow);
240 eina_stringshare_del(frame.file);
241 eina_stringshare_del(frame.group);
242 eina_stringshare_del(frame.swallow);
245 ethumb_video_time_set(e, video_time);
247 ethumb_document_page_set(e, page);
249 if (r && arg_index < argc)
250 r = ethumb_file_set(e, argv[arg_index++], src_key);
253 if (r && arg_index < argc)
254 thumb_path = argv[arg_index++];
255 if (r && arg_index < argc)
256 thumb_key = argv[arg_index];
260 ethumb_thumb_path_set(e, thumb_path, thumb_key);
261 if (ethumb_exists(e))
263 _thumb_report("EXISTS", e);
268 r = ethumb_generate(e, _finished_thumb, NULL, NULL);
271 if (r && !quit_option)
272 ecore_main_loop_begin();