forked from enlightenment/efl
evas: move evas cache API outside of the image data loader API.
This commit is contained in:
parent
6f802ab234
commit
7d83e42046
|
@ -326,7 +326,10 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
|
||||||
EAPI int
|
EAPI int
|
||||||
evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
|
evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
|
||||||
{
|
{
|
||||||
|
void *pixels;
|
||||||
|
Eina_File *f;
|
||||||
Evas_Image_Load_Func *evas_image_load_func = NULL;
|
Evas_Image_Load_Func *evas_image_load_func = NULL;
|
||||||
|
Evas_Image_Property property;
|
||||||
int ret = EVAS_LOAD_ERROR_NONE;
|
int ret = EVAS_LOAD_ERROR_NONE;
|
||||||
|
|
||||||
if ((ie->flags.loaded) && (!ie->animated.animated)) return EVAS_LOAD_ERROR_GENERIC;
|
if ((ie->flags.loaded) && (!ie->animated.animated)) return EVAS_LOAD_ERROR_GENERIC;
|
||||||
|
@ -359,15 +362,52 @@ evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
|
||||||
|
|
||||||
evas_image_load_func = ie->info.loader;
|
evas_image_load_func = ie->info.loader;
|
||||||
evas_module_use((Evas_Module*) ie->info.module);
|
evas_module_use((Evas_Module*) ie->info.module);
|
||||||
if (!evas_image_load_func->file_data(ie, ie->file, ie->key, &ret))
|
|
||||||
|
f = eina_file_open(ie->file, EINA_FALSE);
|
||||||
|
if (!f) return EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
||||||
|
|
||||||
|
memset(&property, 0, sizeof (Evas_Image_Property));
|
||||||
|
if (!(evas_image_load_func->file_head(f, ie->key, &property,
|
||||||
|
&ie->load_opts, &ie->animated,
|
||||||
|
&ret) &&
|
||||||
|
(ret == EVAS_LOAD_ERROR_NONE)))
|
||||||
|
goto on_error;
|
||||||
|
|
||||||
|
ie->w = property.w;
|
||||||
|
ie->h = property.h;
|
||||||
|
ie->scale = property.scale;
|
||||||
|
ie->flags.alpha = property.alpha;
|
||||||
|
if (ie->load_opts.orientation &&
|
||||||
|
ie->load_opts.degree != 0)
|
||||||
|
ie->flags.rotated = EINA_TRUE;
|
||||||
|
|
||||||
|
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
||||||
|
|
||||||
|
pixels = evas_cache_image_pixels(ie);
|
||||||
|
if (!pixels)
|
||||||
{
|
{
|
||||||
return ret;
|
ret = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evas_image_load_func->file_data(f, ie->key,
|
||||||
|
&property,
|
||||||
|
&ie->load_opts,
|
||||||
|
&ie->animated,
|
||||||
|
pixels,
|
||||||
|
&ret);
|
||||||
|
|
||||||
|
ie->flags.alpha_sparse = property.alpha_sparse;
|
||||||
|
|
||||||
|
if (property.premul)
|
||||||
|
evas_common_image_premul(ie);
|
||||||
// evas_module_unref((Evas_Module*) ie->info.module);
|
// evas_module_unref((Evas_Module*) ie->info.module);
|
||||||
// ie->info.module = NULL;
|
// ie->info.module = NULL;
|
||||||
|
|
||||||
return EVAS_LOAD_ERROR_NONE;
|
on_error:
|
||||||
|
eina_file_close(f);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI double
|
EAPI double
|
||||||
|
|
|
@ -579,7 +579,10 @@ struct _Image_Entry_Property
|
||||||
|
|
||||||
unsigned char scale;
|
unsigned char scale;
|
||||||
|
|
||||||
|
Eina_Bool rotated;
|
||||||
Eina_Bool alpha;
|
Eina_Bool alpha;
|
||||||
|
Eina_Bool premul;
|
||||||
|
Eina_Bool alpha_sparse;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _Image_Entry
|
struct _Image_Entry
|
||||||
|
|
|
@ -904,9 +904,16 @@ struct _Evas_Image_Load_Func
|
||||||
{
|
{
|
||||||
Eina_Bool threadable;
|
Eina_Bool threadable;
|
||||||
Eina_Bool (*file_head) (Eina_File *f, const char *key,
|
Eina_Bool (*file_head) (Eina_File *f, const char *key,
|
||||||
Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated,
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated,
|
||||||
|
int *error);
|
||||||
|
Eina_Bool (*file_data) (Eina_File *f, const char *key,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated,
|
||||||
|
void *pixels,
|
||||||
int *error);
|
int *error);
|
||||||
Eina_Bool (*file_data) (Image_Entry *ie, const char *file, const char *key, int *error);
|
|
||||||
double (*frame_duration) (Image_Entry *ie, const char *file, const int start, const int frame_num);
|
double (*frame_duration) (Image_Entry *ie, const char *file, const int start, const int frame_num);
|
||||||
Eina_Bool do_region;
|
Eina_Bool do_region;
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -7,20 +7,6 @@
|
||||||
#include "evas_common.h"
|
#include "evas_common.h"
|
||||||
#include "evas_private.h"
|
#include "evas_private.h"
|
||||||
|
|
||||||
|
|
||||||
static Eina_Bool
|
|
||||||
evas_image_load_file_head_eet(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error);
|
|
||||||
|
|
||||||
Evas_Image_Load_Func evas_image_load_eet_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_eet,
|
|
||||||
evas_image_load_file_data_eet,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_head_eet(Eina_File *f, const char *key,
|
evas_image_load_file_head_eet(Eina_File *f, const char *key,
|
||||||
Evas_Image_Property *prop,
|
Evas_Image_Property *prop,
|
||||||
|
@ -67,72 +53,45 @@ evas_image_load_file_head_eet(Eina_File *f, const char *key,
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error)
|
evas_image_load_file_data_eet(Eina_File *f, const char *key,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
unsigned int w, h;
|
int alpha, compression, quality, lossy, ok;
|
||||||
int alpha, compression, quality, lossy, ok;
|
Eet_File *ef;
|
||||||
Eina_File *f;
|
DATA32 *body, *p, *end;
|
||||||
Eet_File *ef;
|
DATA32 nas = 0;
|
||||||
DATA32 *body, *p, *end, *data;
|
Eina_Bool res = EINA_FALSE;
|
||||||
DATA32 nas = 0;
|
|
||||||
Eina_Bool res = EINA_FALSE;
|
|
||||||
|
|
||||||
if (!key)
|
if (!key)
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
if (ie->flags.loaded)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
|
||||||
return EINA_TRUE;
|
|
||||||
}
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
ef = eet_mmap(f);
|
ef = eet_mmap(f);
|
||||||
if (!ef)
|
if (!ef)
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
ok = eet_data_image_header_read(ef, key,
|
|
||||||
&w, &h, &alpha, &compression, &quality, &lossy);
|
|
||||||
if (IMG_TOO_BIG(w, h))
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
evas_cache_image_surface_alloc(ie, w, h);
|
|
||||||
data = evas_cache_image_pixels(ie);
|
|
||||||
if (!data)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
ok = eet_data_image_read_to_surface(ef, key, 0, 0,
|
ok = eet_data_image_read_to_surface(ef, key, 0, 0,
|
||||||
data, w, h, w * 4,
|
pixels, prop->w, prop->h, prop->w * 4,
|
||||||
&alpha, &compression, &quality, &lossy);
|
&alpha, &compression, &quality, &lossy);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_GENERIC;
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alpha)
|
if (alpha)
|
||||||
{
|
{
|
||||||
ie->flags.alpha = 1;
|
prop->alpha = 1;
|
||||||
|
body = pixels;
|
||||||
|
|
||||||
body = evas_cache_image_pixels(ie);
|
end = body + (prop->w * prop->h);
|
||||||
|
|
||||||
end = body +(w * h);
|
|
||||||
for (p = body; p < end; p++)
|
for (p = body; p < end; p++)
|
||||||
{
|
{
|
||||||
DATA32 r, g, b, a;
|
DATA32 r, g, b, a;
|
||||||
|
@ -147,8 +106,8 @@ evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key
|
||||||
if (b > a) b = a;
|
if (b > a) b = a;
|
||||||
*p = ARGB_JOIN(a, r, g, b);
|
*p = ARGB_JOIN(a, r, g, b);
|
||||||
}
|
}
|
||||||
if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h))
|
if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (prop->w * prop->h))
|
||||||
ie->flags.alpha_sparse = 1;
|
prop->alpha_sparse = 1;
|
||||||
}
|
}
|
||||||
// result is already premultiplied now if u compile with edje
|
// result is already premultiplied now if u compile with edje
|
||||||
// evas_common_image_premul(im);
|
// evas_common_image_premul(im);
|
||||||
|
@ -157,10 +116,18 @@ evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
if (ef) eet_close(ef);
|
if (ef) eet_close(ef);
|
||||||
eina_file_close(f);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Evas_Image_Load_Func evas_image_load_eet_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_eet,
|
||||||
|
evas_image_load_file_data_eet,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,18 +16,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_generic(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
static Eina_Bool evas_image_load_file_data_generic(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
Evas_Image_Load_Func evas_image_load_generic_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_generic,
|
|
||||||
evas_image_load_file_data_generic,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
illegal_char(const char *str)
|
illegal_char(const char *str)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +92,11 @@ dotcat(char *dest, const char *src)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool get_data)
|
_load(Eina_File *ef, const char *key,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
void *pixels,
|
||||||
|
int *error, Eina_Bool get_data)
|
||||||
{
|
{
|
||||||
Eina_Bool res = EINA_FALSE;
|
Eina_Bool res = EINA_FALSE;
|
||||||
int w = 0, h = 0, alpha = 0;
|
int w = 0, h = 0, alpha = 0;
|
||||||
|
@ -129,18 +121,18 @@ _load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool
|
||||||
|
|
||||||
// params excluding file, key and loadopts
|
// params excluding file, key and loadopts
|
||||||
cmd_len += 1024;
|
cmd_len += 1024;
|
||||||
cmd_len += strlen(file) * 2;
|
cmd_len += strlen(eina_file_filename_get(ef)) * 2;
|
||||||
if (key) cmd_len += strlen(key) * 2;
|
if (key) cmd_len += strlen(key) * 2;
|
||||||
cmd = alloca(cmd_len + 1);
|
cmd = alloca(cmd_len + 1);
|
||||||
|
|
||||||
len = strlen(file);
|
len = strlen(eina_file_filename_get(ef));
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
end = file + len;
|
end = eina_file_filename_get(ef) + len;
|
||||||
for (p = end - 1; p >= file; p--)
|
for (p = end - 1; p >= eina_file_filename_get(ef); p--)
|
||||||
{
|
{
|
||||||
if ((!dot1) && (*p == '.')) dot1 = p;
|
if ((!dot1) && (*p == '.')) dot1 = p;
|
||||||
else if ((!dot2) && (*p == '.')) dot2 = p;
|
else if ((!dot2) && (*p == '.')) dot2 = p;
|
||||||
|
@ -196,7 +188,7 @@ _load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool
|
||||||
strcat(cmd, " ");
|
strcat(cmd, " ");
|
||||||
// filename first arg
|
// filename first arg
|
||||||
len = strlen(cmd);
|
len = strlen(cmd);
|
||||||
escape_copy(file, cmd + len);
|
escape_copy(eina_file_filename_get(ef), cmd + len);
|
||||||
if (!get_data)
|
if (!get_data)
|
||||||
{
|
{
|
||||||
strcat(cmd, " -head ");
|
strcat(cmd, " -head ");
|
||||||
|
@ -207,23 +199,23 @@ _load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool
|
||||||
len = strlen(cmd);
|
len = strlen(cmd);
|
||||||
escape_copy(key, cmd + len);
|
escape_copy(key, cmd + len);
|
||||||
}
|
}
|
||||||
if (ie->load_opts.scale_down_by > 1)
|
if (opts->scale_down_by > 1)
|
||||||
{
|
{
|
||||||
strcat(cmd, " -opt-scale-down-by ");
|
strcat(cmd, " -opt-scale-down-by ");
|
||||||
snprintf(buf, sizeof(buf), "%i", ie->load_opts.scale_down_by);
|
snprintf(buf, sizeof(buf), "%i", opts->scale_down_by);
|
||||||
strcat(cmd, buf);
|
strcat(cmd, buf);
|
||||||
}
|
}
|
||||||
if (ie->load_opts.dpi > 0.0)
|
if (opts->dpi > 0.0)
|
||||||
{
|
{
|
||||||
strcat(cmd, " -opt-dpi ");
|
strcat(cmd, " -opt-dpi ");
|
||||||
snprintf(buf, sizeof(buf), "%i", (int)(ie->load_opts.dpi * 1000.0));
|
snprintf(buf, sizeof(buf), "%i", (int)(opts->dpi * 1000.0));
|
||||||
strcat(cmd, buf);
|
strcat(cmd, buf);
|
||||||
}
|
}
|
||||||
if ((ie->load_opts.w > 0) &&
|
if ((opts->w > 0) &&
|
||||||
(ie->load_opts.h > 0))
|
(opts->h > 0))
|
||||||
{
|
{
|
||||||
strcat(cmd, " -opt-size ");
|
strcat(cmd, " -opt-size ");
|
||||||
snprintf(buf, sizeof(buf), "%i %i", ie->load_opts.w, ie->load_opts.h);
|
snprintf(buf, sizeof(buf), "%i %i", opts->w, opts->h);
|
||||||
strcat(cmd, buf);
|
strcat(cmd, buf);
|
||||||
}
|
}
|
||||||
f = popen(cmd, "r");
|
f = popen(cmd, "r");
|
||||||
|
@ -300,28 +292,22 @@ getdata:
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
body = evas_cache_image_pixels(ie);
|
|
||||||
if (body)
|
|
||||||
{
|
|
||||||
if ((w != (int)ie->w) || (h != (int)ie->h))
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (alpha) ie->flags.alpha = 1;
|
|
||||||
ie->w = w;
|
|
||||||
ie->h = h;
|
|
||||||
|
|
||||||
if (get_data)
|
if (!get_data)
|
||||||
{
|
{
|
||||||
if (!body) evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
if (alpha) prop->alpha = 1;
|
||||||
body = evas_cache_image_pixels(ie);
|
prop->w = w;
|
||||||
if (!body)
|
prop->h = h;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((int)prop->w != w ||
|
||||||
|
(int)prop->h != h)
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
body = pixels;
|
||||||
|
|
||||||
if ((tmpfname) || (shmfname))
|
if ((tmpfname) || (shmfname))
|
||||||
{
|
{
|
||||||
|
@ -387,22 +373,35 @@ getdata:
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_head_generic(Image_Entry *ie, const char *file, const char *key, int *error)
|
evas_image_load_file_head_generic(Eina_File *f, const char *key,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
return _load(ie, file, key, error, EINA_FALSE);
|
return _load(f, key, prop, opts, NULL, error, EINA_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_generic(Image_Entry *ie, const char *file, const char *key, int *error)
|
evas_image_load_file_data_generic(Eina_File *f, const char *key,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
DATA32 *body;
|
return _load(f, key, prop, opts, pixels, error, EINA_TRUE);
|
||||||
|
|
||||||
body = evas_cache_image_pixels(ie);
|
|
||||||
if (!body) return _load(ie, file, key, error, EINA_TRUE);
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
|
||||||
return EINA_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Evas_Image_Load_Func evas_image_load_generic_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_generic,
|
||||||
|
evas_image_load_file_data_generic,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,10 +43,8 @@ struct _Gif_Frame
|
||||||
int bg_val;
|
int bg_val;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_data_gif_internal(Image_Entry *ie, Image_Entry_Frame *frame, int *error);
|
|
||||||
|
|
||||||
static double evas_image_load_frame_duration_gif(Image_Entry *ie, const char *file, int start_frame, int frame_num) ;
|
static double evas_image_load_frame_duration_gif(Image_Entry *ie, const char *file, int start_frame, int frame_num) ;
|
||||||
static Eina_Bool evas_image_load_specific_frame(Image_Entry *ie, const char *file, int frame_index, int *error);
|
static Eina_Bool evas_image_load_specific_frame(Eina_File *f, const Evas_Image_Load_Opts *opts, Evas_Image_Property *prop, Evas_Image_Animated *animated, int frame_index, int *error);
|
||||||
|
|
||||||
#define byte2_to_int(a,b) (((b)<<8)|(a))
|
#define byte2_to_int(a,b) (((b)<<8)|(a))
|
||||||
|
|
||||||
|
@ -54,15 +52,14 @@ static Eina_Bool evas_image_load_specific_frame(Image_Entry *ie, const char *fil
|
||||||
|
|
||||||
/* find specific frame in image entry */
|
/* find specific frame in image entry */
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_find_frame(Image_Entry *ie, int frame_index, Image_Entry_Frame **frame)
|
_find_frame(Evas_Image_Animated *animated, int frame_index, Image_Entry_Frame **frame)
|
||||||
{
|
{
|
||||||
Eina_List *l;
|
Eina_List *l;
|
||||||
Image_Entry_Frame *hit_frame = NULL;
|
Image_Entry_Frame *hit_frame = NULL;
|
||||||
|
|
||||||
if (!ie) return EINA_FALSE;
|
if (!animated->frames) return EINA_FALSE;
|
||||||
if (!ie->animated.frames) return EINA_FALSE;
|
|
||||||
|
|
||||||
EINA_LIST_FOREACH(ie->animated.frames, l, hit_frame)
|
EINA_LIST_FOREACH(animated->frames, l, hit_frame)
|
||||||
{
|
{
|
||||||
if (hit_frame->index == frame_index)
|
if (hit_frame->index == frame_index)
|
||||||
{
|
{
|
||||||
|
@ -74,18 +71,18 @@ _find_frame(Image_Entry *ie, int frame_index, Image_Entry_Frame **frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_find_close_frame(Image_Entry *ie, int frame_index, Image_Entry_Frame **frame)
|
_find_close_frame(Evas_Image_Animated *animated, int frame_index, Image_Entry_Frame **frame)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
Eina_Bool hit = EINA_FALSE;
|
Eina_Bool hit = EINA_FALSE;
|
||||||
|
int i;
|
||||||
|
|
||||||
i = frame_index -1;
|
i = frame_index -1;
|
||||||
|
|
||||||
if (!ie) return EINA_FALSE;
|
if (!animated->frames) return EINA_FALSE;
|
||||||
if (!ie->animated.frames) return EINA_FALSE;
|
|
||||||
|
|
||||||
for (; i > 0; i--)
|
for (; i > 0; i--)
|
||||||
{
|
{
|
||||||
hit = _find_frame(ie, i, frame);
|
hit = _find_frame(animated, i, frame);
|
||||||
if (hit)
|
if (hit)
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -182,37 +179,34 @@ _evas_image_load_frame_image_des_info(GifFileType *gif, Image_Entry_Frame *frame
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_evas_image_load_frame_image_data(Image_Entry *ie, GifFileType *gif, Image_Entry_Frame *frame, int *error)
|
_evas_image_load_frame_image_data(Eina_File *f,
|
||||||
|
const Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Animated *animated,
|
||||||
|
GifFileType *gif, Image_Entry_Frame *frame, int *error)
|
||||||
{
|
{
|
||||||
int w;
|
ColorMapObject *cmap;
|
||||||
int h;
|
GifRowType *rows;
|
||||||
int x;
|
GifPixelType *tmp = NULL; /*for skip gif line */
|
||||||
int y;
|
DATA32 *ptr;
|
||||||
int i,j;
|
Gif_Frame *gif_frame = NULL;
|
||||||
int bg;
|
|
||||||
int r;
|
double per;
|
||||||
int g;
|
double per_inc;
|
||||||
int b;
|
size_t siz;
|
||||||
int alpha;
|
int intoffset[] = { 0, 4, 2, 1 };
|
||||||
double per;
|
int intjump[] = { 8, 8, 4, 2 };
|
||||||
double per_inc;
|
int x, y, w, h;
|
||||||
ColorMapObject *cmap;
|
int i, j;
|
||||||
GifRowType *rows;
|
int bg;
|
||||||
GifPixelType *tmp = NULL; /*for skip gif line */
|
int r, g, b, alpha;
|
||||||
int intoffset[] = { 0, 4, 2, 1 };
|
int cache_w, cache_h;
|
||||||
int intjump[] = { 8, 8, 4, 2 };
|
int cur_h, cur_w;
|
||||||
size_t siz;
|
int disposal = 0;
|
||||||
int cache_w;
|
int bg_val = 0;
|
||||||
int cache_h;
|
|
||||||
int cur_h;
|
|
||||||
int cur_w;
|
|
||||||
int disposal = 0;
|
|
||||||
int bg_val = 0;
|
|
||||||
DATA32 *ptr;
|
|
||||||
Gif_Frame *gif_frame = NULL;
|
|
||||||
/* for scale down decoding */
|
/* for scale down decoding */
|
||||||
int scale_ratio = 1;
|
int scale_ratio = 1;
|
||||||
int scale_w, scale_h, scale_x, scale_y;
|
int scale_w, scale_h, scale_x, scale_y;
|
||||||
|
|
||||||
if ((!gif) || (!frame)) return EINA_FALSE;
|
if ((!gif) || (!frame)) return EINA_FALSE;
|
||||||
|
|
||||||
|
@ -221,11 +215,11 @@ _evas_image_load_frame_image_data(Image_Entry *ie, GifFileType *gif, Image_Entry
|
||||||
h = gif->Image.Height;
|
h = gif->Image.Height;
|
||||||
x = gif->Image.Left;
|
x = gif->Image.Left;
|
||||||
y = gif->Image.Top;
|
y = gif->Image.Top;
|
||||||
cache_w = ie->w;
|
cache_w = prop->w;
|
||||||
cache_h = ie->h;
|
cache_h = prop->h;
|
||||||
|
|
||||||
/* if user don't set scale down, default scale_ratio is 1 */
|
/* if user don't set scale down, default scale_ratio is 1 */
|
||||||
if (ie->load_opts.scale_down_by > 1) scale_ratio = ie->load_opts.scale_down_by;
|
if (opts->scale_down_by > 1) scale_ratio = opts->scale_down_by;
|
||||||
scale_w = w / scale_ratio;
|
scale_w = w / scale_ratio;
|
||||||
scale_h = h / scale_ratio;
|
scale_h = h / scale_ratio;
|
||||||
scale_x = x / scale_ratio;
|
scale_x = x / scale_ratio;
|
||||||
|
@ -360,7 +354,7 @@ _evas_image_load_frame_image_data(Image_Entry *ie, GifFileType *gif, Image_Entry
|
||||||
int cur_frame = frame->index;
|
int cur_frame = frame->index;
|
||||||
int start_frame = 1;
|
int start_frame = 1;
|
||||||
|
|
||||||
if (_find_close_frame(ie, cur_frame, &new_frame))
|
if (_find_close_frame(animated, cur_frame, &new_frame))
|
||||||
start_frame = new_frame->index + 1;
|
start_frame = new_frame->index + 1;
|
||||||
|
|
||||||
if ((start_frame < 1) || (start_frame > cur_frame))
|
if ((start_frame < 1) || (start_frame > cur_frame))
|
||||||
|
@ -371,13 +365,14 @@ _evas_image_load_frame_image_data(Image_Entry *ie, GifFileType *gif, Image_Entry
|
||||||
/* load previous frame of cur_frame */
|
/* load previous frame of cur_frame */
|
||||||
for (j = start_frame; j < cur_frame ; j++)
|
for (j = start_frame; j < cur_frame ; j++)
|
||||||
{
|
{
|
||||||
if (!evas_image_load_specific_frame(ie, ie->file, j, error))
|
// FIXME : that one -v
|
||||||
|
if (!evas_image_load_specific_frame(f, opts, prop, animated, j, error))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_find_frame(ie, cur_frame - 1, &new_frame))
|
if (!_find_frame(animated, cur_frame - 1, &new_frame))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -571,7 +566,9 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_evas_image_load_frame(Image_Entry *ie, GifFileType *gif, Image_Entry_Frame *frame, Frame_Load_Type type, int *error)
|
_evas_image_load_frame(Eina_File *f, const Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Property *prop, Evas_Image_Animated *animated,
|
||||||
|
GifFileType *gif, Image_Entry_Frame *frame, Frame_Load_Type type, int *error)
|
||||||
{
|
{
|
||||||
GifRecordType rec;
|
GifRecordType rec;
|
||||||
int gra_res = 0, img_res = 0;
|
int gra_res = 0, img_res = 0;
|
||||||
|
@ -616,7 +613,8 @@ _evas_image_load_frame(Image_Entry *ie, GifFileType *gif, Image_Entry_Frame *fra
|
||||||
|
|
||||||
if ((type == LOAD_FRAME_DATA) || (type == LOAD_FRAME_DATA_INFO))
|
if ((type == LOAD_FRAME_DATA) || (type == LOAD_FRAME_DATA_INFO))
|
||||||
{
|
{
|
||||||
res = _evas_image_load_frame_image_data(ie, gif,frame, error);
|
res = _evas_image_load_frame_image_data(f, opts, prop, animated,
|
||||||
|
gif, frame, error);
|
||||||
if (!res) return EINA_FALSE;
|
if (!res) return EINA_FALSE;
|
||||||
}
|
}
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
@ -625,36 +623,14 @@ _evas_image_load_frame(Image_Entry *ie, GifFileType *gif, Image_Entry_Frame *fra
|
||||||
|
|
||||||
/* set frame data to cache entry's data */
|
/* set frame data to cache entry's data */
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_gif_internal(Image_Entry *ie, Image_Entry_Frame *frame, int *error)
|
evas_image_load_file_data_gif_internal(Evas_Image_Property *prop,
|
||||||
|
Image_Entry_Frame *frame,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
DATA32 *dst;
|
|
||||||
DATA32 *src;
|
|
||||||
int cache_w, cache_h;
|
|
||||||
size_t siz;
|
|
||||||
|
|
||||||
cache_w = ie->w;
|
|
||||||
cache_h = ie->h;
|
|
||||||
|
|
||||||
src = frame->data;
|
|
||||||
|
|
||||||
if (!evas_cache_image_pixels(ie))
|
|
||||||
{
|
|
||||||
evas_cache_image_surface_alloc(ie, cache_w, cache_h);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!evas_cache_image_pixels(ie))
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* only copy real frame part */
|
/* only copy real frame part */
|
||||||
siz = cache_w * cache_h * sizeof(DATA32);
|
memcpy(pixels, frame->data, prop->w * prop->h * sizeof (DATA32));
|
||||||
dst = evas_cache_image_pixels(ie);
|
prop->premul = EINA_TRUE;
|
||||||
|
|
||||||
memcpy(dst, src, siz);
|
|
||||||
|
|
||||||
evas_common_image_premul(ie);
|
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
@ -832,22 +808,18 @@ evas_image_load_file_head_gif(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_specific_frame(Image_Entry *ie, const char *file, int frame_index, int *error)
|
evas_image_load_specific_frame(Eina_File *f,
|
||||||
|
const Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Animated *animated, int frame_index,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Evas_GIF_Info egi;
|
|
||||||
Eina_File *f;
|
|
||||||
GifFileType *gif = NULL;
|
GifFileType *gif = NULL;
|
||||||
Image_Entry_Frame *frame = NULL;
|
Image_Entry_Frame *frame = NULL;
|
||||||
Gif_Frame *gif_frame = NULL;
|
Gif_Frame *gif_frame = NULL;
|
||||||
|
Evas_GIF_Info egi;
|
||||||
Eina_Bool r = EINA_FALSE;
|
Eina_Bool r = EINA_FALSE;
|
||||||
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
if (!egi.map)
|
if (!egi.map)
|
||||||
{
|
{
|
||||||
|
@ -884,36 +856,40 @@ evas_image_load_specific_frame(Image_Entry *ie, const char *file, int frame_inde
|
||||||
}
|
}
|
||||||
frame->info = gif_frame;
|
frame->info = gif_frame;
|
||||||
frame->index = frame_index;
|
frame->index = frame_index;
|
||||||
if (!_evas_image_load_frame(ie,gif, frame, LOAD_FRAME_DATA_INFO,error))
|
if (!_evas_image_load_frame(f, opts, prop, animated, gif, frame, LOAD_FRAME_DATA_INFO, error))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ie->animated.frames = eina_list_append(ie->animated.frames, frame);
|
animated->frames = eina_list_append(animated->frames, frame);
|
||||||
r = EINA_TRUE;
|
r = EINA_TRUE;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
if (gif) DGifCloseFile(gif);
|
if (gif) DGifCloseFile(gif);
|
||||||
if (egi.map) eina_file_map_free(f, egi.map);
|
if (egi.map) eina_file_map_free(f, egi.map);
|
||||||
eina_file_close(f);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_gif(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
int cur_frame_index;
|
|
||||||
Image_Entry_Frame *frame = NULL;
|
Image_Entry_Frame *frame = NULL;
|
||||||
Eina_Bool hit;
|
int cur_frame_index;
|
||||||
|
Eina_Bool hit;
|
||||||
|
|
||||||
if(!ie->animated.animated)
|
if(!animated->animated)
|
||||||
cur_frame_index = 1;
|
cur_frame_index = 1;
|
||||||
else
|
else
|
||||||
cur_frame_index = ie->animated.cur_frame;
|
cur_frame_index = animated->cur_frame;
|
||||||
|
|
||||||
if ((ie->animated.animated) &&
|
if ((animated->animated) &&
|
||||||
((cur_frame_index <0) || (cur_frame_index > FRAME_MAX) || (cur_frame_index > ie->animated.frame_count)))
|
((cur_frame_index < 0) || (cur_frame_index > FRAME_MAX) || (cur_frame_index > animated->frame_count)))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_GENERIC;
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
@ -923,27 +899,21 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
|
||||||
if (cur_frame_index == 0) cur_frame_index++;
|
if (cur_frame_index == 0) cur_frame_index++;
|
||||||
|
|
||||||
/* Check current frame exists in hash table */
|
/* Check current frame exists in hash table */
|
||||||
hit = _find_frame(ie, cur_frame_index, &frame);
|
hit = _find_frame(animated, cur_frame_index, &frame);
|
||||||
|
|
||||||
/* if current frame exist in has table, check load flag */
|
/* if current frame exist in has table, check load flag */
|
||||||
if (hit)
|
if (hit)
|
||||||
{
|
{
|
||||||
if (frame->loaded)
|
if (frame->loaded)
|
||||||
evas_image_load_file_data_gif_internal(ie,frame,error);
|
{
|
||||||
|
evas_image_load_file_data_gif_internal(prop, frame, pixels, error);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Evas_GIF_Info egi;
|
Evas_GIF_Info egi;
|
||||||
GifFileType *gif = NULL;
|
GifFileType *gif = NULL;
|
||||||
Eina_File *f = NULL;
|
|
||||||
Eina_Bool r = EINA_FALSE;
|
Eina_Bool r = EINA_FALSE;
|
||||||
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
if (!egi.map)
|
if (!egi.map)
|
||||||
{
|
{
|
||||||
|
@ -959,13 +929,13 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
_evas_image_skip_frame(gif, cur_frame_index-1);
|
_evas_image_skip_frame(gif, cur_frame_index - 1);
|
||||||
if (!_evas_image_load_frame(ie, gif, frame, LOAD_FRAME_DATA,error))
|
if (!_evas_image_load_frame(f, opts, prop, animated, gif, frame, LOAD_FRAME_DATA, error))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
if (!evas_image_load_file_data_gif_internal(ie, frame, error))
|
if (!evas_image_load_file_data_gif_internal(prop, frame, pixels, error))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
@ -976,22 +946,19 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
|
||||||
on_error:
|
on_error:
|
||||||
if (gif) DGifCloseFile(gif);
|
if (gif) DGifCloseFile(gif);
|
||||||
if (egi.map) eina_file_map_free(f, egi.map);
|
if (egi.map) eina_file_map_free(f, egi.map);
|
||||||
eina_file_close(f);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* current frame does is not exist */
|
/* current frame does is not exist */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!evas_image_load_specific_frame(ie, file, cur_frame_index, error))
|
if (!evas_image_load_specific_frame(f, opts, prop, animated, cur_frame_index, error))
|
||||||
{
|
return EINA_FALSE;
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
hit = EINA_FALSE;
|
hit = EINA_FALSE;
|
||||||
frame = NULL;
|
frame = NULL;
|
||||||
hit = _find_frame(ie, cur_frame_index, &frame);
|
hit = _find_frame(animated, cur_frame_index, &frame);
|
||||||
if (!hit) return EINA_FALSE;
|
if (!hit) return EINA_FALSE;
|
||||||
if (!evas_image_load_file_data_gif_internal(ie, frame, error))
|
if (!evas_image_load_file_data_gif_internal(prop, frame, pixels, error))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
|
|
@ -11,18 +11,6 @@
|
||||||
#include "evas_common.h"
|
#include "evas_common.h"
|
||||||
#include "evas_private.h"
|
#include "evas_private.h"
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_ico(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_ico_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_ico,
|
|
||||||
evas_image_load_file_data_ico,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
read_ushort(unsigned char *map, size_t length, size_t *position, unsigned short *ret)
|
read_ushort(unsigned char *map, size_t length, size_t *position, unsigned short *ret)
|
||||||
{
|
{
|
||||||
|
@ -300,9 +288,13 @@ evas_image_load_file_head_ico(Eina_File *f, const char *key,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key, int *error)
|
evas_image_load_file_data_ico(Eina_File *f, const char *key,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
void *map = NULL;
|
void *map = NULL;
|
||||||
size_t position = 0;
|
size_t position = 0;
|
||||||
unsigned short word;
|
unsigned short word;
|
||||||
|
@ -323,13 +315,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
int hot_x, hot_y;
|
int hot_x, hot_y;
|
||||||
unsigned int bmoffset, bmsize;
|
unsigned int bmoffset, bmsize;
|
||||||
} chosen = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
} chosen = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
|
Eina_Bool res = EINA_FALSE;
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
fsize = eina_file_size_get(f);
|
fsize = eina_file_size_get(f);
|
||||||
|
@ -348,10 +334,10 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
// more ?
|
// more ?
|
||||||
|
|
||||||
search = BIGGEST;
|
search = BIGGEST;
|
||||||
if ((ie->load_opts.w > 0) && (ie->load_opts.h > 0))
|
if ((opts->w > 0) && (opts->h > 0))
|
||||||
{
|
{
|
||||||
wanted_w = ie->load_opts.w;
|
wanted_w = opts->w;
|
||||||
wanted_h = ie->load_opts.h;
|
wanted_h = opts->h;
|
||||||
search = SMALLER;
|
search = SMALLER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +490,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
cols = chosen.cols;
|
cols = chosen.cols;
|
||||||
bpp = chosen.bpp;
|
bpp = chosen.bpp;
|
||||||
// changed since we loaded header?
|
// changed since we loaded header?
|
||||||
if (((int)ie->w != w) || ((int)ie->h != h)) goto close_file;
|
if (((int)prop->w != w) || ((int)prop->h != h)) goto close_file;
|
||||||
|
|
||||||
// read bmp header time... let's do some checking
|
// read bmp header time... let's do some checking
|
||||||
if (!read_uint(map, fsize, &position, &dword)) goto close_file; // headersize - dont care
|
if (!read_uint(map, fsize, &position, &dword)) goto close_file; // headersize - dont care
|
||||||
|
@ -531,7 +517,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
ERR("Broken ICO file: %s - "
|
ERR("Broken ICO file: %s - "
|
||||||
" Reporting size of %ix%i in index, but bitmap is %ix%i. "
|
" Reporting size of %ix%i in index, but bitmap is %ix%i. "
|
||||||
" May be expanded or cropped.",
|
" May be expanded or cropped.",
|
||||||
file, ie->w, ie->h, w, h);
|
eina_file_filename_get(f), prop->w, prop->h, w, h);
|
||||||
}
|
}
|
||||||
if (!read_ushort(map, fsize, &position, &word)) goto close_file; // planes
|
if (!read_ushort(map, fsize, &position, &word)) goto close_file; // planes
|
||||||
//planes2 = word;
|
//planes2 = word;
|
||||||
|
@ -548,14 +534,8 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
if (!read_uint(map, fsize, &position, &dword)) goto close_file; // colors important
|
if (!read_uint(map, fsize, &position, &dword)) goto close_file; // colors important
|
||||||
//colorsimportant = dword;
|
//colorsimportant = dword;
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
surface = pixels;
|
||||||
surface = evas_cache_image_pixels(ie);
|
memset(surface, 0, prop->w * prop->h * 4);
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto close_file;
|
|
||||||
}
|
|
||||||
memset(surface, 0, ie->w * ie->h * 4);
|
|
||||||
|
|
||||||
if (!((bitcount == 1) || (bitcount == 4) || (bitcount == 8) ||
|
if (!((bitcount == 1) || (bitcount == 4) || (bitcount == 8) ||
|
||||||
(bitcount == 24) || (bitcount == 32)))
|
(bitcount == 24) || (bitcount == 32)))
|
||||||
|
@ -591,14 +571,14 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
pstride = stride * 4;
|
pstride = stride * 4;
|
||||||
for (i = 0; i < h; i++)
|
for (i = 0; i < h; i++)
|
||||||
{
|
{
|
||||||
pix = surface + (i * ie->w);
|
pix = surface + (i * w);
|
||||||
if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
|
if (!right_way_up) pix = surface + ((h - 1 - i) * w);
|
||||||
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
||||||
p = pixbuf;
|
p = pixbuf;
|
||||||
if (i >= (int)ie->h) continue;
|
if (i >= h) continue;
|
||||||
for (j = 0; j < w; j++)
|
for (j = 0; j < w; j++)
|
||||||
{
|
{
|
||||||
if (j >= (int)ie->w) break;
|
if (j >= w) break;
|
||||||
if ((j & 0x7) == 0x0)
|
if ((j & 0x7) == 0x0)
|
||||||
{
|
{
|
||||||
*pix = pal[*p >> 7];
|
*pix = pal[*p >> 7];
|
||||||
|
@ -641,14 +621,14 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
pstride = ((w + 7) / 8) * 4;
|
pstride = ((w + 7) / 8) * 4;
|
||||||
for (i = 0; i < h; i++)
|
for (i = 0; i < h; i++)
|
||||||
{
|
{
|
||||||
pix = surface + (i * ie->w);
|
pix = surface + (i * w);
|
||||||
if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
|
if (!right_way_up) pix = surface + ((h - 1 - i) * w);
|
||||||
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
||||||
p = pixbuf;
|
p = pixbuf;
|
||||||
if (i >= (int)ie->h) continue;
|
if (i >= h) continue;
|
||||||
for (j = 0; j < w; j++)
|
for (j = 0; j < w; j++)
|
||||||
{
|
{
|
||||||
if (j >= (int)ie->w) break;
|
if (j >= w) break;
|
||||||
if ((j & 0x1) == 0x1)
|
if ((j & 0x1) == 0x1)
|
||||||
{
|
{
|
||||||
*pix = pal[*p & 0x0f];
|
*pix = pal[*p & 0x0f];
|
||||||
|
@ -667,14 +647,14 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
pstride = ((w + 3) / 4) * 4;
|
pstride = ((w + 3) / 4) * 4;
|
||||||
for (i = 0; i < h; i++)
|
for (i = 0; i < h; i++)
|
||||||
{
|
{
|
||||||
pix = surface + (i * ie->w);
|
pix = surface + (i * w);
|
||||||
if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
|
if (!right_way_up) pix = surface + ((h - 1 - i) * w);
|
||||||
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
||||||
p = pixbuf;
|
p = pixbuf;
|
||||||
if (i >= (int)ie->h) continue;
|
if (i >= h) continue;
|
||||||
for (j = 0; j < w; j++)
|
for (j = 0; j < w; j++)
|
||||||
{
|
{
|
||||||
if (j >= (int)ie->w) break;
|
if (j >= w) break;
|
||||||
*pix = pal[*p];
|
*pix = pal[*p];
|
||||||
p++;
|
p++;
|
||||||
pix++;
|
pix++;
|
||||||
|
@ -686,16 +666,16 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
pstride = w * 3;
|
pstride = w * 3;
|
||||||
for (i = 0; i < h; i++)
|
for (i = 0; i < h; i++)
|
||||||
{
|
{
|
||||||
pix = surface + (i * ie->w);
|
pix = surface + (i * w);
|
||||||
if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
|
if (!right_way_up) pix = surface + ((h - 1 - i) * w);
|
||||||
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
||||||
p = pixbuf;
|
p = pixbuf;
|
||||||
if (i >= (int)ie->h) continue;
|
if (i >= h) continue;
|
||||||
for (j = 0; j < w; j++)
|
for (j = 0; j < w; j++)
|
||||||
{
|
{
|
||||||
unsigned char a, r, g, b;
|
unsigned char a, r, g, b;
|
||||||
|
|
||||||
if (j >= (int)ie->w) break;
|
if (j >= w) break;
|
||||||
b = p[0];
|
b = p[0];
|
||||||
g = p[1];
|
g = p[1];
|
||||||
r = p[2];
|
r = p[2];
|
||||||
|
@ -711,16 +691,16 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
pstride = w * 4;
|
pstride = w * 4;
|
||||||
for (i = 0; i < h; i++)
|
for (i = 0; i < h; i++)
|
||||||
{
|
{
|
||||||
pix = surface + (i * ie->w);
|
pix = surface + (i * w);
|
||||||
if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
|
if (!right_way_up) pix = surface + ((h - 1 - i) * w);
|
||||||
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
|
||||||
p = pixbuf;
|
p = pixbuf;
|
||||||
if (i >= (int)ie->h) continue;
|
if (i >= h) continue;
|
||||||
for (j = 0; j < w; j++)
|
for (j = 0; j < w; j++)
|
||||||
{
|
{
|
||||||
unsigned char a, r, g, b;
|
unsigned char a, r, g, b;
|
||||||
|
|
||||||
if (j >= (int)ie->w) break;
|
if (j >= w) break;
|
||||||
b = p[0];
|
b = p[0];
|
||||||
g = p[1];
|
g = p[1];
|
||||||
r = p[2];
|
r = p[2];
|
||||||
|
@ -741,13 +721,13 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
{
|
{
|
||||||
unsigned char *m;
|
unsigned char *m;
|
||||||
|
|
||||||
pix = surface + (i * ie->w);
|
pix = surface + (i * w);
|
||||||
if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
|
if (!right_way_up) pix = surface + ((h - 1 - i) * w);
|
||||||
m = maskbuf + (stride * i * 4);
|
m = maskbuf + (stride * i * 4);
|
||||||
if (i >= (int)ie->h) continue;
|
if (i >= h) continue;
|
||||||
for (j = 0; j < w; j++)
|
for (j = 0; j < w; j++)
|
||||||
{
|
{
|
||||||
if (j >= (int)ie->w) break;
|
if (j >= w) break;
|
||||||
if (*m & (1 << (7 - (j & 0x7))))
|
if (*m & (1 << (7 - (j & 0x7))))
|
||||||
A_VAL(pix) = 0x00;
|
A_VAL(pix) = 0x00;
|
||||||
else
|
else
|
||||||
|
@ -758,19 +738,27 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eina_file_map_free(f, map);
|
|
||||||
eina_file_close(f);
|
|
||||||
|
|
||||||
evas_common_image_premul(ie);
|
prop->premul = EINA_TRUE;
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
return EINA_TRUE;
|
|
||||||
|
res = EINA_TRUE;
|
||||||
|
|
||||||
close_file:
|
close_file:
|
||||||
if (map) eina_file_map_free(f, map);
|
if (map) eina_file_map_free(f, map);
|
||||||
eina_file_close(f);
|
|
||||||
return EINA_FALSE;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_ico_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_ico,
|
||||||
|
evas_image_load_file_data_ico,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,34 +29,10 @@ static int _get_orientation_app0(char *app0_head, size_t remain_length);
|
||||||
static int _get_orientation_app1(char *app1_head, size_t remain_length);
|
static int _get_orientation_app1(char *app1_head, size_t remain_length);
|
||||||
static int _get_orientation(void *map, size_t length);
|
static int _get_orientation(void *map, size_t length);
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_jpeg_internal(unsigned int *w,
|
|
||||||
unsigned int *h,
|
|
||||||
unsigned char *scale,
|
|
||||||
Evas_Image_Load_Opts *opts,
|
|
||||||
void *map,
|
|
||||||
size_t len,
|
|
||||||
int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
|
||||||
void *map,
|
|
||||||
size_t len,
|
|
||||||
int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
#if 0 /* not used at the moment */
|
#if 0 /* not used at the moment */
|
||||||
static int evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f) EINA_ARG_NONNULL(1, 2);
|
static int evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f) EINA_ARG_NONNULL(1, 2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_jpeg(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_jpeg(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_jpeg_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_jpeg,
|
|
||||||
evas_image_load_file_data_jpeg,
|
|
||||||
NULL,
|
|
||||||
EINA_TRUE
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_JPEGFatalErrorHandler(j_common_ptr cinfo)
|
_JPEGFatalErrorHandler(j_common_ptr cinfo)
|
||||||
{
|
{
|
||||||
|
@ -309,7 +285,7 @@ _get_orientation(void *map, size_t length)
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_head_jpeg_internal(unsigned int *w, unsigned int *h,
|
evas_image_load_file_head_jpeg_internal(unsigned int *w, unsigned int *h,
|
||||||
unsigned char *scale,
|
unsigned char *scale, unsigned char *rotated,
|
||||||
Evas_Image_Load_Opts *opts,
|
Evas_Image_Load_Opts *opts,
|
||||||
void *map, size_t length,
|
void *map, size_t length,
|
||||||
int *error)
|
int *error)
|
||||||
|
@ -320,7 +296,7 @@ evas_image_load_file_head_jpeg_internal(unsigned int *w, unsigned int *h,
|
||||||
|
|
||||||
/* for rotation decoding */
|
/* for rotation decoding */
|
||||||
int degree = 0;
|
int degree = 0;
|
||||||
Eina_Bool change_wh = EINA_FALSE, rotated = EINA_FALSE;
|
Eina_Bool change_wh = EINA_FALSE;
|
||||||
unsigned int load_opts_w = 0, load_opts_h = 0;
|
unsigned int load_opts_w = 0, load_opts_h = 0;
|
||||||
|
|
||||||
memset(&cinfo, 0, sizeof(cinfo));
|
memset(&cinfo, 0, sizeof(cinfo));
|
||||||
|
@ -362,7 +338,7 @@ evas_image_load_file_head_jpeg_internal(unsigned int *w, unsigned int *h,
|
||||||
if (degree != 0)
|
if (degree != 0)
|
||||||
{
|
{
|
||||||
opts->degree = degree;
|
opts->degree = degree;
|
||||||
rotated = EINA_TRUE;
|
*rotated = EINA_TRUE;
|
||||||
|
|
||||||
if (degree == 90 || degree == 270)
|
if (degree == 90 || degree == 270)
|
||||||
change_wh = EINA_TRUE;
|
change_wh = EINA_TRUE;
|
||||||
|
@ -484,7 +460,7 @@ evas_image_load_file_head_jpeg_internal(unsigned int *w, unsigned int *h,
|
||||||
{
|
{
|
||||||
unsigned int load_region_x = 0, load_region_y = 0;
|
unsigned int load_region_x = 0, load_region_y = 0;
|
||||||
unsigned int load_region_w = 0, load_region_h = 0;
|
unsigned int load_region_w = 0, load_region_h = 0;
|
||||||
if (rotated)
|
if (*rotated)
|
||||||
{
|
{
|
||||||
load_region_x = opts->region.x;
|
load_region_x = opts->region.x;
|
||||||
load_region_y = opts->region.y;
|
load_region_y = opts->region.y;
|
||||||
|
@ -527,7 +503,7 @@ evas_image_load_file_head_jpeg_internal(unsigned int *w, unsigned int *h,
|
||||||
}
|
}
|
||||||
*w = opts->region.w;
|
*w = opts->region.w;
|
||||||
*h = opts->region.h;
|
*h = opts->region.h;
|
||||||
if (rotated)
|
if (*rotated)
|
||||||
{
|
{
|
||||||
opts->region.x = load_region_x;
|
opts->region.x = load_region_x;
|
||||||
opts->region.y = load_region_y;
|
opts->region.y = load_region_y;
|
||||||
|
@ -562,7 +538,9 @@ get_time(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
evas_image_load_file_data_jpeg_internal(Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
void *pixels,
|
||||||
void *map, size_t size,
|
void *map, size_t size,
|
||||||
int *error)
|
int *error)
|
||||||
{
|
{
|
||||||
|
@ -582,9 +560,9 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
Eina_Bool line_done = EINA_FALSE;
|
Eina_Bool line_done = EINA_FALSE;
|
||||||
|
|
||||||
memset(&cinfo, 0, sizeof(cinfo));
|
memset(&cinfo, 0, sizeof(cinfo));
|
||||||
if (ie->flags.rotated)
|
if (prop->rotated)
|
||||||
{
|
{
|
||||||
degree = ie->load_opts.degree;
|
degree = opts->degree;
|
||||||
if (degree == 90 || degree == 270)
|
if (degree == 90 || degree == 270)
|
||||||
change_wh = EINA_TRUE;
|
change_wh = EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -616,10 +594,10 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
cinfo.dct_method = JDCT_ISLOW; // JDCT_FLOAT JDCT_IFAST(quality loss)
|
cinfo.dct_method = JDCT_ISLOW; // JDCT_FLOAT JDCT_IFAST(quality loss)
|
||||||
cinfo.dither_mode = JDITHER_ORDERED;
|
cinfo.dither_mode = JDITHER_ORDERED;
|
||||||
|
|
||||||
if (ie->scale > 1)
|
if (prop->scale > 1)
|
||||||
{
|
{
|
||||||
cinfo.scale_num = 1;
|
cinfo.scale_num = 1;
|
||||||
cinfo.scale_denom = ie->scale;
|
cinfo.scale_denom = prop->scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Colorspace conversion options */
|
/* Colorspace conversion options */
|
||||||
|
@ -652,44 +630,44 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
|
|
||||||
if (change_wh)
|
if (change_wh)
|
||||||
{
|
{
|
||||||
ie_w = ie->h;
|
ie_w = prop->h;
|
||||||
ie_h = ie->w;
|
ie_h = prop->w;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ie_w = ie->w;
|
ie_w = prop->w;
|
||||||
ie_h = ie->h;
|
ie_h = prop->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ie->load_opts.region.w > 0) && (ie->load_opts.region.h > 0))
|
if ((opts->region.w > 0) && (opts->region.h > 0))
|
||||||
{
|
{
|
||||||
region = 1;
|
region = 1;
|
||||||
|
|
||||||
if (ie->flags.rotated)
|
if (prop->rotated)
|
||||||
{
|
{
|
||||||
load_region_x = ie->load_opts.region.x;
|
load_region_x = opts->region.x;
|
||||||
load_region_y = ie->load_opts.region.y;
|
load_region_y = opts->region.y;
|
||||||
load_region_w = ie->load_opts.region.w;
|
load_region_w = opts->region.w;
|
||||||
load_region_h = ie->load_opts.region.h;
|
load_region_h = opts->region.h;
|
||||||
|
|
||||||
switch (degree)
|
switch (degree)
|
||||||
{
|
{
|
||||||
case 90:
|
case 90:
|
||||||
ie->load_opts.region.x = load_region_y;
|
opts->region.x = load_region_y;
|
||||||
ie->load_opts.region.y = h - (load_region_x + load_region_w);
|
opts->region.y = h - (load_region_x + load_region_w);
|
||||||
ie->load_opts.region.w = load_region_h;
|
opts->region.w = load_region_h;
|
||||||
ie->load_opts.region.h = load_region_w;
|
opts->region.h = load_region_w;
|
||||||
break;
|
break;
|
||||||
case 180:
|
case 180:
|
||||||
ie->load_opts.region.x = w - (load_region_x+ load_region_w);
|
opts->region.x = w - (load_region_x+ load_region_w);
|
||||||
ie->load_opts.region.y = h - (load_region_y + load_region_h);
|
opts->region.y = h - (load_region_y + load_region_h);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 270:
|
case 270:
|
||||||
ie->load_opts.region.x = w - (load_region_y + load_region_h);
|
opts->region.x = w - (load_region_y + load_region_h);
|
||||||
ie->load_opts.region.y = load_region_x;
|
opts->region.y = load_region_x;
|
||||||
ie->load_opts.region.w = load_region_h;
|
opts->region.w = load_region_h;
|
||||||
ie->load_opts.region.h = load_region_w;
|
opts->region.h = load_region_w;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -697,10 +675,10 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
|
|
||||||
}
|
}
|
||||||
#ifdef BUILD_LOADER_JPEG_REGION
|
#ifdef BUILD_LOADER_JPEG_REGION
|
||||||
cinfo.region_x = ie->load_opts.region.x;
|
cinfo.region_x = opts->region.x;
|
||||||
cinfo.region_y = ie->load_opts.region.y;
|
cinfo.region_y = opts->region.y;
|
||||||
cinfo.region_w = ie->load_opts.region.w;
|
cinfo.region_w = opts->region.w;
|
||||||
cinfo.region_h = ie->load_opts.region.h;
|
cinfo.region_h = opts->region.h;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if ((!region) && ((w != ie_w) || (h != ie_h)))
|
if ((!region) && ((w != ie_w) || (h != ie_h)))
|
||||||
|
@ -713,21 +691,24 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
if ((region) &&
|
if ((region) &&
|
||||||
((ie_w != ie->load_opts.region.w) || (ie_h != ie->load_opts.region.h)))
|
((ie_w != opts->region.w) || (ie_h != opts->region.h)))
|
||||||
{
|
{
|
||||||
ie_w = ie->load_opts.region.w;
|
jpeg_destroy_decompress(&cinfo);
|
||||||
ie_h = ie->load_opts.region.h;
|
_evas_jpeg_membuf_src_term(&cinfo);
|
||||||
if (change_wh)
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
{
|
return EINA_FALSE;
|
||||||
ie->w = ie_h;
|
/* ie_w = opts->region.w; */
|
||||||
ie->h = ie_w;
|
/* ie_h = opts->region.h; */
|
||||||
}
|
/* if (change_wh) */
|
||||||
else
|
/* { */
|
||||||
{
|
/* ie->w = ie_h; */
|
||||||
ie->w = ie_w;
|
/* ie->h = ie_w; */
|
||||||
ie->h = ie_h;
|
/* } */
|
||||||
}
|
/* else */
|
||||||
|
/* { */
|
||||||
|
/* ie->w = ie_w; */
|
||||||
|
/* ie->h = ie_h; */
|
||||||
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(((cinfo.out_color_space == JCS_RGB) &&
|
if (!(((cinfo.out_color_space == JCS_RGB) &&
|
||||||
|
@ -750,28 +731,13 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
data = alloca(w * 16 * cinfo.output_components);
|
data = alloca(w * 16 * cinfo.output_components);
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
if ((prop->rotated) && change_wh)
|
||||||
if (ie->flags.loaded)
|
|
||||||
{
|
{
|
||||||
jpeg_destroy_decompress(&cinfo);
|
ptr2 = malloc(w * h * sizeof(DATA32));
|
||||||
_evas_jpeg_membuf_src_term(&cinfo);
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
|
||||||
if (region && ie->flags.rotated)
|
|
||||||
{
|
|
||||||
ie->load_opts.region.x = load_region_x;
|
|
||||||
ie->load_opts.region.y = load_region_y;
|
|
||||||
ie->load_opts.region.w = load_region_w;
|
|
||||||
ie->load_opts.region.h = load_region_h;
|
|
||||||
}
|
|
||||||
return EINA_TRUE;
|
|
||||||
}
|
|
||||||
if ((ie->flags.rotated) && change_wh)
|
|
||||||
{
|
|
||||||
ptr2 = malloc(ie->w * ie->h * sizeof(DATA32));
|
|
||||||
ptr_rotate = ptr2;
|
ptr_rotate = ptr2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ptr2 = evas_cache_image_pixels(ie);
|
ptr2 = pixels;
|
||||||
|
|
||||||
if (!ptr2)
|
if (!ptr2)
|
||||||
{
|
{
|
||||||
|
@ -841,7 +807,7 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if line # > region last line, break
|
// if line # > region last line, break
|
||||||
if (l >= (ie->load_opts.region.y + ie->load_opts.region.h))
|
if (l >= (opts->region.y + opts->region.h))
|
||||||
{
|
{
|
||||||
line_done = EINA_TRUE;
|
line_done = EINA_TRUE;
|
||||||
/* if rotation flag is set , we have to rotate image */
|
/* if rotation flag is set , we have to rotate image */
|
||||||
|
@ -853,17 +819,17 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
}
|
}
|
||||||
// els if scan block intersects region start or later
|
// els if scan block intersects region start or later
|
||||||
else if ((l + scans) >
|
else if ((l + scans) >
|
||||||
(ie->load_opts.region.y))
|
(opts->region.y))
|
||||||
{
|
{
|
||||||
for (y = 0; y < scans; y++)
|
for (y = 0; y < scans; y++)
|
||||||
{
|
{
|
||||||
if (((y + l) >= ie->load_opts.region.y) &&
|
if (((y + l) >= opts->region.y) &&
|
||||||
((y + l) < (ie->load_opts.region.y + ie->load_opts.region.h)))
|
((y + l) < (opts->region.y + opts->region.h)))
|
||||||
{
|
{
|
||||||
ptr += ie->load_opts.region.x;
|
ptr += opts->region.x;
|
||||||
if (cinfo.saw_Adobe_marker)
|
if (cinfo.saw_Adobe_marker)
|
||||||
{
|
{
|
||||||
for (x = 0; x < ie->load_opts.region.w; x++)
|
for (x = 0; x < opts->region.w; x++)
|
||||||
{
|
{
|
||||||
/* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */
|
/* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */
|
||||||
/* that is C is replaces by 255 - C, etc...*/
|
/* that is C is replaces by 255 - C, etc...*/
|
||||||
|
@ -879,7 +845,7 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (x = 0; x < ie->load_opts.region.w; x++)
|
for (x = 0; x < opts->region.w; x++)
|
||||||
{
|
{
|
||||||
/* Conversion from CMYK to RGB is done in 2 steps: */
|
/* Conversion from CMYK to RGB is done in 2 steps: */
|
||||||
/* CMYK => CMY => RGB (see http://www.easyrgb.com/index.php?X=MATH) */
|
/* CMYK => CMY => RGB (see http://www.easyrgb.com/index.php?X=MATH) */
|
||||||
|
@ -902,7 +868,7 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
ptr2++;
|
ptr2++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr += (4 * (w - (ie->load_opts.region.x + ie->load_opts.region.w)));
|
ptr += (4 * (w - (opts->region.x + opts->region.w)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ptr += (4 * w);
|
ptr += (4 * w);
|
||||||
|
@ -923,10 +889,10 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
ie,
|
ie,
|
||||||
ie->w, ie->h,
|
ie->w, ie->h,
|
||||||
ie->file,
|
ie->file,
|
||||||
ie->load_opts.region.x,
|
opts->region.x,
|
||||||
ie->load_opts.region.y,
|
opts->region.y,
|
||||||
ie->load_opts.region.w,
|
opts->region.w,
|
||||||
ie->load_opts.region.h);
|
opts->region.h);
|
||||||
}
|
}
|
||||||
t = get_time();
|
t = get_time();
|
||||||
*/
|
*/
|
||||||
|
@ -954,7 +920,7 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
{
|
{
|
||||||
// if line # > region last line, break
|
// if line # > region last line, break
|
||||||
// but not return immediately for rotation job
|
// but not return immediately for rotation job
|
||||||
if (l >= (ie->load_opts.region.y + ie->load_opts.region.h))
|
if (l >= (opts->region.y + opts->region.h))
|
||||||
{
|
{
|
||||||
line_done = EINA_TRUE;
|
line_done = EINA_TRUE;
|
||||||
/* if rotation flag is set , we have to rotate image */
|
/* if rotation flag is set , we have to rotate image */
|
||||||
|
@ -962,21 +928,21 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
}
|
}
|
||||||
// else if scan block intersects region start or later
|
// else if scan block intersects region start or later
|
||||||
else if ((l + scans) >
|
else if ((l + scans) >
|
||||||
(ie->load_opts.region.y))
|
(opts->region.y))
|
||||||
{
|
{
|
||||||
for (y = 0; y < scans; y++)
|
for (y = 0; y < scans; y++)
|
||||||
{
|
{
|
||||||
if (((y + l) >= ie->load_opts.region.y) &&
|
if (((y + l) >= opts->region.y) &&
|
||||||
((y + l) < (ie->load_opts.region.y + ie->load_opts.region.h)))
|
((y + l) < (opts->region.y + opts->region.h)))
|
||||||
{
|
{
|
||||||
ptr += (3 * ie->load_opts.region.x);
|
ptr += (3 * opts->region.x);
|
||||||
for (x = 0; x < ie->load_opts.region.w; x++)
|
for (x = 0; x < opts->region.w; x++)
|
||||||
{
|
{
|
||||||
*ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[1], ptr[2]);
|
*ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[1], ptr[2]);
|
||||||
ptr += 3;
|
ptr += 3;
|
||||||
ptr2++;
|
ptr2++;
|
||||||
}
|
}
|
||||||
ptr += (3 * (w - (ie->load_opts.region.x + ie->load_opts.region.w)));
|
ptr += (3 * (w - (opts->region.x + opts->region.w)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ptr += (3 * w);
|
ptr += (3 * w);
|
||||||
|
@ -1015,7 +981,7 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if line # > region last line, break
|
// if line # > region last line, break
|
||||||
if (l >= (ie->load_opts.region.y + ie->load_opts.region.h))
|
if (l >= (opts->region.y + opts->region.h))
|
||||||
{
|
{
|
||||||
line_done = EINA_TRUE;
|
line_done = EINA_TRUE;
|
||||||
/* if rotation flag is set , we have to rotate image */
|
/* if rotation flag is set , we have to rotate image */
|
||||||
|
@ -1027,21 +993,21 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
}
|
}
|
||||||
// els if scan block intersects region start or later
|
// els if scan block intersects region start or later
|
||||||
else if ((l + scans) >
|
else if ((l + scans) >
|
||||||
(ie->load_opts.region.y))
|
(opts->region.y))
|
||||||
{
|
{
|
||||||
for (y = 0; y < scans; y++)
|
for (y = 0; y < scans; y++)
|
||||||
{
|
{
|
||||||
if (((y + l) >= ie->load_opts.region.y) &&
|
if (((y + l) >= opts->region.y) &&
|
||||||
((y + l) < (ie->load_opts.region.y + ie->load_opts.region.h)))
|
((y + l) < (opts->region.y + opts->region.h)))
|
||||||
{
|
{
|
||||||
ptr += ie->load_opts.region.x;
|
ptr += opts->region.x;
|
||||||
for (x = 0; x < ie->load_opts.region.w; x++)
|
for (x = 0; x < opts->region.w; x++)
|
||||||
{
|
{
|
||||||
*ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
|
*ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr2++;
|
ptr2++;
|
||||||
}
|
}
|
||||||
ptr += w - (ie->load_opts.region.x + ie->load_opts.region.w);
|
ptr += w - (opts->region.x + opts->region.w);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ptr += w;
|
ptr += w;
|
||||||
|
@ -1053,16 +1019,16 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie,
|
||||||
/* if rotation operation need, rotate it */
|
/* if rotation operation need, rotate it */
|
||||||
done:
|
done:
|
||||||
|
|
||||||
if (ie->flags.rotated)
|
if (prop->rotated)
|
||||||
{
|
{
|
||||||
DATA32 *data1, *data2, *to, *from;
|
DATA32 *data1, *data2, *to, *from;
|
||||||
int lx, ly, lw, lh, hw;
|
int lx, ly, lw, lh, hw;
|
||||||
|
|
||||||
lw = ie->w;
|
lw = w;
|
||||||
lh = ie->h;
|
lh = h;
|
||||||
hw =lw * lh;
|
hw = lw * lh;
|
||||||
|
|
||||||
data1 = evas_cache_image_pixels(ie);
|
data1 = pixels;
|
||||||
|
|
||||||
if (degree == 180)
|
if (degree == 180)
|
||||||
{
|
{
|
||||||
|
@ -1099,9 +1065,9 @@ done:
|
||||||
if (to)
|
if (to)
|
||||||
{
|
{
|
||||||
from = data2;
|
from = data2;
|
||||||
for (lx = ie->w; --lx >= 0;)
|
for (lx = w; --lx >= 0;)
|
||||||
{
|
{
|
||||||
for (ly =ie->h; --ly >= 0;)
|
for (ly = h; --ly >= 0;)
|
||||||
{
|
{
|
||||||
*to = *from;
|
*to = *from;
|
||||||
from++;
|
from++;
|
||||||
|
@ -1118,10 +1084,10 @@ done:
|
||||||
}
|
}
|
||||||
if (region)
|
if (region)
|
||||||
{
|
{
|
||||||
ie->load_opts.region.x = load_region_x;
|
opts->region.x = load_region_x;
|
||||||
ie->load_opts.region.y = load_region_y;
|
opts->region.y = load_region_y;
|
||||||
ie->load_opts.region.w = load_region_w;
|
opts->region.w = load_region_w;
|
||||||
ie->load_opts.region.h = load_region_h;
|
opts->region.h = load_region_h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1261,7 +1227,7 @@ evas_image_load_file_head_jpeg(Eina_File *f, const char *key EINA_UNUSED, Evas_I
|
||||||
}
|
}
|
||||||
|
|
||||||
val = evas_image_load_file_head_jpeg_internal(&prop->w, &prop->h,
|
val = evas_image_load_file_head_jpeg_internal(&prop->w, &prop->h,
|
||||||
&prop->scale,
|
&prop->scale, &prop->rotated,
|
||||||
opts,
|
opts,
|
||||||
map, eina_file_size_get(f),
|
map, eina_file_size_get(f),
|
||||||
error);
|
error);
|
||||||
|
@ -1273,20 +1239,16 @@ evas_image_load_file_head_jpeg(Eina_File *f, const char *key EINA_UNUSED, Evas_I
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_jpeg(Image_Entry *ie,
|
evas_image_load_file_data_jpeg(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
const char *file, const char *key EINA_UNUSED,
|
Evas_Image_Property *prop,
|
||||||
int *error)
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
void *map;
|
void *map;
|
||||||
Eina_Bool val = EINA_FALSE;
|
Eina_Bool val = EINA_FALSE;
|
||||||
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
map = eina_file_map_all(f, EINA_FILE_WILLNEED);
|
map = eina_file_map_all(f, EINA_FILE_WILLNEED);
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
|
@ -1294,17 +1256,25 @@ evas_image_load_file_data_jpeg(Image_Entry *ie,
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = evas_image_load_file_data_jpeg_internal(ie,
|
val = evas_image_load_file_data_jpeg_internal(opts, prop, pixels,
|
||||||
map, eina_file_size_get(f),
|
map, eina_file_size_get(f),
|
||||||
error);
|
error);
|
||||||
|
|
||||||
eina_file_map_free(f, map);
|
eina_file_map_free(f, map);
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
eina_file_close(f);
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_jpeg_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_jpeg,
|
||||||
|
evas_image_load_file_data_jpeg,
|
||||||
|
NULL,
|
||||||
|
EINA_TRUE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,17 +12,6 @@
|
||||||
#define FILE_BUFFER_SIZE 1024 * 32
|
#define FILE_BUFFER_SIZE 1024 * 32
|
||||||
#define FILE_BUFFER_UNREAD_SIZE 16
|
#define FILE_BUFFER_UNREAD_SIZE 16
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_pmaps(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
Evas_Image_Load_Func evas_image_load_pmaps_func = {
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_pmaps,
|
|
||||||
evas_image_load_file_data_pmaps,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The buffer to load pmaps images */
|
/* The buffer to load pmaps images */
|
||||||
typedef struct Pmaps_Buffer Pmaps_Buffer;
|
typedef struct Pmaps_Buffer Pmaps_Buffer;
|
||||||
|
|
||||||
|
@ -96,73 +85,65 @@ evas_image_load_file_head_pmaps(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_pmaps(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
Pmaps_Buffer b;
|
Pmaps_Buffer b;
|
||||||
int pixels;
|
int size;
|
||||||
DATA32 *ptr;
|
DATA32 *ptr;
|
||||||
Eina_Bool r = EINA_FALSE;
|
Eina_Bool r = EINA_FALSE;
|
||||||
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pmaps_buffer_open(&b, f, error))
|
if (!pmaps_buffer_open(&b, f, error))
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
if (!pmaps_buffer_header_parse(&b, error))
|
if (!pmaps_buffer_header_parse(&b, error))
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
pixels = b.w * b.h;
|
size = b.w * b.h;
|
||||||
|
if ((int) prop->w != b.w ||
|
||||||
evas_cache_image_surface_alloc(ie, b.w, b.h);
|
(int) prop->h != b.h)
|
||||||
ptr = evas_cache_image_pixels(ie);
|
goto on_error;
|
||||||
if (!ptr)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ptr = pixels;
|
||||||
if (b.type[1] != '4')
|
if (b.type[1] != '4')
|
||||||
{
|
{
|
||||||
while (pixels > 0 && b.color_get(&b, ptr))
|
while (size > 0 && b.color_get(&b, ptr))
|
||||||
{
|
{
|
||||||
pixels--;
|
size--;
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (pixels > 0
|
while (size > 0
|
||||||
&& (b.current != b.end || pmaps_buffer_raw_update(&b)))
|
&& (b.current != b.end || pmaps_buffer_raw_update(&b)))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 7; i >= 0 && pixels > 0; i--)
|
for (i = 7; i >= 0 && size > 0; i--)
|
||||||
{
|
{
|
||||||
if (*b.current & (1 << i))
|
if (*b.current & (1 << i))
|
||||||
*ptr = 0xff000000;
|
*ptr = 0xff000000;
|
||||||
else
|
else
|
||||||
*ptr = 0xffffffff;
|
*ptr = 0xffffffff;
|
||||||
ptr++;
|
ptr++;
|
||||||
pixels--;
|
size--;
|
||||||
}
|
}
|
||||||
b.current++;
|
b.current++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if there are some pix missing, give them a proper default */
|
/* if there are some pix missing, give them a proper default */
|
||||||
memset(ptr, 0xff, 4 * pixels);
|
memset(ptr, 0xff, 4 * size);
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
r = EINA_TRUE;
|
r = EINA_TRUE;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
pmaps_buffer_close(&b);
|
pmaps_buffer_close(&b);
|
||||||
eina_file_close(f);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,6 +542,14 @@ pmaps_buffer_plain_bw_get(Pmaps_Buffer *b, DATA32 *val)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* external functions */
|
/* external functions */
|
||||||
|
Evas_Image_Load_Func evas_image_load_pmaps_func = {
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_pmaps,
|
||||||
|
evas_image_load_file_data_pmaps,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,18 +15,6 @@
|
||||||
|
|
||||||
#define PNG_BYTES_TO_CHECK 4
|
#define PNG_BYTES_TO_CHECK 4
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_png(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_png_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_png,
|
|
||||||
evas_image_load_file_data_png,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct _Evas_PNG_Info Evas_PNG_Info;
|
typedef struct _Evas_PNG_Info Evas_PNG_Info;
|
||||||
struct _Evas_PNG_Info
|
struct _Evas_PNG_Info
|
||||||
{
|
{
|
||||||
|
@ -153,9 +141,13 @@ evas_image_load_file_head_png(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_png(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
unsigned char *surface;
|
unsigned char *surface;
|
||||||
unsigned char **lines;
|
unsigned char **lines;
|
||||||
unsigned char *tmp_line;
|
unsigned char *tmp_line;
|
||||||
|
@ -172,12 +164,6 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
|
||||||
Eina_Bool r = EINA_FALSE;
|
Eina_Bool r = EINA_FALSE;
|
||||||
|
|
||||||
hasa = 0;
|
hasa = 0;
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
epi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
epi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
if (!epi.map)
|
if (!epi.map)
|
||||||
|
@ -229,28 +215,24 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
|
||||||
(png_uint_32 *) (&h32), &bit_depth, &color_type,
|
(png_uint_32 *) (&h32), &bit_depth, &color_type,
|
||||||
&interlace_type, NULL, NULL);
|
&interlace_type, NULL, NULL);
|
||||||
image_w = w32;
|
image_w = w32;
|
||||||
if (ie->load_opts.scale_down_by > 1)
|
if (opts->scale_down_by > 1)
|
||||||
{
|
{
|
||||||
scale_ratio = ie->load_opts.scale_down_by;
|
scale_ratio = opts->scale_down_by;
|
||||||
w32 /= scale_ratio;
|
w32 /= scale_ratio;
|
||||||
h32 /= scale_ratio;
|
h32 /= scale_ratio;
|
||||||
}
|
}
|
||||||
evas_cache_image_surface_alloc(ie, w32, h32);
|
if (prop->w != w32 ||
|
||||||
surface = (unsigned char *) evas_cache_image_pixels(ie);
|
prop->h != h32)
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto close_file;
|
|
||||||
}
|
|
||||||
if ((w32 != ie->w) || (h32 != ie->h))
|
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_GENERIC;
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
goto close_file;
|
goto close_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
surface = pixels;
|
||||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1;
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1;
|
||||||
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1;
|
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1;
|
||||||
if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) hasa = 1;
|
if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) hasa = 1;
|
||||||
if (hasa) ie->flags.alpha = 1;
|
if (hasa) prop->alpha = 1;
|
||||||
|
|
||||||
/* Prep for transformations... ultimately we want ARGB */
|
/* Prep for transformations... ultimately we want ARGB */
|
||||||
/* expand palette -> RGB if necessary */
|
/* expand palette -> RGB if necessary */
|
||||||
|
@ -270,8 +252,8 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
|
||||||
/* pack all pixels to byte boundaries */
|
/* pack all pixels to byte boundaries */
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
|
||||||
w = ie->w;
|
w = w32;
|
||||||
h = ie->h;
|
h = h32;
|
||||||
/* we want ARGB */
|
/* we want ARGB */
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
png_set_swap_alpha(png_ptr);
|
png_set_swap_alpha(png_ptr);
|
||||||
|
@ -311,7 +293,7 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evas_common_image_premul(ie);
|
prop->premul = EINA_TRUE;
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
r = EINA_TRUE;
|
r = EINA_TRUE;
|
||||||
|
@ -321,10 +303,18 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
|
||||||
info_ptr ? &info_ptr : NULL,
|
info_ptr ? &info_ptr : NULL,
|
||||||
NULL);
|
NULL);
|
||||||
if (epi.map) eina_file_map_free(f, epi.map);
|
if (epi.map) eina_file_map_free(f, epi.map);
|
||||||
eina_file_close(f);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_png_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_png,
|
||||||
|
evas_image_load_file_data_png,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -240,8 +240,7 @@ read_compressed_channel(const unsigned char *map, size_t length, size_t *positio
|
||||||
|
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
psd_get_data(Image_Entry *ie EINA_UNUSED,
|
psd_get_data(PSD_Header *head,
|
||||||
PSD_Header *head,
|
|
||||||
const unsigned char *map, size_t length, size_t *position,
|
const unsigned char *map, size_t length, size_t *position,
|
||||||
unsigned char *buffer, Eina_Bool compressed,
|
unsigned char *buffer, Eina_Bool compressed,
|
||||||
int *error)
|
int *error)
|
||||||
|
@ -495,8 +494,7 @@ psd_get_data(Image_Entry *ie EINA_UNUSED,
|
||||||
|
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
get_single_channel(Image_Entry *ie EINA_UNUSED,
|
get_single_channel(PSD_Header *head,
|
||||||
PSD_Header *head,
|
|
||||||
const unsigned char *map, size_t length, size_t *position,
|
const unsigned char *map, size_t length, size_t *position,
|
||||||
unsigned char *buffer,
|
unsigned char *buffer,
|
||||||
Eina_Bool compressed)
|
Eina_Bool compressed)
|
||||||
|
@ -556,11 +554,10 @@ get_single_channel(Image_Entry *ie EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
read_psd_grey(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
read_psd_grey(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
||||||
{
|
{
|
||||||
unsigned int color_mode, resource_size, misc_info;
|
unsigned int color_mode, resource_size, misc_info;
|
||||||
unsigned short compressed;
|
unsigned short compressed;
|
||||||
void *surface = NULL;
|
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
|
|
||||||
|
@ -580,11 +577,6 @@ read_psd_grey(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_
|
||||||
|
|
||||||
CHECK_RET(read_ushort(map, length, position, &compressed));
|
CHECK_RET(read_ushort(map, length, position, &compressed));
|
||||||
|
|
||||||
ie->w = head->width;
|
|
||||||
ie->h = head->height;
|
|
||||||
if (head->channels == 3) ie->flags.alpha = 0;
|
|
||||||
else ie->flags.alpha = 1;
|
|
||||||
|
|
||||||
head->channel_num = head->channels;
|
head->channel_num = head->channels;
|
||||||
// Temporary to read only one channel...some greyscale .psd files have 2.
|
// Temporary to read only one channel...some greyscale .psd files have 2.
|
||||||
head->channels = 1;
|
head->channels = 1;
|
||||||
|
@ -599,15 +591,7 @@ read_psd_grey(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
if (!psd_get_data(head, map, length, position, pixels, compressed, error))
|
||||||
surface = evas_cache_image_pixels(ie);
|
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto cleanup_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
|
|
||||||
goto cleanup_error;
|
goto cleanup_error;
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
@ -620,11 +604,10 @@ read_psd_grey(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_
|
||||||
|
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
read_psd_indexed(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
read_psd_indexed(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
||||||
{
|
{
|
||||||
unsigned int color_mode, resource_size, misc_info;
|
unsigned int color_mode, resource_size, misc_info;
|
||||||
unsigned short compressed;
|
unsigned short compressed;
|
||||||
void *surface;
|
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
|
|
||||||
|
@ -659,20 +642,7 @@ read_psd_indexed(Image_Entry *ie, PSD_Header *head, const unsigned char *map, si
|
||||||
}
|
}
|
||||||
head->channel_num = head->channels;
|
head->channel_num = head->channels;
|
||||||
|
|
||||||
ie->w = head->width;
|
if (!psd_get_data(head, map, length, position, pixels, compressed, error))
|
||||||
ie->h = head->height;
|
|
||||||
if (head->channels == 3) ie->flags.alpha = 0;
|
|
||||||
else ie->flags.alpha = 1;
|
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
|
||||||
surface = evas_cache_image_pixels(ie);
|
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
|
@ -680,11 +650,10 @@ read_psd_indexed(Image_Entry *ie, PSD_Header *head, const unsigned char *map, si
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
read_psd_rgb(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
read_psd_rgb(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
||||||
{
|
{
|
||||||
unsigned int color_mode, resource_size, misc_info;
|
unsigned int color_mode, resource_size, misc_info;
|
||||||
unsigned short compressed;
|
unsigned short compressed;
|
||||||
void *surface;
|
|
||||||
|
|
||||||
#define CHECK_RET(Call) \
|
#define CHECK_RET(Call) \
|
||||||
if (!Call) return EINA_FALSE;
|
if (!Call) return EINA_FALSE;
|
||||||
|
@ -713,39 +682,23 @@ read_psd_rgb(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
ie->w = head->width;
|
|
||||||
ie->h = head->height;
|
|
||||||
if (head->channels == 3) ie->flags.alpha = 0;
|
|
||||||
else ie->flags.alpha = 1;
|
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
if (!psd_get_data(head, map, length, position, pixels, compressed, error))
|
||||||
surface = evas_cache_image_pixels(ie);
|
return EINA_FALSE;
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto cleanup_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
|
|
||||||
goto cleanup_error;
|
|
||||||
|
|
||||||
evas_common_image_premul(ie);
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
#undef CHECK_RET
|
#undef CHECK_RET
|
||||||
|
|
||||||
cleanup_error:
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
read_psd_cmyk(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
read_psd_cmyk(Evas_Image_Property *prop, void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
|
||||||
{
|
{
|
||||||
unsigned int color_mode, resource_size, misc_info, size, j, data_size;
|
unsigned int color_mode, resource_size, misc_info, size, j, data_size;
|
||||||
unsigned short compressed;
|
unsigned short compressed;
|
||||||
unsigned int format, type;
|
unsigned int format, type;
|
||||||
unsigned char *kchannel = NULL;
|
unsigned char *kchannel = NULL;
|
||||||
void *surface;
|
Eina_Bool r = EINA_FALSE;
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
|
|
||||||
|
@ -795,33 +748,20 @@ read_psd_cmyk(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ie->w = head->width;
|
if (!psd_get_data(head, map, length, position, pixels, compressed, error))
|
||||||
ie->h = head->height;
|
|
||||||
if (head->channels == 3) ie->flags.alpha = 0;
|
|
||||||
else ie->flags.alpha = 1;
|
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
|
||||||
surface = evas_cache_image_pixels(ie);
|
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto cleanup_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
|
|
||||||
goto cleanup_error;
|
goto cleanup_error;
|
||||||
|
|
||||||
size = type * ie->w * ie->h;
|
size = type * prop->w * prop->h;
|
||||||
kchannel = malloc(size);
|
kchannel = malloc(size);
|
||||||
if (kchannel == NULL)
|
if (kchannel == NULL)
|
||||||
goto cleanup_error;
|
goto cleanup_error;
|
||||||
if (!get_single_channel(ie, head, map, length, position, kchannel, compressed))
|
if (!get_single_channel(head, map, length, position, kchannel, compressed))
|
||||||
goto cleanup_error;
|
goto cleanup_error;
|
||||||
|
|
||||||
data_size = head->channels * type * ie->w * ie->h;
|
data_size = head->channels * type * prop->w * prop->h;
|
||||||
if (format == 0x1907)
|
if (format == 0x1907)
|
||||||
{
|
{
|
||||||
unsigned char *tmp = surface;
|
unsigned char *tmp = pixels;
|
||||||
const unsigned char *limit = tmp + data_size;
|
const unsigned char *limit = tmp + data_size;
|
||||||
|
|
||||||
for (j = 0; tmp < limit; tmp++, j++)
|
for (j = 0; tmp < limit; tmp++, j++)
|
||||||
|
@ -836,7 +776,7 @@ read_psd_cmyk(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // RGBA
|
{ // RGBA
|
||||||
unsigned char *tmp = surface;
|
unsigned char *tmp = pixels;
|
||||||
const unsigned char *limit = tmp + data_size;
|
const unsigned char *limit = tmp + data_size;
|
||||||
|
|
||||||
// The KChannel array really holds the alpha channel on this one.
|
// The KChannel array really holds the alpha channel on this one.
|
||||||
|
@ -849,80 +789,67 @@ read_psd_cmyk(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(kchannel);
|
r = EINA_TRUE;
|
||||||
|
|
||||||
evas_common_image_premul(ie);
|
|
||||||
return EINA_TRUE;
|
|
||||||
|
|
||||||
cleanup_error:
|
cleanup_error:
|
||||||
free(kchannel);
|
free(kchannel);
|
||||||
return EINA_FALSE;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_psd(Image_Entry *ie,
|
evas_image_load_file_data_psd(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
const char *file,
|
Evas_Image_Property *prop,
|
||||||
const char *key EINA_UNUSED,
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
int *error)
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
void *map;
|
void *map;
|
||||||
size_t length;
|
size_t length;
|
||||||
size_t position;
|
size_t position;
|
||||||
PSD_Header header;
|
PSD_Header header;
|
||||||
Eina_Bool bpsd = EINA_FALSE;
|
Eina_Bool bpsd = EINA_FALSE;
|
||||||
|
|
||||||
f = eina_file_open(file, 0);
|
|
||||||
if (f == NULL)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return bpsd;
|
|
||||||
}
|
|
||||||
|
|
||||||
map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
length = eina_file_size_get(f);
|
length = eina_file_size_get(f);
|
||||||
position = 0;
|
position = 0;
|
||||||
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
if (!map || length < 1)
|
if (!map || length < 1)
|
||||||
{
|
goto on_error;
|
||||||
eina_file_close(f);
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
if (!psd_get_header(&header, map, length, &position) || !is_psd(&header))
|
if (!psd_get_header(&header, map, length, &position) || !is_psd(&header))
|
||||||
{
|
goto on_error;
|
||||||
eina_file_map_free(f, map);
|
|
||||||
eina_file_close(f);
|
|
||||||
*error = EVAS_LOAD_ERROR_GENERIC;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ie->w = header.width;
|
if (header.width != prop->w ||
|
||||||
ie->h = header.height;
|
header.height != prop->h)
|
||||||
|
goto on_error;
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
|
|
||||||
switch (header.mode)
|
switch (header.mode)
|
||||||
{
|
{
|
||||||
case PSD_GREYSCALE: // Greyscale
|
case PSD_GREYSCALE: // Greyscale
|
||||||
bpsd = read_psd_grey(ie, &header, map, length, &position, error);
|
bpsd = read_psd_grey(pixels, &header, map, length, &position, error);
|
||||||
break;
|
break;
|
||||||
case PSD_INDEXED: // Indexed
|
case PSD_INDEXED: // Indexed
|
||||||
bpsd = read_psd_indexed(ie, &header, map, length, &position, error);
|
bpsd = read_psd_indexed(pixels, &header, map, length, &position, error);
|
||||||
break;
|
break;
|
||||||
case PSD_RGB: // RGB
|
case PSD_RGB: // RGB
|
||||||
bpsd = read_psd_rgb(ie, &header, map, length, &position, error);
|
bpsd = read_psd_rgb(pixels, &header, map, length, &position, error);
|
||||||
|
prop->premul = EINA_TRUE;
|
||||||
break;
|
break;
|
||||||
case PSD_CMYK: // CMYK
|
case PSD_CMYK: // CMYK
|
||||||
bpsd = read_psd_cmyk(ie, &header, map, length, &position, error);
|
bpsd = read_psd_cmyk(prop, pixels, &header, map, length, &position, error);
|
||||||
|
prop->premul = EINA_TRUE;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
bpsd = EINA_FALSE;
|
bpsd = EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
eina_file_map_free(f, map);
|
on_error:
|
||||||
eina_file_close(f);
|
if (map) eina_file_map_free(f, map);
|
||||||
|
|
||||||
return bpsd;
|
return bpsd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,18 +56,6 @@ struct _tga_footer
|
||||||
char null;
|
char null;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_tga(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
static Eina_Bool evas_image_load_file_data_tga(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_tga_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_tga,
|
|
||||||
evas_image_load_file_data_tga,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_head_tga(Eina_File *f, const char *key EINA_UNUSED,
|
evas_image_load_file_head_tga(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
Evas_Image_Property *prop,
|
Evas_Image_Property *prop,
|
||||||
|
@ -165,9 +153,13 @@ close_file:
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_tga(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_tga(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
unsigned char *seg = NULL, *filedata;
|
unsigned char *seg = NULL, *filedata;
|
||||||
tga_header *header;
|
tga_header *header;
|
||||||
tga_footer *footer, tfooter;
|
tga_footer *footer, tfooter;
|
||||||
|
@ -178,10 +170,7 @@ evas_image_load_file_data_tga(Image_Entry *ie, const char *file, const char *key
|
||||||
unsigned int datasize;
|
unsigned int datasize;
|
||||||
unsigned char *bufptr, *bufend;
|
unsigned char *bufptr, *bufend;
|
||||||
int abits;
|
int abits;
|
||||||
|
Eina_Bool res = EINA_FALSE;
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
if (f == NULL) return EINA_FALSE;
|
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
||||||
if (eina_file_size_get(f) < (off_t)(sizeof(tga_header) + sizeof(tga_footer)))
|
if (eina_file_size_get(f) < (off_t)(sizeof(tga_header) + sizeof(tga_footer)))
|
||||||
|
@ -253,24 +242,17 @@ evas_image_load_file_data_tga(Image_Entry *ie, const char *file, const char *key
|
||||||
IMG_TOO_BIG(w, h))
|
IMG_TOO_BIG(w, h))
|
||||||
goto close_file;
|
goto close_file;
|
||||||
|
|
||||||
if ((w != (int)ie->w) || (h != (int)ie->h))
|
if ((w != (int)prop->w) || (h != (int)prop->h))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_GENERIC;
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
goto close_file;
|
goto close_file;
|
||||||
}
|
}
|
||||||
evas_cache_image_surface_alloc(ie, w, h);
|
surface = pixels;
|
||||||
surface = evas_cache_image_pixels(ie);
|
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto close_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
datasize = size - sizeof(tga_header) - header->idLength;
|
datasize = size - sizeof(tga_header) - header->idLength;
|
||||||
if (footer_present)
|
if (footer_present)
|
||||||
datasize = size - sizeof(tga_header) - header->idLength -
|
datasize -= sizeof(tga_footer);
|
||||||
sizeof(tga_footer);
|
|
||||||
|
|
||||||
bufptr = filedata + header->idLength;
|
bufptr = filedata + header->idLength;
|
||||||
bufend = filedata + datasize;
|
bufend = filedata + datasize;
|
||||||
|
|
||||||
|
@ -544,20 +526,26 @@ evas_image_load_file_data_tga(Image_Entry *ie, const char *file, const char *key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evas_common_image_premul(ie);
|
|
||||||
|
|
||||||
eina_file_map_free(f, seg);
|
prop->premul = EINA_TRUE;
|
||||||
eina_file_close(f);
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
return EINA_TRUE;
|
res = EINA_TRUE;
|
||||||
|
|
||||||
close_file:
|
close_file:
|
||||||
if (seg != NULL) eina_file_map_free(f, seg);
|
if (seg != NULL) eina_file_map_free(f, seg);
|
||||||
eina_file_close(f);
|
return res;
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_tga_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_tga,
|
||||||
|
evas_image_load_file_data_tga,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,23 +26,10 @@ static int _evas_loader_tiff_log_dom = -1;
|
||||||
#endif
|
#endif
|
||||||
#define INF(...) EINA_LOG_DOM_INFO(_evas_loader_tiff_log_dom, __VA_ARGS__)
|
#define INF(...) EINA_LOG_DOM_INFO(_evas_loader_tiff_log_dom, __VA_ARGS__)
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_tiff(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
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);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_tiff_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_tiff,
|
|
||||||
evas_image_load_file_data_tiff,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
|
typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
|
||||||
|
|
||||||
struct TIFFRGBAImage_Extra {
|
struct TIFFRGBAImage_Extra {
|
||||||
TIFFRGBAImage rgba;
|
TIFFRGBAImage rgba;
|
||||||
Image_Entry *image;
|
|
||||||
char pper;
|
char pper;
|
||||||
uint32 num_pixels;
|
uint32 num_pixels;
|
||||||
uint32 py;
|
uint32 py;
|
||||||
|
@ -178,12 +165,16 @@ evas_image_load_file_head_tiff(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_tiff(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
char txt[1024];
|
char txt[1024];
|
||||||
TIFFRGBAImage_Extra rgba_image;
|
TIFFRGBAImage_Extra rgba_image;
|
||||||
TIFF *tif = NULL;
|
TIFF *tif = NULL;
|
||||||
Eina_File *f;
|
|
||||||
unsigned char *map;
|
unsigned char *map;
|
||||||
uint32 *rast = NULL;
|
uint32 *rast = NULL;
|
||||||
uint32 num_pixels;
|
uint32 num_pixels;
|
||||||
|
@ -191,13 +182,6 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
|
||||||
uint16 magic_number;
|
uint16 magic_number;
|
||||||
Eina_Bool res = EINA_FALSE;
|
Eina_Bool res = EINA_FALSE;
|
||||||
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
if (!map || eina_file_size_get(f) < 3)
|
if (!map || eina_file_size_get(f) < 3)
|
||||||
{
|
{
|
||||||
|
@ -237,25 +221,17 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
rgba_image.image = ie;
|
|
||||||
|
|
||||||
if (rgba_image.rgba.alpha != EXTRASAMPLE_UNSPECIFIED)
|
if (rgba_image.rgba.alpha != EXTRASAMPLE_UNSPECIFIED)
|
||||||
ie->flags.alpha = 1;
|
prop->alpha = 1;
|
||||||
if ((rgba_image.rgba.width != ie->w) ||
|
if ((rgba_image.rgba.width != prop->w) ||
|
||||||
(rgba_image.rgba.height != ie->h))
|
(rgba_image.rgba.height != prop->h))
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
goto on_error_end;
|
goto on_error_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height);
|
rgba_image.num_pixels = num_pixels = prop->w * prop->h;
|
||||||
if (!evas_cache_image_pixels(ie))
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto on_error_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
rgba_image.num_pixels = num_pixels = ie->w * ie->h;
|
|
||||||
|
|
||||||
rgba_image.pper = rgba_image.py = 0;
|
rgba_image.pper = rgba_image.py = 0;
|
||||||
rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels);
|
rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels);
|
||||||
|
@ -282,23 +258,24 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
|
||||||
INF("channel bits == %i", (int)rgba_image.rgba.samplesperpixel);
|
INF("channel bits == %i", (int)rgba_image.rgba.samplesperpixel);
|
||||||
}
|
}
|
||||||
/* process rast -> image rgba. really same as prior code anyway just simpler */
|
/* process rast -> image rgba. really same as prior code anyway just simpler */
|
||||||
for (y = 0; y < (int)ie->h; y++)
|
for (y = 0; y < (int)prop->h; y++)
|
||||||
{
|
{
|
||||||
DATA32 *pix, *pd;
|
DATA32 *pix, *pd;
|
||||||
uint32 *ps, pixel;
|
uint32 *ps, pixel;
|
||||||
unsigned int a, r, g, b;
|
unsigned int a, r, g, b;
|
||||||
|
unsigned int nas = 0;
|
||||||
|
|
||||||
pix = evas_cache_image_pixels(ie);
|
pix = pixels;
|
||||||
pd = pix + ((ie->h - y - 1) * ie->w);
|
pd = pix + ((prop->h - y - 1) * prop->w);
|
||||||
ps = rast + (y * ie->w);
|
ps = rast + (y * prop->w);
|
||||||
for (x = 0; x < (int)ie->w; x++)
|
for (x = 0; x < (int)prop->w; x++)
|
||||||
{
|
{
|
||||||
pixel = *ps;
|
pixel = *ps;
|
||||||
a = TIFFGetA(pixel);
|
a = TIFFGetA(pixel);
|
||||||
r = TIFFGetR(pixel);
|
r = TIFFGetR(pixel);
|
||||||
g = TIFFGetG(pixel);
|
g = TIFFGetG(pixel);
|
||||||
b = TIFFGetB(pixel);
|
b = TIFFGetB(pixel);
|
||||||
if (!ie->flags.alpha) a = 255;
|
if (!prop->alpha) a = 255;
|
||||||
if ((rgba_image.rgba.alpha == EXTRASAMPLE_UNASSALPHA) &&
|
if ((rgba_image.rgba.alpha == EXTRASAMPLE_UNASSALPHA) &&
|
||||||
(a < 255))
|
(a < 255))
|
||||||
{
|
{
|
||||||
|
@ -307,14 +284,18 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
|
||||||
b = (b * (a + 1)) >> 8;
|
b = (b * (a + 1)) >> 8;
|
||||||
}
|
}
|
||||||
*pd = ARGB_JOIN(a, r, g, b);
|
*pd = ARGB_JOIN(a, r, g, b);
|
||||||
|
|
||||||
|
if (a == 0xff) nas++;
|
||||||
ps++;
|
ps++;
|
||||||
pd++;
|
pd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (prop->w * prop->h))
|
||||||
|
prop->alpha_sparse = EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_TIFFfree(rast);
|
_TIFFfree(rast);
|
||||||
|
|
||||||
evas_common_image_set_alpha_sparse(ie);
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
res = EINA_TRUE;
|
res = EINA_TRUE;
|
||||||
|
|
||||||
|
@ -323,10 +304,18 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
|
||||||
on_error:
|
on_error:
|
||||||
if (tif) TIFFClose(tif);
|
if (tif) TIFFClose(tif);
|
||||||
if (map) eina_file_map_free(f, map);
|
if (map) eina_file_map_free(f, map);
|
||||||
eina_file_close(f);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_tiff_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_tiff,
|
||||||
|
evas_image_load_file_data_tiff,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,19 +11,6 @@
|
||||||
#include "evas_common.h"
|
#include "evas_common.h"
|
||||||
#include "evas_private.h"
|
#include "evas_private.h"
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_wbmp(Eina_File *f, const char *key, Evas_Image_Property *prop, Evas_Image_Load_Opts *opts, Evas_Image_Animated *animated, int *error);
|
|
||||||
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);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_wbmp_func =
|
|
||||||
{
|
|
||||||
EINA_TRUE,
|
|
||||||
evas_image_load_file_head_wbmp,
|
|
||||||
evas_image_load_file_data_wbmp,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
read_mb(unsigned int *data, void *map, size_t length, size_t *position)
|
read_mb(unsigned int *data, void *map, size_t length, size_t *position)
|
||||||
{
|
{
|
||||||
|
@ -92,9 +79,13 @@ evas_image_load_file_head_wbmp(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_wbmp(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
void *map = NULL;
|
void *map = NULL;
|
||||||
size_t position = 0;
|
size_t position = 0;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
@ -103,15 +94,9 @@ evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *ke
|
||||||
unsigned char *line = NULL;
|
unsigned char *line = NULL;
|
||||||
int cur = 0, x, y;
|
int cur = 0, x, y;
|
||||||
DATA32 *dst_data;
|
DATA32 *dst_data;
|
||||||
|
Eina_Bool r = EINA_FALSE;
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_GENERIC;
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
length = eina_file_size_get(f);
|
length = eina_file_size_get(f);
|
||||||
if (length <= 4) goto bail;
|
if (length <= 4) goto bail;
|
||||||
|
|
||||||
|
@ -136,25 +121,22 @@ evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *ke
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ie->w = w;
|
if (prop->w != w || prop->h != h)
|
||||||
ie->h = h;
|
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
|
||||||
dst_data = evas_cache_image_pixels(ie);
|
|
||||||
if (!dst_data)
|
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
line_length = (ie->w + 7) >> 3;
|
dst_data = pixels;
|
||||||
|
|
||||||
for (y = 0; y < (int)ie->h; y++)
|
line_length = (prop->w + 7) >> 3;
|
||||||
|
|
||||||
|
for (y = 0; y < (int)prop->h; y++)
|
||||||
{
|
{
|
||||||
if (position + line_length > length) goto bail;
|
if (position + line_length > length) goto bail;
|
||||||
line = ((unsigned char*) map) + position;
|
line = ((unsigned char*) map) + position;
|
||||||
position += line_length;
|
position += line_length;
|
||||||
for (x = 0; x < (int)ie->w; x++)
|
for (x = 0; x < (int)prop->w; x++)
|
||||||
{
|
{
|
||||||
int idx = x >> 3;
|
int idx = x >> 3;
|
||||||
int offset = 1 << (0x07 - (x & 0x07));
|
int offset = 1 << (0x07 - (x & 0x07));
|
||||||
|
@ -163,16 +145,24 @@ evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *ke
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eina_file_map_free(f, map);
|
|
||||||
eina_file_close(f);
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
return EINA_TRUE;
|
r = EINA_TRUE;
|
||||||
bail:
|
|
||||||
|
bail:
|
||||||
if (map) eina_file_map_free(f, map);
|
if (map) eina_file_map_free(f, map);
|
||||||
eina_file_close(f);
|
return r;
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_wbmp_func =
|
||||||
|
{
|
||||||
|
EINA_TRUE,
|
||||||
|
evas_image_load_file_head_wbmp,
|
||||||
|
evas_image_load_file_data_wbmp,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,37 +63,21 @@ evas_image_load_file_head_webp(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_webp(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int *error)
|
evas_image_load_file_data_webp(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
Eina_File *f;
|
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
void *decoded = NULL;
|
void *decoded = NULL;
|
||||||
void *surface = NULL;
|
void *surface = NULL;
|
||||||
int width, height;
|
int width, height;
|
||||||
Eina_Bool alpha;
|
|
||||||
|
|
||||||
// XXX: use eina_file to mmap things
|
|
||||||
f = eina_file_open(file, EINA_FALSE);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
|
|
||||||
if (!evas_image_load_file_check(f, data, &ie->w, &ie->h, &alpha, error))
|
surface = pixels;
|
||||||
goto free_data;
|
|
||||||
|
|
||||||
ie->flags.alpha = alpha;
|
|
||||||
|
|
||||||
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
|
||||||
surface = evas_cache_image_pixels(ie);
|
|
||||||
if (!surface)
|
|
||||||
{
|
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
||||||
goto free_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
decoded = WebPDecodeBGRA(data, eina_file_size_get(f), &width, &height);
|
decoded = WebPDecodeBGRA(data, eina_file_size_get(f), &width, &height);
|
||||||
if (!decoded)
|
if (!decoded)
|
||||||
|
@ -103,13 +87,16 @@ evas_image_load_file_data_webp(Image_Entry *ie, const char *file, const char *ke
|
||||||
}
|
}
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
|
|
||||||
|
if ((int) prop->w != width ||
|
||||||
|
(int) prop->h != height)
|
||||||
|
goto free_data;
|
||||||
|
|
||||||
// XXX: this copy of the surface is inefficient
|
// XXX: this copy of the surface is inefficient
|
||||||
memcpy(surface, decoded, width * height * 4);
|
memcpy(surface, decoded, width * height * 4);
|
||||||
evas_common_image_premul(ie);
|
prop->premul = EINA_TRUE;
|
||||||
|
|
||||||
free_data:
|
free_data:
|
||||||
if (data) eina_file_map_free(f, data);
|
if (data) eina_file_map_free(f, data);
|
||||||
eina_file_close(f);
|
|
||||||
free(decoded);
|
free(decoded);
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
|
@ -16,18 +16,6 @@ static int _evas_loader_xpm_log_dom = -1;
|
||||||
#endif
|
#endif
|
||||||
#define ERR(...) EINA_LOG_DOM_ERR(_evas_loader_xpm_log_dom, __VA_ARGS__)
|
#define ERR(...) EINA_LOG_DOM_ERR(_evas_loader_xpm_log_dom, __VA_ARGS__)
|
||||||
|
|
||||||
static Eina_Bool evas_image_load_file_head_xpm(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
static Eina_Bool evas_image_load_file_data_xpm(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
||||||
|
|
||||||
static Evas_Image_Load_Func evas_image_load_xpm_func =
|
|
||||||
{
|
|
||||||
EINA_FALSE,
|
|
||||||
evas_image_load_file_head_xpm,
|
|
||||||
evas_image_load_file_data_xpm,
|
|
||||||
NULL,
|
|
||||||
EINA_FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
static Eina_File *rgb_txt;
|
static Eina_File *rgb_txt;
|
||||||
static void *rgb_txt_map;
|
static void *rgb_txt_map;
|
||||||
|
|
||||||
|
@ -149,10 +137,9 @@ _cmap_cmp_key_cb(const Eina_Rbtree *node, const void *key, int length EINA_UNUSE
|
||||||
|
|
||||||
/** FIXME: clean this up and make more efficient **/
|
/** FIXME: clean this up and make more efficient **/
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA_UNUSED, int load_data, int *error)
|
evas_image_load_file_xpm(Eina_File *f, Evas_Image_Property *prop, void *pixels, int load_data, int *error)
|
||||||
{
|
{
|
||||||
DATA32 *ptr, *end, *head = NULL;
|
DATA32 *ptr, *end, *head = NULL;
|
||||||
Eina_File *f;
|
|
||||||
const char *map;
|
const char *map;
|
||||||
size_t length;
|
size_t length;
|
||||||
size_t position;
|
size_t position;
|
||||||
|
@ -166,7 +153,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA
|
||||||
Eina_Rbtree *root = NULL;
|
Eina_Rbtree *root = NULL;
|
||||||
|
|
||||||
short lookup[128 - 32][128 - 32];
|
short lookup[128 - 32][128 - 32];
|
||||||
int count, pixels;
|
int count, size;
|
||||||
|
Eina_Bool res = EINA_FALSE;
|
||||||
|
|
||||||
done = 0;
|
done = 0;
|
||||||
// transp = -1;
|
// transp = -1;
|
||||||
|
@ -175,33 +163,20 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA
|
||||||
/* if immediate_load is 1, then dont delay image laoding as below, or */
|
/* if immediate_load is 1, then dont delay image laoding as below, or */
|
||||||
/* already data in this image - dont load it again */
|
/* already data in this image - dont load it again */
|
||||||
|
|
||||||
f = eina_file_open(file, 0);
|
|
||||||
if (!f)
|
|
||||||
{
|
|
||||||
if (load_data)
|
|
||||||
ERR("XPM ERROR: file failed to open");
|
|
||||||
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
length = eina_file_size_get(f);
|
length = eina_file_size_get(f);
|
||||||
position = 0;
|
position = 0;
|
||||||
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
||||||
if (length < 9)
|
if (length < 9)
|
||||||
{
|
{
|
||||||
if (load_data)
|
ERR("XPM ERROR: file size, %zd, is to small", length);
|
||||||
ERR("XPM ERROR: file size, %zd, is to small", length);
|
goto on_error;
|
||||||
eina_file_close(f);
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
if (load_data)
|
ERR("XPM ERROR: file failed to mmap");
|
||||||
ERR("XPM ERROR: file failed to mmap");
|
goto on_error;
|
||||||
eina_file_close(f);
|
|
||||||
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp("/* XPM */", map, 9))
|
if (strncmp("/* XPM */", map, 9))
|
||||||
|
@ -221,7 +196,7 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA
|
||||||
comment = 0;
|
comment = 0;
|
||||||
quote = 0;
|
quote = 0;
|
||||||
context = 0;
|
context = 0;
|
||||||
pixels = 0;
|
size = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
line = malloc(lsz);
|
line = malloc(lsz);
|
||||||
if (!line)
|
if (!line)
|
||||||
|
@ -304,8 +279,19 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ie->w = w;
|
|
||||||
ie->h = h;
|
if (!load_data)
|
||||||
|
{
|
||||||
|
prop->w = w;
|
||||||
|
prop->h = h;
|
||||||
|
}
|
||||||
|
else if ((int) prop->w != w ||
|
||||||
|
(int) prop->h != h)
|
||||||
|
{
|
||||||
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
|
goto on_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
context++;
|
context++;
|
||||||
|
@ -418,20 +404,19 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA
|
||||||
context++;
|
context++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transp) ie->flags.alpha = 1;
|
if (transp) prop->alpha = 1;
|
||||||
|
|
||||||
if (load_data)
|
if (load_data)
|
||||||
{
|
{
|
||||||
evas_cache_image_surface_alloc(ie, w, h);
|
ptr = pixels;
|
||||||
ptr = evas_cache_image_pixels(ie);
|
|
||||||
head = ptr;
|
head = ptr;
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
{
|
{
|
||||||
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
pixels = w * h;
|
size = w * h;
|
||||||
end = ptr + pixels;
|
end = ptr + size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -648,39 +633,51 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key EINA
|
||||||
line = tl;
|
line = tl;
|
||||||
}
|
}
|
||||||
if (((ptr) && ((ptr - head) >= (w * h * (int)sizeof(DATA32)))) ||
|
if (((ptr) && ((ptr - head) >= (w * h * (int)sizeof(DATA32)))) ||
|
||||||
((context > 1) && (count >= pixels)))
|
((context > 1) && (count >= size)))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
on_success:
|
on_success:
|
||||||
free(cmap);
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
eina_file_map_free(f, (void*) map);
|
|
||||||
eina_file_close(f);
|
|
||||||
|
|
||||||
*error = EVAS_LOAD_ERROR_NONE;
|
*error = EVAS_LOAD_ERROR_NONE;
|
||||||
return EINA_TRUE;
|
res = EINA_TRUE;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
|
if (map) eina_file_map_free(f, (void*) map);
|
||||||
|
free(cmap);
|
||||||
free(line);
|
free(line);
|
||||||
eina_file_map_free(f, (void*) map);
|
return res;
|
||||||
eina_file_close(f);
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_head_xpm(Image_Entry *ie, const char *file, const char *key, int *error)
|
evas_image_load_file_head_xpm(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
return evas_image_load_file_xpm(ie, file, key, 0, error);
|
return evas_image_load_file_xpm(f, prop, NULL, 0, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
evas_image_load_file_data_xpm(Image_Entry *ie, const char *file, const char *key, int *error)
|
evas_image_load_file_data_xpm(Eina_File *f, const char *key EINA_UNUSED,
|
||||||
|
Evas_Image_Property *prop,
|
||||||
|
Evas_Image_Load_Opts *opts EINA_UNUSED,
|
||||||
|
Evas_Image_Animated *animated EINA_UNUSED,
|
||||||
|
void *pixels,
|
||||||
|
int *error)
|
||||||
{
|
{
|
||||||
return evas_image_load_file_xpm(ie, file, key, 1, error);
|
return evas_image_load_file_xpm(f, prop, pixels, 1, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Evas_Image_Load_Func evas_image_load_xpm_func =
|
||||||
|
{
|
||||||
|
EINA_FALSE,
|
||||||
|
evas_image_load_file_head_xpm,
|
||||||
|
evas_image_load_file_data_xpm,
|
||||||
|
NULL,
|
||||||
|
EINA_FALSE
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_open(Evas_Module *em)
|
module_open(Evas_Module *em)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue