2009-03-30 14:22:52 -07:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 by ProFUSION embedded systems
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* @author Rafael Antognolli <antognolli@profusion.mobi>
|
|
|
|
*/
|
2009-04-13 15:25:09 -07:00
|
|
|
#include <config.h>
|
2009-03-30 14:22:52 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-04-13 15:25:09 -07:00
|
|
|
#include <limits.h>
|
2009-03-30 14:22:52 -07:00
|
|
|
#include <Ethumb.h>
|
|
|
|
#include <Eina.h>
|
2009-04-13 15:25:09 -07:00
|
|
|
#include <Ecore_Getopt.h>
|
2009-04-17 16:33:45 -07:00
|
|
|
#include <Ecore.h>
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
const char *aspect_opt[] = { "keep", "ignore", "crop", NULL };
|
|
|
|
const char *format_opt[] = { "png", "jpg", NULL };
|
|
|
|
struct frame
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-13 15:25:09 -07:00
|
|
|
const char *file;
|
|
|
|
const char *group;
|
|
|
|
const char *swallow;
|
|
|
|
};
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
static unsigned char
|
|
|
|
_ethumb_getopt_callback_frame_parse(const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage)
|
2009-03-30 14:22:52 -07:00
|
|
|
{
|
2009-04-13 15:25:09 -07:00
|
|
|
struct frame *f = (struct frame *)storage->ptrp;
|
2009-03-30 14:22:52 -07:00
|
|
|
const char *tfile, *tgroup, *tswallow;
|
2009-04-13 15:25:09 -07:00
|
|
|
char *text;
|
|
|
|
char *sep;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
tfile = NULL;
|
|
|
|
tgroup = NULL;
|
|
|
|
tswallow = NULL;
|
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
text = strdup(str);
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
sep = strchr(text, ':');
|
|
|
|
if (!sep)
|
|
|
|
{
|
2009-04-13 15:25:09 -07:00
|
|
|
fprintf(stderr, "ERROR: invalid theme: '%s'\n", text);
|
2009-03-30 14:22:52 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
*sep = '\0';
|
|
|
|
tfile = eina_stringshare_add(text);
|
|
|
|
|
|
|
|
sep++;
|
|
|
|
text = sep;
|
|
|
|
sep = strchr(text, ':');
|
|
|
|
if (!sep)
|
|
|
|
{
|
2009-04-13 15:25:09 -07:00
|
|
|
fprintf(stderr, "ERROR: invalid theme: '%s'\n", text);
|
2009-03-30 14:22:52 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
*sep = '\0';
|
|
|
|
tgroup = eina_stringshare_add(text);
|
|
|
|
|
|
|
|
sep++;
|
|
|
|
tswallow = eina_stringshare_add(sep);
|
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
f->file = tfile;
|
|
|
|
f->group = tgroup;
|
|
|
|
f->swallow = tswallow;
|
2009-03-30 14:22:52 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
|
|
|
eina_stringshare_del(tfile);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
const Ecore_Getopt optdesc = {
|
|
|
|
"ethumb",
|
|
|
|
NULL,
|
|
|
|
PACKAGE_VERSION,
|
|
|
|
"(C) 2009 - ProFUSION embedded systems",
|
|
|
|
"LGPL v3 - GNU Lesser General Public License",
|
|
|
|
"Thumbnails generator.\n"
|
|
|
|
"\n"
|
|
|
|
"This program uses ethumb to create thumbnails from pictures. "
|
|
|
|
"It's an example of use and a test for ethumb.\n",
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
ECORE_GETOPT_CALLBACK_ARGS
|
|
|
|
('s', "size", "thumbnail size expected.",
|
|
|
|
"WxH", ecore_getopt_callback_size_parse, NULL),
|
|
|
|
ECORE_GETOPT_CHOICE
|
|
|
|
('f', "format", "file format to save.", format_opt),
|
|
|
|
ECORE_GETOPT_CHOICE
|
|
|
|
('a', "aspect", "original image aspect ratio.", aspect_opt),
|
|
|
|
ECORE_GETOPT_STORE_STR
|
|
|
|
('d', "directory", "directory to save thumbnails."),
|
|
|
|
ECORE_GETOPT_STORE_STR
|
|
|
|
('c', "category", "thumbnails category."),
|
|
|
|
ECORE_GETOPT_CALLBACK_ARGS
|
|
|
|
('t', "theme", "path to theme file, group and swallow part.",
|
|
|
|
"file:group:swallow_part", _ethumb_getopt_callback_frame_parse, NULL),
|
2009-04-14 12:14:08 -07:00
|
|
|
ECORE_GETOPT_STORE_STR
|
|
|
|
('k', "key", "key inside eet file to read image from."),
|
2009-04-17 16:33:45 -07:00
|
|
|
ECORE_GETOPT_STORE_DOUBLE
|
|
|
|
('v', "video_time", "time of video frame to use as thumbnail."),
|
2009-04-21 16:03:50 -07:00
|
|
|
ECORE_GETOPT_STORE_INT
|
|
|
|
('p', "document_page", "document page to use as thumbnail."),
|
2009-04-13 15:25:09 -07:00
|
|
|
ECORE_GETOPT_LICENSE('L', "license"),
|
|
|
|
ECORE_GETOPT_COPYRIGHT('C', "copyright"),
|
|
|
|
ECORE_GETOPT_VERSION('V', "version"),
|
|
|
|
ECORE_GETOPT_HELP('h', "help"),
|
|
|
|
ECORE_GETOPT_SENTINEL
|
|
|
|
}
|
|
|
|
};
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
static void
|
2009-05-19 06:18:51 -07:00
|
|
|
_finished_thumb(Ethumb *e, Eina_Bool success, void *data)
|
2009-04-17 16:33:45 -07:00
|
|
|
{
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
Ethumb *e;
|
2009-04-13 15:25:09 -07:00
|
|
|
Eina_Bool quit_option = 0;
|
|
|
|
Eina_Rectangle geometry = {-1, -1, -1, -1};
|
|
|
|
unsigned int format = 0, aspect = 0;
|
|
|
|
char *format_str = NULL;
|
|
|
|
char *aspect_str = NULL;
|
|
|
|
char *directory = NULL;
|
|
|
|
char *category = NULL;
|
2009-04-14 12:14:08 -07:00
|
|
|
char *src_key = NULL;
|
2009-04-13 15:25:09 -07:00
|
|
|
struct frame frame = {NULL};
|
2009-04-14 12:14:08 -07:00
|
|
|
const char *thumb_path = NULL;
|
|
|
|
const char *thumb_key = NULL;
|
2009-04-17 16:33:45 -07:00
|
|
|
double video_time = 0;
|
2009-04-21 16:03:50 -07:00
|
|
|
int page = 0;
|
2009-04-13 15:25:09 -07:00
|
|
|
int arg_index;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int r = 1;
|
|
|
|
ethumb_init();
|
2009-04-17 16:33:45 -07:00
|
|
|
ecore_init();
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
Ecore_Getopt_Value values[] = {
|
|
|
|
ECORE_GETOPT_VALUE_PTR_CAST(geometry),
|
|
|
|
ECORE_GETOPT_VALUE_PTR_CAST(format_str),
|
|
|
|
ECORE_GETOPT_VALUE_PTR_CAST(aspect_str),
|
|
|
|
ECORE_GETOPT_VALUE_STR(directory),
|
|
|
|
ECORE_GETOPT_VALUE_STR(category),
|
|
|
|
ECORE_GETOPT_VALUE_PTR_CAST(frame),
|
2009-04-14 12:14:08 -07:00
|
|
|
ECORE_GETOPT_VALUE_STR(src_key),
|
2009-04-17 16:33:45 -07:00
|
|
|
ECORE_GETOPT_VALUE_DOUBLE(video_time),
|
2009-04-21 16:03:50 -07:00
|
|
|
ECORE_GETOPT_VALUE_INT(page),
|
2009-04-13 15:25:09 -07:00
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
|
|
|
|
if (arg_index < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not parse arguments.\n");
|
|
|
|
r = 0;
|
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
if (format_opt[i] == format_str)
|
|
|
|
{
|
|
|
|
format = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
if (aspect_opt[i] == aspect_str)
|
|
|
|
{
|
|
|
|
aspect = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-30 14:22:52 -07:00
|
|
|
e = ethumb_new();
|
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
ethumb_thumb_format_set(e, format);
|
|
|
|
ethumb_thumb_aspect_set(e, aspect);
|
|
|
|
if (directory) ethumb_thumb_dir_path_set(e, directory);
|
|
|
|
if (category) ethumb_thumb_category_set(e, category);
|
|
|
|
if (geometry.w > 0 && geometry.h > 0)
|
|
|
|
ethumb_thumb_size_set(e, geometry.w, geometry.h);
|
|
|
|
if (frame.file)
|
|
|
|
{
|
|
|
|
ethumb_frame_set(e, frame.file, frame.group, frame.swallow);
|
|
|
|
eina_stringshare_del(frame.file);
|
|
|
|
eina_stringshare_del(frame.group);
|
|
|
|
eina_stringshare_del(frame.swallow);
|
|
|
|
}
|
2009-04-17 16:33:45 -07:00
|
|
|
if (video_time > 0)
|
|
|
|
ethumb_video_time_set(e, video_time);
|
2009-04-21 16:03:50 -07:00
|
|
|
if (page > 0)
|
|
|
|
ethumb_document_page_set(e, page);
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
if (r && arg_index < argc)
|
2009-04-21 16:08:17 -07:00
|
|
|
r = ethumb_file_set(e, argv[arg_index++], src_key);
|
2009-05-26 13:33:58 -07:00
|
|
|
else
|
|
|
|
r = 0;
|
2009-04-21 16:08:17 -07:00
|
|
|
if (r && arg_index < argc)
|
2009-04-14 12:14:08 -07:00
|
|
|
thumb_path = argv[arg_index++];
|
2009-04-21 16:08:17 -07:00
|
|
|
if (r && arg_index < argc)
|
2009-04-14 12:14:08 -07:00
|
|
|
thumb_key = argv[arg_index];
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
if (r)
|
2009-04-17 16:31:41 -07:00
|
|
|
{
|
2009-04-21 16:11:37 -07:00
|
|
|
ethumb_thumb_path_set(e, thumb_path, thumb_key);
|
|
|
|
if (ethumb_exists(e))
|
|
|
|
{
|
|
|
|
quit_option = 1;
|
|
|
|
r = 1;
|
|
|
|
}
|
|
|
|
else
|
2009-07-09 12:14:29 -07:00
|
|
|
r = ethumb_generate(e, _finished_thumb, NULL, NULL);
|
2009-04-17 16:31:41 -07:00
|
|
|
}
|
2009-03-30 14:22:52 -07:00
|
|
|
|
2009-04-21 16:03:50 -07:00
|
|
|
if (r && !quit_option)
|
2009-04-17 16:33:45 -07:00
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2009-04-21 16:08:17 -07:00
|
|
|
ethumb_file_free(e);
|
2009-03-30 14:22:52 -07:00
|
|
|
ethumb_free(e);
|
|
|
|
|
2009-04-17 16:33:45 -07:00
|
|
|
ecore_shutdown();
|
2009-03-30 14:22:52 -07:00
|
|
|
ethumb_shutdown();
|
|
|
|
|
2009-04-13 15:25:09 -07:00
|
|
|
return !r;
|
2009-03-30 14:22:52 -07:00
|
|
|
}
|