diff options
author | Cedric BAIL <cedric.bail@samsung.com> | 2014-03-12 18:00:41 +0900 |
---|---|---|
committer | Cedric BAIL <cedric.bail@free.fr> | 2014-04-01 22:00:13 +0900 |
commit | a086a4f089138ddaf1f14602328def619e9df202 (patch) | |
tree | 29ea98547ddd9048d4988d270744b54b913544bf /src/bin/ecore_evas | |
parent | 0609779f1701b04c51032e62e284fee66db0bb14 (diff) |
ecore_evas: add a tool that can convert file using Evas internal loaders and savers.
Diffstat (limited to 'src/bin/ecore_evas')
-rw-r--r-- | src/bin/ecore_evas/.gitignore | 1 | ||||
-rw-r--r-- | src/bin/ecore_evas/ecore_evas_convert.c | 115 |
2 files changed, 116 insertions, 0 deletions
diff --git a/src/bin/ecore_evas/.gitignore b/src/bin/ecore_evas/.gitignore new file mode 100644 index 0000000000..4d54b46925 --- /dev/null +++ b/src/bin/ecore_evas/.gitignore | |||
@@ -0,0 +1 @@ | |||
/ecore_evas_convert | |||
diff --git a/src/bin/ecore_evas/ecore_evas_convert.c b/src/bin/ecore_evas/ecore_evas_convert.c new file mode 100644 index 0000000000..78c8d3c1f0 --- /dev/null +++ b/src/bin/ecore_evas/ecore_evas_convert.c | |||
@@ -0,0 +1,115 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #ifdef HAVE_EVIL | ||
6 | # include <Evil.h> | ||
7 | #endif | ||
8 | |||
9 | #include <Eina.h> | ||
10 | #include <Evas.h> | ||
11 | #include <Ecore.h> | ||
12 | #include <Ecore_Getopt.h> | ||
13 | #include <Ecore_Evas.h> | ||
14 | |||
15 | #undef EINA_LOG_DOMAIN_DEFAULT | ||
16 | #define EINA_LOG_DOMAIN_DEFAULT _log_dom | ||
17 | static int _log_dom = -1; | ||
18 | |||
19 | const Ecore_Getopt optdesc = { | ||
20 | "ecore_evas_convert", | ||
21 | "%prog [options] <filename-source> <filename-destination>", | ||
22 | PACKAGE_VERSION, | ||
23 | "(C) 2014 Enlightenment", | ||
24 | "BSD with advertisement clause", | ||
25 | "Simple application to convert image.", | ||
26 | 0, | ||
27 | { | ||
28 | ECORE_GETOPT_STORE_INT('q', "quality", "define encoding quality in percent."), | ||
29 | ECORE_GETOPT_STORE_TRUE('c', "compress", "define if data should be compressed."), | ||
30 | ECORE_GETOPT_LICENSE('L', "license"), | ||
31 | ECORE_GETOPT_COPYRIGHT('C', "copyright"), | ||
32 | ECORE_GETOPT_VERSION('V', "version"), | ||
33 | ECORE_GETOPT_HELP('h', "help"), | ||
34 | ECORE_GETOPT_SENTINEL | ||
35 | } | ||
36 | }; | ||
37 | |||
38 | int | ||
39 | main(int argc, char *argv[]) | ||
40 | { | ||
41 | char flags[128]; | ||
42 | Ecore_Evas *ee; | ||
43 | Evas *e; | ||
44 | Evas_Object *im; | ||
45 | int arg_index; | ||
46 | int quality = 100; | ||
47 | int r = -1; | ||
48 | Eina_Bool compress = 1; | ||
49 | Eina_Bool quit_option = EINA_FALSE; | ||
50 | |||
51 | Ecore_Getopt_Value values[] = { | ||
52 | ECORE_GETOPT_VALUE_INT(quality), | ||
53 | ECORE_GETOPT_VALUE_BOOL(compress), | ||
54 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
55 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
56 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
57 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
58 | ECORE_GETOPT_VALUE_NONE | ||
59 | }; | ||
60 | |||
61 | eina_init(); | ||
62 | _log_dom = eina_log_domain_register(argv[0], EINA_COLOR_CYAN); | ||
63 | |||
64 | ecore_init(); | ||
65 | ecore_evas_init(); | ||
66 | |||
67 | arg_index = ecore_getopt_parse(&optdesc, values, argc, argv); | ||
68 | if (quit_option) goto end; | ||
69 | |||
70 | if (arg_index < 0) | ||
71 | { | ||
72 | EINA_LOG_ERR("Could not parse argument."); | ||
73 | goto end; | ||
74 | } | ||
75 | if (arg_index + 2 != argc) | ||
76 | { | ||
77 | EINA_LOG_ERR("File not correctly specified."); | ||
78 | goto end; | ||
79 | } | ||
80 | |||
81 | ee = ecore_evas_buffer_new(1, 1); | ||
82 | e = ecore_evas_get(ee); | ||
83 | if (!e) | ||
84 | { | ||
85 | EINA_LOG_ERR("Impossible to create a canvas to do the conversion."); | ||
86 | goto end; | ||
87 | } | ||
88 | |||
89 | snprintf(flags, sizeof (flags), "compress=%i quality=%i", compress, quality); | ||
90 | |||
91 | im = evas_object_image_add(e); | ||
92 | evas_object_image_file_set(im, argv[arg_index], NULL); | ||
93 | |||
94 | if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE) | ||
95 | { | ||
96 | EINA_LOG_ERR("Could not open '%s'. Error was \"%s\".", | ||
97 | argv[arg_index], | ||
98 | evas_load_error_str(evas_object_image_load_error_get(im))); | ||
99 | goto end; | ||
100 | } | ||
101 | |||
102 | if (!evas_object_image_save(im, argv[arg_index + 1], NULL, flags)) | ||
103 | { | ||
104 | EINA_LOG_ERR("Could not convert file to '%s'.", argv[arg_index + 1]); | ||
105 | goto end; | ||
106 | } | ||
107 | |||
108 | r = 0; | ||
109 | |||
110 | end: | ||
111 | ecore_evas_shutdown(); | ||
112 | ecore_shutdown(); | ||
113 | |||
114 | return r; | ||
115 | } | ||