diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c b/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c new file mode 100644 index 0000000..fa6fab2 --- /dev/null +++ b/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c | |||
@@ -0,0 +1,170 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <stdio.h> | ||
6 | |||
7 | #ifdef HAVE_EVIL | ||
8 | # include <Evil.h> | ||
9 | #endif | ||
10 | |||
11 | #include "evas_common.h" | ||
12 | #include "evas_private.h" | ||
13 | |||
14 | static Eina_Bool evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
15 | static Eina_Bool evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
16 | |||
17 | static Evas_Image_Load_Func evas_image_load_wbmp_func = | ||
18 | { | ||
19 | EINA_TRUE, | ||
20 | evas_image_load_file_head_wbmp, | ||
21 | evas_image_load_file_data_wbmp, | ||
22 | NULL | ||
23 | }; | ||
24 | |||
25 | |||
26 | static int | ||
27 | read_mb(unsigned int *data, FILE *f) | ||
28 | { | ||
29 | int ac = 0, ct; | ||
30 | unsigned char buf; | ||
31 | |||
32 | for (ct = 0;;) | ||
33 | { | ||
34 | if ((ct++) == 5) return -1; | ||
35 | if ((fread(&buf, 1, 1, f)) < 1) | ||
36 | return -1; | ||
37 | ac = (ac << 7) | (buf & 0x7f); | ||
38 | if ((buf & 0x80) == 0) break; | ||
39 | } | ||
40 | *data = ac; | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | static Eina_Bool | ||
45 | evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | ||
46 | { | ||
47 | FILE *f; | ||
48 | unsigned int type, w, h; | ||
49 | unsigned char fixed_header; | ||
50 | struct stat statbuf; | ||
51 | |||
52 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
53 | f = fopen(file, "rb"); | ||
54 | if (!f) | ||
55 | { | ||
56 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
57 | return EINA_FALSE; | ||
58 | } | ||
59 | |||
60 | if (stat(file, &statbuf) == -1) goto bail; | ||
61 | if (read_mb(&type, f) < 0) goto bail; | ||
62 | |||
63 | if (type != 0) | ||
64 | { | ||
65 | *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; | ||
66 | goto bail; | ||
67 | } | ||
68 | |||
69 | if (fread(&fixed_header, 1, 1, f) != 1) goto bail; | ||
70 | if (read_mb(&w, f) < 0) goto bail; | ||
71 | if (read_mb(&h, f) < 0) goto bail; | ||
72 | if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || | ||
73 | IMG_TOO_BIG(w, h)) | ||
74 | { | ||
75 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
76 | goto bail; | ||
77 | } | ||
78 | |||
79 | fclose(f); | ||
80 | ie->w = w; | ||
81 | ie->h = h; | ||
82 | |||
83 | *error = EVAS_LOAD_ERROR_NONE; | ||
84 | return EINA_TRUE; | ||
85 | bail: | ||
86 | fclose(f); | ||
87 | return EINA_FALSE; | ||
88 | } | ||
89 | |||
90 | static Eina_Bool | ||
91 | evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | ||
92 | { | ||
93 | FILE *f; | ||
94 | unsigned int dummy, line_length; | ||
95 | unsigned char *line = NULL; | ||
96 | int cur = 0, x, y; | ||
97 | DATA32 *dst_data; | ||
98 | |||
99 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
100 | f = fopen(file, "rb"); | ||
101 | if (!f) | ||
102 | { | ||
103 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
104 | return EINA_FALSE; | ||
105 | } | ||
106 | if (read_mb(&dummy, f) < 0) goto bail; | ||
107 | if (fread(&dummy, 1, 1, f) != 1) goto bail; | ||
108 | if (read_mb(&dummy, f) < 0) goto bail; | ||
109 | if (read_mb(&dummy, f) < 0) goto bail; | ||
110 | |||
111 | evas_cache_image_surface_alloc(ie, ie->w, ie->h); | ||
112 | dst_data = evas_cache_image_pixels(ie); | ||
113 | if (!dst_data) | ||
114 | { | ||
115 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
116 | goto bail; | ||
117 | } | ||
118 | |||
119 | line_length = (ie->w + 7) >> 3; | ||
120 | line = alloca(line_length); | ||
121 | |||
122 | for (y = 0; y < (int)ie->h; y++) | ||
123 | { | ||
124 | if (fread(line, 1, line_length, f) != line_length) goto bail; | ||
125 | for (x = 0; x < (int)ie->w; x++) | ||
126 | { | ||
127 | int idx = x >> 3; | ||
128 | int offset = 1 << (0x07 - (x & 0x07)); | ||
129 | if (line[idx] & offset) dst_data[cur] = 0xffffffff; | ||
130 | else dst_data[cur] = 0xff000000; | ||
131 | cur++; | ||
132 | } | ||
133 | } | ||
134 | fclose(f); | ||
135 | *error = EVAS_LOAD_ERROR_NONE; | ||
136 | return EINA_TRUE; | ||
137 | bail: | ||
138 | fclose(f); | ||
139 | return EINA_FALSE; | ||
140 | } | ||
141 | |||
142 | static int | ||
143 | module_open(Evas_Module *em) | ||
144 | { | ||
145 | if (!em) return 0; | ||
146 | em->functions = (void *)(&evas_image_load_wbmp_func); | ||
147 | return 1; | ||
148 | } | ||
149 | |||
150 | static void | ||
151 | module_close(Evas_Module *em __UNUSED__) | ||
152 | { | ||
153 | } | ||
154 | |||
155 | static Evas_Module_Api evas_modapi = | ||
156 | { | ||
157 | EVAS_MODULE_API_VERSION, | ||
158 | "wbmp", | ||
159 | "none", | ||
160 | { | ||
161 | module_open, | ||
162 | module_close | ||
163 | } | ||
164 | }; | ||
165 | |||
166 | EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, wbmp); | ||
167 | |||
168 | #ifndef EVAS_STATIC_BUILD_WBMP | ||
169 | EVAS_EINA_MODULE_DEFINE(image_loader, wbmp); | ||
170 | #endif | ||