summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2013-01-02 06:44:26 +0000
committerCedric BAIL <cedric.bail@free.fr>2013-01-02 06:44:26 +0000
commit49b2bfea5ad49f1fef182893f6713de1af4bfc4c (patch)
tree11eafbcc81cb00bfc495a3c6266b68d45c9e4eb2
parent42b877cace3365449257a669427516d4529c587a (diff)
efl: and now tiff also use Eina_File.
SVN revision: 81973
-rw-r--r--ChangeLog2
-rw-r--r--NEWS2
-rw-r--r--src/modules/evas/loaders/tiff/evas_image_load_tiff.c184
3 files changed, 117 insertions, 71 deletions
diff --git a/ChangeLog b/ChangeLog
index 91645a40de..65f80c5dd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
12013-01-02 Cedric Bail 12013-01-02 Cedric Bail
2 2
3 * Use Eina_File for evas webp, gif and eet loader. 3 * Use Eina_File for evas webp, gif, tiff and eet loader.
4 * Add eet_map to open an Eet file from an Eina_File. 4 * Add eet_map to open an Eet file from an Eina_File.
5 5
62012-12-31 Gustavo Sverzut Barbieri (k-s) 62012-12-31 Gustavo Sverzut Barbieri (k-s)
diff --git a/NEWS b/NEWS
index a16d0491dd..f0b0e1db07 100644
--- a/NEWS
+++ b/NEWS
@@ -69,7 +69,7 @@ Improvements:
69 * Display more information with eet -l -v. 69 * Display more information with eet -l -v.
70 * eina_magic_fail() now throws error messages on NULL pointers instead of critical 70 * eina_magic_fail() now throws error messages on NULL pointers instead of critical
71 * all efl object-freeing functions now take NULL without crashing or erroring 71 * all efl object-freeing functions now take NULL without crashing or erroring
72 * use Eina_File in webp, gif and eet loader 72 * use Eina_File in webp, gif, tiff and eet loader
73 73
74Fixes: 74Fixes:
75 * Fix PPC (big endian) image codec bug. 75 * Fix PPC (big endian) image codec bug.
diff --git a/src/modules/evas/loaders/tiff/evas_image_load_tiff.c b/src/modules/evas/loaders/tiff/evas_image_load_tiff.c
index f2f1c595a8..d5472a7fa5 100644
--- a/src/modules/evas/loaders/tiff/evas_image_load_tiff.c
+++ b/src/modules/evas/loaders/tiff/evas_image_load_tiff.c
@@ -48,65 +48,111 @@ struct TIFFRGBAImage_Extra {
48 uint32 py; 48 uint32 py;
49}; 49};
50 50
51static tsize_t
52_evas_tiff_RWProc(thandle_t handle EINA_UNUSED,
53 tdata_t data EINA_UNUSED,
54 tsize_t size EINA_UNUSED)
55{
56 return 0;
57}
58
59static toff_t
60_evas_tiff_SeekProc(thandle_t handle EINA_UNUSED,
61 toff_t size EINA_UNUSED,
62 int origin EINA_UNUSED)
63{
64 return 0;
65}
66
67static int
68_evas_tiff_CloseProc(thandle_t handle EINA_UNUSED)
69{
70 return 0;
71}
72
73static toff_t
74_evas_tiff_SizeProc(thandle_t handle)
75{
76 Eina_File *f = (Eina_File *) handle;
77
78 return eina_file_size_get(f);
79}
80
81static int
82_evas_tiff_MapProc(thandle_t handle, tdata_t *mem, toff_t *size)
83{
84 Eina_File *f = (Eina_File *) handle;
85
86 *mem = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
87 *size = eina_file_size_get(f);
88
89 return 1;
90}
91
92static void
93_evas_tiff_UnmapProc(thandle_t handle, tdata_t data, toff_t size EINA_UNUSED)
94{
95 Eina_File *f = (Eina_File *) handle;
96
97 eina_file_map_free(f, data);
98}
99
51static Eina_Bool 100static Eina_Bool
52evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error) 101evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
53{ 102{
54 char txt[1024]; 103 char txt[1024];
55 TIFFRGBAImage tiff_image; 104 TIFFRGBAImage tiff_image;
56 TIFF *tif = NULL; 105 TIFF *tif = NULL;
57 FILE *ffile; 106 Eina_File *f;
58 int fd; 107 unsigned char *map;
59 uint16 magic_number; 108 uint16 magic_number;
109 Eina_Bool r = EINA_FALSE;
60 110
61 ffile = fopen(file, "rb"); 111 f = eina_file_open(file, EINA_FALSE);
62 if (!ffile) 112 if (!f)
63 { 113 {
64 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 114 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
65 return EINA_FALSE; 115 return EINA_FALSE;
66 } 116 }
67 117
68 if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1) 118 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
119 if (!map || eina_file_size_get(f) < 3)
69 { 120 {
70 fclose(ffile); 121 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
71 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 122 goto on_error;
72 return EINA_FALSE;
73 } 123 }
74 /* Apparently rewind(f) isn't sufficient */ 124
75 fseek(ffile, 0, SEEK_SET); 125 magic_number = *((uint16*) map);
76 126
77 if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */ 127 if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
78 && (magic_number != TIFF_LITTLEENDIAN)) 128 && (magic_number != TIFF_LITTLEENDIAN))
79 { 129 {
80 fclose(ffile);
81 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 130 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
82 return EINA_FALSE; 131 goto on_error;
83 } 132 }
84 133
85 fd = fileno(ffile); 134 tif = TIFFClientOpen("evas", "rM", f,
86 fd = dup(fd); 135 _evas_tiff_RWProc, _evas_tiff_RWProc,
87 lseek(fd, (long)0, SEEK_SET); 136 _evas_tiff_SeekProc, _evas_tiff_CloseProc,
88 fclose(ffile); 137 _evas_tiff_SizeProc,
89 138 _evas_tiff_MapProc, _evas_tiff_UnmapProc);
90 tif = TIFFFdOpen(fd, file, "r");
91 if (!tif) 139 if (!tif)
92 { 140 {
93 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 141 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
94 return EINA_FALSE; 142 goto on_error;
95 } 143 }
96 144
97 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff"); 145 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff");
98 if (!TIFFRGBAImageOK(tif, txt)) 146 if (!TIFFRGBAImageOK(tif, txt))
99 { 147 {
100 TIFFClose(tif);
101 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 148 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
102 return EINA_FALSE; 149 goto on_error;
103 } 150 }
104 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff"); 151 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff");
105 if (!TIFFRGBAImageBegin(& tiff_image, tif, 1, txt)) 152 if (!TIFFRGBAImageBegin(& tiff_image, tif, 1, txt))
106 { 153 {
107 TIFFClose(tif);
108 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 154 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
109 return EINA_FALSE; 155 goto on_error;
110 } 156 }
111 157
112 if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED) 158 if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED)
@@ -115,20 +161,25 @@ evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *ke
115 (tiff_image.width > IMG_MAX_SIZE) || (tiff_image.height > IMG_MAX_SIZE) || 161 (tiff_image.width > IMG_MAX_SIZE) || (tiff_image.height > IMG_MAX_SIZE) ||
116 IMG_TOO_BIG(tiff_image.width, tiff_image.height)) 162 IMG_TOO_BIG(tiff_image.width, tiff_image.height))
117 { 163 {
118 TIFFClose(tif);
119 if (IMG_TOO_BIG(tiff_image.width, tiff_image.height)) 164 if (IMG_TOO_BIG(tiff_image.width, tiff_image.height))
120 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 165 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
121 else 166 else
122 *error = EVAS_LOAD_ERROR_GENERIC; 167 *error = EVAS_LOAD_ERROR_GENERIC;
123 return EINA_FALSE; 168 goto on_error_end;
124 } 169 }
125 ie->w = tiff_image.width; 170 ie->w = tiff_image.width;
126 ie->h = tiff_image.height; 171 ie->h = tiff_image.height;
127 172
128 TIFFRGBAImageEnd(&tiff_image);
129 TIFFClose(tif);
130 *error = EVAS_LOAD_ERROR_NONE; 173 *error = EVAS_LOAD_ERROR_NONE;
131 return EINA_TRUE; 174 r = EINA_TRUE;
175
176 on_error_end:
177 TIFFRGBAImageEnd(&tiff_image);
178 on_error:
179 if (tif) TIFFClose(tif);
180 if (map) eina_file_map_free(f, map);
181 eina_file_close(f);
182 return r;
132} 183}
133 184
134static Eina_Bool 185static Eina_Bool
@@ -137,61 +188,59 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
137 char txt[1024]; 188 char txt[1024];
138 TIFFRGBAImage_Extra rgba_image; 189 TIFFRGBAImage_Extra rgba_image;
139 TIFF *tif = NULL; 190 TIFF *tif = NULL;
140 FILE *ffile; 191 Eina_File *f;
192 unsigned char *map;
141 uint32 *rast = NULL; 193 uint32 *rast = NULL;
142 uint32 num_pixels; 194 uint32 num_pixels;
143 int fd, x, y; 195 int x, y;
144 uint16 magic_number; 196 uint16 magic_number;
197 Eina_Bool res = EINA_FALSE;
145 198
146 ffile = fopen(file, "rb"); 199 f = eina_file_open(file, EINA_FALSE);
147 if (!ffile) 200 if (!f)
148 { 201 {
149 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 202 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
150 return EINA_FALSE; 203 return EINA_FALSE;
151 } 204 }
152 205
153 if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1) 206 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
207 if (!map || eina_file_size_get(f) < 3)
154 { 208 {
155 fclose(ffile); 209 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
156 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 210 goto on_error;
157 return EINA_FALSE;
158 } 211 }
159 /* Apparently rewind(f) isn't sufficient */ 212
160 fseek(ffile, (long)0, SEEK_SET); 213 magic_number = *((uint16*) map);
161 214
162 if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */ 215 if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
163 && (magic_number != TIFF_LITTLEENDIAN)) 216 && (magic_number != TIFF_LITTLEENDIAN))
164 { 217 {
165 fclose(ffile);
166 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 218 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
167 return EINA_FALSE; 219 goto on_error;
168 } 220 }
169 221
170 fd = fileno(ffile); 222 tif = TIFFClientOpen("evas", "rM", f,
171 fd = dup(fd); 223 _evas_tiff_RWProc, _evas_tiff_RWProc,
172 lseek(fd, (long)0, SEEK_SET); 224 _evas_tiff_SeekProc, _evas_tiff_CloseProc,
173 fclose(ffile); 225 _evas_tiff_SizeProc,
174 226 _evas_tiff_MapProc, _evas_tiff_UnmapProc);
175 tif = TIFFFdOpen(fd, file, "r");
176 if (!tif) 227 if (!tif)
177 { 228 {
178 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 229 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
179 return EINA_FALSE; 230 goto on_error;
180 } 231 }
181 232
182 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff"); 233 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff");
183 if (!TIFFRGBAImageOK(tif, txt)) 234 if (!TIFFRGBAImageOK(tif, txt))
184 { 235 {
185 TIFFClose(tif);
186 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 236 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
187 return EINA_FALSE; 237 goto on_error;
188 } 238 }
189 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff"); 239 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff");
190 if (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0, txt)) 240 if (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0, txt))
191 { 241 {
192 TIFFClose(tif);
193 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 242 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
194 return EINA_FALSE; 243 goto on_error;
195 } 244 }
196 rgba_image.image = ie; 245 rgba_image.image = ie;
197 246
@@ -200,18 +249,15 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
200 if ((rgba_image.rgba.width != ie->w) || 249 if ((rgba_image.rgba.width != ie->w) ||
201 (rgba_image.rgba.height != ie->h)) 250 (rgba_image.rgba.height != ie->h))
202 { 251 {
203 TIFFClose(tif);
204 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 252 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
205 return EINA_FALSE; 253 goto on_error_end;
206 } 254 }
207 255
208 evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height); 256 evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height);
209 if (!evas_cache_image_pixels(ie)) 257 if (!evas_cache_image_pixels(ie))
210 { 258 {
211 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
212 TIFFClose(tif);
213 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 259 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
214 return EINA_FALSE; 260 goto on_error_end;
215 } 261 }
216 262
217 rgba_image.num_pixels = num_pixels = ie->w * ie->h; 263 rgba_image.num_pixels = num_pixels = ie->w * ie->h;
@@ -221,12 +267,10 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
221 267
222 if (!rast) 268 if (!rast)
223 { 269 {
224 ERR("Evas Tiff loader: out of memory"); 270 ERR("Evas Tiff loader: out of memory");
225 271
226 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
227 TIFFClose(tif);
228 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 272 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
229 return EINA_FALSE; 273 goto on_error_end;
230 } 274 }
231 if (rgba_image.rgba.bitspersample == 8) 275 if (rgba_image.rgba.bitspersample == 8)
232 { 276 {
@@ -234,10 +278,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
234 rgba_image.rgba.width, rgba_image.rgba.height)) 278 rgba_image.rgba.width, rgba_image.rgba.height))
235 { 279 {
236 _TIFFfree(rast); 280 _TIFFfree(rast);
237 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
238 TIFFClose(tif);
239 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 281 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
240 return EINA_FALSE; 282 goto on_error_end;
241 } 283 }
242 } 284 }
243 else 285 else
@@ -277,13 +319,17 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
277 319
278 _TIFFfree(rast); 320 _TIFFfree(rast);
279 321
280 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
281
282 TIFFClose(tif);
283
284 evas_common_image_set_alpha_sparse(ie); 322 evas_common_image_set_alpha_sparse(ie);
285 *error = EVAS_LOAD_ERROR_NONE; 323 *error = EVAS_LOAD_ERROR_NONE;
286 return EINA_TRUE; 324 res = EINA_TRUE;
325
326 on_error_end:
327 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
328 on_error:
329 if (tif) TIFFClose(tif);
330 if (map) eina_file_map_free(f, map);
331 eina_file_close(f);
332 return res;
287} 333}
288 334
289static int 335static int