summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-07-22 10:27:10 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-07-22 10:39:42 +0200
commit6da5bd35a9e10c1229a213894795ec841936eee1 (patch)
tree2c4b23568113692eacaad459c2a1d84def3e51ef
parent44363bb70f3cf92f87755a9f34674a318e50779f (diff)
ecore_evas_convert: add the ability to split large jpeg file.
Summary: After trying convert to split very large image and running out of memory, this few line of code did seems like the best solution. Maybe there is some benefit to try to make Ecore_Evas_Convert more useful. Reviewers: zmike, raster, segfaultxavi Reviewed By: segfaultxavi Subscribers: #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9337
-rw-r--r--src/bin/ecore_evas/ecore_evas_convert.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/src/bin/ecore_evas/ecore_evas_convert.c b/src/bin/ecore_evas/ecore_evas_convert.c
index 019e42c7ff..2cddad1052 100644
--- a/src/bin/ecore_evas/ecore_evas_convert.c
+++ b/src/bin/ecore_evas/ecore_evas_convert.c
@@ -30,6 +30,7 @@ const Ecore_Getopt optdesc = {
30 ECORE_GETOPT_STORE_INT('q', "quality", "define encoding quality in percent."), 30 ECORE_GETOPT_STORE_INT('q', "quality", "define encoding quality in percent."),
31 ECORE_GETOPT_STORE_TRUE('c', "compress", "define if data should be compressed."), 31 ECORE_GETOPT_STORE_TRUE('c', "compress", "define if data should be compressed."),
32 ECORE_GETOPT_STORE_STR('e', "encoding", "define the codec (for TGV files: 'etc1', 'etc2', 'etc1+alpha')"), 32 ECORE_GETOPT_STORE_STR('e', "encoding", "define the codec (for TGV files: 'etc1', 'etc2', 'etc1+alpha')"),
33 ECORE_GETOPT_STORE_STR('m', "max-geometry", "define the max size in pixels (WidthxHeight) of any converted image, splitting the image as necessary in a grid pattern ('_XxY' will be appended to the file name)"),
33 ECORE_GETOPT_LICENSE('L', "license"), 34 ECORE_GETOPT_LICENSE('L', "license"),
34 ECORE_GETOPT_COPYRIGHT('C', "copyright"), 35 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
35 ECORE_GETOPT_VERSION('V', "version"), 36 ECORE_GETOPT_VERSION('V', "version"),
@@ -40,24 +41,50 @@ const Ecore_Getopt optdesc = {
40 41
41typedef struct _Save_Job { 42typedef struct _Save_Job {
42 const char *output; 43 const char *output;
44 const char *extension;
43 const char *flags; 45 const char *flags;
44 Evas_Object *im; 46 Evas_Object *im;
45 int ret; 47 int ret;
46} Save_Job; 48} Save_Job;
47 49
48static Save_Job job = { NULL, NULL, NULL, -1 }; 50static Save_Job job = { NULL, NULL, NULL, NULL, -1 };
51static unsigned int width = 0, height = 0;
52static unsigned int x = 0, y = 0;
53static int image_w, image_h;
49 54
50static void 55static void
51_save_do(void *data EINA_UNUSED) 56_save_do(void *data EINA_UNUSED)
52{ 57{
58 const char *output = job.output;
59
53 job.ret = 0; 60 job.ret = 0;
54 if (!evas_object_image_save(job.im, job.output, NULL, job.flags)) 61 if (width || height)
62 {
63 Eina_Slstr *str;
64
65 str = eina_slstr_printf("%s_%ux%u.%s", output, x / width, y / height, job.extension);
66 output = str;
67
68 evas_object_image_load_region_set(job.im, x, y, width, height);
69 x += width;
70
71 if ((int)x > image_w)
72 {
73 y += height;
74 x = 0;
75 }
76
77 }
78
79 fprintf(stderr, "Saving image '%s'\n", output);
80 if (!evas_object_image_save(job.im, output, NULL, job.flags))
55 { 81 {
56 EINA_LOG_ERR("Could not convert file to '%s'.", job.output); 82 EINA_LOG_ERR("Could not convert file to '%s'.", job.output);
57 job.ret = 1; 83 job.ret = 1;
58 } 84 }
59 85
60 ecore_main_loop_quit(); 86 if (!width || ((int)y > image_h)) ecore_main_loop_quit();
87 else ecore_job_add(_save_do, NULL);
61} 88}
62 89
63#ifndef NO_SIGNAL 90#ifndef NO_SIGNAL
@@ -81,6 +108,7 @@ main(int argc, char *argv[])
81 int quality = -1; 108 int quality = -1;
82 int r = -1; 109 int r = -1;
83 char *encoding = NULL; 110 char *encoding = NULL;
111 char *maxgeometry = NULL;
84 Eina_Bool compress = 1; 112 Eina_Bool compress = 1;
85 Eina_Bool quit_option = EINA_FALSE; 113 Eina_Bool quit_option = EINA_FALSE;
86 Eina_Strbuf *flags = NULL; 114 Eina_Strbuf *flags = NULL;
@@ -89,6 +117,7 @@ main(int argc, char *argv[])
89 ECORE_GETOPT_VALUE_INT(quality), 117 ECORE_GETOPT_VALUE_INT(quality),
90 ECORE_GETOPT_VALUE_BOOL(compress), 118 ECORE_GETOPT_VALUE_BOOL(compress),
91 ECORE_GETOPT_VALUE_STR(encoding), 119 ECORE_GETOPT_VALUE_STR(encoding),
120 ECORE_GETOPT_VALUE_STR(maxgeometry),
92 ECORE_GETOPT_VALUE_BOOL(quit_option), 121 ECORE_GETOPT_VALUE_BOOL(quit_option),
93 ECORE_GETOPT_VALUE_BOOL(quit_option), 122 ECORE_GETOPT_VALUE_BOOL(quit_option),
94 ECORE_GETOPT_VALUE_BOOL(quit_option), 123 ECORE_GETOPT_VALUE_BOOL(quit_option),
@@ -116,6 +145,20 @@ main(int argc, char *argv[])
116 goto end; 145 goto end;
117 } 146 }
118 147
148 if (maxgeometry)
149 {
150 if (sscanf(maxgeometry, "%ux%u", &width, &height) != 2)
151 {
152 EINA_LOG_ERR("max-geometry should be specified as WidthxHeight, like 1920x1280.");
153 goto end;
154 }
155 if (width == 0 || height == 0)
156 {
157 EINA_LOG_ERR("max-geometry width and height must be greater than 0.");
158 goto end;
159 }
160 }
161
119 ee = ecore_evas_buffer_new(1, 1); 162 ee = ecore_evas_buffer_new(1, 1);
120 e = ecore_evas_get(ee); 163 e = ecore_evas_get(ee);
121 if (!e) 164 if (!e)
@@ -142,11 +185,22 @@ main(int argc, char *argv[])
142 goto end; 185 goto end;
143 } 186 }
144 187
188 evas_object_image_size_get(im, &image_w, &image_h);
189
145#ifndef NO_SIGNAL 190#ifndef NO_SIGNAL
146 // Brutal way of 191 // Brutal way of
147 signal(SIGINT, _sigint); 192 signal(SIGINT, _sigint);
148#endif 193#endif
149 194
195 // Find the extension and remove it
196 if (width || height)
197 {
198 char *tmp = strrchr(argv[arg_index + 1], '.');
199
200 if (tmp) *tmp = '\0';
201 if (tmp) job.extension = tmp + 1;
202 }
203
150 job.output = argv[arg_index + 1]; 204 job.output = argv[arg_index + 1];
151 job.flags = eina_strbuf_string_get(flags); 205 job.flags = eina_strbuf_string_get(flags);
152 job.im = im; 206 job.im = im;