summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorIgor Murzov <e-mail@date.by>2012-09-03 06:22:59 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-09-03 06:22:59 +0000
commite42648154ff65e676ce1dec02ea00d5bc8308d46 (patch)
treeadf0710a752ba580703b4097c8f1fe959bf3ded8 /legacy
parente7d316dbc211331dcdd8410f41deb881bbd888eb (diff)
From: Igor Murzov <e-mail@date.by>
Subject: [E-devel] [PATCH][RESEND][Evas] WebP image loader This patch adds a WebP image loader to Evas. No saver, no animation support for now, just loader. Tested with the libwebp-0.2.0 only, but should work fine with older versions. SVN revision: 75951
Diffstat (limited to 'legacy')
-rw-r--r--legacy/evas/AUTHORS1
-rw-r--r--legacy/evas/ChangeLog4
-rw-r--r--legacy/evas/NEWS4
-rw-r--r--legacy/evas/README3
-rw-r--r--legacy/evas/configure.ac6
-rw-r--r--legacy/evas/m4/evas_check_loader.m432
-rw-r--r--legacy/evas/src/bin/evas_cserve2_slave.c3
-rw-r--r--legacy/evas/src/bin/loaders/Makefile.am4
-rw-r--r--legacy/evas/src/bin/loaders/webp/Makefile.am33
-rw-r--r--legacy/evas/src/bin/loaders/webp/evas_image_load_webp.c135
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image_load.c3
-rw-r--r--legacy/evas/src/lib/file/evas_module.c4
-rw-r--r--legacy/evas/src/modules/loaders/Makefile.am6
-rw-r--r--legacy/evas/src/modules/loaders/webp/Makefile.am35
-rw-r--r--legacy/evas/src/modules/loaders/webp/evas_image_load_webp.c165
15 files changed, 436 insertions, 2 deletions
diff --git a/legacy/evas/AUTHORS b/legacy/evas/AUTHORS
index ae614e5..f8c2a51 100644
--- a/legacy/evas/AUTHORS
+++ b/legacy/evas/AUTHORS
@@ -37,3 +37,4 @@ Jérôme Pinot <ngc891@gmail.com>
37Rafael Antognolli <antognolli@profusion.mobi> 37Rafael Antognolli <antognolli@profusion.mobi>
38Daniel Zaoui <daniel.zaoui@samsung.com> 38Daniel Zaoui <daniel.zaoui@samsung.com>
39Christophe Sadoine <chris@indefini.org> 39Christophe Sadoine <chris@indefini.org>
40Igor Murzov <e-mail@date.by>
diff --git a/legacy/evas/ChangeLog b/legacy/evas/ChangeLog
index 2e9c5c9..dfce0a1 100644
--- a/legacy/evas/ChangeLog
+++ b/legacy/evas/ChangeLog
@@ -1008,3 +1008,7 @@
1008 1008
1009 * Fix seg fault in the esvg loader, latest code is required, and 1009 * Fix seg fault in the esvg loader, latest code is required, and
1010 enable it on Windows. 1010 enable it on Windows.
1011
10122012-09-03 Igor Murzov
1013
1014 * Add WEBP loader module and cserve2 binary loader patch.
diff --git a/legacy/evas/NEWS b/legacy/evas/NEWS
index 27c0875..6b96648 100644
--- a/legacy/evas/NEWS
+++ b/legacy/evas/NEWS
@@ -3,6 +3,10 @@ Evas 1.8.0
3Changes since Evas 1.7.0: 3Changes since Evas 1.7.0:
4------------------------- 4-------------------------
5 5
6Additions:
7
8 * WEBP image loader support.
9
6Improvements: 10Improvements:
7 11
8 * Function to rotate an evas map with a quaternion: evas_map_util_quat_rotate(). 12 * Function to rotate an evas map with a quaternion: evas_map_util_quat_rotate().
diff --git a/legacy/evas/README b/legacy/evas/README
index 5e0b0bc..7660890 100644
--- a/legacy/evas/README
+++ b/legacy/evas/README
@@ -527,6 +527,9 @@ egueb
527 527
528this loader uses libtiff to load tiff image files 528this loader uses libtiff to load tiff image files
529 529
530--enable-image-loader-webp[=static]
531
532this loader uses libwebp to load webp image files
530 533
531--enable-image-loader-xpm[=static] 534--enable-image-loader-xpm[=static]
532 535
diff --git a/legacy/evas/configure.ac b/legacy/evas/configure.ac
index 30f5785..8dfd9bb 100644
--- a/legacy/evas/configure.ac
+++ b/legacy/evas/configure.ac
@@ -126,6 +126,7 @@ want_evas_image_loader_xpm="yes"
126want_evas_image_loader_bmp="yes" 126want_evas_image_loader_bmp="yes"
127want_evas_image_loader_tga="yes" 127want_evas_image_loader_tga="yes"
128want_evas_image_loader_wbmp="yes" 128want_evas_image_loader_wbmp="yes"
129want_evas_image_loader_webp="yes"
129want_evas_image_loader_ico="yes" 130want_evas_image_loader_ico="yes"
130want_evas_image_loader_psd="yes" 131want_evas_image_loader_psd="yes"
131want_evas_image_loader_generic="yes" 132want_evas_image_loader_generic="yes"
@@ -1058,6 +1059,8 @@ EVAS_CHECK_IMAGE_LOADER([TGA], [${want_evas_image_loader_tga}])
1058 1059
1059EVAS_CHECK_IMAGE_LOADER([WBMP], [${want_evas_image_loader_wbmp}]) 1060EVAS_CHECK_IMAGE_LOADER([WBMP], [${want_evas_image_loader_wbmp}])
1060 1061
1062EVAS_CHECK_IMAGE_LOADER([WEBP], [${want_evas_image_loader_webp}])
1063
1061EVAS_CHECK_IMAGE_LOADER([ICO], [${want_evas_image_loader_ico}]) 1064EVAS_CHECK_IMAGE_LOADER([ICO], [${want_evas_image_loader_ico}])
1062 1065
1063EVAS_CHECK_IMAGE_LOADER([PSD], [${want_evas_image_loader_psd}]) 1066EVAS_CHECK_IMAGE_LOADER([PSD], [${want_evas_image_loader_psd}])
@@ -1845,6 +1848,7 @@ src/bin/loaders/ico/Makefile
1845src/bin/loaders/tga/Makefile 1848src/bin/loaders/tga/Makefile
1846src/bin/loaders/pmaps/Makefile 1849src/bin/loaders/pmaps/Makefile
1847src/bin/loaders/wbmp/Makefile 1850src/bin/loaders/wbmp/Makefile
1851src/bin/loaders/webp/Makefile
1848src/bin/loaders/psd/Makefile 1852src/bin/loaders/psd/Makefile
1849src/lib/Makefile 1853src/lib/Makefile
1850src/lib/canvas/Makefile 1854src/lib/canvas/Makefile
@@ -1900,6 +1904,7 @@ src/modules/loaders/tga/Makefile
1900src/modules/loaders/svg/Makefile 1904src/modules/loaders/svg/Makefile
1901src/modules/loaders/pmaps/Makefile 1905src/modules/loaders/pmaps/Makefile
1902src/modules/loaders/wbmp/Makefile 1906src/modules/loaders/wbmp/Makefile
1907src/modules/loaders/webp/Makefile
1903src/modules/loaders/psd/Makefile 1908src/modules/loaders/psd/Makefile
1904src/modules/loaders/generic/Makefile 1909src/modules/loaders/generic/Makefile
1905src/modules/savers/Makefile 1910src/modules/savers/Makefile
@@ -1994,6 +1999,7 @@ echo " SVG.....................: $have_evas_image_loader_svg"
1994echo " TGA.....................: $have_evas_image_loader_tga" 1999echo " TGA.....................: $have_evas_image_loader_tga"
1995echo " TIFF....................: $have_evas_image_loader_tiff" 2000echo " TIFF....................: $have_evas_image_loader_tiff"
1996echo " WBMP....................: $have_evas_image_loader_wbmp" 2001echo " WBMP....................: $have_evas_image_loader_wbmp"
2002echo " WEBP....................: $have_evas_image_loader_webp"
1997echo " XPM.....................: $have_evas_image_loader_xpm" 2003echo " XPM.....................: $have_evas_image_loader_xpm"
1998echo 2004echo
1999echo "Font Sourcing Systems:" 2005echo "Font Sourcing Systems:"
diff --git a/legacy/evas/m4/evas_check_loader.m4 b/legacy/evas/m4/evas_check_loader.m4
index cf4924e..0130484 100644
--- a/legacy/evas/m4/evas_check_loader.m4
+++ b/legacy/evas/m4/evas_check_loader.m4
@@ -429,6 +429,38 @@ fi
429 429
430]) 430])
431 431
432dnl use: EVAS_CHECK_LOADER_DEP_WEBP(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
433
434AC_DEFUN([EVAS_CHECK_LOADER_DEP_WEBP],
435[
436
437have_dep="no"
438evas_image_loader_[]$1[]_cflags=""
439evas_image_loader_[]$1[]_libs=""
440
441AC_CHECK_HEADER([webp/decode.h], [have_dep="yes"])
442
443if test "x${have_dep}" = "xyes" ; then
444 AC_CHECK_LIB([webp],
445 [WebPDecodeRGBA],
446 [
447 evas_image_loader_[]$1[]_libs="-lwebp"
448 ],
449 [have_dep="no"]
450 )
451fi
452
453AC_SUBST([evas_image_loader_$1_cflags])
454AC_SUBST([evas_image_loader_$1_libs])
455
456if test "x${have_dep}" = "xyes" ; then
457 m4_default([$3], [:])
458else
459 m4_default([$4], [:])
460fi
461
462])
463
432dnl use: EVAS_CHECK_LOADER_DEP_GENERIC(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 464dnl use: EVAS_CHECK_LOADER_DEP_GENERIC(loader, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
433 465
434AC_DEFUN([EVAS_CHECK_LOADER_DEP_GENERIC], 466AC_DEFUN([EVAS_CHECK_LOADER_DEP_GENERIC],
diff --git a/legacy/evas/src/bin/evas_cserve2_slave.c b/legacy/evas/src/bin/evas_cserve2_slave.c
index a11c635..9a1e01b 100644
--- a/legacy/evas/src/bin/evas_cserve2_slave.c
+++ b/legacy/evas/src/bin/evas_cserve2_slave.c
@@ -50,6 +50,7 @@ static const struct ext_loader_s map_loaders[] =
50 MATCHING(".bmp", "bmp"), 50 MATCHING(".bmp", "bmp"),
51 MATCHING(".tga", "tga"), 51 MATCHING(".tga", "tga"),
52 MATCHING(".wbmp", "wbmp"), 52 MATCHING(".wbmp", "wbmp"),
53 MATCHING(".webp", "webp"),
53 MATCHING(".ico", "ico"), 54 MATCHING(".ico", "ico"),
54 MATCHING(".cur", "ico"), 55 MATCHING(".cur", "ico"),
55 MATCHING(".psd", "psd") 56 MATCHING(".psd", "psd")
@@ -57,7 +58,7 @@ static const struct ext_loader_s map_loaders[] =
57 58
58static const char *loaders_name[] = 59static const char *loaders_name[] =
59{ /* in order of most likely needed */ 60{ /* in order of most likely needed */
60 "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "bmp", "tga", "wbmp", "ico", "psd", "edb" 61 "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "webp", "pmaps", "bmp", "tga", "wbmp", "ico", "psd", "edb"
61}; 62};
62 63
63Eina_Bool 64Eina_Bool
diff --git a/legacy/evas/src/bin/loaders/Makefile.am b/legacy/evas/src/bin/loaders/Makefile.am
index 46222c8..96d0c5e 100644
--- a/legacy/evas/src/bin/loaders/Makefile.am
+++ b/legacy/evas/src/bin/loaders/Makefile.am
@@ -42,6 +42,10 @@ if BUILD_LOADER_WBMP
42SUBDIRS += wbmp 42SUBDIRS += wbmp
43endif 43endif
44 44
45if BUILD_LOADER_WEBP
46SUBDIRS += webp
47endif
48
45if BUILD_LOADER_XPM 49if BUILD_LOADER_XPM
46SUBDIRS += xpm 50SUBDIRS += xpm
47endif 51endif
diff --git a/legacy/evas/src/bin/loaders/webp/Makefile.am b/legacy/evas/src/bin/loaders/webp/Makefile.am
new file mode 100644
index 0000000..9f186ff
--- /dev/null
+++ b/legacy/evas/src/bin/loaders/webp/Makefile.am
@@ -0,0 +1,33 @@
1
2MAINTAINERCLEANFILES = Makefile.in
3
4AM_CPPFLAGS = \
5-I. \
6-I$(top_srcdir)/src/lib \
7-I$(top_srcdir)/src/lib/include \
8-I$(top_srcdir)/src/lib/cserve2 \
9-I$(top_srcdir)/src/bin \
10@EINA_CFLAGS@ \
11@evas_image_loader_webp_cflags@ \
12@EVIL_CFLAGS@
13
14if BUILD_LOADER_WEBP
15#if !EVAS_STATIC_BUILD_WEBP
16
17pkgdir = $(libdir)/evas/cserve2/loaders/webp/$(MODULE_ARCH)
18pkg_LTLIBRARIES = module.la
19
20module_la_SOURCES = evas_image_load_webp.c
21
22module_la_LIBADD = @EINA_LIBS@ @evas_image_loader_webp_libs@ @EVIL_LIBS@
23module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
24module_la_LIBTOOLFLAGS = --tag=disable-static
25
26#else
27
28#noinst_LTLIBRARIES = libevas_loader_webp.la
29#libevas_loader_webp_la_SOURCES = evas_image_load_webp.c
30#libevas_loader_webp_la_LIBADD = @evas_image_loader_webp_libs@
31
32#endif
33endif
diff --git a/legacy/evas/src/bin/loaders/webp/evas_image_load_webp.c b/legacy/evas/src/bin/loaders/webp/evas_image_load_webp.c
new file mode 100644
index 0000000..6adf0ea
--- /dev/null
+++ b/legacy/evas/src/bin/loaders/webp/evas_image_load_webp.c
@@ -0,0 +1,135 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <webp/decode.h>
7
8#ifdef HAVE_EVIL
9# include <Evil.h>
10#endif
11
12#include "evas_macros.h"
13
14#include "evas_cserve2.h"
15#include "evas_cserve2_slave.h"
16
17
18static Eina_Bool
19evas_image_load_file_head_webp(Evas_Img_Load_Params *ilp, const char *file, const char *key __UNUSED__, int *error)
20{
21 WebPDecoderConfig config;
22 FILE *f;
23 size_t header_size = 30;
24 uint8_t header[30];
25
26 f = fopen(file, "rb");
27 if (!f)
28 {
29 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
30 return EINA_FALSE;
31 }
32 if (fread(header, header_size, 1, f) != 1)
33 {
34 fclose(f);
35 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
36 return EINA_FALSE;
37 }
38 fclose(f);
39
40 if (!WebPInitDecoderConfig(&config))
41 {
42 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
43 return EINA_FALSE;
44 }
45 if (WebPGetFeatures(header, header_size, &config.input) != VP8_STATUS_OK)
46 {
47 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
48 return EINA_FALSE;
49 }
50
51 ilp->w = config.input.width;
52 ilp->h = config.input.height;
53 ilp->alpha = config.input.has_alpha;
54
55 *error = EVAS_LOAD_ERROR_NONE;
56 return EINA_TRUE;
57}
58
59static Eina_Bool
60evas_image_load_file_data_webp(Evas_Img_Load_Params *ilp, const char *file, const char *key __UNUSED__, int *error)
61{
62 FILE *f;
63 size_t file_size;
64 uint8_t *data, *decoded;
65 int width, height;
66
67 f = fopen(file, "rb");
68 if (!f)
69 {
70 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
71 return EINA_FALSE;
72 }
73
74 if (fseek(f, 0, SEEK_END) != 0)
75 {
76 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
77 goto close_file;
78 }
79 file_size = ftell(f);
80 if (fseek(f, 0, SEEK_SET) != 0)
81 {
82 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
83 goto close_file;
84 }
85
86 data = malloc(file_size);
87 if (!data)
88 {
89 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
90 goto close_file;
91 }
92 if (fread(data, file_size, 1, f) != 1)
93 {
94 free(data);
95 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
96 goto close_file;
97 }
98 fclose(f);
99
100 decoded = WebPDecodeBGRA(data, file_size, &width, &height);
101 memcpy(ilp->buffer, decoded, width * height * 4);
102 evas_cserve2_image_premul(ilp);
103
104 free(decoded);
105 free(data);
106
107 *error = EVAS_LOAD_ERROR_NONE;
108 return EINA_TRUE;
109
110close_file:
111 fclose(f);
112 return EINA_FALSE;
113}
114
115static Evas_Loader_Module_Api modapi =
116{
117 EVAS_CSERVE2_MODULE_API_VERSION,
118 "webp",
119 evas_image_load_file_head_webp,
120 evas_image_load_file_data_webp
121};
122
123static Eina_Bool
124module_init(void)
125{
126 return evas_cserve2_loader_register(&modapi);
127}
128
129static void
130module_shutdown(void)
131{
132}
133
134EINA_MODULE_INIT(module_init);
135EINA_MODULE_SHUTDOWN(module_shutdown);
diff --git a/legacy/evas/src/lib/engines/common/evas_image_load.c b/legacy/evas/src/lib/engines/common/evas_image_load.c
index 386bb76..d88cbec 100644
--- a/legacy/evas/src/lib/engines/common/evas_image_load.c
+++ b/legacy/evas/src/lib/engines/common/evas_image_load.c
@@ -47,6 +47,7 @@ static const struct ext_loader_s loaders[] =
47 MATCHING(".bmp", "bmp"), 47 MATCHING(".bmp", "bmp"),
48 MATCHING(".tga", "tga"), 48 MATCHING(".tga", "tga"),
49 MATCHING(".wbmp", "wbmp"), 49 MATCHING(".wbmp", "wbmp"),
50 MATCHING(".webp", "webp"),
50 MATCHING(".ico", "ico"), 51 MATCHING(".ico", "ico"),
51 MATCHING(".cur", "ico"), 52 MATCHING(".cur", "ico"),
52 MATCHING(".psd", "psd"), 53 MATCHING(".psd", "psd"),
@@ -127,7 +128,7 @@ static const struct ext_loader_s loaders[] =
127 128
128static const char *loaders_name[] = 129static const char *loaders_name[] =
129{ /* in order of most likely needed */ 130{ /* in order of most likely needed */
130 "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "bmp", "tga", "wbmp", "ico", "psd", "edb", "generic" 131 "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "webp", "pmaps", "bmp", "tga", "wbmp", "ico", "psd", "edb", "generic"
131}; 132};
132 133
133struct evas_image_foreach_loader_data 134struct evas_image_foreach_loader_data
diff --git a/legacy/evas/src/lib/file/evas_module.c b/legacy/evas/src/lib/file/evas_module.c
index 3c9378d..7bc52bc 100644
--- a/legacy/evas/src/lib/file/evas_module.c
+++ b/legacy/evas/src/lib/file/evas_module.c
@@ -123,6 +123,7 @@ EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, svg);
123EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, tga); 123EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, tga);
124EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, tiff); 124EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, tiff);
125EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, wbmp); 125EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, wbmp);
126EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, webp);
126EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, xpm); 127EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, xpm);
127EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, edb); 128EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, edb);
128EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, eet); 129EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, eet);
@@ -233,6 +234,9 @@ static const struct {
233#ifdef EVAS_STATIC_BUILD_WBMP 234#ifdef EVAS_STATIC_BUILD_WBMP
234 EVAS_EINA_STATIC_MODULE_USE(image_loader, wbmp), 235 EVAS_EINA_STATIC_MODULE_USE(image_loader, wbmp),
235#endif 236#endif
237#ifdef EVAS_STATIC_BUILD_WEBP
238 EVAS_EINA_STATIC_MODULE_USE(image_loader, webp),
239#endif
236#ifdef EVAS_STATIC_BUILD_XPM 240#ifdef EVAS_STATIC_BUILD_XPM
237 EVAS_EINA_STATIC_MODULE_USE(image_loader, xpm), 241 EVAS_EINA_STATIC_MODULE_USE(image_loader, xpm),
238#endif 242#endif
diff --git a/legacy/evas/src/modules/loaders/Makefile.am b/legacy/evas/src/modules/loaders/Makefile.am
index b7ed9a5..8122e56 100644
--- a/legacy/evas/src/modules/loaders/Makefile.am
+++ b/legacy/evas/src/modules/loaders/Makefile.am
@@ -86,6 +86,12 @@ SUBDIRS += wbmp
86endif 86endif
87endif 87endif
88 88
89if BUILD_LOADER_WEBP
90if !EVAS_STATIC_BUILD_WEBP
91SUBDIRS += webp
92endif
93endif
94
89if BUILD_LOADER_XPM 95if BUILD_LOADER_XPM
90if !EVAS_STATIC_BUILD_XPM 96if !EVAS_STATIC_BUILD_XPM
91SUBDIRS += xpm 97SUBDIRS += xpm
diff --git a/legacy/evas/src/modules/loaders/webp/Makefile.am b/legacy/evas/src/modules/loaders/webp/Makefile.am
new file mode 100644
index 0000000..c10b5b9
--- /dev/null
+++ b/legacy/evas/src/modules/loaders/webp/Makefile.am
@@ -0,0 +1,35 @@
1
2MAINTAINERCLEANFILES = Makefile.in
3
4AM_CPPFLAGS = \
5-I. \
6-I$(top_srcdir)/src/lib \
7-I$(top_srcdir)/src/lib/include \
8@FREETYPE_CFLAGS@ \
9@PIXMAN_CFLAGS@ \
10@EINA_CFLAGS@ \
11@FRIBIDI_CFLAGS@ \
12@evas_image_loader_webp_cflags@ \
13@EVIL_CFLAGS@
14
15if BUILD_LOADER_WEBP
16if !EVAS_STATIC_BUILD_WEBP
17
18pkgdir = $(libdir)/evas/modules/loaders/webp/$(MODULE_ARCH)
19pkg_LTLIBRARIES = module.la
20
21module_la_SOURCES = evas_image_load_webp.c
22
23module_la_LIBADD = @EINA_LIBS@ @EVIL_LIBS@ @evas_image_loader_webp_libs@ $(top_builddir)/src/lib/libevas.la
24module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
25module_la_LIBTOOLFLAGS = --tag=disable-static
26
27else
28
29noinst_LTLIBRARIES = libevas_loader_webp.la
30
31libevas_loader_webp_la_SOURCES = evas_image_load_webp.c
32libevas_loader_webp_la_LIBADD = @evas_image_loader_webp_libs@
33
34endif
35endif
diff --git a/legacy/evas/src/modules/loaders/webp/evas_image_load_webp.c b/legacy/evas/src/modules/loaders/webp/evas_image_load_webp.c
new file mode 100644
index 0000000..5b23910
--- /dev/null
+++ b/legacy/evas/src/modules/loaders/webp/evas_image_load_webp.c
@@ -0,0 +1,165 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <string.h>
7#include <webp/decode.h>
8
9#ifdef HAVE_EVIL
10# include <Evil.h>
11#endif
12
13#include "evas_common.h"
14#include "evas_private.h"
15
16static Eina_Bool evas_image_load_file_head_webp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
17static Eina_Bool evas_image_load_file_data_webp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
18
19static Evas_Image_Load_Func evas_image_load_webp_func =
20{
21 EINA_TRUE,
22 evas_image_load_file_head_webp,
23 evas_image_load_file_data_webp,
24 NULL,
25 EINA_FALSE
26};
27
28
29static Eina_Bool
30evas_image_load_file_head_webp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
31{
32 WebPDecoderConfig config;
33 FILE *f;
34 size_t header_size = 30;
35 uint8_t header[30];
36
37 f = fopen(file, "rb");
38 if (!f)
39 {
40 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
41 return EINA_FALSE;
42 }
43 if (fread(header, header_size, 1, f) != 1)
44 {
45 fclose(f);
46 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
47 return EINA_FALSE;
48 }
49 fclose(f);
50
51 if (!WebPInitDecoderConfig(&config))
52 {
53 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
54 return EINA_FALSE;
55 }
56 if (WebPGetFeatures(header, header_size, &config.input) != VP8_STATUS_OK)
57 {
58 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
59 return EINA_FALSE;
60 }
61
62 ie->w = config.input.width;
63 ie->h = config.input.height;
64 ie->flags.alpha = config.input.has_alpha;
65
66 *error = EVAS_LOAD_ERROR_NONE;
67 return EINA_TRUE;
68}
69
70static Eina_Bool
71evas_image_load_file_data_webp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
72{
73 FILE *f;
74 size_t file_size;
75 uint8_t *data, *decoded, *surface;
76 int width, height;
77
78 f = fopen(file, "rb");
79 if (!f)
80 {
81 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
82 return EINA_FALSE;
83 }
84
85 if (fseek(f, 0, SEEK_END) != 0)
86 {
87 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
88 goto close_file;
89 }
90 file_size = ftell(f);
91
92 if (fseek(f, 0, SEEK_SET) != 0)
93 {
94 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
95 goto close_file;
96 }
97
98 data = malloc(file_size);
99 if (!data)
100 {
101 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
102 goto close_file;
103 }
104 if (fread(data, file_size, 1, f) != 1)
105 {
106 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
107 goto free_data;
108 }
109
110 evas_cache_image_surface_alloc(ie, ie->w, ie->h);
111 surface = evas_cache_image_pixels(ie);
112 if (!surface)
113 {
114 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
115 goto free_data;
116 }
117
118 decoded = WebPDecodeBGRA(data, file_size, &width, &height);
119 memcpy(surface, decoded, width * height * 4);
120 evas_common_image_premul(ie);
121
122 free(decoded);
123 free(data);
124 fclose(f);
125
126 *error = EVAS_LOAD_ERROR_NONE;
127 return EINA_TRUE;
128
129free_data:
130 free(data);
131
132close_file:
133 fclose(f);
134 return EINA_FALSE;
135}
136
137static int
138module_open(Evas_Module *em)
139{
140 if (!em) return 0;
141 em->functions = (void *)(&evas_image_load_webp_func);
142 return 1;
143}
144
145static void
146module_close(Evas_Module *em __UNUSED__)
147{
148}
149
150static Evas_Module_Api evas_modapi =
151{
152 EVAS_MODULE_API_VERSION,
153 "webp",
154 "none",
155 {
156 module_open,
157 module_close
158 }
159};
160
161EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, webp);
162
163#ifndef EVAS_STATIC_BUILD_WEBP
164EVAS_EINA_MODULE_DEFINE(image_loader, webp);
165#endif