aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c')
-rw-r--r--libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c b/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c
new file mode 100644
index 0000000..a187b9e
--- /dev/null
+++ b/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c
@@ -0,0 +1,182 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h" /* so that EAPI in Eet.h is correctly defined */
3#endif
4
5#include <Eet.h>
6
7#include "evas_common.h"
8#include "evas_private.h"
9
10
11static Eina_Bool evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
12static Eina_Bool evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
13
14Evas_Image_Load_Func evas_image_load_eet_func =
15{
16 EINA_TRUE,
17 evas_image_load_file_head_eet,
18 evas_image_load_file_data_eet,
19 NULL
20};
21
22
23static Eina_Bool
24evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key, int *error)
25{
26 int alpha, compression, quality, lossy;
27 unsigned int w, h;
28 Eet_File *ef;
29 int ok;
30 Eina_Bool res = EINA_FALSE;
31
32 if (!key)
33 {
34 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
35 return EINA_FALSE;
36 }
37
38 ef = eet_open((char *)file, EET_FILE_MODE_READ);
39 if (!ef)
40 {
41 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
42 return EINA_FALSE;
43 }
44 ok = eet_data_image_header_read(ef, key,
45 &w, &h, &alpha, &compression, &quality, &lossy);
46 if (!ok)
47 {
48 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
49 goto on_error;
50 }
51 if (IMG_TOO_BIG(w, h))
52 {
53 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
54 goto on_error;
55 }
56 if (alpha) ie->flags.alpha = 1;
57 ie->w = w;
58 ie->h = h;
59 res = EINA_TRUE;
60 *error = EVAS_LOAD_ERROR_NONE;
61
62 on_error:
63 eet_close(ef);
64 return res;
65}
66
67Eina_Bool
68evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error)
69{
70 unsigned int w, h;
71 int alpha, compression, quality, lossy, ok;
72 Eet_File *ef;
73 DATA32 *body, *p, *end, *data;
74 DATA32 nas = 0;
75 Eina_Bool res = EINA_FALSE;
76
77 if (!key)
78 {
79 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
80 return EINA_FALSE;
81 }
82 if (ie->flags.loaded)
83 {
84 *error = EVAS_LOAD_ERROR_NONE;
85 return EINA_TRUE;
86 }
87 ef = eet_open(file, EET_FILE_MODE_READ);
88 if (!ef)
89 {
90 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
91 return EINA_FALSE;
92 }
93 ok = eet_data_image_header_read(ef, key,
94 &w, &h, &alpha, &compression, &quality, &lossy);
95 if (IMG_TOO_BIG(w, h))
96 {
97 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
98 goto on_error;
99 }
100 if (!ok)
101 {
102 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
103 goto on_error;
104 }
105 evas_cache_image_surface_alloc(ie, w, h);
106 data = evas_cache_image_pixels(ie);
107 if (!data)
108 {
109 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
110 goto on_error;
111 }
112 ok = eet_data_image_read_to_surface(ef, key, 0, 0,
113 data, w, h, w * 4,
114 &alpha, &compression, &quality, &lossy);
115 if (!ok)
116 {
117 *error = EVAS_LOAD_ERROR_GENERIC;
118 goto on_error;
119 }
120 if (alpha)
121 {
122 ie->flags.alpha = 1;
123
124 body = evas_cache_image_pixels(ie);
125
126 end = body +(w * h);
127 for (p = body; p < end; p++)
128 {
129 DATA32 r, g, b, a;
130
131 a = A_VAL(p);
132 r = R_VAL(p);
133 g = G_VAL(p);
134 b = B_VAL(p);
135 if ((a == 0) || (a == 255)) nas++;
136 if (r > a) r = a;
137 if (g > a) g = a;
138 if (b > a) b = a;
139 *p = ARGB_JOIN(a, r, g, b);
140 }
141 if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h))
142 ie->flags.alpha_sparse = 1;
143 }
144// result is already premultiplied now if u compile with edje
145// evas_common_image_premul(im);
146 *error = EVAS_LOAD_ERROR_NONE;
147 res = EINA_TRUE;
148
149 on_error:
150 eet_close(ef);
151 return res;
152}
153
154static int
155module_open(Evas_Module *em)
156{
157 if (!em) return 0;
158 em->functions = (void *)(&evas_image_load_eet_func);
159 return 1;
160}
161
162static void
163module_close(Evas_Module *em __UNUSED__)
164{
165}
166
167static Evas_Module_Api evas_modapi =
168{
169 EVAS_MODULE_API_VERSION,
170 "eet",
171 "none",
172 {
173 module_open,
174 module_close
175 }
176};
177
178EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, eet);
179
180#ifndef EVAS_STATIC_BUILD_EET
181EVAS_EINA_MODULE_DEFINE(image_loader, eet);
182#endif