summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2019-02-27 13:17:35 -0500
committerMike Blumenkrantz <zmike@samsung.com>2019-02-27 13:17:35 -0500
commit540d3b95874e1ebdcbd6ccf9eaf1cab0af30f833 (patch)
tree34575d7a518cecc4745576be7ea3099a5087268d
parent4192753490a3c791cc18c57be07c230b9ca33732 (diff)
efl.file_save: rework save flags
Summary: instead of passing a string which requires reading docs to know which arbitrary string key=value sets can be passed, use an extensible struct which contains more easily referenced values ref T7672 Depends on D8035 Reviewers: segfaultxavi Reviewed By: segfaultxavi Subscribers: segfaultxavi, cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7672 Differential Revision: https://phab.enlightenment.org/D8039
-rw-r--r--src/lib/efl/interfaces/efl_file_save.eo12
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg_object.c6
-rw-r--r--src/lib/evas/canvas/evas_canvas3d_mesh.c2
-rw-r--r--src/lib/evas/canvas/evas_image_legacy.c33
-rw-r--r--src/lib/evas/canvas/evas_object_image.c61
-rw-r--r--src/lib/evas/canvas/evas_vg_private.h4
-rw-r--r--src/lib/evas/vg/evas_vg_cache.c31
7 files changed, 76 insertions, 73 deletions
diff --git a/src/lib/efl/interfaces/efl_file_save.eo b/src/lib/efl/interfaces/efl_file_save.eo
index 3cdc234fff..43c8d4c8f6 100644
--- a/src/lib/efl/interfaces/efl_file_save.eo
+++ b/src/lib/efl/interfaces/efl_file_save.eo
@@ -1,5 +1,14 @@
1import eina_types; 1import eina_types;
2 2
3
4struct Efl.File_Save_Info
5{
6 [[Info used to determine various attributes when saving a file.]]
7 quality: uint; [[The quality level (0-100) to save the file with; commonly used when saving image files.]]
8 compression: uint; [[The compression level (0-100) to save the file with.]]
9 encoding: string; [[The encoding to use when saving the file.]]
10}
11
3interface @beta Efl.File_Save { 12interface @beta Efl.File_Save {
4 [[Efl file saving interface]] 13 [[Efl file saving interface]]
5 methods { 14 methods {
@@ -20,8 +29,7 @@ interface @beta Efl.File_Save {
20 obligatory).]] 29 obligatory).]]
21 @in key: string; [[The image key in the file (if an Eet one), or $null, 30 @in key: string; [[The image key in the file (if an Eet one), or $null,
22 otherwise.]] 31 otherwise.]]
23 @in flags: string; [[String containing the flags to be used ($null for 32 @in info: const(ptr(Efl.File_Save_Info)); [[The flags to be used ($null for defaults).]]
24 none).]]
25 } 33 }
26 return: bool; [[$true on success, $false otherwise]] 34 return: bool; [[$true on success, $false otherwise]]
27 } 35 }
diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.c b/src/lib/evas/canvas/efl_canvas_vg_object.c
index db224fdaab..25c092f1d1 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_object.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_object.c
@@ -292,14 +292,14 @@ _efl_canvas_vg_object_efl_file_unload(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd)
292} 292}
293 293
294EOLIAN static Eina_Bool 294EOLIAN static Eina_Bool
295_efl_canvas_vg_object_efl_file_save_save(const Eo *obj, Efl_Canvas_Vg_Object_Data *pd, const char *file, const char *key, const char *flags) 295_efl_canvas_vg_object_efl_file_save_save(const Eo *obj, Efl_Canvas_Vg_Object_Data *pd, const char *file, const char *key, const Efl_File_Save_Info *info)
296{ 296{
297 if (pd->vg_entry) 297 if (pd->vg_entry)
298 return evas_cache_vg_entry_file_save(pd->vg_entry, file, key, flags); 298 return evas_cache_vg_entry_file_save(pd->vg_entry, file, key, info);
299 299
300 Evas_Coord w, h; 300 Evas_Coord w, h;
301 evas_object_geometry_get(obj, NULL, NULL, &w, &h); 301 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
302 return evas_cache_vg_file_save(pd->root, w, h, file, key, flags); 302 return evas_cache_vg_file_save(pd->root, w, h, file, key, info);
303} 303}
304 304
305static void 305static void
diff --git a/src/lib/evas/canvas/evas_canvas3d_mesh.c b/src/lib/evas/canvas/evas_canvas3d_mesh.c
index ccac776dd5..bdf50e0d89 100644
--- a/src/lib/evas/canvas/evas_canvas3d_mesh.c
+++ b/src/lib/evas/canvas/evas_canvas3d_mesh.c
@@ -887,7 +887,7 @@ EOLIAN static Eina_Bool
887_evas_canvas3d_mesh_efl_file_save_save(const Eo *obj, Evas_Canvas3D_Mesh_Data *pd, 887_evas_canvas3d_mesh_efl_file_save_save(const Eo *obj, Evas_Canvas3D_Mesh_Data *pd,
888 const char *file, 888 const char *file,
889 const char *key EINA_UNUSED, 889 const char *key EINA_UNUSED,
890 const char *flags EINA_UNUSED) 890 const Efl_File_Save_Info *info EINA_UNUSED)
891{ 891{
892 if ((file == NULL) || (obj == NULL) || (pd == NULL)) return EINA_FALSE; 892 if ((file == NULL) || (obj == NULL) || (pd == NULL)) return EINA_FALSE;
893 893
diff --git a/src/lib/evas/canvas/evas_image_legacy.c b/src/lib/evas/canvas/evas_image_legacy.c
index 886a37feba..88052a7deb 100644
--- a/src/lib/evas/canvas/evas_image_legacy.c
+++ b/src/lib/evas/canvas/evas_image_legacy.c
@@ -221,8 +221,39 @@ evas_object_image_mmap_get(const Evas_Object *obj, const Eina_File **f, const ch
221EAPI Eina_Bool 221EAPI Eina_Bool
222evas_object_image_save(const Evas_Object *obj, const char *file, const char *key, const char *flags) 222evas_object_image_save(const Evas_Object *obj, const char *file, const char *key, const char *flags)
223{ 223{
224 char *encoding = NULL;
225 Efl_File_Save_Info info;
226 Eina_Error ret;
227
224 EVAS_IMAGE_API(obj, EINA_FALSE); 228 EVAS_IMAGE_API(obj, EINA_FALSE);
225 return efl_file_save(obj, file, key, flags); 229
230 if (flags)
231 {
232 char *p, *pp;
233 char *tflags;
234 int quality = 80, compress = 9;
235
236 tflags = alloca(strlen(flags) + 1);
237 strcpy(tflags, flags);
238 p = tflags;
239 while (p)
240 {
241 pp = strchr(p, ' ');
242 if (pp) *pp = 0;
243 sscanf(p, "quality=%4i", &quality);
244 sscanf(p, "compress=%4i", &compress);
245 sscanf(p, "encoding=%ms", &encoding);
246 if (pp) p = pp + 1;
247 else break;
248 }
249 info.quality = quality;
250 info.compression = compress;
251 info.encoding = encoding;
252
253 }
254 ret = efl_file_save(obj, file, key, flags ? &info : NULL);
255 free(encoding);
256 return ret;
226} 257}
227 258
228EAPI Eina_Bool 259EAPI Eina_Bool
diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c
index a47934ea3b..1053451ee8 100644
--- a/src/lib/evas/canvas/evas_object_image.c
+++ b/src/lib/evas/canvas/evas_object_image.c
@@ -861,10 +861,10 @@ _efl_canvas_image_internal_efl_gfx_image_image_load_error_get(const Eo *eo_obj E
861} 861}
862 862
863EOLIAN static Eina_Bool 863EOLIAN static Eina_Bool
864_efl_canvas_image_internal_efl_file_save_save(const Eo *eo_obj, Evas_Image_Data *o, const char *file, const char *key, const char *flags) 864_efl_canvas_image_internal_efl_file_save_save(const Eo *eo_obj, Evas_Image_Data *o, const char *file, const char *key, const Efl_File_Save_Info *info)
865{ 865{
866 int quality = 80, compress = 9, ok = 0; 866 int quality = 80, compress = 9, ok = 0;
867 char *encoding = NULL; 867 const char *encoding = NULL;
868 Image_Entry *ie; 868 Image_Entry *ie;
869 Evas_Colorspace cspace = EVAS_COLORSPACE_ARGB8888; 869 Evas_Colorspace cspace = EVAS_COLORSPACE_ARGB8888;
870 Evas_Colorspace want_cspace = EVAS_COLORSPACE_ARGB8888; 870 Evas_Colorspace want_cspace = EVAS_COLORSPACE_ARGB8888;
@@ -889,46 +889,31 @@ _efl_canvas_image_internal_efl_file_save_save(const Eo *eo_obj, Evas_Image_Data
889 889
890 cspace = ENFN->image_file_colorspace_get(ENC, pixels); 890 cspace = ENFN->image_file_colorspace_get(ENC, pixels);
891 want_cspace = cspace; 891 want_cspace = cspace;
892 892 if (info)
893 if (flags)
894 { 893 {
895 const char *ext; 894 encoding = info->encoding;
896 char *p, *pp; 895 quality = info->quality;
897 char *tflags; 896 compress = info->compression;
898 897 }
899 tflags = alloca(strlen(flags) + 1);
900 strcpy(tflags, flags);
901 p = tflags;
902 while (p)
903 {
904 pp = strchr(p, ' ');
905 if (pp) *pp = 0;
906 sscanf(p, "quality=%4i", &quality);
907 sscanf(p, "compress=%4i", &compress);
908 sscanf(p, "encoding=%ms", &encoding);
909 if (pp) p = pp + 1;
910 else break;
911 }
912 898
913 if (encoding) 899 if (encoding)
900 {
901 const char *ext = strrchr(file, '.');
902 if (ext && !strcasecmp(ext, ".tgv"))
914 { 903 {
915 ext = strrchr(file, '.'); 904 if (!strcmp(encoding, "auto"))
916 if (ext && !strcasecmp(ext, ".tgv")) 905 want_cspace = cspace;
906 else if (!strcmp(encoding, "etc1"))
907 want_cspace = EVAS_COLORSPACE_ETC1;
908 else if (!strcmp(encoding, "etc2"))
917 { 909 {
918 if (!strcmp(encoding, "auto")) 910 if (!ENFN->image_alpha_get(ENC, pixels))
919 want_cspace = cspace; 911 want_cspace = EVAS_COLORSPACE_RGB8_ETC2;
920 else if (!strcmp(encoding, "etc1")) 912 else
921 want_cspace = EVAS_COLORSPACE_ETC1; 913 want_cspace = EVAS_COLORSPACE_RGBA8_ETC2_EAC;
922 else if (!strcmp(encoding, "etc2"))
923 {
924 if (!ENFN->image_alpha_get(ENC, pixels))
925 want_cspace = EVAS_COLORSPACE_RGB8_ETC2;
926 else
927 want_cspace = EVAS_COLORSPACE_RGBA8_ETC2_EAC;
928 }
929 else if (!strcmp(encoding, "etc1+alpha"))
930 want_cspace = EVAS_COLORSPACE_ETC1_ALPHA;
931 } 914 }
915 else if (!strcmp(encoding, "etc1+alpha"))
916 want_cspace = EVAS_COLORSPACE_ETC1_ALPHA;
932 } 917 }
933 } 918 }
934 919
@@ -971,12 +956,10 @@ _efl_canvas_image_internal_efl_file_save_save(const Eo *eo_obj, Evas_Image_Data
971 if (unmap_it) 956 if (unmap_it)
972 ENFN->image_data_unmap(ENC, pixels, &slice); 957 ENFN->image_data_unmap(ENC, pixels, &slice);
973 958
974 free(encoding);
975 if (!ok) ERR("Image save failed."); 959 if (!ok) ERR("Image save failed.");
976 return ok; 960 return ok;
977 961
978no_pixels: 962no_pixels:
979 free(encoding);
980 ERR("Could not get image pixels for saving."); 963 ERR("Could not get image pixels for saving.");
981 return EINA_FALSE; 964 return EINA_FALSE;
982} 965}
diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h
index 904c42506c..7fb62d4827 100644
--- a/src/lib/evas/canvas/evas_vg_private.h
+++ b/src/lib/evas/canvas/evas_vg_private.h
@@ -123,8 +123,8 @@ Vg_Cache_Entry* evas_cache_vg_entry_create(const char *file, const c
123Efl_VG* evas_cache_vg_tree_get(Vg_Cache_Entry *vg_entry); 123Efl_VG* evas_cache_vg_tree_get(Vg_Cache_Entry *vg_entry);
124void evas_cache_vg_entry_del(Vg_Cache_Entry *vg_entry); 124void evas_cache_vg_entry_del(Vg_Cache_Entry *vg_entry);
125Vg_File_Data * evas_cache_vg_file_open(const char *file, const char *key); 125Vg_File_Data * evas_cache_vg_file_open(const char *file, const char *key);
126Eina_Bool evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char *key, const char *flags); 126Eina_Bool evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char *key, const Efl_File_Save_Info *info);
127Eina_Bool evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, const char *flags); 127Eina_Bool evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, const Efl_File_Save_Info *info);
128void efl_canvas_vg_node_vg_obj_set(Efl_VG *node, Efl_VG *vg_obj, Efl_Canvas_Vg_Object_Data *vd); 128void efl_canvas_vg_node_vg_obj_set(Efl_VG *node, Efl_VG *vg_obj, Efl_Canvas_Vg_Object_Data *vd);
129void efl_canvas_vg_node_change(Efl_VG *node); 129void efl_canvas_vg_node_change(Efl_VG *node);
130void efl_canvas_vg_container_vg_obj_update(Efl_VG *obj, Efl_Canvas_Vg_Node_Data *nd); 130void efl_canvas_vg_container_vg_obj_update(Efl_VG *obj, Efl_Canvas_Vg_Node_Data *nd);
diff --git a/src/lib/evas/vg/evas_vg_cache.c b/src/lib/evas/vg/evas_vg_cache.c
index bd5a4a4f14..e3a5d60529 100644
--- a/src/lib/evas/vg/evas_vg_cache.c
+++ b/src/lib/evas/vg/evas_vg_cache.c
@@ -167,7 +167,7 @@ _evas_cache_vg_entry_free_cb(void *data)
167} 167}
168 168
169static Eina_Bool 169static Eina_Bool
170_vg_file_save(Vg_File_Data *vfd, const char *file, const char *key, const char *flags) 170_vg_file_save(Vg_File_Data *vfd, const char *file, const char *key, const Efl_File_Save_Info *info)
171{ 171{
172 Evas_Module *em; 172 Evas_Module *em;
173 Evas_Vg_Save_Func *saver; 173 Evas_Vg_Save_Func *saver;
@@ -176,24 +176,7 @@ _vg_file_save(Vg_File_Data *vfd, const char *file, const char *key, const char *
176 176
177 if (!file) return EINA_FALSE; 177 if (!file) return EINA_FALSE;
178 178
179 if (flags) 179 if (info) compress = info->compression;
180 {
181 char *p, *pp;
182 char *tflags;
183
184 int len = strlen(flags) + 1;
185 tflags = alloca(len);
186 strncpy(tflags, flags, len);
187 p = tflags;
188 while (p)
189 {
190 pp = strchr(p, ' ');
191 if (pp) *pp = 0;
192 sscanf(p, "compress=%i", &compress);
193 if (pp) p = pp + 1;
194 else break;
195 }
196 }
197 180
198 em = _find_saver_module(file); 181 em = _find_saver_module(file);
199 if (em) 182 if (em)
@@ -408,20 +391,18 @@ evas_cache_vg_entry_del(Vg_Cache_Entry *vg_entry)
408} 391}
409 392
410Eina_Bool 393Eina_Bool
411evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, 394evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, const Efl_File_Save_Info *info)
412 const char *flags)
413{ 395{
414 Vg_File_Data *vfd = 396 Vg_File_Data *vfd =
415 evas_cache_vg_file_open(vg_entry->file, vg_entry->key); 397 evas_cache_vg_file_open(vg_entry->file, vg_entry->key);
416 398
417 if (!vfd) return EINA_FALSE; 399 if (!vfd) return EINA_FALSE;
418 400
419 return _vg_file_save(vfd, file, key, flags); 401 return _vg_file_save(vfd, file, key, info);
420} 402}
421 403
422Eina_Bool 404Eina_Bool
423evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char *key, 405evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char *key, const Efl_File_Save_Info *info)
424 const char *flags)
425{ 406{
426 Vg_File_Data vfd = {}; 407 Vg_File_Data vfd = {};
427 408
@@ -432,5 +413,5 @@ evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char
432 vfd.root = root; 413 vfd.root = root;
433 vfd.preserve_aspect = EINA_FALSE; 414 vfd.preserve_aspect = EINA_FALSE;
434 415
435 return _vg_file_save(&vfd, file, key, flags); 416 return _vg_file_save(&vfd, file, key, info);
436} 417}