move around - flatter.
[profile/ivi/evas.git] / src / modules / loaders / eet / evas_image_load_eet.c
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"  /* so that EAPI in Eet.h is correctly defined */
3 #endif
4
5 #include <Eet.h>
6
7 #include "evas_common.h"
8 #include "evas_private.h"
9
10
11 int evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key);
12 int evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key);
13
14 Evas_Image_Load_Func evas_image_load_eet_func =
15 {
16   evas_image_load_file_head_eet,
17   evas_image_load_file_data_eet
18 };
19
20
21 int
22 evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key)
23 {
24    int                  alpha, compression, quality, lossy;
25    unsigned int         w, h;
26    Eet_File            *ef;
27    int                  ok;
28    int                  res = 0;
29
30    if ((!file) || (!key)) return 0;
31    ef = eet_open((char *)file, EET_FILE_MODE_READ);
32    if (!ef) return 0;
33    ok = eet_data_image_header_read(ef, key,
34                                    &w, &h, &alpha, &compression, &quality, &lossy);
35    if (!ok) goto on_error;
36    if (alpha) ie->flags.alpha = 1;
37    ie->w = w;
38    ie->h = h;
39    res = 1;
40
41  on_error:
42    eet_close(ef);
43    return res;
44 }
45
46 int
47 evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key)
48 {
49    unsigned int         w, h;
50    int                  alpha, compression, quality, lossy, ok;
51    Eet_File            *ef;
52    DATA32              *body, *p, *end;
53    DATA32               nas = 0;
54    int                  res = 0;
55
56    if ((!file) || (!key)) return 0;
57    if (ie->flags.loaded) return 1;
58    ef = eet_open(file, EET_FILE_MODE_READ);
59    if (!ef) return 0;
60    ok = eet_data_image_header_read(ef, key,
61                                    &w, &h, &alpha, &compression, &quality, &lossy);
62    if (!ok) goto on_error;
63    evas_cache_image_surface_alloc(ie, w, h);
64    ok = eet_data_image_read_to_surface(ef, key, 0, 0,
65                                        evas_cache_image_pixels(ie), w, h, w * 4,
66                                        &alpha, &compression, &quality, &lossy);
67    if (!ok) goto on_error;
68    if (alpha)
69      {
70         ie->flags.alpha = 1;
71
72         body = evas_cache_image_pixels(ie);
73
74         end = body +(w * h);
75         for (p = body; p < end; p++)
76           {
77              DATA32 r, g, b, a;
78
79              a = A_VAL(p);
80              r = R_VAL(p);
81              g = G_VAL(p);
82              b = B_VAL(p);
83              if ((a == 0) || (a == 255)) nas++;
84              if (r > a) r = a;
85              if (g > a) g = a;
86              if (b > a) b = a;
87              *p = ARGB_JOIN(a, r, g, b);
88           }
89         if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h))
90           ie->flags.alpha_sparse = 1;
91      }
92 // result is already premultiplied now if u compile with edje
93 //   evas_common_image_premul(im);
94    res = 1;
95
96  on_error:
97    eet_close(ef);
98    return res;
99 }
100
101 EAPI int
102 module_open(Evas_Module *em)
103 {
104    if (!em) return 0;
105    em->functions = (void *)(&evas_image_load_eet_func);
106    return 1;
107 }
108
109 EAPI void
110 module_close(void)
111 {
112    
113 }
114
115 EAPI Evas_Module_Api evas_modapi =
116 {
117    EVAS_MODULE_API_VERSION,
118      EVAS_MODULE_TYPE_IMAGE_LOADER,
119      "eet",
120      "none"
121 };