2012-01-04 03:45:22 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2011-05-06 02:36:24 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-06-20 03:53:29 -07:00
|
|
|
#include "evas_common_private.h"
|
2002-11-08 00:02:15 -08:00
|
|
|
#include "evas_private.h"
|
2012-10-11 23:36:06 -07:00
|
|
|
//#include "evas_cs.h"
|
2002-11-08 00:02:15 -08:00
|
|
|
|
2010-05-30 06:04:34 -07:00
|
|
|
struct ext_loader_s
|
|
|
|
{
|
2011-06-01 07:32:08 -07:00
|
|
|
unsigned int length;
|
2010-09-07 20:51:24 -07:00
|
|
|
const char *extension;
|
2010-05-30 06:04:34 -07:00
|
|
|
const char *loader;
|
2007-07-16 00:25:35 -07:00
|
|
|
};
|
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
#define MATCHING(Ext, Module) \
|
2017-01-01 05:15:24 -08:00
|
|
|
{ sizeof (Ext), Ext, Module }
|
2011-06-01 07:32:08 -07:00
|
|
|
|
2010-05-30 06:04:34 -07:00
|
|
|
static const struct ext_loader_s loaders[] =
|
2011-04-25 18:03:06 -07:00
|
|
|
{ /* map extensions to loaders to use for good first-guess tries */
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".png", "png"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".jpg", "jpeg"),
|
|
|
|
MATCHING(".jpeg", "jpeg"),
|
|
|
|
MATCHING(".jfif", "jpeg"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2013-09-28 05:28:41 -07:00
|
|
|
MATCHING(".j2k", "jp2k"),
|
|
|
|
MATCHING(".jp2", "jp2k"),
|
|
|
|
MATCHING(".jpx", "jp2k"),
|
|
|
|
MATCHING(".jpf", "jp2k"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".eet", "eet"),
|
|
|
|
MATCHING(".edj", "eet"),
|
|
|
|
MATCHING(".eap", "eet"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".xpm", "xpm"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".tiff", "tiff"),
|
|
|
|
MATCHING(".tif", "tiff"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".gif", "gif"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".pbm", "pmaps"),
|
|
|
|
MATCHING(".pgm", "pmaps"),
|
|
|
|
MATCHING(".ppm", "pmaps"),
|
|
|
|
MATCHING(".pnm", "pmaps"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".bmp", "bmp"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".tga", "tga"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".wbmp", "wbmp"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2012-09-02 23:22:59 -07:00
|
|
|
MATCHING(".webp", "webp"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".ico", "ico"),
|
|
|
|
MATCHING(".cur", "ico"),
|
2020-06-20 02:52:54 -07:00
|
|
|
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".psd", "psd"),
|
2014-03-11 03:08:40 -07:00
|
|
|
|
|
|
|
MATCHING(".tgv", "tgv"),
|
|
|
|
|
2014-10-21 07:47:05 -07:00
|
|
|
MATCHING(".dds", "dds"),
|
|
|
|
|
Evas: add avif evas loader and saver
Summary:
Add AV1 image file loader and saver to Evas
The loader can be tested with this code :
```
#include <stdlib.h>
#include <stdio.h>
#include <Eina.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
static int i = 0;
static unsigned char _timer(void *data)
{
Evas_Object *o = (Evas_Object *)data;
if (i < evas_object_image_animated_frame_count_get(o))
{
evas_object_image_animated_frame_set(o, i);
i++;
return ECORE_CALLBACK_RENEW;
}
return ECORE_CALLBACK_DONE;
}
static void _quit(Ecore_Evas *ee)
{
ecore_main_loop_quit();
(void)ee;
}
int main(int argc, char *argv[])
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
int w,h;
Evas_Load_Error err;
if (argc < 2)
{
printf("usage : %s file\n", argv[0]);
return 1;
}
ecore_evas_init();
ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
if (!ee)
{
printf("no ee\n");
return 0;
}
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, "avif test");
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_file_set(o, argv[1], NULL);
err = evas_object_image_load_error_get(o);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
argv[1], evas_load_error_str(err));
return 1;
}
evas_object_image_size_get(o, &w, &h);
evas_object_image_fill_set(o, 0, 0, w, h);
evas_object_move(o, 0, 0);
evas_object_resize(o, w, h);
evas_object_show(o);
printf("animated : %s\n", evas_object_image_animated_get(o) ? "yes" : "no");
fflush(stdout);
if (evas_object_image_animated_get(o))
{
Ecore_Timer *timer;
printf("frame count : %d\n", evas_object_image_animated_frame_count_get(o));
printf("duration : %f\n", evas_object_image_animated_frame_duration_get(o,1,0));
printf("loop count : %d\n", evas_object_image_animated_loop_count_get(o));
fflush(stdout);
timer = ecore_timer_add(evas_object_image_animated_frame_duration_get(o,1,0), _timer, o);
}
ecore_evas_resize(ee, w, h);
ecore_evas_show(ee);
ecore_main_loop_begin();
ecore_evas_shutdown();
return 0;
}
```
non animated files : https://github.com/AOMediaCodec/libavif/tree/master/tests/data/originals
animated files : https://github.com/AOMediaCodec/av1-avif/tree/master/testFiles/Netflix/avifs
to test the saver :
```
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <Eina.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
void _quit(Ecore_Evas *ee)
{
ecore_main_loop_quit();
(void)ee;
}
static Evas_Object *
display_data(int w, int h, const char *title, unsigned int *data)
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
unsigned int *d;
ee = ecore_evas_new(NULL, 0, 0, w, h, NULL);
if (!ee)
return NULL;
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, title);
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_fill_set(o, 0, 0, w, h);
evas_object_image_size_set(o, w, h);
d = evas_object_image_data_get(o, 1);
for (int i = 0; i < w*h; i++)
d[i] = data[i];
evas_object_image_data_set(o, d);
evas_object_image_data_update_add(o, 0, 0, w, h);
evas_object_move(o, 0, 0);
evas_object_resize(o, w, h);
evas_object_show(o);
ecore_evas_show(ee);
return o;
}
static unsigned int *
display_file(const char *title, const char *filename, int *w, int *h)
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
Evas_Load_Error err;
unsigned int *data;
ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
if (!ee)
return NULL;
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, title);
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_file_set(o, filename, NULL);
err = evas_object_image_load_error_get(o);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
filename, evas_load_error_str(err));
fflush(stderr);
return NULL;
}
evas_object_image_size_get(o, w, h);
evas_object_image_fill_set(o, 0, 0, *w, *h);
evas_object_image_size_set(o, *w, *h);
evas_object_move(o, 0, 0);
evas_object_resize(o, *w, *h);
evas_object_show(o);
ecore_evas_resize(ee, *w, *h);
ecore_evas_show(ee);
data = evas_object_image_data_get(o, 1);
return data;
}
double psnr(int w, int h, unsigned int *data_orig, unsigned int *data)
{
unsigned char *iter_orig;
unsigned char *iter;
double psnr;
psnr = 0.0;
iter_orig = (unsigned char *)data_orig;
iter = (unsigned char *)data;
for (int i = 0; i < 4 * w * h; i++, iter_orig++, iter++)
psnr += (*iter_orig - *iter) * (*iter_orig - *iter);
psnr /= 4 * w * h;
psnr = 10 * log10(255.0 * 255.0 / psnr);
return psnr;
}
void compare(int quality, int w, int h, unsigned int *data_orig)
{
char title[1024];
char filename[1024];
unsigned char *data;
unsigned int *data_jpeg;
unsigned int *data_avif;
unsigned char *iter_orig;
unsigned char *iter_jpeg;
unsigned char *iter_avif;
double psnr_jpeg;
double psnr_avif;
Eina_File *f_jpeg;
Eina_File *f_avif;
size_t size_jpeg;
size_t size_avif;
/* jpeg */
snprintf(title, sizeof(title), "jpeg test quality %d", quality);
snprintf(filename, sizeof(filename), "test_%d.jpg", quality);
data_jpeg = display_file(title, filename, &w, &h);
if (!data_jpeg)
return;
f_jpeg = eina_file_open(filename, EINA_FALSE);
size_jpeg = eina_file_size_get(f_jpeg);
eina_file_close(f_jpeg);
fprintf(stderr, "size : %u\n", (unsigned int)size_jpeg);
fflush(stderr);
/* avif */
snprintf(title, sizeof(title), "avif test quality %d", quality);
snprintf(filename, sizeof(filename), "test_%d.avif", quality);
data_avif = display_file(title, filename, &w, &h);
if (!data_avif)
return;
f_avif = eina_file_open(filename, EINA_FALSE);
size_avif = eina_file_size_get(f_avif);
eina_file_close(f_avif);
fprintf(stderr, "size : %u\n", (unsigned int)size_avif);
fflush(stderr);
psnr_jpeg = psnr(w, h, data_orig, data_jpeg);
fprintf(stderr, "psnr jpeg : %f\n", psnr_jpeg);
fflush(stderr);
snprintf(title, sizeof(title), "jpeg vs orig (psnr: %.2f, size: %u b)", psnr_jpeg, (unsigned int)size_jpeg);
iter_orig = (unsigned char *)data_orig;
iter_jpeg = (unsigned char *)data_jpeg;
data = malloc(4*w*h);
for (int i = 0; i < 4*w*h; i++, iter_orig++, iter_jpeg++)
data[i] = abs(*iter_jpeg - *iter_orig);
display_data(w, h, title, (unsigned int *)data);
psnr_avif = psnr(w, h, data_orig, data_avif);
fprintf(stderr, "psnr avif : %f\n", psnr_avif);
fflush(stderr);
snprintf(title, sizeof(title), "avif vs orig (psnr: %.2f, size: %u b)", psnr_avif, (unsigned int)size_avif);
iter_orig = (unsigned char *)data_orig;
iter_avif = (unsigned char *)data_avif;
data = malloc(4*w*h);
for (int i = 0; i < 4*w*h; i++, iter_orig++, iter_avif++)
data[i] = abs(*iter_avif - *iter_orig);
display_data(w, h, title, (unsigned int *)data);
}
int main()
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
Evas_Load_Error err;
unsigned int *data;
int w,h;
ecore_evas_init();
ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
if (!ee)
return 1;
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, "original");
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_file_set(o, "x1d-II-sample-02.fff", NULL);
err = evas_object_image_load_error_get(o);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
"x1d-II-sample-02.fff", evas_load_error_str(err));
fflush(stderr);
return 1;
}
evas_object_image_size_get(o, &w, &h);
evas_object_image_fill_set(o, 0, 0, w, h);
evas_object_image_size_set(o, w, h);
evas_object_move(o, 0, 0);
evas_object_resize(o, w, h);
evas_object_show(o);
data = evas_object_image_data_get(o, 1);
ecore_evas_resize(ee, w, h);
ecore_evas_show(ee);
/* evas_object_image_save(o, "test_100.jpg", NULL, "quality=100"); */
evas_object_image_save(o, "test_90.jpg", NULL, "quality=90");
/* evas_object_image_save(o, "test_70.jpg", NULL, "quality=70"); */
/* evas_object_image_save(o, "test_50.jpg", NULL, "quality=50"); */
/* evas_object_image_save(o, "test_100.avif", NULL, "quality=100"); */
evas_object_image_save(o, "test_90.avif", NULL, "quality=90");
/* evas_object_image_save(o, "test_70.avif", NULL, "quality=70"); */
/* evas_object_image_save(o, "test_50.avif", NULL, "quality=50"); */
compare(90, w, h, data);
ecore_main_loop_begin();
ecore_evas_shutdown();
return 0;
}
```
the raw file canbe found here : https://www.hasselblad.com/learn/sample-images/
Test Plan: test executable with avif files found in libavif project
Reviewers: raster, q66
Reviewed By: q66
Subscribers: q66, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12051
2020-07-15 10:51:27 -07:00
|
|
|
MATCHING(".avif", "avif"),
|
|
|
|
MATCHING(".avifs", "avif"),
|
|
|
|
|
2021-02-06 07:45:42 -08:00
|
|
|
MATCHING(".heif", "heif"),
|
|
|
|
MATCHING(".heic", "heif"),
|
|
|
|
// MATCHING(".avif", "heif"),
|
|
|
|
|
2013-11-23 18:48:40 -08:00
|
|
|
/* xcf - gefenric */
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".xcf", "generic"),
|
|
|
|
MATCHING(".xcf.gz", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
/* docs */
|
|
|
|
MATCHING(".doc", "generic"),
|
|
|
|
MATCHING(".docx", "generic"),
|
|
|
|
MATCHING(".odp", "generic"),
|
|
|
|
MATCHING(".ods", "generic"),
|
|
|
|
MATCHING(".odt", "generic"),
|
|
|
|
MATCHING(".pdf", "generic"),
|
|
|
|
MATCHING(".ps", "generic"),
|
|
|
|
MATCHING(".ppt", "generic"),
|
|
|
|
MATCHING(".pptx", "generic"),
|
|
|
|
MATCHING(".rtf", "generic"),
|
|
|
|
MATCHING(".xls", "generic"),
|
|
|
|
MATCHING(".xlsx", "generic"),
|
|
|
|
/* svg - generic */
|
|
|
|
MATCHING(".svg", "generic"),
|
|
|
|
MATCHING(".svgz", "generic"),
|
|
|
|
MATCHING(".svg.gz", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
/* RAW */
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".arw", "generic"),
|
|
|
|
MATCHING(".cr2", "generic"),
|
|
|
|
MATCHING(".crw", "generic"),
|
|
|
|
MATCHING(".dcr", "generic"),
|
|
|
|
MATCHING(".dng", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
MATCHING(".erf", "generic"),
|
Evas: add avif evas loader and saver
Summary:
Add AV1 image file loader and saver to Evas
The loader can be tested with this code :
```
#include <stdlib.h>
#include <stdio.h>
#include <Eina.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
static int i = 0;
static unsigned char _timer(void *data)
{
Evas_Object *o = (Evas_Object *)data;
if (i < evas_object_image_animated_frame_count_get(o))
{
evas_object_image_animated_frame_set(o, i);
i++;
return ECORE_CALLBACK_RENEW;
}
return ECORE_CALLBACK_DONE;
}
static void _quit(Ecore_Evas *ee)
{
ecore_main_loop_quit();
(void)ee;
}
int main(int argc, char *argv[])
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
int w,h;
Evas_Load_Error err;
if (argc < 2)
{
printf("usage : %s file\n", argv[0]);
return 1;
}
ecore_evas_init();
ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
if (!ee)
{
printf("no ee\n");
return 0;
}
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, "avif test");
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_file_set(o, argv[1], NULL);
err = evas_object_image_load_error_get(o);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
argv[1], evas_load_error_str(err));
return 1;
}
evas_object_image_size_get(o, &w, &h);
evas_object_image_fill_set(o, 0, 0, w, h);
evas_object_move(o, 0, 0);
evas_object_resize(o, w, h);
evas_object_show(o);
printf("animated : %s\n", evas_object_image_animated_get(o) ? "yes" : "no");
fflush(stdout);
if (evas_object_image_animated_get(o))
{
Ecore_Timer *timer;
printf("frame count : %d\n", evas_object_image_animated_frame_count_get(o));
printf("duration : %f\n", evas_object_image_animated_frame_duration_get(o,1,0));
printf("loop count : %d\n", evas_object_image_animated_loop_count_get(o));
fflush(stdout);
timer = ecore_timer_add(evas_object_image_animated_frame_duration_get(o,1,0), _timer, o);
}
ecore_evas_resize(ee, w, h);
ecore_evas_show(ee);
ecore_main_loop_begin();
ecore_evas_shutdown();
return 0;
}
```
non animated files : https://github.com/AOMediaCodec/libavif/tree/master/tests/data/originals
animated files : https://github.com/AOMediaCodec/av1-avif/tree/master/testFiles/Netflix/avifs
to test the saver :
```
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <Eina.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
void _quit(Ecore_Evas *ee)
{
ecore_main_loop_quit();
(void)ee;
}
static Evas_Object *
display_data(int w, int h, const char *title, unsigned int *data)
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
unsigned int *d;
ee = ecore_evas_new(NULL, 0, 0, w, h, NULL);
if (!ee)
return NULL;
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, title);
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_fill_set(o, 0, 0, w, h);
evas_object_image_size_set(o, w, h);
d = evas_object_image_data_get(o, 1);
for (int i = 0; i < w*h; i++)
d[i] = data[i];
evas_object_image_data_set(o, d);
evas_object_image_data_update_add(o, 0, 0, w, h);
evas_object_move(o, 0, 0);
evas_object_resize(o, w, h);
evas_object_show(o);
ecore_evas_show(ee);
return o;
}
static unsigned int *
display_file(const char *title, const char *filename, int *w, int *h)
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
Evas_Load_Error err;
unsigned int *data;
ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
if (!ee)
return NULL;
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, title);
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_file_set(o, filename, NULL);
err = evas_object_image_load_error_get(o);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
filename, evas_load_error_str(err));
fflush(stderr);
return NULL;
}
evas_object_image_size_get(o, w, h);
evas_object_image_fill_set(o, 0, 0, *w, *h);
evas_object_image_size_set(o, *w, *h);
evas_object_move(o, 0, 0);
evas_object_resize(o, *w, *h);
evas_object_show(o);
ecore_evas_resize(ee, *w, *h);
ecore_evas_show(ee);
data = evas_object_image_data_get(o, 1);
return data;
}
double psnr(int w, int h, unsigned int *data_orig, unsigned int *data)
{
unsigned char *iter_orig;
unsigned char *iter;
double psnr;
psnr = 0.0;
iter_orig = (unsigned char *)data_orig;
iter = (unsigned char *)data;
for (int i = 0; i < 4 * w * h; i++, iter_orig++, iter++)
psnr += (*iter_orig - *iter) * (*iter_orig - *iter);
psnr /= 4 * w * h;
psnr = 10 * log10(255.0 * 255.0 / psnr);
return psnr;
}
void compare(int quality, int w, int h, unsigned int *data_orig)
{
char title[1024];
char filename[1024];
unsigned char *data;
unsigned int *data_jpeg;
unsigned int *data_avif;
unsigned char *iter_orig;
unsigned char *iter_jpeg;
unsigned char *iter_avif;
double psnr_jpeg;
double psnr_avif;
Eina_File *f_jpeg;
Eina_File *f_avif;
size_t size_jpeg;
size_t size_avif;
/* jpeg */
snprintf(title, sizeof(title), "jpeg test quality %d", quality);
snprintf(filename, sizeof(filename), "test_%d.jpg", quality);
data_jpeg = display_file(title, filename, &w, &h);
if (!data_jpeg)
return;
f_jpeg = eina_file_open(filename, EINA_FALSE);
size_jpeg = eina_file_size_get(f_jpeg);
eina_file_close(f_jpeg);
fprintf(stderr, "size : %u\n", (unsigned int)size_jpeg);
fflush(stderr);
/* avif */
snprintf(title, sizeof(title), "avif test quality %d", quality);
snprintf(filename, sizeof(filename), "test_%d.avif", quality);
data_avif = display_file(title, filename, &w, &h);
if (!data_avif)
return;
f_avif = eina_file_open(filename, EINA_FALSE);
size_avif = eina_file_size_get(f_avif);
eina_file_close(f_avif);
fprintf(stderr, "size : %u\n", (unsigned int)size_avif);
fflush(stderr);
psnr_jpeg = psnr(w, h, data_orig, data_jpeg);
fprintf(stderr, "psnr jpeg : %f\n", psnr_jpeg);
fflush(stderr);
snprintf(title, sizeof(title), "jpeg vs orig (psnr: %.2f, size: %u b)", psnr_jpeg, (unsigned int)size_jpeg);
iter_orig = (unsigned char *)data_orig;
iter_jpeg = (unsigned char *)data_jpeg;
data = malloc(4*w*h);
for (int i = 0; i < 4*w*h; i++, iter_orig++, iter_jpeg++)
data[i] = abs(*iter_jpeg - *iter_orig);
display_data(w, h, title, (unsigned int *)data);
psnr_avif = psnr(w, h, data_orig, data_avif);
fprintf(stderr, "psnr avif : %f\n", psnr_avif);
fflush(stderr);
snprintf(title, sizeof(title), "avif vs orig (psnr: %.2f, size: %u b)", psnr_avif, (unsigned int)size_avif);
iter_orig = (unsigned char *)data_orig;
iter_avif = (unsigned char *)data_avif;
data = malloc(4*w*h);
for (int i = 0; i < 4*w*h; i++, iter_orig++, iter_avif++)
data[i] = abs(*iter_avif - *iter_orig);
display_data(w, h, title, (unsigned int *)data);
}
int main()
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *o;
Evas_Load_Error err;
unsigned int *data;
int w,h;
ecore_evas_init();
ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
if (!ee)
return 1;
evas = ecore_evas_get(ee);
ecore_evas_title_set(ee, "original");
ecore_evas_callback_delete_request_set(ee, _quit);
o = evas_object_image_add(evas);
evas_object_image_file_set(o, "x1d-II-sample-02.fff", NULL);
err = evas_object_image_load_error_get(o);
if (err != EVAS_LOAD_ERROR_NONE)
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
"x1d-II-sample-02.fff", evas_load_error_str(err));
fflush(stderr);
return 1;
}
evas_object_image_size_get(o, &w, &h);
evas_object_image_fill_set(o, 0, 0, w, h);
evas_object_image_size_set(o, w, h);
evas_object_move(o, 0, 0);
evas_object_resize(o, w, h);
evas_object_show(o);
data = evas_object_image_data_get(o, 1);
ecore_evas_resize(ee, w, h);
ecore_evas_show(ee);
/* evas_object_image_save(o, "test_100.jpg", NULL, "quality=100"); */
evas_object_image_save(o, "test_90.jpg", NULL, "quality=90");
/* evas_object_image_save(o, "test_70.jpg", NULL, "quality=70"); */
/* evas_object_image_save(o, "test_50.jpg", NULL, "quality=50"); */
/* evas_object_image_save(o, "test_100.avif", NULL, "quality=100"); */
evas_object_image_save(o, "test_90.avif", NULL, "quality=90");
/* evas_object_image_save(o, "test_70.avif", NULL, "quality=70"); */
/* evas_object_image_save(o, "test_50.avif", NULL, "quality=50"); */
compare(90, w, h, data);
ecore_main_loop_begin();
ecore_evas_shutdown();
return 0;
}
```
the raw file canbe found here : https://www.hasselblad.com/learn/sample-images/
Test Plan: test executable with avif files found in libavif project
Reviewers: raster, q66
Reviewed By: q66
Subscribers: q66, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12051
2020-07-15 10:51:27 -07:00
|
|
|
MATCHING(".fff", "generic"),
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".k25", "generic"),
|
|
|
|
MATCHING(".kdc", "generic"),
|
|
|
|
MATCHING(".mrw", "generic"),
|
|
|
|
MATCHING(".nef", "generic"),
|
|
|
|
MATCHING(".nrf", "generic"),
|
|
|
|
MATCHING(".nrw", "generic"),
|
|
|
|
MATCHING(".orf", "generic"),
|
|
|
|
MATCHING(".pef", "generic"),
|
|
|
|
MATCHING(".raf", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
MATCHING(".raw", "generic"),
|
|
|
|
MATCHING(".rw2", "generic"),
|
2011-06-01 07:32:08 -07:00
|
|
|
MATCHING(".sr2", "generic"),
|
|
|
|
MATCHING(".srf", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".x3f", "generic"),
|
|
|
|
/* video */
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".264", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".3g2", "generic"),
|
|
|
|
MATCHING(".3gp", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".3gp2", "generic"),
|
|
|
|
MATCHING(".3gpp", "generic"),
|
|
|
|
MATCHING(".3gpp2", "generic"),
|
|
|
|
MATCHING(".3p2", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".asf", "generic"),
|
|
|
|
MATCHING(".avi", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".bdm", "generic"),
|
|
|
|
MATCHING(".bdmv", "generic"),
|
|
|
|
MATCHING(".clpi", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
MATCHING(".cpi", "generic"),
|
|
|
|
MATCHING(".dv", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".fla", "generic"),
|
|
|
|
MATCHING(".flv", "generic"),
|
|
|
|
MATCHING(".m1v", "generic"),
|
|
|
|
MATCHING(".m2t", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
MATCHING(".m2v", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".m4v", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".mkv", "generic"),
|
|
|
|
MATCHING(".mov", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".mp2", "generic"),
|
|
|
|
MATCHING(".mp2ts", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".mp4", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".mpe", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".mpeg", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".mpg", "generic"),
|
|
|
|
MATCHING(".mpl", "generic"),
|
|
|
|
MATCHING(".mpls", "generic"),
|
|
|
|
MATCHING(".mts", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".mxf", "generic"),
|
|
|
|
MATCHING(".nut", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".nuv", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".ogg", "generic"),
|
|
|
|
MATCHING(".ogm", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".ogv", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
MATCHING(".qt", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".rm", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".rmj", "generic"),
|
|
|
|
MATCHING(".rmm", "generic"),
|
|
|
|
MATCHING(".rms", "generic"),
|
|
|
|
MATCHING(".rmvb", "generic"),
|
2013-11-23 18:48:40 -08:00
|
|
|
MATCHING(".rmx", "generic"),
|
|
|
|
MATCHING(".rv", "generic"),
|
2011-06-03 22:26:56 -07:00
|
|
|
MATCHING(".swf", "generic"),
|
|
|
|
MATCHING(".ts", "generic"),
|
2011-06-03 15:39:03 -07:00
|
|
|
MATCHING(".weba", "generic"),
|
|
|
|
MATCHING(".webm", "generic"),
|
|
|
|
MATCHING(".wmv", "generic")
|
2007-07-16 00:25:35 -07:00
|
|
|
};
|
|
|
|
|
2010-05-30 06:04:34 -07:00
|
|
|
static const char *loaders_name[] =
|
2011-04-25 18:03:06 -07:00
|
|
|
{ /* in order of most likely needed */
|
2013-11-23 18:48:40 -08:00
|
|
|
"png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "webp", "pmaps",
|
2021-02-06 07:45:42 -08:00
|
|
|
"bmp", "tga", "wbmp", "ico", "psd", "jp2k", "dds", "avif", "heif",
|
|
|
|
"generic"
|
2009-07-07 04:07:43 -07:00
|
|
|
};
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
struct evas_image_foreach_loader_data
|
|
|
|
{
|
|
|
|
Image_Entry *ie;
|
|
|
|
int *error;
|
|
|
|
Evas_Module *em;
|
|
|
|
};
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Eina_Bool
|
2013-04-24 23:07:11 -07:00
|
|
|
_evas_image_file_header(Evas_Module *em, Image_Entry *ie, int *error)
|
2009-06-16 06:01:36 -07:00
|
|
|
{
|
|
|
|
Evas_Image_Load_Func *evas_image_load_func = NULL;
|
2013-04-24 23:07:11 -07:00
|
|
|
Eina_Bool r = EINA_TRUE;
|
2017-01-01 05:15:24 -08:00
|
|
|
|
2013-04-24 23:07:11 -07:00
|
|
|
if (!evas_module_load(em)) goto load_error;
|
2009-06-16 06:01:36 -07:00
|
|
|
evas_image_load_func = em->functions;
|
|
|
|
evas_module_use(em);
|
2013-04-24 23:07:11 -07:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
2019-05-31 10:43:32 -07:00
|
|
|
if (evas_image_load_func && evas_image_load_func->version == EVAS_IMAGE_LOAD_VERSION)
|
2009-06-16 06:01:36 -07:00
|
|
|
{
|
2013-04-24 23:07:11 -07:00
|
|
|
Evas_Image_Property property;
|
2013-05-07 23:37:37 -07:00
|
|
|
const char *file;
|
2013-04-24 23:07:11 -07:00
|
|
|
|
2013-05-07 23:37:37 -07:00
|
|
|
if (!ie->f)
|
|
|
|
{
|
|
|
|
ie->f = eina_file_open(ie->file, EINA_FALSE);
|
2019-08-20 16:32:38 -07:00
|
|
|
ie->flags.given_mmap = EINA_FALSE;
|
2013-05-07 23:37:37 -07:00
|
|
|
file = ie->file;
|
|
|
|
}
|
2017-01-01 05:15:24 -08:00
|
|
|
else file = eina_file_filename_get(ie->f);
|
|
|
|
|
2013-05-06 03:01:35 -07:00
|
|
|
if (!ie->f)
|
2013-04-24 23:07:11 -07:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
2013-05-06 03:01:35 -07:00
|
|
|
goto load_error;
|
2013-04-24 23:07:11 -07:00
|
|
|
}
|
|
|
|
|
2017-01-01 05:15:24 -08:00
|
|
|
ie->loader_data = evas_image_load_func->file_open(ie->f, ie->key,
|
|
|
|
&ie->load_opts,
|
|
|
|
&ie->animated,
|
|
|
|
error);
|
|
|
|
if (!ie->loader_data) goto load_error;
|
2013-05-06 03:01:35 -07:00
|
|
|
|
2015-10-28 23:30:16 -07:00
|
|
|
memset(&property, 0, sizeof (property));
|
2013-05-06 03:01:35 -07:00
|
|
|
if (evas_image_load_func->file_head(ie->loader_data, &property,
|
2013-04-24 23:07:11 -07:00
|
|
|
error) &&
|
|
|
|
(*error == EVAS_LOAD_ERROR_NONE))
|
|
|
|
{
|
|
|
|
DBG("loaded file head using module '%s' (%p): %s",
|
2013-05-07 23:37:37 -07:00
|
|
|
em->definition->name, em, file);
|
2013-04-24 23:07:11 -07:00
|
|
|
|
2019-05-31 11:57:53 -07:00
|
|
|
ie->w = property.info.w;
|
|
|
|
ie->h = property.info.h;
|
|
|
|
ie->borders.l = property.info.borders.l;
|
|
|
|
ie->borders.r = property.info.borders.r;
|
|
|
|
ie->borders.t = property.info.borders.t;
|
|
|
|
ie->borders.b = property.info.borders.b;
|
|
|
|
ie->scale = property.info.scale;
|
|
|
|
ie->flags.alpha = property.info.alpha;
|
2019-06-13 15:34:09 -07:00
|
|
|
ie->need_data = property.need_data;
|
2019-05-31 11:57:53 -07:00
|
|
|
if (property.info.cspaces) ie->cspaces = property.info.cspaces;
|
|
|
|
ie->flags.rotated = property.info.rotated;
|
|
|
|
ie->flags.flipped = property.info.flipped;
|
2013-04-24 23:07:11 -07:00
|
|
|
r = EINA_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-01 20:32:54 -07:00
|
|
|
evas_image_load_func->file_close(ie->loader_data);
|
|
|
|
ie->loader_data = NULL;
|
2013-04-24 23:07:11 -07:00
|
|
|
evas_module_unload(em);
|
|
|
|
INF("failed to load file head using module '%s' (%p): "
|
|
|
|
"%s (%s)",
|
2013-05-07 23:37:37 -07:00
|
|
|
em->definition->name, em, file, evas_load_error_str(*error));
|
2013-04-24 23:07:11 -07:00
|
|
|
}
|
2009-06-16 06:01:36 -07:00
|
|
|
}
|
2013-04-24 23:07:11 -07:00
|
|
|
else
|
|
|
|
{
|
2017-01-01 05:15:24 -08:00
|
|
|
load_error:
|
2013-04-24 23:07:11 -07:00
|
|
|
evas_module_unload(em);
|
|
|
|
WRN("failed to load module '%s'.", em->definition->name);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_evas_image_foreach_loader(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata)
|
|
|
|
{
|
|
|
|
struct evas_image_foreach_loader_data *d = fdata;
|
|
|
|
Evas_Module *em = data;
|
|
|
|
Image_Entry *ie = d->ie;
|
|
|
|
Eina_Bool r;
|
2009-06-16 06:01:36 -07:00
|
|
|
|
2013-04-24 23:07:11 -07:00
|
|
|
r = _evas_image_file_header(em, ie, d->error);
|
2017-01-01 05:15:24 -08:00
|
|
|
if (!r) d->em = em;
|
2013-04-24 23:07:11 -07:00
|
|
|
return r;
|
2009-06-16 06:01:36 -07:00
|
|
|
}
|
|
|
|
|
evas: Rename EAPI macro to EVAS_API in Evas library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
= The Rationale =
This patch is from a series of patches to rename EAPI symbols to
specific library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`.
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
LIBAPI is the only solution that works for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Reviewers: vtorri, woohyun, jptiz, lucas
Reviewed By: vtorri, lucas
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12214
2020-12-15 18:02:20 -08:00
|
|
|
EVAS_API int
|
2008-04-11 17:32:30 -07:00
|
|
|
evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2011-04-25 18:03:06 -07:00
|
|
|
const char *loader = NULL, *end;
|
2013-05-07 23:37:37 -07:00
|
|
|
const char *file;
|
2007-07-16 00:25:35 -07:00
|
|
|
Evas_Module *em;
|
2010-09-18 16:07:31 -07:00
|
|
|
unsigned int i;
|
2011-04-25 18:03:06 -07:00
|
|
|
int len, ret = EVAS_LOAD_ERROR_NONE;
|
2009-12-22 15:11:57 -08:00
|
|
|
struct evas_image_foreach_loader_data fdata;
|
2017-01-01 05:15:24 -08:00
|
|
|
Eina_Bool skip;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2017-01-01 05:15:24 -08:00
|
|
|
skip = ie->load_opts.skip_head;
|
2013-05-07 23:37:37 -07:00
|
|
|
if (ie->f)
|
2011-05-06 02:36:24 -07:00
|
|
|
{
|
2013-05-07 23:37:37 -07:00
|
|
|
len = strlen(eina_file_filename_get(ie->f));
|
|
|
|
end = eina_file_filename_get(ie->f) + len;
|
|
|
|
file = eina_file_filename_get(ie->f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 05:15:24 -08:00
|
|
|
if (!skip)
|
2013-05-07 23:37:37 -07:00
|
|
|
{
|
2017-01-01 05:15:24 -08:00
|
|
|
struct stat st;
|
2013-05-07 23:37:37 -07:00
|
|
|
|
2017-01-01 05:15:24 -08:00
|
|
|
if (stat(ie->file, &st) != 0 || S_ISDIR(st.st_mode))
|
|
|
|
{
|
|
|
|
DBG("trying to open directory '%s' !", ie->file);
|
|
|
|
return EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
}
|
|
|
|
}
|
2013-05-07 23:37:37 -07:00
|
|
|
len = strlen(ie->file);
|
|
|
|
end = ie->file + len;
|
|
|
|
file = ie->file;
|
2011-05-06 02:36:24 -07:00
|
|
|
}
|
|
|
|
|
2011-04-25 18:03:06 -07:00
|
|
|
for (i = 0; i < (sizeof (loaders) / sizeof(struct ext_loader_s)); i++)
|
2004-08-28 01:41:12 -07:00
|
|
|
{
|
2011-04-25 18:03:06 -07:00
|
|
|
int len2 = strlen(loaders[i].extension);
|
|
|
|
if (len2 > len) continue;
|
|
|
|
if (!strcasecmp(end - len2, loaders[i].extension))
|
|
|
|
{
|
|
|
|
loader = loaders[i].loader;
|
|
|
|
DBG("known loader '%s' handles extension '%s' of file '%s'",
|
2013-05-07 23:37:37 -07:00
|
|
|
loader, end - len2, file);
|
2011-04-25 18:03:06 -07:00
|
|
|
break;
|
|
|
|
}
|
2004-08-28 01:41:12 -07:00
|
|
|
}
|
2007-07-16 00:25:35 -07:00
|
|
|
|
2006-01-14 21:04:32 -08:00
|
|
|
if (loader)
|
|
|
|
{
|
2017-01-01 05:15:24 -08:00
|
|
|
em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
|
|
|
|
if (em)
|
|
|
|
{
|
|
|
|
if (!((Evas_Image_Load_Func *)em->functions)->threadable)
|
|
|
|
skip = EINA_FALSE;
|
|
|
|
DBG("found image loader '%s' (%p)", loader, em);
|
|
|
|
if (!skip)
|
|
|
|
{
|
|
|
|
if (!_evas_image_file_header(em, ie, &ret)) goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else INF("image loader '%s' is not enabled or missing!", loader);
|
|
|
|
if (skip) goto end;
|
2006-01-14 21:04:32 -08:00
|
|
|
}
|
2006-01-14 12:03:42 -08:00
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
fdata.ie = ie;
|
|
|
|
fdata.error = &ret;
|
|
|
|
fdata.em = NULL;
|
|
|
|
ret = EVAS_LOAD_ERROR_NONE;
|
|
|
|
evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata);
|
|
|
|
em = fdata.em;
|
|
|
|
if (em) goto end;
|
2006-01-14 22:21:05 -08:00
|
|
|
|
2009-07-07 04:07:43 -07:00
|
|
|
/* This is our last chance, try all known image loader. */
|
|
|
|
/* FIXME: We could use eina recursive module search ability. */
|
2009-09-16 02:48:05 -07:00
|
|
|
for (i = 0; i < sizeof (loaders_name) / sizeof (char *); i++)
|
2009-07-07 04:07:43 -07:00
|
|
|
{
|
2017-01-01 05:15:24 -08:00
|
|
|
em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]);
|
|
|
|
if (em)
|
|
|
|
{
|
|
|
|
if (!ie->load_opts.skip_head)
|
|
|
|
{
|
|
|
|
if (!_evas_image_file_header(em, ie, &ret)) goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DBG("could not find module '%s'", loaders_name[i]);
|
2009-07-07 04:07:43 -07:00
|
|
|
}
|
2013-05-07 23:37:37 -07:00
|
|
|
INF("exhausted all means to load image '%s'", file);
|
2009-12-22 15:11:57 -08:00
|
|
|
return EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
|
|
|
|
2017-01-01 05:15:24 -08:00
|
|
|
end:
|
2009-12-22 15:11:57 -08:00
|
|
|
DBG("loader '%s' used for file %s",
|
|
|
|
(em && em->definition && em->definition->name) ?
|
|
|
|
em->definition->name : "<UNKNOWN>",
|
2013-05-07 23:37:37 -07:00
|
|
|
file);
|
2007-07-16 00:25:35 -07:00
|
|
|
|
2017-02-07 18:45:09 -08:00
|
|
|
if (em)
|
|
|
|
{
|
|
|
|
ie->info.module = em;
|
|
|
|
ie->info.loader = em->functions;
|
|
|
|
evas_module_ref(em);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ie->info.module = NULL;
|
|
|
|
ie->info.loader = NULL;
|
|
|
|
}
|
2009-12-22 15:11:57 -08:00
|
|
|
return ret;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
2017-01-01 05:15:24 -08:00
|
|
|
static void
|
|
|
|
_timestamp_build(Image_Timestamp *tstamp, struct stat *st)
|
|
|
|
{
|
|
|
|
tstamp->mtime = st->st_mtime;
|
|
|
|
tstamp->size = st->st_size;
|
|
|
|
tstamp->ino = st->st_ino;
|
|
|
|
#ifdef _STAT_VER_LINUX
|
|
|
|
# if (defined __USE_MISC && defined st_mtime)
|
|
|
|
tstamp->mtime_nsec = (unsigned long int)st->st_mtim.tv_nsec;
|
|
|
|
# else
|
|
|
|
tstamp->mtime_nsec = (unsigned long int)st->st_mtimensec;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
evas: Rename EAPI macro to EVAS_API in Evas library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
= The Rationale =
This patch is from a series of patches to rename EAPI symbols to
specific library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`.
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
LIBAPI is the only solution that works for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Reviewers: vtorri, woohyun, jptiz, lucas
Reviewed By: vtorri, lucas
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12214
2020-12-15 18:02:20 -08:00
|
|
|
EVAS_API int
|
2008-04-11 17:32:30 -07:00
|
|
|
evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2013-05-02 01:17:42 -07:00
|
|
|
void *pixels;
|
2006-01-14 22:21:05 -08:00
|
|
|
Evas_Image_Load_Func *evas_image_load_func = NULL;
|
2013-05-02 01:17:42 -07:00
|
|
|
Evas_Image_Property property;
|
2009-12-22 15:11:57 -08:00
|
|
|
int ret = EVAS_LOAD_ERROR_NONE;
|
2017-01-01 05:15:24 -08:00
|
|
|
struct stat st;
|
|
|
|
unsigned int i;
|
2007-07-16 00:25:35 -07:00
|
|
|
|
2013-04-24 23:07:11 -07:00
|
|
|
if ((ie->flags.loaded) && (!ie->animated.animated)) return EVAS_LOAD_ERROR_GENERIC;
|
2006-01-14 12:03:42 -08:00
|
|
|
|
2017-01-05 16:37:40 -08:00
|
|
|
if (!ie->info.module)
|
|
|
|
{
|
|
|
|
ie->load_failed = 1;
|
|
|
|
return EVAS_LOAD_ERROR_GENERIC;
|
|
|
|
}
|
2009-05-01 00:11:07 -07:00
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
evas_image_load_func = ie->info.loader;
|
2013-06-03 19:17:21 -07:00
|
|
|
evas_module_use(ie->info.module);
|
2013-05-02 01:17:42 -07:00
|
|
|
|
2017-10-05 16:02:47 -07:00
|
|
|
if (!ie->loader_data)
|
2017-01-01 05:15:24 -08:00
|
|
|
{
|
|
|
|
Evas_Module *em = ie->info.module;
|
|
|
|
|
|
|
|
if (_evas_image_file_header(em, ie, &ret))
|
|
|
|
{
|
|
|
|
em = NULL;
|
2017-01-05 16:37:40 -08:00
|
|
|
if (!ie->load_opts.skip_head)
|
2017-01-01 05:15:24 -08:00
|
|
|
{
|
2017-01-05 16:37:40 -08:00
|
|
|
for (i = 0; i < sizeof(loaders_name) / sizeof (char *); i++)
|
2017-01-01 05:15:24 -08:00
|
|
|
{
|
2017-01-05 16:37:40 -08:00
|
|
|
em = evas_module_find_type
|
|
|
|
(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]);
|
|
|
|
if (em)
|
2017-01-01 05:15:24 -08:00
|
|
|
{
|
|
|
|
if (!_evas_image_file_header(em, ie, &ret))
|
|
|
|
goto end;
|
|
|
|
}
|
2017-01-05 16:37:40 -08:00
|
|
|
else DBG("could not find module '%s'", loaders_name[i]);
|
|
|
|
em = NULL;
|
2017-01-01 05:15:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
if (ie->info.module != em)
|
|
|
|
{
|
2017-01-04 03:18:42 -08:00
|
|
|
if (em) evas_module_ref(em);
|
2017-01-01 05:15:24 -08:00
|
|
|
evas_module_unref(ie->info.module);
|
|
|
|
ie->info.module = em;
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 16:02:47 -07:00
|
|
|
if ((!ie->f) || (!ie->info.module) || (!ie->loader_data))
|
2017-01-05 16:37:40 -08:00
|
|
|
{
|
|
|
|
ie->load_failed = 1;
|
|
|
|
return EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
}
|
2013-05-02 01:17:42 -07:00
|
|
|
|
2017-01-02 05:58:24 -08:00
|
|
|
if ((ie->file) && (stat(ie->file, &st) == 0))
|
|
|
|
_timestamp_build(&(ie->tstamp), &st);
|
2017-01-01 05:15:24 -08:00
|
|
|
|
2015-10-28 23:30:16 -07:00
|
|
|
memset(&property, 0, sizeof (property));
|
2019-05-31 11:57:53 -07:00
|
|
|
property.info.w = ie->w;
|
|
|
|
property.info.h = ie->h;
|
|
|
|
property.info.scale = ie->scale;
|
|
|
|
property.info.rotated = ie->flags.rotated;
|
|
|
|
property.info.flipped = ie->flags.flipped;
|
|
|
|
property.info.premul = EINA_FALSE;
|
|
|
|
property.info.alpha_sparse = EINA_FALSE;
|
|
|
|
property.info.cspace = ie->space;
|
2013-05-02 01:17:42 -07:00
|
|
|
|
|
|
|
evas_cache_image_surface_alloc(ie, ie->w, ie->h);
|
2019-05-31 11:57:53 -07:00
|
|
|
property.info.borders.l = ie->borders.l;
|
|
|
|
property.info.borders.r = ie->borders.r;
|
|
|
|
property.info.borders.t = ie->borders.t;
|
|
|
|
property.info.borders.b = ie->borders.b;
|
2013-05-02 01:17:42 -07:00
|
|
|
|
|
|
|
pixels = evas_cache_image_pixels(ie);
|
2017-01-05 16:37:40 -08:00
|
|
|
if (!pixels)
|
|
|
|
{
|
|
|
|
ie->load_failed = 1;
|
|
|
|
return EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
}
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2019-06-13 15:34:09 -07:00
|
|
|
if (ie->need_data)
|
|
|
|
{
|
|
|
|
evas_image_load_func->file_head_with_data(ie->loader_data, &property, pixels, &ret);
|
|
|
|
memcpy(&ie->content, &property.content, sizeof (Eina_Rectangle));
|
|
|
|
ie->stretch.horizontal.region = property.stretch.horizontal.region;
|
|
|
|
ie->stretch.vertical.region = property.stretch.vertical.region;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_image_load_func->file_data(ie->loader_data, &property, pixels, &ret);
|
|
|
|
}
|
2013-05-02 01:17:42 -07:00
|
|
|
|
2019-05-31 11:57:53 -07:00
|
|
|
ie->flags.alpha_sparse = property.info.alpha_sparse;
|
2013-05-02 01:17:42 -07:00
|
|
|
|
2019-05-31 11:57:53 -07:00
|
|
|
if (property.info.premul) evas_common_image_premul(ie);
|
2008-04-11 17:32:30 -07:00
|
|
|
|
2013-05-02 01:17:42 -07:00
|
|
|
return ret;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
2011-06-01 07:32:08 -07:00
|
|
|
|
evas: Rename EAPI macro to EVAS_API in Evas library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
= The Rationale =
This patch is from a series of patches to rename EAPI symbols to
specific library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`.
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
LIBAPI is the only solution that works for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Reviewers: vtorri, woohyun, jptiz, lucas
Reviewed By: vtorri, lucas
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12214
2020-12-15 18:02:20 -08:00
|
|
|
EVAS_API double
|
2011-08-10 23:04:08 -07:00
|
|
|
evas_common_load_rgba_image_frame_duration_from_file(Image_Entry *ie, const int start, const int frame_num)
|
|
|
|
{
|
|
|
|
Evas_Image_Load_Func *evas_image_load_func = NULL;
|
|
|
|
|
|
|
|
if (!ie->info.module) return -1;
|
|
|
|
|
|
|
|
evas_image_load_func = ie->info.loader;
|
2013-06-03 19:17:21 -07:00
|
|
|
evas_module_use(ie->info.module);
|
2011-08-10 23:04:08 -07:00
|
|
|
if (evas_image_load_func->frame_duration)
|
2013-05-02 02:41:26 -07:00
|
|
|
{
|
2013-05-06 03:01:35 -07:00
|
|
|
if (!ie->f) return -1;
|
|
|
|
return evas_image_load_func->frame_duration(ie->loader_data, start, frame_num);
|
2013-05-02 02:41:26 -07:00
|
|
|
}
|
2011-08-10 23:04:08 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
evas: Rename EAPI macro to EVAS_API in Evas library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
= The Rationale =
This patch is from a series of patches to rename EAPI symbols to
specific library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`.
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
LIBAPI is the only solution that works for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Reviewers: vtorri, woohyun, jptiz, lucas
Reviewed By: vtorri, lucas
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12214
2020-12-15 18:02:20 -08:00
|
|
|
EVAS_API Eina_Bool
|
2011-06-01 07:32:08 -07:00
|
|
|
evas_common_extension_can_load_get(const char *file)
|
|
|
|
{
|
|
|
|
unsigned int length;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
length = eina_stringshare_strlen(file) + 1;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (loaders) / sizeof (struct ext_loader_s); ++i)
|
|
|
|
{
|
|
|
|
if (loaders[i].length > length) continue;
|
|
|
|
|
|
|
|
if (!strcasecmp(loaders[i].extension, file + length - loaders[i].length))
|
2018-04-12 04:55:22 -07:00
|
|
|
{
|
|
|
|
if ((file[length - loaders[i].length] != '/') ||
|
|
|
|
(length == loaders[i].length))
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2011-06-01 07:32:08 -07:00
|
|
|
}
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|