summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murzov <e-mail@date.by>2013-03-06 03:09:05 +0400
committerIgor Murzov <e-mail@date.by>2013-03-09 14:11:35 +0400
commit7a794f8477945b42a3278c5dbf33321123658c43 (patch)
tree8ffa5b97615798c0e86968e5094dcc4abc72a973
parent5d20302c35a52342a05c9229c3b47f3397c2a4b6 (diff)
evas: Add WebP image saver
-rw-r--r--ChangeLog7
-rw-r--r--NEWS1
-rw-r--r--src/Makefile_Evas.am16
-rw-r--r--src/lib/evas/common/evas_image_save.c2
-rw-r--r--src/lib/evas/file/evas_module.c4
-rw-r--r--src/modules/evas/savers/webp/evas_image_save_webp.c108
6 files changed, 137 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ca6a15e..966f18a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
12013-03-08 Igor Murzov
2
3 * Add WebP image saver.
4
12013-03-07 Jiyoun Park (Jypark) 52013-03-07 Jiyoun Park (Jypark)
2 6
3 * Ecore_x: Add manual render code before deiconify 7 * Ecore_x: Add manual render code before deiconify
@@ -603,4 +607,7 @@
603 * Fix EINA_INLIST_FOREACH_SAFE macro to work when inlist is not the 607 * Fix EINA_INLIST_FOREACH_SAFE macro to work when inlist is not the
604 first item in the struct. 608 first item in the struct.
605 609
6102012-09-03 Igor Murzov
611
612 * Add WebP image loader.
606 613
diff --git a/NEWS b/NEWS
index 002ccdf..c4dbeb3 100644
--- a/NEWS
+++ b/NEWS
@@ -52,6 +52,7 @@ Additions:
52 - Add window profile support. 52 - Add window profile support.
53 * ecore_getopt: add ECORE_GETOPT_ACTION_BREAK 53 * ecore_getopt: add ECORE_GETOPT_ACTION_BREAK
54 * evas: 54 * evas:
55 - Add WebP image loader and saver modules.
55 - Add ellipsis support in Evas_Object_Text. 56 - Add ellipsis support in Evas_Object_Text.
56 - Add EVAS_GL_LINE_OFFSET_HACK_DISABLE to turn off line shift correction by evas. 57 - Add EVAS_GL_LINE_OFFSET_HACK_DISABLE to turn off line shift correction by evas.
57 - Add EVAS_GL_DIRECT_MEM_OPT to enable on-demand fallback memory allocation policy for EvasGL direct rendering. 58 - Add EVAS_GL_DIRECT_MEM_OPT to enable on-demand fallback memory allocation policy for EvasGL direct rendering.
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index e6ecfd4..1bd921d 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -1264,7 +1264,7 @@ endif
1264 1264
1265if BUILD_LOADER_WEBP 1265if BUILD_LOADER_WEBP
1266if EVAS_STATIC_BUILD_WEBP 1266if EVAS_STATIC_BUILD_WEBP
1267lib_evas_libevas_la_SOURCES += modules/evas/loaders/webp/evas_image_load_webp.c 1267lib_evas_libevas_la_SOURCES += modules/evas/loaders/webp/evas_image_load_webp.c modules/evas/savers/webp/evas_image_save_webp.c
1268lib_evas_libevas_la_CPPFLAGS += @evas_image_loader_webp_cflags@ 1268lib_evas_libevas_la_CPPFLAGS += @evas_image_loader_webp_cflags@
1269lib_evas_libevas_la_LIBADD += @evas_image_loader_webp_libs@ 1269lib_evas_libevas_la_LIBADD += @evas_image_loader_webp_libs@
1270else 1270else
@@ -1281,6 +1281,20 @@ modules_evas_loaders_webp_module_la_LIBADD = \
1281modules_evas_loaders_webp_module_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@ 1281modules_evas_loaders_webp_module_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@
1282modules_evas_loaders_webp_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ 1282modules_evas_loaders_webp_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
1283modules_evas_loaders_webp_module_la_LIBTOOLFLAGS = --tag=disable-static 1283modules_evas_loaders_webp_module_la_LIBTOOLFLAGS = --tag=disable-static
1284
1285saverwebppkgdir = $(libdir)/evas/modules/savers/webp/$(MODULE_ARCH)
1286saverwebppkg_LTLIBRARIES = modules/evas/savers/webp/module.la
1287modules_evas_savers_webp_module_la_SOURCES = modules/evas/savers/webp/evas_image_save_webp.c
1288modules_evas_savers_webp_module_la_CPPFLAGS = \
1289-I$(top_srcdir)/src/lib/evas/include \
1290@EVAS_CFLAGS@ \
1291@evas_image_loader_webp_cflags@
1292modules_evas_savers_webp_module_la_LIBADD = \
1293@USE_EVAS_LIBS@ \
1294@evas_image_loader_webp_libs@
1295modules_evas_savers_webp_module_la_DEPENDENCIES = @USE_EVAS_INTERNAL_LIBS@
1296modules_evas_savers_webp_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
1297modules_evas_savers_webp_module_la_LIBTOOLFLAGS = --tag=disable-static
1284endif 1298endif
1285endif 1299endif
1286 1300
diff --git a/src/lib/evas/common/evas_image_save.c b/src/lib/evas/common/evas_image_save.c
index d97cc5b..ad69a10 100644
--- a/src/lib/evas/common/evas_image_save.c
+++ b/src/lib/evas/common/evas_image_save.c
@@ -28,6 +28,8 @@ evas_common_save_image_to_file(RGBA_Image *im, const char *file, const char *key
28 if ((!strcasecmp(p, "eet")) || (!strcasecmp(p, "edj")) || 28 if ((!strcasecmp(p, "eet")) || (!strcasecmp(p, "edj")) ||
29 (!strcasecmp(p, "eap"))) 29 (!strcasecmp(p, "eap")))
30 saver = "eet"; 30 saver = "eet";
31 if (!strcasecmp(p, "webp"))
32 saver = "webp";
31 } 33 }
32 34
33 if (saver) 35 if (saver)
diff --git a/src/lib/evas/file/evas_module.c b/src/lib/evas/file/evas_module.c
index 0a5e302..03ab41c 100644
--- a/src/lib/evas/file/evas_module.c
+++ b/src/lib/evas/file/evas_module.c
@@ -133,6 +133,7 @@ EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, eet);
133EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, jpeg); 133EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, jpeg);
134EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, png); 134EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, png);
135EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, tiff); 135EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, tiff);
136EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, webp);
136 137
137static const struct { 138static const struct {
138 Eina_Bool (*init)(void); 139 Eina_Bool (*init)(void);
@@ -222,6 +223,9 @@ static const struct {
222#ifdef EVAS_STATIC_BUILD_TIFF 223#ifdef EVAS_STATIC_BUILD_TIFF
223 EVAS_EINA_STATIC_MODULE_USE(image_saver, tiff), 224 EVAS_EINA_STATIC_MODULE_USE(image_saver, tiff),
224#endif 225#endif
226#ifdef EVAS_STATIC_BUILD_WEBP
227 EVAS_EINA_STATIC_MODULE_USE(image_saver, webp),
228#endif
225 { NULL, NULL } 229 { NULL, NULL }
226}; 230};
227 231
diff --git a/src/modules/evas/savers/webp/evas_image_save_webp.c b/src/modules/evas/savers/webp/evas_image_save_webp.c
new file mode 100644
index 0000000..9c2cbd1
--- /dev/null
+++ b/src/modules/evas/savers/webp/evas_image_save_webp.c
@@ -0,0 +1,108 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <webp/encode.h>
7
8#include "evas_common.h"
9#include "evas_private.h"
10
11static int evas_image_save_file_webp(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
12
13static Evas_Image_Save_Func evas_image_save_webp_func =
14{
15 evas_image_save_file_webp
16};
17
18static int writer(const uint8_t *data, size_t data_size, const WebPPicture *const pic)
19{
20 FILE *out = (FILE *)pic->custom_ptr;
21 return data_size ? (fwrite(data, data_size, 1, out) == 1) : 1;
22}
23
24static int
25save_image_webp(RGBA_Image *im, const char *file, int quality)
26{
27 WebPPicture picture;
28 WebPConfig config;
29 int result = 0;
30
31 if (!im || !im->image.data || !file)
32 return 0;
33
34 if (!WebPPictureInit(&picture) || !WebPConfigInit(&config))
35 return 0;
36
37 picture.width = im->cache_entry.w;
38 picture.height = im->cache_entry.h;
39 picture.use_argb = 1;
40 if (im->cache_entry.flags.alpha)
41 picture.colorspace |= WEBP_CSP_ALPHA_BIT;
42 else
43 picture.colorspace &= ~WEBP_CSP_ALPHA_BIT;
44
45 if (!WebPPictureAlloc(&picture)) // allocates picture.argb
46 return 0;
47 memcpy(picture.argb, im->image.data, picture.width * picture.height * sizeof(DATA32));
48 evas_common_convert_argb_unpremul(picture.argb, picture.width * picture.height);
49
50 if (quality == 100)
51 config.lossless = 1;
52 else
53 config.quality = quality;
54 // config.method = 6; // slower, but better quality
55
56 if (!WebPValidateConfig(&config))
57 goto free_picture;
58
59 FILE *f = fopen(file, "wb");
60 if (f == NULL)
61 goto free_picture;
62
63 picture.writer = writer;
64 picture.custom_ptr = (void *)f;
65
66 result = WebPEncode(&config, &picture);
67
68 fclose(f);
69 free_picture:
70 WebPPictureFree(&picture);
71
72 return result;
73}
74
75static int evas_image_save_file_webp(RGBA_Image *im, const char *file, const char *key EINA_UNUSED, int quality, int compress EINA_UNUSED)
76{
77 return save_image_webp(im, file, quality);
78}
79
80static int
81module_open(Evas_Module *em)
82{
83 if (!em) return 0;
84 em->functions = (void *)(&evas_image_save_webp_func);
85 return 1;
86}
87
88static void
89module_close(Evas_Module *em EINA_UNUSED)
90{
91}
92
93static Evas_Module_Api evas_modapi =
94{
95 EVAS_MODULE_API_VERSION,
96 "webp",
97 "none",
98 {
99 module_open,
100 module_close
101 }
102};
103
104EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_SAVER, image_saver, webp);
105
106#ifndef EVAS_STATIC_BUILD_WEBP
107EVAS_EINA_MODULE_DEFINE(image_saver, webp);
108#endif