summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorHermet Park <chuneon.park@samsung.com>2021-02-18 13:21:16 +0900
committerHermet Park <chuneon.park@samsung.com>2021-02-18 13:21:16 +0900
commit23cce0129cad582fa892dba3e431f745a8009011 (patch)
tree833211c72ab7cb7517ee2a1f470a2e00543add24 /src/modules
parentd33454cfdef203c3aa4ec33e46ae0829c7aa5efa (diff)
parent1842d3997a88e22421eddeed49be50a0db08b7ce (diff)
Merge branch 'master' into devs/hermet/lottie
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_context.c3
-rw-r--r--src/modules/evas/engines/gl_generic/evas_engine.c1
-rw-r--r--src/modules/evas/engines/gl_x11/evas_engine.c2
-rw-r--r--src/modules/evas/image_loaders/heif/evas_image_load_heif.c300
-rw-r--r--src/modules/evas/image_loaders/tga/evas_image_load_tga.c20
5 files changed, 313 insertions, 13 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c b/src/modules/evas/engines/gl_common/evas_gl_context.c
index 5b40037560..26ff021cd4 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -381,7 +381,8 @@ evas_gl_symbols(void *(*GetProcAddress)(const char *name), const char *extsn)
381 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriEXT", "GL_EXT_geometry_shader4", glsym_func_void); 381 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriEXT", "GL_EXT_geometry_shader4", glsym_func_void);
382 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriARB", "GL_ARB_geometry_shader4", glsym_func_void); 382 FINDSYM(glsym_glProgramParameteri, "glProgramParameteriARB", "GL_ARB_geometry_shader4", glsym_func_void);
383 383
384 FINDSYMN(secsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image_external", glsym_func_void); 384 FINDSYM(secsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image_external", glsym_func_void);
385 FINDSYM(secsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image", glsym_func_void);
385 386
386 // Old SEC extensions 387 // Old SEC extensions
387 FINDSYMN(secsym_eglMapImageSEC, "eglMapImageSEC", NULL, secsym_func_void_ptr); 388 FINDSYMN(secsym_eglMapImageSEC, "eglMapImageSEC", NULL, secsym_func_void_ptr);
diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c b/src/modules/evas/engines/gl_generic/evas_engine.c
index a1c48ae451..021e798169 100644
--- a/src/modules/evas/engines/gl_generic/evas_engine.c
+++ b/src/modules/evas/engines/gl_generic/evas_engine.c
@@ -1167,7 +1167,6 @@ eng_image_orient_set(void *engine, void *image, Evas_Image_Orient orient)
1167 { 1167 {
1168 im_new->tex = im->tex; 1168 im_new->tex = im->tex;
1169 im_new->tex->references++; 1169 im_new->tex->references++;
1170 im_new->tex->pt->references++;
1171 } 1170 }
1172 1171
1173 evas_gl_common_image_free(im); 1172 evas_gl_common_image_free(im);
diff --git a/src/modules/evas/engines/gl_x11/evas_engine.c b/src/modules/evas/engines/gl_x11/evas_engine.c
index a22e9d95db..580921ff01 100644
--- a/src/modules/evas/engines/gl_x11/evas_engine.c
+++ b/src/modules/evas/engines/gl_x11/evas_engine.c
@@ -1376,8 +1376,8 @@ eng_gl_symbols(Outbuf *ob)
1376 1376
1377 // This is a GL extension 1377 // This is a GL extension
1378 exts = (const char *) glGetString(GL_EXTENSIONS); 1378 exts = (const char *) glGetString(GL_EXTENSIONS);
1379 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image", glsym_func_void);
1380 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image_external", glsym_func_void); 1379 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image_external", glsym_func_void);
1380 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", "GL_OES_EGL_image", glsym_func_void);
1381 1381
1382#else 1382#else
1383 1383
diff --git a/src/modules/evas/image_loaders/heif/evas_image_load_heif.c b/src/modules/evas/image_loaders/heif/evas_image_load_heif.c
new file mode 100644
index 0000000000..bc9f2a1e06
--- /dev/null
+++ b/src/modules/evas/image_loaders/heif/evas_image_load_heif.c
@@ -0,0 +1,300 @@
1#define _XOPEN_SOURCE 600
2
3#ifdef HAVE_CONFIG_H
4# include <config.h>
5#endif
6
7#include <stdlib.h>
8#include <stdio.h>
9#include <string.h>
10#include <errno.h>
11
12#include <math.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <unistd.h>
16#include <fcntl.h>
17
18#ifdef HAVE_NETINET_IN_H
19# include <netinet/in.h>
20#endif
21
22#include <libheif/heif.h>
23
24#include "evas_common_private.h"
25#include "evas_private.h"
26
27static int _evas_loader_heif_log_dom = -1;
28
29#ifdef ERR
30# undef ERR
31#endif
32#define ERR(...) EINA_LOG_DOM_ERR(_evas_loader_heif_log_dom, __VA_ARGS__)
33
34#ifdef INF
35# undef INF
36#endif
37#define INF(...) EINA_LOG_DOM_INFO(_evas_loader_heif_log_dom, __VA_ARGS__)
38
39
40static void *
41evas_image_load_file_open_heif(Eina_File *f, Eina_Stringshare *key EINA_UNUSED,
42 Evas_Image_Load_Opts *opts EINA_UNUSED,
43 Evas_Image_Animated *animated EINA_UNUSED,
44 int *error EINA_UNUSED)
45{
46 return f;
47}
48
49static void
50evas_image_load_file_close_heif(void *loader_data EINA_UNUSED)
51{
52}
53
54static Eina_Bool
55evas_image_load_file_head_heif(void *loader_data,
56 Emile_Image_Property *prop,
57 int *error)
58{
59 Eina_File *f = loader_data;
60 void *map;
61 size_t length;
62 struct heif_error err;
63 struct heif_context* hc = NULL;
64 struct heif_image_handle* hdl = NULL;
65 struct heif_image* img = NULL;
66 Eina_Bool r = EINA_FALSE;
67
68 *error = EVAS_LOAD_ERROR_NONE;
69
70 map = eina_file_map_all(f, EINA_FILE_RANDOM);
71 length = eina_file_size_get(f);
72
73 // init prop struct with some default null values
74 prop->w = 0;
75 prop->h = 0;
76
77 if (!map || length < 1)
78 {
79 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
80 goto on_error;
81 }
82
83 hc = heif_context_alloc();
84 if (!hc) {
85 INF("cannot allocate heif_context");
86 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
87 goto on_error;
88 }
89
90 err = heif_context_read_from_memory_without_copy(hc, map, length, NULL);
91 if (err.code != heif_error_Ok) {
92 INF("%s", err.message);
93 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
94 goto on_error;
95 }
96
97 err = heif_context_get_primary_image_handle(hc, &hdl);
98 if (err.code != heif_error_Ok) {
99 INF("%s", err.message);
100 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
101 goto on_error;
102 }
103
104 int has_alpha = heif_image_handle_has_alpha_channel(hdl);
105
106 err = heif_decode_image(hdl, &img, heif_colorspace_RGB,
107 has_alpha ? heif_chroma_interleaved_RGBA : heif_chroma_interleaved_RGB,
108 NULL);
109 if (err.code != heif_error_Ok) {
110 INF("%s", err.message);
111 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
112 goto on_error;
113 }
114
115 prop->w = heif_image_get_width(img, heif_channel_interleaved);
116 prop->h = heif_image_get_height(img, heif_channel_interleaved);
117 if (has_alpha != 3)
118 prop->alpha = 1;
119
120 r = EINA_TRUE;
121
122 on_error:
123 if (img) {
124 heif_image_release(img);
125 }
126
127 if (hdl) {
128 heif_image_handle_release(hdl);
129 }
130
131 if (hc) {
132 heif_context_free(hc);
133 }
134 eina_file_map_free(f, map);
135 return r;
136}
137
138static Eina_Bool
139evas_image_load_file_data_heif(void *loader_data,
140 Emile_Image_Property *prop,
141 void *pixels,
142 int *error)
143{
144 Eina_File *f = loader_data;
145
146 void *map;
147 size_t length;
148 struct heif_error err;
149 struct heif_context* hc = NULL;
150 struct heif_image_handle* hdl = NULL;
151 struct heif_image* img = NULL;
152 unsigned int x, y;
153 int stride, bps = 3;
154 const uint8_t* data;
155 uint8_t* dd = (uint8_t*)pixels, *ds = NULL;
156 Eina_Bool result = EINA_FALSE;
157
158 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
159 length = eina_file_size_get(f);
160 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
161 if (!map || length < 1)
162 goto on_error;
163
164 *error = EVAS_LOAD_ERROR_GENERIC;
165 result = EINA_FALSE;
166
167 hc = heif_context_alloc();
168 if (!hc) {
169 INF("cannot allocate heif_context");
170 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
171 goto on_error;
172 }
173
174 err = heif_context_read_from_memory_without_copy(hc, map, length, NULL);
175 if (err.code != heif_error_Ok) {
176 INF("%s", err.message);
177 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
178 goto on_error;
179 }
180
181 err = heif_context_get_primary_image_handle(hc, &hdl);
182 if (err.code != heif_error_Ok) {
183 INF("%s", err.message);
184 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
185 goto on_error;
186 }
187
188 err = heif_decode_image(hdl, &img, heif_colorspace_RGB,
189 prop->alpha ? heif_chroma_interleaved_RGBA : heif_chroma_interleaved_RGB,
190 NULL);
191 if (err.code != heif_error_Ok) {
192 INF("%s", err.message);
193 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
194 goto on_error;
195 }
196 if (prop->alpha) bps = 4;
197 data = heif_image_get_plane_readonly(img, heif_channel_interleaved, &stride);
198 ds = (uint8_t*)data;
199 for (y = 0; y < prop->h; y++)
200 for (x = 0; x < prop->w; x++)
201 {
202 if (bps == 3)
203 {
204 dd[3] = 0xff;
205 dd[0] = ds[2];
206 dd[1] = ds[1];
207 dd[2] = ds[0];
208 ds+=3;
209 dd+=4;
210 }
211 else
212 {
213 dd[0] = ds[2];
214 dd[1] = ds[1];
215 dd[2] = ds[0];
216 dd[3] = ds[3];
217 ds+=4;
218 dd+=4;
219 }
220 }
221 result = EINA_TRUE;
222
223 *error = EVAS_LOAD_ERROR_NONE;
224 prop->premul = EINA_TRUE;
225
226on_error:
227
228 if (map) eina_file_map_free(f, map);
229
230 if (img) {
231 // Do not free the image here when we pass it to gdk-pixbuf, as its memory will still be used by gdk-pixbuf.
232 heif_image_release(img);
233 }
234
235 if (hdl) {
236 heif_image_handle_release(hdl);
237 }
238
239 if (hc) {
240 heif_context_free(hc);
241 }
242
243 return result;
244}
245
246static const Evas_Image_Load_Func evas_image_load_heif_func = {
247 EVAS_IMAGE_LOAD_VERSION,
248 evas_image_load_file_open_heif,
249 evas_image_load_file_close_heif,
250 (void*) evas_image_load_file_head_heif,
251 NULL,
252 (void*) evas_image_load_file_data_heif,
253 NULL,
254 EINA_TRUE,
255 EINA_FALSE
256};
257
258static int
259module_open(Evas_Module *em)
260{
261 if (!em) return 0;
262 _evas_loader_heif_log_dom = eina_log_domain_register
263 ("evas-heif", EVAS_DEFAULT_LOG_COLOR);
264 if (_evas_loader_heif_log_dom < 0)
265 {
266 EINA_LOG_ERR("Can not create a module log domain.");
267 return 0;
268 }
269
270 em->functions = (void *)(&evas_image_load_heif_func);
271 return 1;
272}
273
274static void
275module_close(Evas_Module *em EINA_UNUSED)
276{
277 if (_evas_loader_heif_log_dom >= 0)
278 {
279 eina_log_domain_unregister(_evas_loader_heif_log_dom);
280 _evas_loader_heif_log_dom = -1;
281 }
282}
283
284static Evas_Module_Api evas_modapi =
285 {
286 EVAS_MODULE_API_VERSION,
287 "heif",
288 "none",
289 {
290 module_open,
291 module_close
292 }
293 };
294
295EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, heif);
296
297
298#ifndef EVAS_STATIC_BUILD_HEIF
299EVAS_EINA_MODULE_DEFINE(image_loader, heif);
300#endif
diff --git a/src/modules/evas/image_loaders/tga/evas_image_load_tga.c b/src/modules/evas/image_loaders/tga/evas_image_load_tga.c
index d8ef67fc59..34ee83e0b1 100644
--- a/src/modules/evas/image_loaders/tga/evas_image_load_tga.c
+++ b/src/modules/evas/image_loaders/tga/evas_image_load_tga.c
@@ -77,7 +77,7 @@ evas_image_load_file_head_tga(void *loader_data,
77 tga_footer *footer, tfooter; 77 tga_footer *footer, tfooter;
78 char hasa = 0; 78 char hasa = 0;
79 int w, h, bpp; 79 int w, h, bpp;
80 int x, y; 80// int x, y;
81 Eina_Bool r = EINA_FALSE; 81 Eina_Bool r = EINA_FALSE;
82 82
83 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 83 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
@@ -104,7 +104,6 @@ evas_image_load_file_head_tga(void *loader_data,
104 } 104 }
105 } 105 }
106// else goto close_file; 106// else goto close_file;
107 //printf("1\n");
108 107
109 filedata = (unsigned char *)filedata + sizeof(tga_header); 108 filedata = (unsigned char *)filedata + sizeof(tga_header);
110 switch (header->imageType) 109 switch (header->imageType)
@@ -135,13 +134,14 @@ evas_image_load_file_head_tga(void *loader_data,
135 (header->colorMapSize == 24) || 134 (header->colorMapSize == 24) ||
136 (header->colorMapSize == 32))) 135 (header->colorMapSize == 32)))
137 goto close_file; 136 goto close_file;
138 x = (header->xOriginHi << 8) | (header->xOriginLo); 137// x = (header->xOriginHi << 8) | (header->xOriginLo);
139 y = (header->yOriginHi << 8) | (header->yOriginLo); 138// y = (header->yOriginHi << 8) | (header->yOriginLo);
140 w = (header->widthHi << 8) | header->widthLo; 139 w = (header->widthHi << 8) | header->widthLo;
141 h = (header->heightHi << 8) | header->heightLo; 140 h = (header->heightHi << 8) | header->heightLo;
142 // x origin gerater that width, y origin greater than height - wrong file 141 // x origin gerater that width, y origin greater than height - wrong file
143 if ((x >= w) || (y >= h)) 142// if ((x >= w) || (y >= h))
144 goto close_file; 143// goto close_file;
144 printf("x\n");
145 // if descriptor has either of the top 2 bits set... not tga 145 // if descriptor has either of the top 2 bits set... not tga
146 if (header->descriptor & 0xc0) 146 if (header->descriptor & 0xc0)
147 goto close_file; 147 goto close_file;
@@ -237,13 +237,13 @@ evas_image_load_file_data_tga(void *loader_data,
237 (header->colorMapSize == 24) || 237 (header->colorMapSize == 24) ||
238 (header->colorMapSize == 32))) 238 (header->colorMapSize == 32)))
239 goto close_file; 239 goto close_file;
240 x = (header->xOriginHi << 8) | (header->xOriginLo); 240// x = (header->xOriginHi << 8) | (header->xOriginLo);
241 y = (header->yOriginHi << 8) | (header->yOriginLo); 241// y = (header->yOriginHi << 8) | (header->yOriginLo);
242 w = (header->widthHi << 8) | header->widthLo; 242 w = (header->widthHi << 8) | header->widthLo;
243 h = (header->heightHi << 8) | header->heightLo; 243 h = (header->heightHi << 8) | header->heightLo;
244 // x origin gerater that width, y origin greater than height - wrong file 244 // x origin gerater that width, y origin greater than height - wrong file
245 if ((x >= w) || (y >= h)) 245// if ((x >= w) || (y >= h))
246 goto close_file; 246// goto close_file;
247 // if descriptor has either of the top 2 bits set... not tga 247 // if descriptor has either of the top 2 bits set... not tga
248 if (header->descriptor & 0xc0) 248 if (header->descriptor & 0xc0)
249 goto close_file; 249 goto close_file;