diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c | 325 |
1 files changed, 0 insertions, 325 deletions
diff --git a/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c b/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c deleted file mode 100644 index e17d5a6..0000000 --- a/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <stdio.h> | ||
7 | #include <unistd.h> | ||
8 | #include <tiffio.h> | ||
9 | |||
10 | #ifdef HAVE_EVIL | ||
11 | # include <Evil.h> | ||
12 | #endif | ||
13 | |||
14 | #include "evas_common.h" | ||
15 | #include "evas_private.h" | ||
16 | |||
17 | static int _evas_loader_tiff_log_dom = -1; | ||
18 | |||
19 | #ifdef ERR | ||
20 | # undef ERR | ||
21 | #endif | ||
22 | #define ERR(...) EINA_LOG_DOM_ERR(_evas_loader_tiff_log_dom, __VA_ARGS__) | ||
23 | |||
24 | #ifdef INF | ||
25 | # undef INF | ||
26 | #endif | ||
27 | #define INF(...) EINA_LOG_DOM_INFO(_evas_loader_tiff_log_dom, __VA_ARGS__) | ||
28 | |||
29 | static Eina_Bool evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
30 | static Eina_Bool evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
31 | |||
32 | static Evas_Image_Load_Func evas_image_load_tiff_func = | ||
33 | { | ||
34 | EINA_TRUE, | ||
35 | evas_image_load_file_head_tiff, | ||
36 | evas_image_load_file_data_tiff, | ||
37 | NULL, | ||
38 | EINA_FALSE | ||
39 | }; | ||
40 | |||
41 | typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra; | ||
42 | |||
43 | struct TIFFRGBAImage_Extra { | ||
44 | TIFFRGBAImage rgba; | ||
45 | Image_Entry *image; | ||
46 | char pper; | ||
47 | uint32 num_pixels; | ||
48 | uint32 py; | ||
49 | }; | ||
50 | |||
51 | static Eina_Bool | ||
52 | evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | ||
53 | { | ||
54 | char txt[1024]; | ||
55 | TIFFRGBAImage tiff_image; | ||
56 | TIFF *tif = NULL; | ||
57 | FILE *ffile; | ||
58 | int fd; | ||
59 | uint16 magic_number; | ||
60 | |||
61 | ffile = fopen(file, "rb"); | ||
62 | if (!ffile) | ||
63 | { | ||
64 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
65 | return EINA_FALSE; | ||
66 | } | ||
67 | |||
68 | if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1) | ||
69 | { | ||
70 | fclose(ffile); | ||
71 | *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; | ||
72 | return EINA_FALSE; | ||
73 | } | ||
74 | /* Apparently rewind(f) isn't sufficient */ | ||
75 | fseek(ffile, 0, SEEK_SET); | ||
76 | |||
77 | if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */ | ||
78 | && (magic_number != TIFF_LITTLEENDIAN)) | ||
79 | { | ||
80 | fclose(ffile); | ||
81 | *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; | ||
82 | return EINA_FALSE; | ||
83 | } | ||
84 | |||
85 | fd = fileno(ffile); | ||
86 | fd = dup(fd); | ||
87 | lseek(fd, (long)0, SEEK_SET); | ||
88 | fclose(ffile); | ||
89 | |||
90 | tif = TIFFFdOpen(fd, file, "r"); | ||
91 | if (!tif) | ||
92 | { | ||
93 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
94 | return EINA_FALSE; | ||
95 | } | ||
96 | |||
97 | strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff"); | ||
98 | if (!TIFFRGBAImageOK(tif, txt)) | ||
99 | { | ||
100 | TIFFClose(tif); | ||
101 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
102 | return EINA_FALSE; | ||
103 | } | ||
104 | strcpy(txt, "Evas Tiff loader: cannot begin reading tiff"); | ||
105 | if (!TIFFRGBAImageBegin(& tiff_image, tif, 1, txt)) | ||
106 | { | ||
107 | TIFFClose(tif); | ||
108 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
109 | return EINA_FALSE; | ||
110 | } | ||
111 | |||
112 | if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED) | ||
113 | ie->flags.alpha = 1; | ||
114 | if ((tiff_image.width < 1) || (tiff_image.height < 1) || | ||
115 | (tiff_image.width > IMG_MAX_SIZE) || (tiff_image.height > IMG_MAX_SIZE) || | ||
116 | IMG_TOO_BIG(tiff_image.width, tiff_image.height)) | ||
117 | { | ||
118 | TIFFClose(tif); | ||
119 | if (IMG_TOO_BIG(tiff_image.width, tiff_image.height)) | ||
120 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
121 | else | ||
122 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
123 | return EINA_FALSE; | ||
124 | } | ||
125 | ie->w = tiff_image.width; | ||
126 | ie->h = tiff_image.height; | ||
127 | |||
128 | TIFFRGBAImageEnd(&tiff_image); | ||
129 | TIFFClose(tif); | ||
130 | *error = EVAS_LOAD_ERROR_NONE; | ||
131 | return EINA_TRUE; | ||
132 | } | ||
133 | |||
134 | static Eina_Bool | ||
135 | evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | ||
136 | { | ||
137 | char txt[1024]; | ||
138 | TIFFRGBAImage_Extra rgba_image; | ||
139 | TIFF *tif = NULL; | ||
140 | FILE *ffile; | ||
141 | uint32 *rast = NULL; | ||
142 | uint32 num_pixels; | ||
143 | int fd, x, y; | ||
144 | uint16 magic_number; | ||
145 | |||
146 | ffile = fopen(file, "rb"); | ||
147 | if (!ffile) | ||
148 | { | ||
149 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
150 | return EINA_FALSE; | ||
151 | } | ||
152 | |||
153 | if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1) | ||
154 | { | ||
155 | fclose(ffile); | ||
156 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
157 | return EINA_FALSE; | ||
158 | } | ||
159 | /* Apparently rewind(f) isn't sufficient */ | ||
160 | fseek(ffile, (long)0, SEEK_SET); | ||
161 | |||
162 | if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */ | ||
163 | && (magic_number != TIFF_LITTLEENDIAN)) | ||
164 | { | ||
165 | fclose(ffile); | ||
166 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
167 | return EINA_FALSE; | ||
168 | } | ||
169 | |||
170 | fd = fileno(ffile); | ||
171 | fd = dup(fd); | ||
172 | lseek(fd, (long)0, SEEK_SET); | ||
173 | fclose(ffile); | ||
174 | |||
175 | tif = TIFFFdOpen(fd, file, "r"); | ||
176 | if (!tif) | ||
177 | { | ||
178 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
179 | return EINA_FALSE; | ||
180 | } | ||
181 | |||
182 | strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff"); | ||
183 | if (!TIFFRGBAImageOK(tif, txt)) | ||
184 | { | ||
185 | TIFFClose(tif); | ||
186 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
187 | return EINA_FALSE; | ||
188 | } | ||
189 | strcpy(txt, "Evas Tiff loader: cannot begin reading tiff"); | ||
190 | if (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0, txt)) | ||
191 | { | ||
192 | TIFFClose(tif); | ||
193 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
194 | return EINA_FALSE; | ||
195 | } | ||
196 | rgba_image.image = ie; | ||
197 | |||
198 | if (rgba_image.rgba.alpha != EXTRASAMPLE_UNSPECIFIED) | ||
199 | ie->flags.alpha = 1; | ||
200 | if ((rgba_image.rgba.width != ie->w) || | ||
201 | (rgba_image.rgba.height != ie->h)) | ||
202 | { | ||
203 | TIFFClose(tif); | ||
204 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
205 | return EINA_FALSE; | ||
206 | } | ||
207 | |||
208 | evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height); | ||
209 | if (!evas_cache_image_pixels(ie)) | ||
210 | { | ||
211 | TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); | ||
212 | TIFFClose(tif); | ||
213 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
214 | return EINA_FALSE; | ||
215 | } | ||
216 | |||
217 | rgba_image.num_pixels = num_pixels = ie->w * ie->h; | ||
218 | |||
219 | rgba_image.pper = rgba_image.py = 0; | ||
220 | rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels); | ||
221 | |||
222 | if (!rast) | ||
223 | { | ||
224 | ERR("Evas Tiff loader: out of memory"); | ||
225 | |||
226 | TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); | ||
227 | TIFFClose(tif); | ||
228 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
229 | return EINA_FALSE; | ||
230 | } | ||
231 | if (rgba_image.rgba.bitspersample == 8) | ||
232 | { | ||
233 | if (!TIFFRGBAImageGet((TIFFRGBAImage *) &rgba_image, rast, | ||
234 | rgba_image.rgba.width, rgba_image.rgba.height)) | ||
235 | { | ||
236 | _TIFFfree(rast); | ||
237 | TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); | ||
238 | TIFFClose(tif); | ||
239 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
240 | return EINA_FALSE; | ||
241 | } | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | INF("channel bits == %i", (int)rgba_image.rgba.samplesperpixel); | ||
246 | } | ||
247 | /* process rast -> image rgba. really same as prior code anyway just simpler */ | ||
248 | for (y = 0; y < (int)ie->h; y++) | ||
249 | { | ||
250 | DATA32 *pix, *pd; | ||
251 | uint32 *ps, pixel; | ||
252 | unsigned int a, r, g, b; | ||
253 | |||
254 | pix = evas_cache_image_pixels(ie); | ||
255 | pd = pix + ((ie->h - y - 1) * ie->w); | ||
256 | ps = rast + (y * ie->w); | ||
257 | for (x = 0; x < (int)ie->w; x++) | ||
258 | { | ||
259 | pixel = *ps; | ||
260 | a = TIFFGetA(pixel); | ||
261 | r = TIFFGetR(pixel); | ||
262 | g = TIFFGetG(pixel); | ||
263 | b = TIFFGetB(pixel); | ||
264 | if (!ie->flags.alpha) a = 255; | ||
265 | if ((rgba_image.rgba.alpha == EXTRASAMPLE_UNASSALPHA) && | ||
266 | (a < 255)) | ||
267 | { | ||
268 | r = (r * (a + 1)) >> 8; | ||
269 | g = (g * (a + 1)) >> 8; | ||
270 | b = (b * (a + 1)) >> 8; | ||
271 | } | ||
272 | *pd = ARGB_JOIN(a, r, g, b); | ||
273 | ps++; | ||
274 | pd++; | ||
275 | } | ||
276 | } | ||
277 | |||
278 | _TIFFfree(rast); | ||
279 | |||
280 | TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); | ||
281 | |||
282 | TIFFClose(tif); | ||
283 | |||
284 | evas_common_image_set_alpha_sparse(ie); | ||
285 | *error = EVAS_LOAD_ERROR_NONE; | ||
286 | return EINA_TRUE; | ||
287 | } | ||
288 | |||
289 | static int | ||
290 | module_open(Evas_Module *em) | ||
291 | { | ||
292 | if (!em) return 0; | ||
293 | _evas_loader_tiff_log_dom = eina_log_domain_register | ||
294 | ("evas-tiff", EVAS_DEFAULT_LOG_COLOR); | ||
295 | if (_evas_loader_tiff_log_dom < 0) | ||
296 | { | ||
297 | EINA_LOG_ERR("Can not create a module log domain."); | ||
298 | return 0; | ||
299 | } | ||
300 | em->functions = (void *)(&evas_image_load_tiff_func); | ||
301 | return 1; | ||
302 | } | ||
303 | |||
304 | static void | ||
305 | module_close(Evas_Module *em __UNUSED__) | ||
306 | { | ||
307 | eina_log_domain_unregister(_evas_loader_tiff_log_dom); | ||
308 | } | ||
309 | |||
310 | static Evas_Module_Api evas_modapi = | ||
311 | { | ||
312 | EVAS_MODULE_API_VERSION, | ||
313 | "tiff", | ||
314 | "none", | ||
315 | { | ||
316 | module_open, | ||
317 | module_close | ||
318 | } | ||
319 | }; | ||
320 | |||
321 | EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, tiff); | ||
322 | |||
323 | #ifndef EVAS_STATIC_BUILD_TIFF | ||
324 | EVAS_EINA_MODULE_DEFINE(image_loader, tiff); | ||
325 | #endif | ||