4 * Copyright (C) 2009 by ProFUSION embedded systems
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 * @author Rafael Antognolli <antognolli@profusion.mobi>
22 * @author Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
31 #include <Ecore_Getopt.h>
34 const char *aspect_opt[] = { "keep", "ignore", "crop", NULL };
35 const char *format_opt[] = { "png", "jpg", "eet", NULL };
44 _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)
46 struct frame *f = (struct frame *)storage->ptrp;
47 const char *tfile, *tgroup, *tswallow, *base, *sep;
50 sep = strchr(base, ':');
53 tfile = eina_stringshare_add_length(base, sep - base);
56 sep = strchr(base, ':');
59 eina_stringshare_del(tfile);
62 tgroup = eina_stringshare_add_length(base, sep - base);
66 eina_stringshare_del(tfile);
67 eina_stringshare_del(tgroup);
70 tswallow = eina_stringshare_add(base);
74 f->swallow = tswallow;
79 "ERROR: invalid theme, not in format "
80 "'file:group:swallow_part': '%s'\n",
85 const Ecore_Getopt optdesc = {
89 "(C) 2009 - ProFUSION embedded systems",
90 "LGPL v3 - GNU Lesser General Public License",
91 "Thumbnails generator.\n"
93 "This program uses ethumb to create thumbnails from pictures. "
94 "It's an example of use and a test for ethumb.\n",
97 ECORE_GETOPT_CALLBACK_ARGS
98 ('s', "size", "thumbnail size expected.",
99 "WxH", ecore_getopt_callback_size_parse, NULL),
101 ('f', "format", "file format to save.", format_opt),
103 ('a', "aspect", "original image aspect ratio.", aspect_opt),
104 ECORE_GETOPT_STORE_STR
105 ('d', "directory", "directory to save thumbnails."),
106 ECORE_GETOPT_STORE_STR
107 ('c', "category", "thumbnails category."),
108 ECORE_GETOPT_CALLBACK_ARGS
109 ('t', "theme", "path to theme file, group and swallow part.",
110 "file:group:swallow_part", _ethumb_getopt_callback_frame_parse, NULL),
111 ECORE_GETOPT_STORE_STR
112 ('k', "key", "key inside eet file to read image from."),
113 ECORE_GETOPT_STORE_DOUBLE
114 ('v', "video_time", "time of video frame to use as thumbnail."),
115 ECORE_GETOPT_STORE_INT
116 ('p', "document_page", "document page to use as thumbnail."),
117 ECORE_GETOPT_LICENSE('L', "license"),
118 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
119 ECORE_GETOPT_VERSION('V', "version"),
120 ECORE_GETOPT_HELP('h', "help"),
121 ECORE_GETOPT_SENTINEL
126 _thumb_report(const char *mode, Ethumb *e)
128 const char *ap, *ak, *gp, *gk;
129 ethumb_file_get(e, &ap, &ak);
130 ethumb_thumb_path_get(e, &gp, &gk);
131 printf("%s '%s' '%s' => '%s' '%s'\n",
132 mode, ap, ak ? ak : "", gp, gk ? gk : "");
136 _finished_thumb( void *data __UNUSED__, Ethumb *e, Eina_Bool success)
138 const char *mode = success ? "GENERATED" : "FAILED";
139 _thumb_report(mode, e);
140 ecore_main_loop_quit();
144 main(int argc, char *argv[])
147 Eina_Bool quit_option = 0;
148 Eina_Rectangle geometry = {-1, -1, -1, -1};
149 unsigned int format = 0, aspect = 0;
150 char *format_str = NULL;
151 char *aspect_str = NULL;
152 char *directory = NULL;
153 char *category = NULL;
154 char *src_key = NULL;
155 struct frame frame = {NULL, NULL, NULL};
156 const char *thumb_path = NULL;
157 const char *thumb_key = NULL;
158 double video_time = 0;
168 Ecore_Getopt_Value values[] = {
169 ECORE_GETOPT_VALUE_PTR_CAST(geometry),
170 ECORE_GETOPT_VALUE_PTR_CAST(format_str),
171 ECORE_GETOPT_VALUE_PTR_CAST(aspect_str),
172 ECORE_GETOPT_VALUE_STR(directory),
173 ECORE_GETOPT_VALUE_STR(category),
174 ECORE_GETOPT_VALUE_PTR_CAST(frame),
175 ECORE_GETOPT_VALUE_STR(src_key),
176 ECORE_GETOPT_VALUE_DOUBLE(video_time),
177 ECORE_GETOPT_VALUE_INT(page),
178 ECORE_GETOPT_VALUE_BOOL(quit_option),
179 ECORE_GETOPT_VALUE_BOOL(quit_option),
180 ECORE_GETOPT_VALUE_BOOL(quit_option),
181 ECORE_GETOPT_VALUE_BOOL(quit_option),
182 ECORE_GETOPT_VALUE_NONE
185 arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
188 fprintf(stderr, "Could not parse arguments.\n");
191 eina_stringshare_del(frame.file);
192 eina_stringshare_del(frame.group);
193 eina_stringshare_del(frame.swallow);
204 eina_stringshare_del(frame.file);
205 eina_stringshare_del(frame.group);
206 eina_stringshare_del(frame.swallow);
213 for (i = 0; i < 3; i++)
214 if (format_opt[i] == format_str)
220 for (i = 0; i < 3; i++)
221 if (aspect_opt[i] == aspect_str)
229 ethumb_thumb_format_set(e, format);
230 ethumb_thumb_aspect_set(e, aspect);
231 if (directory) ethumb_thumb_dir_path_set(e, directory);
232 if (category) ethumb_thumb_category_set(e, category);
233 if (geometry.w > 0 && geometry.h > 0)
234 ethumb_thumb_size_set(e, geometry.w, geometry.h);
237 ethumb_frame_set(e, frame.file, frame.group, frame.swallow);
238 eina_stringshare_del(frame.file);
239 eina_stringshare_del(frame.group);
240 eina_stringshare_del(frame.swallow);
243 ethumb_video_time_set(e, video_time);
245 ethumb_document_page_set(e, page);
247 if (r && arg_index < argc)
248 r = ethumb_file_set(e, argv[arg_index++], src_key);
251 if (r && arg_index < argc)
252 thumb_path = argv[arg_index++];
253 if (r && arg_index < argc)
254 thumb_key = argv[arg_index];
258 ethumb_thumb_path_set(e, thumb_path, thumb_key);
259 if (ethumb_exists(e))
261 _thumb_report("EXISTS", e);
266 r = ethumb_generate(e, _finished_thumb, NULL, NULL);
269 if (r && !quit_option)
270 ecore_main_loop_begin();