diff options
author | Cedric BAIL <cedric@osg.samsung.com> | 2015-03-17 08:51:01 +0100 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2015-03-17 09:58:21 +0100 |
commit | f875f759ca71428fd2d7e2943ba086c5f45c877f (patch) | |
tree | 0e859326b4b1a6d01e60bcec79bf6f4e4ca144cc /src/lib/emile | |
parent | aa3b6615ee60180708d27e64b0ef0b4f04cbbcc1 (diff) |
emile: fix coding style with ecrustify.
Diffstat (limited to 'src/lib/emile')
-rw-r--r-- | src/lib/emile/emile_cipher.h | 45 | ||||
-rw-r--r-- | src/lib/emile/emile_compress.c | 126 | ||||
-rw-r--r-- | src/lib/emile/emile_compress.h | 12 | ||||
-rw-r--r-- | src/lib/emile/emile_image.c | 747 | ||||
-rw-r--r-- | src/lib/emile/emile_image.h | 150 | ||||
-rw-r--r-- | src/lib/emile/emile_main.c | 48 |
6 files changed, 587 insertions, 541 deletions
diff --git a/src/lib/emile/emile_cipher.h b/src/lib/emile/emile_cipher.h index 73298b4f40..74a1b51b9d 100644 --- a/src/lib/emile/emile_cipher.h +++ b/src/lib/emile/emile_cipher.h | |||
@@ -66,9 +66,7 @@ EAPI Emile_Cipher_Backend emile_cipher_module_get(void); | |||
66 | * | 66 | * |
67 | * @since 1.14 | 67 | * @since 1.14 |
68 | */ | 68 | */ |
69 | EAPI Eina_Binbuf *emile_binbuf_cipher(Emile_Cipher_Algorithm algo, | 69 | EAPI Eina_Binbuf *emile_binbuf_cipher(Emile_Cipher_Algorithm algo, const Eina_Binbuf * in, const char *key, unsigned int length); |
70 | const Eina_Binbuf *in, | ||
71 | const char *key, unsigned int length); | ||
72 | 70 | ||
73 | /** | 71 | /** |
74 | * Decipher a buffer with a defined algorithm and key. | 72 | * Decipher a buffer with a defined algorithm and key. |
@@ -85,9 +83,7 @@ EAPI Eina_Binbuf *emile_binbuf_cipher(Emile_Cipher_Algorithm algo, | |||
85 | * | 83 | * |
86 | * @since 1.14 | 84 | * @since 1.14 |
87 | */ | 85 | */ |
88 | EAPI Eina_Binbuf *emile_binbuf_decipher(Emile_Cipher_Algorithm algo, | 86 | EAPI Eina_Binbuf *emile_binbuf_decipher(Emile_Cipher_Algorithm algo, const Eina_Binbuf * in, const char *key, unsigned int length); |
89 | const Eina_Binbuf *in, | ||
90 | const char *key, unsigned int length); | ||
91 | 87 | ||
92 | #ifdef EFL_BETA_API_SUPPORT | 88 | #ifdef EFL_BETA_API_SUPPORT |
93 | 89 | ||
@@ -107,30 +103,27 @@ typedef enum | |||
107 | EMILE_WANT_WRITE = 3 | 103 | EMILE_WANT_WRITE = 3 |
108 | } Emile_Want_Type; | 104 | } Emile_Want_Type; |
109 | 105 | ||
110 | EAPI Eina_Bool emile_binbuf_sha1(const char *key, | 106 | EAPI Eina_Bool emile_binbuf_sha1(const char *key, unsigned int key_len, const Eina_Binbuf * data, unsigned char digest[20]); |
111 | unsigned int key_len, | ||
112 | const Eina_Binbuf *data, | ||
113 | unsigned char digest[20]); | ||
114 | 107 | ||
115 | 108 | ||
116 | EAPI Emile_SSL *emile_cipher_server_listen(Emile_Cipher_Type t); | 109 | EAPI Emile_SSL *emile_cipher_server_listen(Emile_Cipher_Type t); |
117 | EAPI Emile_SSL *emile_cipher_client_connect(Emile_SSL *server, int fd); | 110 | EAPI Emile_SSL *emile_cipher_client_connect(Emile_SSL * server, int fd); |
118 | EAPI Emile_SSL *emile_cipher_server_connect(Emile_Cipher_Type t); | 111 | EAPI Emile_SSL *emile_cipher_server_connect(Emile_Cipher_Type t); |
119 | EAPI Eina_Bool emile_cipher_free(Emile_SSL *emile); | 112 | EAPI Eina_Bool emile_cipher_free(Emile_SSL * emile); |
120 | 113 | ||
121 | EAPI Eina_Bool emile_cipher_cafile_add(Emile_SSL *emile, const char *file); | 114 | EAPI Eina_Bool emile_cipher_cafile_add(Emile_SSL * emile, const char *file); |
122 | EAPI Eina_Bool emile_cipher_cert_add(Emile_SSL *emile, const char *file); | 115 | EAPI Eina_Bool emile_cipher_cert_add(Emile_SSL * emile, const char *file); |
123 | EAPI Eina_Bool emile_cipher_privkey_add(Emile_SSL *emile, const char *file); | 116 | EAPI Eina_Bool emile_cipher_privkey_add(Emile_SSL * emile, const char *file); |
124 | EAPI Eina_Bool emile_cipher_crl_add(Emile_SSL *emile, const char *file); | 117 | EAPI Eina_Bool emile_cipher_crl_add(Emile_SSL * emile, const char *file); |
125 | EAPI int emile_cipher_read(Emile_SSL *emile, Eina_Binbuf *buffer); | 118 | EAPI int emile_cipher_read(Emile_SSL * emile, Eina_Binbuf * buffer); |
126 | EAPI int emile_cipher_write(Emile_SSL *emile, const Eina_Binbuf *buffer); | 119 | EAPI int emile_cipher_write(Emile_SSL * emile, const Eina_Binbuf * buffer); |
127 | EAPI const char *emile_cipher_error_get(const Emile_SSL *emile); | 120 | EAPI const char *emile_cipher_error_get(const Emile_SSL * emile); |
128 | EAPI Eina_Bool emile_cipher_verify_name_set(Emile_SSL *emile, const char *name); | 121 | EAPI Eina_Bool emile_cipher_verify_name_set(Emile_SSL * emile, const char *name); |
129 | EAPI const char *emile_cipher_verify_name_get(const Emile_SSL *emile); | 122 | EAPI const char *emile_cipher_verify_name_get(const Emile_SSL * emile); |
130 | EAPI void emile_cipher_verify_set(Emile_SSL *emile, Eina_Bool verify); | 123 | EAPI void emile_cipher_verify_set(Emile_SSL * emile, Eina_Bool verify); |
131 | EAPI void emile_cipher_verify_basic_set(Emile_SSL *emile, Eina_Bool verify_basic); | 124 | EAPI void emile_cipher_verify_basic_set(Emile_SSL * emile, Eina_Bool verify_basic); |
132 | EAPI Eina_Bool emile_cipher_verify_get(const Emile_SSL *emile); | 125 | EAPI Eina_Bool emile_cipher_verify_get(const Emile_SSL * emile); |
133 | EAPI Eina_Bool emile_cipher_verify_basic_get(const Emile_SSL *emile); | 126 | EAPI Eina_Bool emile_cipher_verify_basic_get(const Emile_SSL * emile); |
134 | 127 | ||
135 | #endif | 128 | #endif |
136 | 129 | ||
diff --git a/src/lib/emile/emile_compress.c b/src/lib/emile/emile_compress.c index d5a60ee125..f45546d85f 100644 --- a/src/lib/emile/emile_compress.c +++ b/src/lib/emile/emile_compress.c | |||
@@ -1,15 +1,15 @@ | |||
1 | #ifdef HAVE_CONFIG_H | 1 | #ifdef HAVE_CONFIG_H |
2 | # include <config.h> | 2 | #include <config.h> |
3 | #endif | 3 | #endif |
4 | 4 | ||
5 | #include <zlib.h> | 5 | #include <zlib.h> |
6 | 6 | ||
7 | #ifdef ENABLE_LIBLZ4 | 7 | #ifdef ENABLE_LIBLZ4 |
8 | # include <lz4.h> | 8 | #include <lz4.h> |
9 | # include <lz4hc.h> | 9 | #include <lz4hc.h> |
10 | #else | 10 | #else |
11 | # include "lz4.h" | 11 | #include "lz4.h" |
12 | # include "lz4hc.h" | 12 | #include "lz4hc.h" |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include <Eina.h> | 15 | #include <Eina.h> |
@@ -22,12 +22,14 @@ _emile_compress_buffer_size(const Eina_Binbuf *data, Emile_Compressor_Type t) | |||
22 | switch (t) | 22 | switch (t) |
23 | { | 23 | { |
24 | case EMILE_ZLIB: | 24 | case EMILE_ZLIB: |
25 | return 12 + ((eina_binbuf_length_get(data) * 101) / 100); | 25 | return 12 + ((eina_binbuf_length_get(data) * 101) / 100); |
26 | |||
26 | case EMILE_LZ4: | 27 | case EMILE_LZ4: |
27 | case EMILE_LZ4HC: | 28 | case EMILE_LZ4HC: |
28 | return LZ4_compressBound(eina_binbuf_length_get(data)); | 29 | return LZ4_compressBound(eina_binbuf_length_get(data)); |
30 | |||
29 | default: | 31 | default: |
30 | return -1; | 32 | return -1; |
31 | } | 33 | } |
32 | } | 34 | } |
33 | 35 | ||
@@ -44,29 +46,38 @@ emile_compress(const Eina_Binbuf *data, | |||
44 | length = _emile_compress_buffer_size(data, t); | 46 | length = _emile_compress_buffer_size(data, t); |
45 | 47 | ||
46 | compact = malloc(length); | 48 | compact = malloc(length); |
47 | if (!compact) return NULL; | 49 | if (!compact) |
50 | return NULL; | ||
48 | 51 | ||
49 | switch (t) | 52 | switch (t) |
50 | { | 53 | { |
51 | case EMILE_LZ4: | 54 | case EMILE_LZ4: |
52 | length = LZ4_compress((const char *) eina_binbuf_string_get(data), compact, eina_binbuf_length_get(data)); | 55 | length = LZ4_compress((const char *)eina_binbuf_string_get(data), |
53 | if (length > 0) ok = EINA_TRUE; | 56 | compact, |
54 | compact = realloc(compact, length); /* It is going to be smaller and should never fail, if it does you are in deep poo. */ | 57 | eina_binbuf_length_get(data)); |
55 | break; | 58 | if (length > 0) |
59 | ok = EINA_TRUE; | ||
60 | /* It is going to be smaller and should never fail, if it does you are in deep poo. */ | ||
61 | compact = realloc(compact, length); | ||
62 | break; | ||
63 | |||
56 | case EMILE_LZ4HC: | 64 | case EMILE_LZ4HC: |
57 | length = LZ4_compressHC((const char *) eina_binbuf_string_get(data), compact, eina_binbuf_length_get(data)); | 65 | length = LZ4_compressHC((const char *)eina_binbuf_string_get(data), |
58 | if (length > 0) ok = EINA_TRUE; | 66 | compact, |
59 | compact = realloc(compact, length); | 67 | eina_binbuf_length_get(data)); |
60 | break; | 68 | if (length > 0) |
69 | ok = EINA_TRUE; | ||
70 | compact = realloc(compact, length); | ||
71 | break; | ||
72 | |||
61 | case EMILE_ZLIB: | 73 | case EMILE_ZLIB: |
62 | { | 74 | { |
63 | uLongf buflen = (uLongf) length; | 75 | uLongf buflen = (uLongf)length; |
64 | 76 | ||
65 | if (compress2((Bytef *)compact, &buflen, (Bytef *) eina_binbuf_string_get(data), | 77 | if (compress2((Bytef *)compact, &buflen, (Bytef *)eina_binbuf_string_get(data), (uLong)eina_binbuf_length_get(data), level) == Z_OK) |
66 | (uLong) eina_binbuf_length_get(data), level) == Z_OK) | 78 | ok = EINA_TRUE; |
67 | ok = EINA_TRUE; | 79 | length = (int)buflen; |
68 | length = (int) buflen; | 80 | } |
69 | } | ||
70 | } | 81 | } |
71 | 82 | ||
72 | if (!ok) | 83 | if (!ok) |
@@ -79,62 +90,67 @@ emile_compress(const Eina_Binbuf *data, | |||
79 | } | 90 | } |
80 | 91 | ||
81 | EAPI Eina_Bool | 92 | EAPI Eina_Bool |
82 | emile_expand(const Eina_Binbuf *in, | 93 | emile_expand(const Eina_Binbuf *in, Eina_Binbuf *out, Emile_Compressor_Type t) |
83 | Eina_Binbuf *out, | ||
84 | Emile_Compressor_Type t) | ||
85 | { | 94 | { |
86 | if (!in || !out) return EINA_FALSE; | 95 | if (!in || !out) |
96 | return EINA_FALSE; | ||
87 | 97 | ||
88 | switch (t) | 98 | switch (t) |
89 | { | 99 | { |
90 | case EMILE_LZ4: | 100 | case EMILE_LZ4: |
91 | case EMILE_LZ4HC: | 101 | case EMILE_LZ4HC: |
92 | { | 102 | { |
93 | int ret; | 103 | int ret; |
94 | 104 | ||
95 | ret = LZ4_decompress_fast((const char*) eina_binbuf_string_get(in), | 105 | ret = LZ4_decompress_fast((const char *)eina_binbuf_string_get(in), |
96 | (char*) eina_binbuf_string_get(out), | 106 | (char *)eina_binbuf_string_get(out), |
97 | eina_binbuf_length_get(out)); | 107 | eina_binbuf_length_get(out)); |
98 | if ((unsigned int) ret != eina_binbuf_length_get(in)) | 108 | if ((unsigned int)ret != eina_binbuf_length_get(in)) |
99 | return EINA_FALSE; | 109 | return EINA_FALSE; |
100 | break; | 110 | break; |
101 | } | 111 | } |
112 | |||
102 | case EMILE_ZLIB: | 113 | case EMILE_ZLIB: |
103 | { | 114 | { |
104 | uLongf dlen = eina_binbuf_length_get(out); | 115 | uLongf dlen = eina_binbuf_length_get(out); |
105 | 116 | ||
106 | if (uncompress((Bytef *) eina_binbuf_string_get(out), &dlen, | 117 | if (uncompress((Bytef *)eina_binbuf_string_get(out), &dlen, eina_binbuf_string_get(in), (uLongf)eina_binbuf_length_get(in)) != Z_OK) |
107 | eina_binbuf_string_get(in), | 118 | return EINA_FALSE; |
108 | (uLongf) eina_binbuf_length_get(in)) != Z_OK) | 119 | break; |
109 | return EINA_FALSE; | 120 | } |
110 | break; | 121 | |
111 | } | ||
112 | default: | 122 | default: |
113 | return EINA_FALSE; | 123 | return EINA_FALSE; |
114 | } | 124 | } |
115 | 125 | ||
116 | return EINA_TRUE; | 126 | return EINA_TRUE; |
117 | } | 127 | } |
118 | 128 | ||
119 | EAPI Eina_Binbuf * | 129 | EAPI Eina_Binbuf * |
120 | emile_decompress(const Eina_Binbuf *data, Emile_Compressor_Type t, unsigned int dest_length) | 130 | emile_decompress(const Eina_Binbuf *data, |
131 | Emile_Compressor_Type t, | ||
132 | unsigned int dest_length) | ||
121 | { | 133 | { |
122 | Eina_Binbuf *out; | 134 | Eina_Binbuf *out; |
123 | void *expanded; | 135 | void *expanded; |
124 | 136 | ||
125 | expanded = malloc(dest_length); | 137 | expanded = malloc(dest_length); |
126 | if (!expanded) return NULL; | 138 | if (!expanded) |
139 | return NULL; | ||
127 | 140 | ||
128 | out = eina_binbuf_manage_new(expanded, dest_length, EINA_FALSE); | 141 | out = eina_binbuf_manage_new(expanded, dest_length, EINA_FALSE); |
129 | if (!out) goto on_error; | 142 | if (!out) |
143 | goto on_error; | ||
130 | 144 | ||
131 | if (!emile_expand(data, out, t)) | 145 | if (!emile_expand(data, out, t)) |
132 | goto on_error; | 146 | goto on_error; |
133 | 147 | ||
134 | return out; | 148 | return out; |
135 | 149 | ||
136 | on_error: | 150 | on_error: |
137 | if (!out) free(expanded); | 151 | if (!out) |
138 | if (out) eina_binbuf_free(out); | 152 | free(expanded); |
153 | if (out) | ||
154 | eina_binbuf_free(out); | ||
139 | return NULL; | 155 | return NULL; |
140 | } | 156 | } |
diff --git a/src/lib/emile/emile_compress.h b/src/lib/emile/emile_compress.h index 83af4cd30b..d1539ac96b 100644 --- a/src/lib/emile/emile_compress.h +++ b/src/lib/emile/emile_compress.h | |||
@@ -51,9 +51,7 @@ typedef enum | |||
51 | * | 51 | * |
52 | * @since 1.14 | 52 | * @since 1.14 |
53 | */ | 53 | */ |
54 | EAPI Eina_Binbuf *emile_compress(const Eina_Binbuf *in, | 54 | EAPI Eina_Binbuf *emile_compress(const Eina_Binbuf * in, Emile_Compressor_Type t, Emile_Compressor_Level level); |
55 | Emile_Compressor_Type t, | ||
56 | Emile_Compressor_Level level); | ||
57 | /** | 55 | /** |
58 | * @brief Uncompress a buffer into a newly allocated buffer. | 56 | * @brief Uncompress a buffer into a newly allocated buffer. |
59 | * | 57 | * |
@@ -69,9 +67,7 @@ EAPI Eina_Binbuf *emile_compress(const Eina_Binbuf *in, | |||
69 | * @note That if dest_length doesn't match the expanded data, it will | 67 | * @note That if dest_length doesn't match the expanded data, it will |
70 | * just fail and return @c NULL. | 68 | * just fail and return @c NULL. |
71 | */ | 69 | */ |
72 | EAPI Eina_Binbuf *emile_decompress(const Eina_Binbuf *in, | 70 | EAPI Eina_Binbuf *emile_decompress(const Eina_Binbuf * in, Emile_Compressor_Type t, unsigned int dest_length); |
73 | Emile_Compressor_Type t, | ||
74 | unsigned int dest_length); | ||
75 | 71 | ||
76 | /** | 72 | /** |
77 | * @brief Uncompress a buffer into an existing buffer. | 73 | * @brief Uncompress a buffer into an existing buffer. |
@@ -87,9 +83,7 @@ EAPI Eina_Binbuf *emile_decompress(const Eina_Binbuf *in, | |||
87 | * expanded data or it will fail. In case of failure, random garbage | 83 | * expanded data or it will fail. In case of failure, random garbage |
88 | * could fill the out buffer. | 84 | * could fill the out buffer. |
89 | */ | 85 | */ |
90 | EAPI Eina_Bool emile_expand(const Eina_Binbuf *in, | 86 | EAPI Eina_Bool emile_expand(const Eina_Binbuf * in, Eina_Binbuf * out, Emile_Compressor_Type t); |
91 | Eina_Binbuf *out, | ||
92 | Emile_Compressor_Type t); | ||
93 | /** | 87 | /** |
94 | * @} | 88 | * @} |
95 | */ | 89 | */ |
diff --git a/src/lib/emile/emile_image.c b/src/lib/emile/emile_image.c index 7e889bb1f7..55ad99de43 100644 --- a/src/lib/emile/emile_image.c +++ b/src/lib/emile/emile_image.c | |||
@@ -1,23 +1,23 @@ | |||
1 | #ifdef HAVE_CONFIG_H | 1 | #ifdef HAVE_CONFIG_H |
2 | # include <config.h> | 2 | #include <config.h> |
3 | #endif | 3 | #endif |
4 | 4 | ||
5 | #ifdef HAVE_NETINET_IN_H | 5 | #ifdef HAVE_NETINET_IN_H |
6 | # include <netinet/in.h> | 6 | #include <netinet/in.h> |
7 | #endif | 7 | #endif |
8 | 8 | ||
9 | #ifdef _WIN32 | 9 | #ifdef _WIN32 |
10 | # include <winsock2.h> | 10 | #include <winsock2.h> |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #ifdef ENABLE_LIBLZ4 | 13 | #ifdef ENABLE_LIBLZ4 |
14 | # include <lz4.h> | 14 | #include <lz4.h> |
15 | #else | 15 | #else |
16 | # include "lz4.h" | 16 | #include "lz4.h" |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | #ifdef _WIN32 | 19 | #ifdef _WIN32 |
20 | # define XMD_H /* This prevents libjpeg to redefine INT32 */ | 20 | #define XMD_H /* This prevents libjpeg to redefine INT32 */ |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | #include <stdio.h> | 23 | #include <stdio.h> |
@@ -25,7 +25,7 @@ | |||
25 | #include <jpeglib.h> | 25 | #include <jpeglib.h> |
26 | 26 | ||
27 | #ifdef HAVE_EVIL | 27 | #ifdef HAVE_EVIL |
28 | # include <Evil.h> | 28 | #include <Evil.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | #include "rg_etc1.h" | 31 | #include "rg_etc1.h" |
@@ -38,41 +38,41 @@ | |||
38 | 38 | ||
39 | #define IMG_MAX_SIZE 65000 | 39 | #define IMG_MAX_SIZE 65000 |
40 | 40 | ||
41 | #define IMG_TOO_BIG(w, h) \ | 41 | #define IMG_TOO_BIG(w, h) \ |
42 | ((((unsigned long long)w) * ((unsigned long long)h)) >= \ | 42 | ((((unsigned long long)w) * ((unsigned long long)h)) >= \ |
43 | ((1ULL << (29 * (sizeof(void *) / 4))) - 2048)) | 43 | ((1ULL << (29 * (sizeof(void *) / 4))) - 2048)) |
44 | 44 | ||
45 | #define SPANS_COMMON(x1, w1, x2, w2) \ | 45 | #define SPANS_COMMON(x1, w1, x2, w2) \ |
46 | (!(( (int)((x2) + (int)(w2)) <= (int)(x1)) || (int)((x2) >= (int)((x1) + (int)(w1))))) | 46 | (!(((int)((x2) + (int)(w2)) <= (int)(x1)) || (int)((x2) >= (int)((x1) + (int)(w1))))) |
47 | 47 | ||
48 | #define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \ | 48 | #define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \ |
49 | ((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh)))) | 49 | ((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh)))) |
50 | 50 | ||
51 | #define RECTS_CLIP_TO_RECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch) \ | 51 | #define RECTS_CLIP_TO_RECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch) \ |
52 | { \ | 52 | { \ |
53 | if (RECTS_INTERSECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch)) \ | 53 | if (RECTS_INTERSECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch)) \ |
54 | { \ | 54 | { \ |
55 | if ((int)_x < (int)(_cx)) \ | 55 | if ((int)_x < (int)(_cx)) \ |
56 | { \ | 56 | { \ |
57 | if ((int)_w + ((int)_x - (int)(_cx)) < 0) _w = 0; \ | 57 | if ((int)_w + ((int)_x - (int)(_cx)) < 0) _w = 0; \ |
58 | else _w += ((int)_x - (int)(_cx)); \ | 58 | else _w += ((int)_x - (int)(_cx)); \ |
59 | _x = (_cx); \ | 59 | _x = (_cx); \ |
60 | } \ | 60 | } \ |
61 | if ((int)(_x + _w) > (int)((_cx) + (_cw))) \ | 61 | if ((int)(_x + _w) > (int)((_cx) + (_cw))) \ |
62 | _w = (_cx) + (_cw) - _x; \ | 62 | _w = (_cx) + (_cw) - _x; \ |
63 | if ((int)_y < (int)(_cy)) \ | 63 | if ((int)_y < (int)(_cy)) \ |
64 | { \ | 64 | { \ |
65 | if ((int)_h + ((int)_y - (int)(_cy)) < 0) _h = 0; \ | 65 | if ((int)_h + ((int)_y - (int)(_cy)) < 0) _h = 0; \ |
66 | else _h += ((int)_y - (int)(_cy)); \ | 66 | else _h += ((int)_y - (int)(_cy)); \ |
67 | _y = (_cy); \ | 67 | _y = (_cy); \ |
68 | } \ | 68 | } \ |
69 | if ((int)(_y + _h) > (int)((_cy) + (_ch))) \ | 69 | if ((int)(_y + _h) > (int)((_cy) + (_ch))) \ |
70 | _h = (_cy) + (_ch) - _y; \ | 70 | _h = (_cy) + (_ch) - _y; \ |
71 | } \ | 71 | } \ |
72 | else \ | 72 | else \ |
73 | { \ | 73 | { \ |
74 | _w = 0; _h = 0; \ | 74 | _w = 0; _h = 0; \ |
75 | } \ | 75 | } \ |
76 | } | 76 | } |
77 | 77 | ||
78 | #ifndef WORDS_BIGENDIAN | 78 | #ifndef WORDS_BIGENDIAN |
@@ -89,76 +89,70 @@ | |||
89 | #define B_VAL(p) (((uint8_t *)(p))[3]) | 89 | #define B_VAL(p) (((uint8_t *)(p))[3]) |
90 | #endif | 90 | #endif |
91 | 91 | ||
92 | #define ARGB_JOIN(a,r,g,b) \ | 92 | #define ARGB_JOIN(a, r, g, b) \ |
93 | (((a) << 24) + ((r) << 16) + ((g) << 8) + (b)) | 93 | (((a) << 24) + ((r) << 16) + ((g) << 8) + (b)) |
94 | 94 | ||
95 | #define OFFSET_BLOCK_SIZE 4 | 95 | #define OFFSET_BLOCK_SIZE 4 |
96 | #define OFFSET_ALGORITHM 5 | 96 | #define OFFSET_ALGORITHM 5 |
97 | #define OFFSET_OPTIONS 6 | 97 | #define OFFSET_OPTIONS 6 |
98 | #define OFFSET_WIDTH 8 | 98 | #define OFFSET_WIDTH 8 |
99 | #define OFFSET_HEIGHT 12 | 99 | #define OFFSET_HEIGHT 12 |
100 | #define OFFSET_BLOCKS 16 | 100 | #define OFFSET_BLOCKS 16 |
101 | 101 | ||
102 | struct _Emile_Image | 102 | struct _Emile_Image |
103 | { | 103 | { |
104 | Emile_Image_Load_Opts opts; | 104 | Emile_Image_Load_Opts opts; |
105 | 105 | ||
106 | struct { | 106 | struct |
107 | { | ||
107 | unsigned int width; | 108 | unsigned int width; |
108 | unsigned int height; | 109 | unsigned int height; |
109 | } size, block; | 110 | } size, block; |
110 | 111 | ||
111 | Eina_Rectangle region; | 112 | Eina_Rectangle region; |
112 | 113 | ||
113 | union { | 114 | union |
115 | { | ||
114 | Eina_Binbuf *bin; | 116 | Eina_Binbuf *bin; |
115 | Eina_File *f; | 117 | Eina_File *f; |
116 | } source; | 118 | } source; |
117 | 119 | ||
118 | const unsigned char *source_data; | 120 | const unsigned char *source_data; |
119 | 121 | ||
120 | Eina_Bool (*bind)(Emile_Image *image, | 122 | Eina_Bool (*bind)(Emile_Image *image, Emile_Image_Load_Opts *opts, Emile_Image_Animated *animated, Emile_Image_Load_Error *error); |
121 | Emile_Image_Load_Opts *opts, | 123 | Eina_Bool (*head)(Emile_Image *image, Emile_Image_Property *prop, unsigned int property_size, Emile_Image_Load_Error *error); |
122 | Emile_Image_Animated *animated, | 124 | Eina_Bool (*data)(Emile_Image *image, Emile_Image_Property *prop, unsigned int property_size, void *pixels, Emile_Image_Load_Error *error); |
123 | Emile_Image_Load_Error *error); | 125 | void (*close)(Emile_Image *image); |
124 | Eina_Bool (*head)(Emile_Image *image, | ||
125 | Emile_Image_Property *prop, | ||
126 | unsigned int property_size, | ||
127 | Emile_Image_Load_Error *error); | ||
128 | Eina_Bool (*data)(Emile_Image *image, | ||
129 | Emile_Image_Property *prop, | ||
130 | unsigned int property_size, | ||
131 | void *pixels, | ||
132 | Emile_Image_Load_Error *error); | ||
133 | void (*close)(Emile_Image *image); | ||
134 | 126 | ||
135 | Emile_Colorspace cspace; | 127 | Emile_Colorspace cspace; |
136 | 128 | ||
137 | Eina_Bool bin_source : 1; | 129 | Eina_Bool bin_source : 1; |
138 | 130 | ||
139 | /* TGV option */ | 131 | /* TGV option */ |
140 | Eina_Bool unpremul : 1; | 132 | Eina_Bool unpremul : 1; |
141 | Eina_Bool compress : 1; | 133 | Eina_Bool compress : 1; |
142 | Eina_Bool blockless : 1; | 134 | Eina_Bool blockless : 1; |
143 | Eina_Bool load_opts : 1; | 135 | Eina_Bool load_opts : 1; |
144 | }; | 136 | }; |
145 | 137 | ||
146 | static const unsigned char * | 138 | static const unsigned char * |
147 | _emile_image_file_source_map(Emile_Image *image, unsigned int *length) | 139 | _emile_image_file_source_map(Emile_Image *image, unsigned int *length) |
148 | { | 140 | { |
149 | if (!image) return NULL; | 141 | if (!image) |
142 | return NULL; | ||
150 | 143 | ||
151 | if (image->bin_source) | 144 | if (image->bin_source) |
152 | { | 145 | { |
153 | if (length) *length = eina_binbuf_length_get(image->source.bin); | 146 | if (length) |
147 | *length = eina_binbuf_length_get(image->source.bin); | ||
154 | return eina_binbuf_string_get(image->source.bin); | 148 | return eina_binbuf_string_get(image->source.bin); |
155 | } | 149 | } |
156 | 150 | ||
157 | if (length) *length = eina_file_size_get(image->source.f); | 151 | if (length) |
152 | *length = eina_file_size_get(image->source.f); | ||
158 | if (!image->source_data) | 153 | if (!image->source_data) |
159 | { | 154 | { |
160 | image->source_data = eina_file_map_all(image->source.f, | 155 | image->source_data = eina_file_map_all(image->source.f, EINA_FILE_SEQUENTIAL); |
161 | EINA_FILE_SEQUENTIAL); | ||
162 | } | 156 | } |
163 | return image->source_data; | 157 | return image->source_data; |
164 | } | 158 | } |
@@ -166,9 +160,9 @@ _emile_image_file_source_map(Emile_Image *image, unsigned int *length) | |||
166 | static void | 160 | static void |
167 | _emile_image_file_source_unmap(Emile_Image *image) | 161 | _emile_image_file_source_unmap(Emile_Image *image) |
168 | { | 162 | { |
169 | if (!(image && image->source_data)) return ; | 163 | if (!(image && image->source_data)) |
170 | eina_file_map_free(image->source.f, | 164 | return; |
171 | (void*) image->source_data); | 165 | eina_file_map_free(image->source.f, (void *)image->source_data); |
172 | image->source_data = NULL; | 166 | image->source_data = NULL; |
173 | } | 167 | } |
174 | 168 | ||
@@ -183,59 +177,59 @@ _roundup(int val, int rup) | |||
183 | /* TGV Handling */ | 177 | /* TGV Handling */ |
184 | 178 | ||
185 | static const Emile_Colorspace cspaces_etc1[2] = { | 179 | static const Emile_Colorspace cspaces_etc1[2] = { |
186 | EMILE_COLORSPACE_ETC1, | 180 | EMILE_COLORSPACE_ETC1, |
187 | EMILE_COLORSPACE_ARGB8888 | 181 | EMILE_COLORSPACE_ARGB8888 |
188 | }; | 182 | }; |
189 | 183 | ||
190 | static const Emile_Colorspace cspaces_rgb8_etc2[2] = { | 184 | static const Emile_Colorspace cspaces_rgb8_etc2[2] = { |
191 | EMILE_COLORSPACE_RGB8_ETC2, | 185 | EMILE_COLORSPACE_RGB8_ETC2, |
192 | EMILE_COLORSPACE_ARGB8888 | 186 | EMILE_COLORSPACE_ARGB8888 |
193 | }; | 187 | }; |
194 | 188 | ||
195 | static const Emile_Colorspace cspaces_rgba8_etc2_eac[2] = { | 189 | static const Emile_Colorspace cspaces_rgba8_etc2_eac[2] = { |
196 | EMILE_COLORSPACE_RGBA8_ETC2_EAC, | 190 | EMILE_COLORSPACE_RGBA8_ETC2_EAC, |
197 | EMILE_COLORSPACE_ARGB8888 | 191 | EMILE_COLORSPACE_ARGB8888 |
198 | }; | 192 | }; |
199 | 193 | ||
200 | static const Emile_Colorspace cspaces_etc1_alpha[2] = { | 194 | static const Emile_Colorspace cspaces_etc1_alpha[2] = { |
201 | EMILE_COLORSPACE_ETC1_ALPHA, | 195 | EMILE_COLORSPACE_ETC1_ALPHA, |
202 | EMILE_COLORSPACE_ARGB8888 | 196 | EMILE_COLORSPACE_ARGB8888 |
203 | }; | 197 | }; |
204 | 198 | ||
205 | static const Emile_Colorspace cspaces_agry[3] = { | 199 | static const Emile_Colorspace cspaces_agry[3] = { |
206 | EMILE_COLORSPACE_GRY8, | 200 | EMILE_COLORSPACE_GRY8, |
207 | EMILE_COLORSPACE_AGRY88, | 201 | EMILE_COLORSPACE_AGRY88, |
208 | EMILE_COLORSPACE_ARGB8888 | 202 | EMILE_COLORSPACE_ARGB8888 |
209 | }; | 203 | }; |
210 | 204 | ||
211 | /************************************************************** | 205 | /************************************************************** |
212 | * The TGV file format is oriented around compression mecanism | 206 | * The TGV file format is oriented around compression mecanism |
213 | * that hardware are good at decompressing. We do still provide | 207 | * that hardware are good at decompressing. We do still provide |
214 | * a fully software implementation in case your hardware doesn't | 208 | * a fully software implementation in case your hardware doesn't |
215 | * handle it. As OpenGL is pretty bad at handling border of | 209 | * handle it. As OpenGL is pretty bad at handling border of |
216 | * texture, we do duplicate the first pixels of every border. | 210 | * texture, we do duplicate the first pixels of every border. |
217 | * | 211 | * |
218 | * This file format is designed to compress/decompress things | 212 | * This file format is designed to compress/decompress things |
219 | * in block area. Giving opportunity to store really huge file | 213 | * in block area. Giving opportunity to store really huge file |
220 | * and only decompress/compress them as we need. Note that region | 214 | * and only decompress/compress them as we need. Note that region |
221 | * only work with software decompression as we don't have a sane | 215 | * only work with software decompression as we don't have a sane |
222 | * way to duplicate border to avoid artifact when scaling texture. | 216 | * way to duplicate border to avoid artifact when scaling texture. |
223 | * | 217 | * |
224 | * The file format is as follow : | 218 | * The file format is as follow : |
225 | * - char magic[4]: "TGV1" | 219 | * - char magic[4]: "TGV1" |
226 | * - uint8_t block_size (real block size = (4 << bits[0-3], 4 << bits[4-7]) | 220 | * - uint8_t block_size (real block size = (4 << bits[0-3], 4 << bits[4-7]) |
227 | * - uint8_t algorithm (0 -> ETC1, 1 -> ETC2 RGB, 2 -> ETC2 RGBA, 3 -> ETC1+Alpha) | 221 | * - uint8_t algorithm (0 -> ETC1, 1 -> ETC2 RGB, 2 -> ETC2 RGBA, 3 -> ETC1+Alpha) |
228 | * - uint8_t options[2] (bitmask: 1 -> lz4, 2 for block-less, 4 -> unpremultiplied) | 222 | * - uint8_t options[2] (bitmask: 1 -> lz4, 2 for block-less, 4 -> unpremultiplied) |
229 | * - uint32_t width | 223 | * - uint32_t width |
230 | * - uint32_t height | 224 | * - uint32_t height |
231 | * - blocks[] | 225 | * - blocks[] |
232 | * - 0 length encoded compress size (if length == 64 * block_size => no compression) | 226 | * - 0 length encoded compress size (if length == 64 * block_size => no compression) |
233 | * - lzma encoded etc1 block | 227 | * - lzma encoded etc1 block |
234 | * | 228 | * |
235 | * If the format is ETC1+Alpha (algo = 3), then a second image is encoded | 229 | * If the format is ETC1+Alpha (algo = 3), then a second image is encoded |
236 | * in ETC1 right after the first one, and it contains grey-scale alpha | 230 | * in ETC1 right after the first one, and it contains grey-scale alpha |
237 | * values. | 231 | * values. |
238 | **************************************************************/ | 232 | **************************************************************/ |
239 | 233 | ||
240 | // FIXME: wondering if we should support mipmap | 234 | // FIXME: wondering if we should support mipmap |
241 | // TODO: support ETC1+ETC2 images (RGB only) | 235 | // TODO: support ETC1+ETC2 images (RGB only) |
@@ -250,12 +244,12 @@ _emile_tgv_bind(Emile_Image *image, | |||
250 | unsigned int length; | 244 | unsigned int length; |
251 | 245 | ||
252 | m = _emile_image_file_source_map(image, &length); | 246 | m = _emile_image_file_source_map(image, &length); |
253 | if (!m) return EINA_FALSE; | 247 | if (!m) |
248 | return EINA_FALSE; | ||
254 | 249 | ||
255 | /* Fast check for file characteristic (useful when trying to guess | 250 | /* Fast check for file characteristic (useful when trying to guess |
256 | a file format without extention). */ | 251 | a file format without extention). */ |
257 | if (length < 16 || | 252 | if (length < 16 || strncmp((const char *)m, "TGV1", 4) != 0) |
258 | strncmp((const char*) m, "TGV1", 4) != 0) | ||
259 | goto on_error; | 253 | goto on_error; |
260 | 254 | ||
261 | if ((m[OFFSET_ALGORITHM] & 0xFF) > 3) | 255 | if ((m[OFFSET_ALGORITHM] & 0xFF) > 3) |
@@ -263,7 +257,7 @@ _emile_tgv_bind(Emile_Image *image, | |||
263 | 257 | ||
264 | return EINA_TRUE; | 258 | return EINA_TRUE; |
265 | 259 | ||
266 | on_error: | 260 | on_error: |
267 | *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; | 261 | *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; |
268 | _emile_image_file_source_unmap(image); | 262 | _emile_image_file_source_unmap(image); |
269 | return EINA_FALSE; | 263 | return EINA_FALSE; |
@@ -279,44 +273,50 @@ _emile_tgv_head(Emile_Image *image, | |||
279 | unsigned int length; | 273 | unsigned int length; |
280 | 274 | ||
281 | m = _emile_image_file_source_map(image, &length); | 275 | m = _emile_image_file_source_map(image, &length); |
282 | if (!m) return EINA_FALSE; | 276 | if (!m) |
277 | return EINA_FALSE; | ||
283 | 278 | ||
284 | /* This can be used for later ABI change of the structure. */ | 279 | /* This can be used for later ABI change of the structure. */ |
285 | if (sizeof (Emile_Image_Property) != property_size) return EINA_FALSE; | 280 | if (sizeof(Emile_Image_Property) != property_size) |
281 | return EINA_FALSE; | ||
286 | 282 | ||
287 | switch (m[OFFSET_ALGORITHM] & 0xFF) | 283 | switch (m[OFFSET_ALGORITHM] & 0xFF) |
288 | { | 284 | { |
289 | case 0: | 285 | case 0: |
290 | prop->cspaces = cspaces_etc1; | 286 | prop->cspaces = cspaces_etc1; |
291 | prop->alpha = EINA_FALSE; | 287 | prop->alpha = EINA_FALSE; |
292 | image->cspace = EMILE_COLORSPACE_ETC1; | 288 | image->cspace = EMILE_COLORSPACE_ETC1; |
293 | break; | 289 | break; |
290 | |||
294 | case 1: | 291 | case 1: |
295 | prop->cspaces = cspaces_rgb8_etc2; | 292 | prop->cspaces = cspaces_rgb8_etc2; |
296 | prop->alpha = EINA_FALSE; | 293 | prop->alpha = EINA_FALSE; |
297 | image->cspace = EMILE_COLORSPACE_RGB8_ETC2; | 294 | image->cspace = EMILE_COLORSPACE_RGB8_ETC2; |
298 | break; | 295 | break; |
296 | |||
299 | case 2: | 297 | case 2: |
300 | prop->cspaces = cspaces_rgba8_etc2_eac; | 298 | prop->cspaces = cspaces_rgba8_etc2_eac; |
301 | prop->alpha = EINA_TRUE; | 299 | prop->alpha = EINA_TRUE; |
302 | image->cspace = EMILE_COLORSPACE_RGBA8_ETC2_EAC; | 300 | image->cspace = EMILE_COLORSPACE_RGBA8_ETC2_EAC; |
303 | break; | 301 | break; |
302 | |||
304 | case 3: | 303 | case 3: |
305 | prop->cspaces = cspaces_etc1_alpha; | 304 | prop->cspaces = cspaces_etc1_alpha; |
306 | prop->alpha = EINA_TRUE; | 305 | prop->alpha = EINA_TRUE; |
307 | prop->premul = !!(m[OFFSET_OPTIONS] & 0x4); | 306 | prop->premul = !!(m[OFFSET_OPTIONS] & 0x4); |
308 | image->unpremul = prop->premul; | 307 | image->unpremul = prop->premul; |
309 | break; | 308 | break; |
309 | |||
310 | default: | 310 | default: |
311 | *error = EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE; | 311 | *error = EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE; |
312 | return EINA_FALSE; | 312 | return EINA_FALSE; |
313 | } | 313 | } |
314 | 314 | ||
315 | image->compress = m[OFFSET_OPTIONS] & 0x1; | 315 | image->compress = m[OFFSET_OPTIONS] & 0x1; |
316 | image->blockless = (m[OFFSET_OPTIONS] & 0x2) != 0; | 316 | image->blockless = (m[OFFSET_OPTIONS] & 0x2) != 0; |
317 | 317 | ||
318 | image->size.width = ntohl(*((unsigned int*) &(m[OFFSET_WIDTH]))); | 318 | image->size.width = ntohl(*((unsigned int *)&(m[OFFSET_WIDTH]))); |
319 | image->size.height = ntohl(*((unsigned int*) &(m[OFFSET_HEIGHT]))); | 319 | image->size.height = ntohl(*((unsigned int *)&(m[OFFSET_HEIGHT]))); |
320 | 320 | ||
321 | if (image->blockless) | 321 | if (image->blockless) |
322 | { | 322 | { |
@@ -329,7 +329,8 @@ _emile_tgv_head(Emile_Image *image, | |||
329 | image->block.height = 4 << ((m[OFFSET_BLOCK_SIZE] & 0xf0) >> 4); | 329 | image->block.height = 4 << ((m[OFFSET_BLOCK_SIZE] & 0xf0) >> 4); |
330 | } | 330 | } |
331 | 331 | ||
332 | EINA_RECTANGLE_SET(&image->region, 0, 0, | 332 | EINA_RECTANGLE_SET(&image->region, |
333 | 0, 0, | ||
333 | image->size.width, image->size.height); | 334 | image->size.width, image->size.height); |
334 | if (image->load_opts && | 335 | if (image->load_opts && |
335 | (image->opts.region.w > 0 && image->opts.region.h > 0)) | 336 | (image->opts.region.w > 0 && image->opts.region.h > 0)) |
@@ -337,8 +338,7 @@ _emile_tgv_head(Emile_Image *image, | |||
337 | /* ETC colorspace doesn't work with region for now */ | 338 | /* ETC colorspace doesn't work with region for now */ |
338 | prop->cspaces = NULL; | 339 | prop->cspaces = NULL; |
339 | 340 | ||
340 | if (!eina_rectangle_intersection(&image->region, | 341 | if (!eina_rectangle_intersection(&image->region, &image->opts.region)) |
341 | &image->opts.region)) | ||
342 | { | 342 | { |
343 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; | 343 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; |
344 | return EINA_FALSE; | 344 | return EINA_FALSE; |
@@ -407,7 +407,8 @@ _emile_tgv_data(Emile_Image *image, | |||
407 | return EINA_FALSE; | 407 | return EINA_FALSE; |
408 | } | 408 | } |
409 | 409 | ||
410 | if (sizeof (Emile_Image_Property) != property_size) return EINA_FALSE; | 410 | if (sizeof(Emile_Image_Property) != property_size) |
411 | return EINA_FALSE; | ||
411 | 412 | ||
412 | offset = OFFSET_BLOCKS; | 413 | offset = OFFSET_BLOCKS; |
413 | 414 | ||
@@ -424,15 +425,19 @@ _emile_tgv_data(Emile_Image *image, | |||
424 | case EMILE_COLORSPACE_RGB8_ETC2: | 425 | case EMILE_COLORSPACE_RGB8_ETC2: |
425 | etc_block_size = 8; | 426 | etc_block_size = 8; |
426 | break; | 427 | break; |
428 | |||
427 | case EMILE_COLORSPACE_RGBA8_ETC2_EAC: | 429 | case EMILE_COLORSPACE_RGBA8_ETC2_EAC: |
428 | etc_block_size = 16; | 430 | etc_block_size = 16; |
429 | break; | 431 | break; |
432 | |||
430 | case EMILE_COLORSPACE_ETC1_ALPHA: | 433 | case EMILE_COLORSPACE_ETC1_ALPHA: |
431 | etc_block_size = 8; | 434 | etc_block_size = 8; |
432 | num_planes = 2; | 435 | num_planes = 2; |
433 | alpha_offset = ((prop->w + 2 + 3) / 4) * ((prop->h + 2 + 3) / 4) * 8 / sizeof(*p_etc); | 436 | alpha_offset = ((prop->w + 2 + 3) / 4) * ((prop->h + 2 + 3) / 4) * 8 / sizeof(*p_etc); |
434 | break; | 437 | break; |
435 | default: abort(); | 438 | |
439 | default: | ||
440 | abort(); | ||
436 | } | 441 | } |
437 | etc_width = ((prop->w + 2 + 3) / 4) * etc_block_size; | 442 | etc_width = ((prop->w + 2 + 3) / 4) * etc_block_size; |
438 | 443 | ||
@@ -446,16 +451,19 @@ _emile_tgv_data(Emile_Image *image, | |||
446 | // FIXME: Should we really abort here ? Seems like a late check for me | 451 | // FIXME: Should we really abort here ? Seems like a late check for me |
447 | abort(); | 452 | abort(); |
448 | break; | 453 | break; |
454 | |||
449 | case EMILE_COLORSPACE_ARGB8888: | 455 | case EMILE_COLORSPACE_ARGB8888: |
450 | /* Offset to take duplicated pixels into account */ | 456 | /* Offset to take duplicated pixels into account */ |
451 | master.x += 1; | 457 | master.x += 1; |
452 | master.y += 1; | 458 | master.y += 1; |
453 | break; | 459 | break; |
454 | default: abort(); | ||
455 | } | ||
456 | 460 | ||
461 | default: | ||
462 | abort(); | ||
463 | } | ||
457 | 464 | ||
458 | if (prop->cspace != EMILE_COLORSPACE_ARGB8888 && prop->cspace != image->cspace) | 465 | if (prop->cspace != EMILE_COLORSPACE_ARGB8888 && |
466 | prop->cspace != image->cspace) | ||
459 | { | 467 | { |
460 | if (!((prop->cspace == EMILE_COLORSPACE_RGB8_ETC2) && | 468 | if (!((prop->cspace == EMILE_COLORSPACE_RGB8_ETC2) && |
461 | (image->cspace == EMILE_COLORSPACE_ETC1))) | 469 | (image->cspace == EMILE_COLORSPACE_ETC1))) |
@@ -469,7 +477,9 @@ _emile_tgv_data(Emile_Image *image, | |||
469 | /* Allocate space for each ETC block (8 or 16 bytes per 4 * 4 pixels group) */ | 477 | /* Allocate space for each ETC block (8 or 16 bytes per 4 * 4 pixels group) */ |
470 | block_count = image->block.width * image->block.height / (4 * 4); | 478 | block_count = image->block.width * image->block.height / (4 * 4); |
471 | if (image->compress) | 479 | if (image->compress) |
472 | buffer = eina_binbuf_manage_new(alloca(etc_block_size * block_count), etc_block_size * block_count, EINA_TRUE); | 480 | buffer = eina_binbuf_manage_new(alloca(etc_block_size * block_count), |
481 | etc_block_size * block_count, | ||
482 | EINA_TRUE); | ||
473 | 483 | ||
474 | for (plane = 0; plane < num_planes; plane++) | 484 | for (plane = 0; plane < num_planes; plane++) |
475 | for (y = 0; y < image->size.height + 2; y += image->block.height) | 485 | for (y = 0; y < image->size.height + 2; y += image->block.height) |
@@ -488,10 +498,13 @@ _emile_tgv_data(Emile_Image *image, | |||
488 | return EINA_FALSE; | 498 | return EINA_FALSE; |
489 | } | 499 | } |
490 | 500 | ||
491 | data_start = eina_binbuf_manage_new(m + offset, block_length, EINA_TRUE); | 501 | data_start = eina_binbuf_manage_new(m + offset, |
502 | block_length, | ||
503 | EINA_TRUE); | ||
492 | offset += block_length; | 504 | offset += block_length; |
493 | 505 | ||
494 | EINA_RECTANGLE_SET(¤t, x, y, | 506 | EINA_RECTANGLE_SET(¤t, |
507 | x, y, | ||
495 | image->block.width, image->block.height); | 508 | image->block.width, image->block.height); |
496 | 509 | ||
497 | if (!eina_rectangle_intersection(¤t, &master)) | 510 | if (!eina_rectangle_intersection(¤t, &master)) |
@@ -537,13 +550,17 @@ _emile_tgv_data(Emile_Image *image, | |||
537 | continue; | 550 | continue; |
538 | } | 551 | } |
539 | break; | 552 | break; |
553 | |||
540 | case EMILE_COLORSPACE_RGB8_ETC2: | 554 | case EMILE_COLORSPACE_RGB8_ETC2: |
541 | rg_etc2_rgb8_decode_block((uint8_t *) it, temporary); | 555 | rg_etc2_rgb8_decode_block((uint8_t *)it, temporary); |
542 | break; | 556 | break; |
557 | |||
543 | case EMILE_COLORSPACE_RGBA8_ETC2_EAC: | 558 | case EMILE_COLORSPACE_RGBA8_ETC2_EAC: |
544 | rg_etc2_rgba8_decode_block((uint8_t *) it, temporary); | 559 | rg_etc2_rgba8_decode_block((uint8_t *)it, temporary); |
545 | break; | 560 | break; |
546 | default: abort(); | 561 | |
562 | default: | ||
563 | abort(); | ||
547 | } | 564 | } |
548 | 565 | ||
549 | offset_x = current_etc.x - x - j; | 566 | offset_x = current_etc.x - x - j; |
@@ -568,7 +585,7 @@ _emile_tgv_data(Emile_Image *image, | |||
568 | else if (current_etc.w == 2) | 585 | else if (current_etc.w == 2) |
569 | vst1_u32(dst, vld1_u32(src)); | 586 | vst1_u32(dst, vld1_u32(src)); |
570 | else | 587 | else |
571 | *dst = *src; | 588 | *dst = *src; |
572 | dst += master.w; | 589 | dst += master.w; |
573 | src += 4; | 590 | src += 4; |
574 | } | 591 | } |
@@ -579,7 +596,7 @@ _emile_tgv_data(Emile_Image *image, | |||
579 | { | 596 | { |
580 | memcpy(&p[current_etc.x - 1 + (current_etc.y - 1 + k) * master.w], | 597 | memcpy(&p[current_etc.x - 1 + (current_etc.y - 1 + k) * master.w], |
581 | &temporary[offset_x + (offset_y + k) * 4], | 598 | &temporary[offset_x + (offset_y + k) * 4], |
582 | current_etc.w * sizeof (unsigned int)); | 599 | current_etc.w * sizeof(unsigned int)); |
583 | } | 600 | } |
584 | } | 601 | } |
585 | else | 602 | else |
@@ -587,27 +604,27 @@ _emile_tgv_data(Emile_Image *image, | |||
587 | for (k = 0; k < current_etc.h; k++) | 604 | for (k = 0; k < current_etc.h; k++) |
588 | for (l = 0; l < current_etc.w; l++) | 605 | for (l = 0; l < current_etc.w; l++) |
589 | { | 606 | { |
590 | unsigned int *rgbdata = | 607 | unsigned int *rgbdata = &p[current_etc.x - 1 + (current_etc.y - 1 + k) * master.w + l]; |
591 | &p[current_etc.x - 1 + (current_etc.y - 1 + k) * master.w + l]; | 608 | unsigned int *adata = &temporary[offset_x + (offset_y + k) * 4 + l]; |
592 | unsigned int *adata = | ||
593 | &temporary[offset_x + (offset_y + k) * 4 + l]; | ||
594 | A_VAL(rgbdata) = G_VAL(adata); | 609 | A_VAL(rgbdata) = G_VAL(adata); |
595 | } | 610 | } |
596 | } | 611 | } |
597 | break; | 612 | break; |
613 | |||
598 | case EMILE_COLORSPACE_ETC1: | 614 | case EMILE_COLORSPACE_ETC1: |
599 | case EMILE_COLORSPACE_RGB8_ETC2: | 615 | case EMILE_COLORSPACE_RGB8_ETC2: |
600 | case EMILE_COLORSPACE_RGBA8_ETC2_EAC: | 616 | case EMILE_COLORSPACE_RGBA8_ETC2_EAC: |
601 | memcpy(&p_etc[(current_etc.x / 4) * etc_block_size + | 617 | memcpy(&p_etc[(current_etc.x / 4) * etc_block_size + (current_etc.y / 4) * etc_width], |
602 | (current_etc.y / 4) * etc_width], | 618 | it, |
603 | it, etc_block_size); | 619 | etc_block_size); |
604 | break; | 620 | break; |
621 | |||
605 | case EMILE_COLORSPACE_ETC1_ALPHA: | 622 | case EMILE_COLORSPACE_ETC1_ALPHA: |
606 | memcpy(&p_etc[(current_etc.x / 4) * etc_block_size + | 623 | memcpy(&p_etc[(current_etc.x / 4) * etc_block_size + (current_etc.y / 4) * etc_width + plane * alpha_offset], |
607 | (current_etc.y / 4) * etc_width + | 624 | it, |
608 | plane * alpha_offset], | 625 | etc_block_size); |
609 | it, etc_block_size); | ||
610 | break; | 626 | break; |
627 | |||
611 | default: | 628 | default: |
612 | abort(); | 629 | abort(); |
613 | } | 630 | } |
@@ -616,11 +633,11 @@ _emile_tgv_data(Emile_Image *image, | |||
616 | 633 | ||
617 | // TODO: Add support for more unpremultiplied modes (ETC2) | 634 | // TODO: Add support for more unpremultiplied modes (ETC2) |
618 | if (prop->cspace == EMILE_COLORSPACE_ARGB8888) | 635 | if (prop->cspace == EMILE_COLORSPACE_ARGB8888) |
619 | prop->premul = image->unpremul; /* call premul if unpremul data */ | 636 | prop->premul = image->unpremul; /* call premul if unpremul data */ |
620 | 637 | ||
621 | r = EINA_TRUE; | 638 | r = EINA_TRUE; |
622 | 639 | ||
623 | on_error: | 640 | on_error: |
624 | return r; | 641 | return r; |
625 | } | 642 | } |
626 | 643 | ||
@@ -635,13 +652,13 @@ _emile_tgv_close(Emile_Image *image EINA_UNUSED) | |||
635 | typedef struct _JPEG_error_mgr *emptr; | 652 | typedef struct _JPEG_error_mgr *emptr; |
636 | struct _JPEG_error_mgr | 653 | struct _JPEG_error_mgr |
637 | { | 654 | { |
638 | struct jpeg_error_mgr pub; | 655 | struct jpeg_error_mgr pub; |
639 | jmp_buf setjmp_buffer; | 656 | jmp_buf setjmp_buffer; |
640 | }; | 657 | }; |
641 | 658 | ||
642 | struct jpeg_membuf_src | 659 | struct jpeg_membuf_src |
643 | { | 660 | { |
644 | struct jpeg_source_mgr pub; | 661 | struct jpeg_source_mgr pub; |
645 | 662 | ||
646 | const unsigned char *buf; | 663 | const unsigned char *buf; |
647 | size_t len; | 664 | size_t len; |
@@ -661,8 +678,7 @@ _emile_image_jpeg_error_exit_cb(j_common_ptr cinfo) | |||
661 | } | 678 | } |
662 | 679 | ||
663 | static void | 680 | static void |
664 | _emile_image_jpeg_emit_message_cb(j_common_ptr cinfo, | 681 | _emile_image_jpeg_emit_message_cb(j_common_ptr cinfo, int msg_level) |
665 | int msg_level) | ||
666 | { | 682 | { |
667 | char buffer[JMSG_LENGTH_MAX]; | 683 | char buffer[JMSG_LENGTH_MAX]; |
668 | struct jpeg_error_mgr *err; | 684 | struct jpeg_error_mgr *err; |
@@ -714,15 +730,14 @@ _emile_jpeg_membuf_src_fill(j_decompress_ptr cinfo) | |||
714 | } | 730 | } |
715 | 731 | ||
716 | static void | 732 | static void |
717 | _emile_jpeg_membuf_src_skip(j_decompress_ptr cinfo, | 733 | _emile_jpeg_membuf_src_skip(j_decompress_ptr cinfo, long num_bytes) |
718 | long num_bytes) | ||
719 | { | 734 | { |
720 | struct jpeg_membuf_src *src = (struct jpeg_membuf_src *)cinfo->src; | 735 | struct jpeg_membuf_src *src = (struct jpeg_membuf_src *)cinfo->src; |
721 | 736 | ||
722 | if ((((long)src->pub.bytes_in_buffer - (long)src->len) > num_bytes) || | 737 | if ((((long)src->pub.bytes_in_buffer - (long)src->len) > num_bytes) || |
723 | ((long)src->pub.bytes_in_buffer < num_bytes)) | 738 | ((long)src->pub.bytes_in_buffer < num_bytes)) |
724 | { | 739 | { |
725 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)); | 740 | (*(cinfo)->err->error_exit)((j_common_ptr)(cinfo)); |
726 | return; | 741 | return; |
727 | } | 742 | } |
728 | src->pub.bytes_in_buffer -= num_bytes; | 743 | src->pub.bytes_in_buffer -= num_bytes; |
@@ -733,20 +748,20 @@ static void | |||
733 | _emile_jpeg_membuf_src_term(j_decompress_ptr cinfo) | 748 | _emile_jpeg_membuf_src_term(j_decompress_ptr cinfo) |
734 | { | 749 | { |
735 | struct jpeg_membuf_src *src = (struct jpeg_membuf_src *)cinfo->src; | 750 | struct jpeg_membuf_src *src = (struct jpeg_membuf_src *)cinfo->src; |
736 | if (!src) return; | 751 | if (!src) |
752 | return; | ||
737 | free(src); | 753 | free(src); |
738 | cinfo->src = NULL; | 754 | cinfo->src = NULL; |
739 | } | 755 | } |
740 | 756 | ||
741 | static int | 757 | static int |
742 | _emile_jpeg_membuf_src(j_decompress_ptr cinfo, | 758 | _emile_jpeg_membuf_src(j_decompress_ptr cinfo, const void *map, size_t length) |
743 | const void *map, size_t length) | ||
744 | { | 759 | { |
745 | struct jpeg_membuf_src *src; | 760 | struct jpeg_membuf_src *src; |
746 | 761 | ||
747 | src = calloc(1, sizeof(*src)); | 762 | src = calloc(1, sizeof(*src)); |
748 | if (!src) | 763 | if (!src) |
749 | return -1; | 764 | return -1; |
750 | 765 | ||
751 | src->self = src; | 766 | src->self = src; |
752 | 767 | ||
@@ -765,16 +780,18 @@ _emile_jpeg_membuf_src(j_decompress_ptr cinfo, | |||
765 | } | 780 | } |
766 | 781 | ||
767 | /*! Magic number for EXIF header, App0, App1*/ | 782 | /*! Magic number for EXIF header, App0, App1*/ |
768 | static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}; | 783 | static const unsigned char ExifHeader[] = { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 }; |
769 | static const unsigned char JfifHeader[] = {0x4A, 0x46, 0x49, 0x46, 0x00}; | 784 | static const unsigned char JfifHeader[] = { 0x4A, 0x46, 0x49, 0x46, 0x00 }; |
770 | static const unsigned char JfxxHeader[] = {0x4A, 0x46, 0x58, 0x58, 0x00}; | 785 | static const unsigned char JfxxHeader[] = { 0x4A, 0x46, 0x58, 0x58, 0x00 }; |
771 | static const unsigned char App0[] = {0xff, 0xe0}; | 786 | static const unsigned char App0[] = { 0xff, 0xe0 }; |
772 | static const unsigned char App1[] = {0xff, 0xe1}; | 787 | static const unsigned char App1[] = { 0xff, 0xe1 }; |
773 | static const unsigned char II[] = {0x49, 0x49}; | 788 | static const unsigned char II[] = { 0x49, 0x49 }; |
774 | static const unsigned char MM[] = {0x4d, 0x4d}; | 789 | static const unsigned char MM[] = { 0x4d, 0x4d }; |
775 | typedef enum { | 790 | |
776 | EXIF_BYTE_ALIGN_II, | 791 | typedef enum |
777 | EXIF_BYTE_ALIGN_MM | 792 | { |
793 | EXIF_BYTE_ALIGN_II, | ||
794 | EXIF_BYTE_ALIGN_MM | ||
778 | } ExifByteAlign; | 795 | } ExifByteAlign; |
779 | 796 | ||
780 | static Eina_Bool | 797 | static Eina_Bool |
@@ -787,7 +804,8 @@ _get_next_app0(const unsigned char *map, size_t fsize, size_t *position) | |||
787 | const unsigned char *app0_head, *p; | 804 | const unsigned char *app0_head, *p; |
788 | 805 | ||
789 | /* header_mark:2, length:2, identifier:5 version:2, unit:1, den=4 thum=2 */ | 806 | /* header_mark:2, length:2, identifier:5 version:2, unit:1, den=4 thum=2 */ |
790 | if ((*position + 16) >= fsize) return EINA_FALSE; | 807 | if ((*position + 16) >= fsize) |
808 | return EINA_FALSE; | ||
791 | app0_head = map + *position; | 809 | app0_head = map + *position; |
792 | 810 | ||
793 | /* p is appn's start pointer excluding app0 marker */ | 811 | /* p is appn's start pointer excluding app0 marker */ |
@@ -796,13 +814,13 @@ _get_next_app0(const unsigned char *map, size_t fsize, size_t *position) | |||
796 | length = ((*p << 8) + *(p + 1)); | 814 | length = ((*p << 8) + *(p + 1)); |
797 | 815 | ||
798 | /* JFIF segment format */ | 816 | /* JFIF segment format */ |
799 | if (!memcmp(p + 2, JfifHeader, sizeof (JfifHeader))) | 817 | if (!memcmp(p + 2, JfifHeader, sizeof(JfifHeader))) |
800 | { | 818 | { |
801 | format = 3; | 819 | format = 3; |
802 | w = *(p + 14); | 820 | w = *(p + 14); |
803 | h = *(p + 15); | 821 | h = *(p + 15); |
804 | } | 822 | } |
805 | else if (!memcmp(p + 2, JfxxHeader, sizeof (JfxxHeader))) | 823 | else if (!memcmp(p + 2, JfxxHeader, sizeof(JfxxHeader))) |
806 | { | 824 | { |
807 | if (*(p + 7) == 0x11) | 825 | if (*(p + 7) == 0x11) |
808 | format = 1; | 826 | format = 1; |
@@ -812,14 +830,14 @@ _get_next_app0(const unsigned char *map, size_t fsize, size_t *position) | |||
812 | h = *(p + 9); | 830 | h = *(p + 9); |
813 | } | 831 | } |
814 | 832 | ||
815 | data_size = format * w * h; | 833 | data_size = format * w * h; |
816 | 834 | ||
817 | if ((*position + 2+ length + data_size) > fsize) | 835 | if ((*position + 2 + length + data_size) > fsize) |
818 | return EINA_FALSE; | 836 | return EINA_FALSE; |
819 | 837 | ||
820 | *position = *position + 2 + length + data_size; | 838 | *position = *position + 2 + length + data_size; |
821 | 839 | ||
822 | return EINA_TRUE; | 840 | return EINA_TRUE; |
823 | } | 841 | } |
824 | 842 | ||
825 | /* If app1 data is abnormal, returns EINA_FALSE. | 843 | /* If app1 data is abnormal, returns EINA_FALSE. |
@@ -828,8 +846,11 @@ _get_next_app0(const unsigned char *map, size_t fsize, size_t *position) | |||
828 | */ | 846 | */ |
829 | 847 | ||
830 | static Eina_Bool | 848 | static Eina_Bool |
831 | _get_orientation_app1(const unsigned char *map, size_t fsize, size_t *position, | 849 | _get_orientation_app1(const unsigned char *map, |
832 | int *orientation_res, Eina_Bool *flipped) | 850 | size_t fsize, |
851 | size_t *position, | ||
852 | int *orientation_res, | ||
853 | Eina_Bool *flipped) | ||
833 | { | 854 | { |
834 | const unsigned char *app1_head, *buf; | 855 | const unsigned char *app1_head, *buf; |
835 | unsigned char orientation[2]; | 856 | unsigned char orientation[2]; |
@@ -840,14 +861,16 @@ _get_orientation_app1(const unsigned char *map, size_t fsize, size_t *position, | |||
840 | unsigned int data_size = 0; | 861 | unsigned int data_size = 0; |
841 | 862 | ||
842 | /* app1 mark:2, data_size:2, exif:6 tiff:8 */ | 863 | /* app1 mark:2, data_size:2, exif:6 tiff:8 */ |
843 | if ((*position + 18) >= fsize) return EINA_FALSE; | 864 | if ((*position + 18) >= fsize) |
844 | app1_head = map + *position; | 865 | return EINA_FALSE; |
866 | app1_head = map + *position; | ||
845 | buf = app1_head; | 867 | buf = app1_head; |
846 | 868 | ||
847 | data_size = ((*(buf + 2) << 8) + *(buf + 3)); | 869 | data_size = ((*(buf + 2) << 8) + *(buf + 3)); |
848 | if ((*position + 2 + data_size) > fsize) return EINA_FALSE; | 870 | if ((*position + 2 + data_size) > fsize) |
871 | return EINA_FALSE; | ||
849 | 872 | ||
850 | if (memcmp(buf + 4, ExifHeader, sizeof (ExifHeader))) | 873 | if (memcmp(buf + 4, ExifHeader, sizeof(ExifHeader))) |
851 | { | 874 | { |
852 | *position = *position + 2 + data_size; | 875 | *position = *position + 2 + data_size; |
853 | *orientation_res = -1; | 876 | *orientation_res = -1; |
@@ -856,67 +879,77 @@ _get_orientation_app1(const unsigned char *map, size_t fsize, size_t *position, | |||
856 | 879 | ||
857 | /* 2. get 10&11 byte get info of "II(0x4949)" or "MM(0x4d4d)" */ | 880 | /* 2. get 10&11 byte get info of "II(0x4949)" or "MM(0x4d4d)" */ |
858 | /* 3. get [18]&[19] get directory entry # */ | 881 | /* 3. get [18]&[19] get directory entry # */ |
859 | if (!memcmp(buf + 10, MM, sizeof (MM))) | 882 | if (!memcmp(buf + 10, MM, sizeof(MM))) |
860 | { | 883 | { |
861 | byte_align = EXIF_BYTE_ALIGN_MM; | 884 | byte_align = EXIF_BYTE_ALIGN_MM; |
862 | num_directory = ((*(buf + 18) << 8) + *(buf + 19)); | 885 | num_directory = ((*(buf + 18) << 8) + *(buf + 19)); |
863 | orientation[0] = 0x01; | 886 | orientation[0] = 0x01; |
864 | orientation[1] = 0x12; | 887 | orientation[1] = 0x12; |
865 | } | 888 | } |
866 | else if (!memcmp(buf + 10, II, sizeof (II))) | 889 | else if (!memcmp(buf + 10, II, sizeof(II))) |
867 | { | 890 | { |
868 | byte_align = EXIF_BYTE_ALIGN_II; | 891 | byte_align = EXIF_BYTE_ALIGN_II; |
869 | num_directory = ((*(buf + 19) << 8) + *(buf + 18)); | 892 | num_directory = ((*(buf + 19) << 8) + *(buf + 18)); |
870 | orientation[0] = 0x12; | 893 | orientation[0] = 0x12; |
871 | orientation[1] = 0x01; | 894 | orientation[1] = 0x01; |
872 | } | 895 | } |
873 | else return EINA_FALSE; | 896 | else |
897 | return EINA_FALSE; | ||
874 | 898 | ||
875 | /* check num_directory data */ | 899 | /* check num_directory data */ |
876 | if ((*position + (12 * num_directory + 20)) > fsize) return EINA_FALSE; | 900 | if ((*position + (12 * num_directory + 20)) > fsize) |
901 | return EINA_FALSE; | ||
877 | 902 | ||
878 | buf = app1_head + 20; | 903 | buf = app1_head + 20; |
879 | 904 | ||
880 | j = 0; | 905 | j = 0; |
881 | 906 | ||
882 | for (i = 0; i < num_directory; i++ ) | 907 | for (i = 0; i < num_directory; i++) |
883 | { | 908 | { |
884 | if (!memcmp(buf + j, orientation, 2)) | 909 | if (!memcmp(buf + j, orientation, 2)) |
885 | { | 910 | { |
886 | /*get orientation tag */ | 911 | /*get orientation tag */ |
887 | if (byte_align == EXIF_BYTE_ALIGN_MM) | 912 | if (byte_align == EXIF_BYTE_ALIGN_MM) |
888 | direction = *(buf+ j + 9); | 913 | direction = *(buf + j + 9); |
889 | else direction = *(buf+ j + 8); | 914 | else |
915 | direction = *(buf + j + 8); | ||
890 | switch (direction) | 916 | switch (direction) |
891 | { | 917 | { |
892 | case 3: | 918 | case 3: |
893 | *orientation_res = 180; | 919 | *orientation_res = 180; |
894 | *flipped = EINA_FALSE; | 920 | *flipped = EINA_FALSE; |
895 | return EINA_TRUE; | 921 | return EINA_TRUE; |
922 | |||
896 | case 4: | 923 | case 4: |
897 | *orientation_res = 180; | 924 | *orientation_res = 180; |
898 | *flipped = EINA_TRUE; | 925 | *flipped = EINA_TRUE; |
899 | return EINA_TRUE; | 926 | return EINA_TRUE; |
927 | |||
900 | case 6: | 928 | case 6: |
901 | *orientation_res = 90; | 929 | *orientation_res = 90; |
902 | *flipped = EINA_FALSE; | 930 | *flipped = EINA_FALSE; |
903 | return EINA_TRUE; | 931 | return EINA_TRUE; |
932 | |||
904 | case 7: | 933 | case 7: |
905 | *orientation_res = 90; | 934 | *orientation_res = 90; |
906 | *flipped = EINA_TRUE; | 935 | *flipped = EINA_TRUE; |
907 | return EINA_TRUE; | 936 | return EINA_TRUE; |
937 | |||
908 | case 5: | 938 | case 5: |
909 | *orientation_res = 270; | 939 | *orientation_res = 270; |
910 | *flipped = EINA_TRUE; | 940 | *flipped = EINA_TRUE; |
911 | return EINA_TRUE; | 941 | return EINA_TRUE; |
942 | |||
912 | case 8: | 943 | case 8: |
913 | *orientation_res = 270; | 944 | *orientation_res = 270; |
914 | *flipped = EINA_FALSE; | 945 | *flipped = EINA_FALSE; |
915 | return EINA_TRUE; | 946 | return EINA_TRUE; |
947 | |||
916 | case 2: | 948 | case 2: |
917 | *orientation_res = 0; | 949 | *orientation_res = 0; |
918 | *flipped = EINA_TRUE; | 950 | *flipped = EINA_TRUE; |
919 | return EINA_TRUE; | 951 | return EINA_TRUE; |
952 | |||
920 | default: | 953 | default: |
921 | *orientation_res = 0; | 954 | *orientation_res = 0; |
922 | *flipped = EINA_FALSE; | 955 | *flipped = EINA_FALSE; |
@@ -940,34 +973,46 @@ _get_orientation(const void *map, size_t length, Eina_Bool *flipped) | |||
940 | *flipped = EINA_FALSE; | 973 | *flipped = EINA_FALSE; |
941 | 974 | ||
942 | /* open file and get 22 byte frome file */ | 975 | /* open file and get 22 byte frome file */ |
943 | if (!map) return 0; | 976 | if (!map) |
977 | return 0; | ||
944 | /* 1. read 22byte */ | 978 | /* 1. read 22byte */ |
945 | if (length < 22) return 0; | 979 | if (length < 22) |
980 | return 0; | ||
946 | buf = (unsigned char *)map; | 981 | buf = (unsigned char *)map; |
947 | 982 | ||
948 | position = 2; | 983 | position = 2; |
949 | /* 2. check 2,3 bypte with APP0(0xFFE0) or APP1(0xFFE1) */ | 984 | /* 2. check 2,3 bypte with APP0(0xFFE0) or APP1(0xFFE1) */ |
950 | while((length - position) > 0) | 985 | while ((length - position) > 0) |
951 | { | 986 | { |
952 | if (!memcmp(buf + position, App0, sizeof (App0))) | 987 | if (!memcmp(buf + position, App0, sizeof(App0))) |
953 | { | 988 | { |
954 | res = _get_next_app0(map, length, &position); | 989 | res = _get_next_app0(map, length, &position); |
955 | if (!res) break; | 990 | if (!res) |
991 | break; | ||
956 | } | 992 | } |
957 | else if (!memcmp(buf + position, App1, sizeof (App1))) | 993 | else if (!memcmp(buf + position, App1, sizeof(App1))) |
958 | { | 994 | { |
959 | res = _get_orientation_app1(map, length, &position, &orientation, flipped); | 995 | res = _get_orientation_app1(map, |
960 | if (!res) break; | 996 | length, |
961 | if (orientation != -1) return orientation; | 997 | &position, |
998 | &orientation, | ||
999 | flipped); | ||
1000 | if (!res) | ||
1001 | break; | ||
1002 | if (orientation != -1) | ||
1003 | return orientation; | ||
962 | } | 1004 | } |
963 | else break; | 1005 | else |
1006 | break; | ||
964 | } | 1007 | } |
965 | return 0; | 1008 | return 0; |
966 | } | 1009 | } |
967 | 1010 | ||
968 | static void | 1011 | static void |
969 | _rotate_region(unsigned int *r_x, unsigned int *r_y, unsigned int *r_w, unsigned int *r_h, | 1012 | _rotate_region(unsigned int *r_x, unsigned int *r_y, |
970 | unsigned int x, unsigned int y, unsigned int w, unsigned int h, | 1013 | unsigned int *r_w, unsigned int *r_h, |
1014 | unsigned int x, unsigned int y, | ||
1015 | unsigned int w, unsigned int h, | ||
971 | unsigned int output_w, unsigned int output_h, | 1016 | unsigned int output_w, unsigned int output_h, |
972 | int degree, Eina_Bool flipped) | 1017 | int degree, Eina_Bool flipped) |
973 | { | 1018 | { |
@@ -989,6 +1034,7 @@ _rotate_region(unsigned int *r_x, unsigned int *r_y, unsigned int *r_w, unsigned | |||
989 | *r_h = w; | 1034 | *r_h = w; |
990 | } | 1035 | } |
991 | break; | 1036 | break; |
1037 | |||
992 | case 180: | 1038 | case 180: |
993 | if (flipped) | 1039 | if (flipped) |
994 | { | 1040 | { |
@@ -1000,6 +1046,7 @@ _rotate_region(unsigned int *r_x, unsigned int *r_y, unsigned int *r_w, unsigned | |||
1000 | *r_y = output_h - (y + h); | 1046 | *r_y = output_h - (y + h); |
1001 | } | 1047 | } |
1002 | break; | 1048 | break; |
1049 | |||
1003 | case 270: | 1050 | case 270: |
1004 | if (flipped) | 1051 | if (flipped) |
1005 | { | 1052 | { |
@@ -1016,9 +1063,10 @@ _rotate_region(unsigned int *r_x, unsigned int *r_y, unsigned int *r_w, unsigned | |||
1016 | *r_h = w; | 1063 | *r_h = w; |
1017 | } | 1064 | } |
1018 | break; | 1065 | break; |
1066 | |||
1019 | default: | 1067 | default: |
1020 | if (flipped) | 1068 | if (flipped) |
1021 | *r_x = output_w - (x + w); | 1069 | *r_x = output_w - (x + w); |
1022 | break; | 1070 | break; |
1023 | } | 1071 | } |
1024 | } | 1072 | } |
@@ -1032,7 +1080,7 @@ _rotate_180(uint32_t *data, int w, int h) | |||
1032 | 1080 | ||
1033 | p1 = data; | 1081 | p1 = data; |
1034 | p2 = data + (h * w) - 1; | 1082 | p2 = data + (h * w) - 1; |
1035 | for (x = (w * h) / 2; --x >= 0;) | 1083 | for (x = (w * h) / 2; --x >= 0; ) |
1036 | { | 1084 | { |
1037 | pt = *p1; | 1085 | pt = *p1; |
1038 | *p1 = *p2; | 1086 | *p1 = *p2; |
@@ -1087,15 +1135,13 @@ _flip_vertical(uint32_t *data, int w, int h) | |||
1087 | } | 1135 | } |
1088 | 1136 | ||
1089 | static void | 1137 | static void |
1090 | _rotate_change_wh(uint32_t *to, uint32_t *from, | 1138 | _rotate_change_wh(uint32_t *to, uint32_t *from, int w, int h, int dx, int dy) |
1091 | int w, int h, | ||
1092 | int dx, int dy) | ||
1093 | { | 1139 | { |
1094 | int x, y; | 1140 | int x, y; |
1095 | 1141 | ||
1096 | for (x = h; --x >= 0;) | 1142 | for (x = h; --x >= 0; ) |
1097 | { | 1143 | { |
1098 | for (y = w; --y >= 0;) | 1144 | for (y = w; --y >= 0; ) |
1099 | { | 1145 | { |
1100 | *to = *from; | 1146 | *to = *from; |
1101 | from++; | 1147 | from++; |
@@ -1114,7 +1160,7 @@ _rotate8_180(uint8_t *data, int w, int h) | |||
1114 | 1160 | ||
1115 | p1 = data; | 1161 | p1 = data; |
1116 | p2 = data + (h * w) - 1; | 1162 | p2 = data + (h * w) - 1; |
1117 | for (x = (w * h) / 2; --x >= 0;) | 1163 | for (x = (w * h) / 2; --x >= 0; ) |
1118 | { | 1164 | { |
1119 | pt = *p1; | 1165 | pt = *p1; |
1120 | *p1 = *p2; | 1166 | *p1 = *p2; |
@@ -1169,15 +1215,13 @@ _flip_vertical8(uint8_t *data, int w, int h) | |||
1169 | } | 1215 | } |
1170 | 1216 | ||
1171 | static void | 1217 | static void |
1172 | _rotate_change_wh8(uint8_t *to, uint8_t *from, | 1218 | _rotate_change_wh8(uint8_t *to, uint8_t *from, int w, int h, int dx, int dy) |
1173 | int w, int h, | ||
1174 | int dx, int dy) | ||
1175 | { | 1219 | { |
1176 | int x, y; | 1220 | int x, y; |
1177 | 1221 | ||
1178 | for (x = h; --x >= 0;) | 1222 | for (x = h; --x >= 0; ) |
1179 | { | 1223 | { |
1180 | for (y = w; --y >= 0;) | 1224 | for (y = w; --y >= 0; ) |
1181 | { | 1225 | { |
1182 | *to = *from; | 1226 | *to = *from; |
1183 | from++; | 1227 | from++; |
@@ -1196,7 +1240,7 @@ _rotate16_180(uint16_t *data, int w, int h) | |||
1196 | 1240 | ||
1197 | p1 = data; | 1241 | p1 = data; |
1198 | p2 = data + (h * w) - 1; | 1242 | p2 = data + (h * w) - 1; |
1199 | for (x = (w * h) / 2; --x >= 0;) | 1243 | for (x = (w * h) / 2; --x >= 0; ) |
1200 | { | 1244 | { |
1201 | pt = *p1; | 1245 | pt = *p1; |
1202 | *p1 = *p2; | 1246 | *p1 = *p2; |
@@ -1251,15 +1295,13 @@ _flip_vertical16(uint16_t *data, int w, int h) | |||
1251 | } | 1295 | } |
1252 | 1296 | ||
1253 | static void | 1297 | static void |
1254 | _rotate_change_wh16(uint16_t *to, uint16_t *from, | 1298 | _rotate_change_wh16(uint16_t *to, uint16_t *from, int w, int h, int dx, int dy) |
1255 | int w, int h, | ||
1256 | int dx, int dy) | ||
1257 | { | 1299 | { |
1258 | int x, y; | 1300 | int x, y; |
1259 | 1301 | ||
1260 | for (x = h; --x >= 0;) | 1302 | for (x = h; --x >= 0; ) |
1261 | { | 1303 | { |
1262 | for (y = w; --y >= 0;) | 1304 | for (y = w; --y >= 0; ) |
1263 | { | 1305 | { |
1264 | *to = *from; | 1306 | *to = *from; |
1265 | from++; | 1307 | from++; |
@@ -1296,12 +1338,12 @@ _emile_jpeg_head(Emile_Image *image, | |||
1296 | Eina_Bool change_wh = EINA_FALSE; | 1338 | Eina_Bool change_wh = EINA_FALSE; |
1297 | unsigned int load_opts_w = 0, load_opts_h = 0; | 1339 | unsigned int load_opts_w = 0, load_opts_h = 0; |
1298 | 1340 | ||
1299 | 1341 | if (sizeof(Emile_Image_Property) != property_size) | |
1300 | if (sizeof (Emile_Image_Property) != property_size) | ||
1301 | return EINA_FALSE; | 1342 | return EINA_FALSE; |
1302 | 1343 | ||
1303 | m = _emile_image_file_source_map(image, &length); | 1344 | m = _emile_image_file_source_map(image, &length); |
1304 | if (!m) return EINA_FALSE; | 1345 | if (!m) |
1346 | return EINA_FALSE; | ||
1305 | 1347 | ||
1306 | if (image->load_opts) | 1348 | if (image->load_opts) |
1307 | opts = &image->opts; | 1349 | opts = &image->opts; |
@@ -1357,13 +1399,15 @@ _emile_jpeg_head(Emile_Image *image, | |||
1357 | if (degree == 90 || degree == 270) | 1399 | if (degree == 90 || degree == 270) |
1358 | change_wh = EINA_TRUE; | 1400 | change_wh = EINA_TRUE; |
1359 | } | 1401 | } |
1360 | |||
1361 | } | 1402 | } |
1362 | 1403 | ||
1363 | /* head decoding */ | 1404 | /* head decoding */ |
1364 | prop->w = cinfo.output_width; | 1405 | prop->w = cinfo.output_width; |
1365 | prop->h = cinfo.output_height; | 1406 | prop->h = cinfo.output_height; |
1366 | if ((prop->w < 1) || (prop->h < 1) || (prop->w > IMG_MAX_SIZE) || (prop->h > IMG_MAX_SIZE) || | 1407 | if ((prop->w < 1) || |
1408 | (prop->h < 1) || | ||
1409 | (prop->w > IMG_MAX_SIZE) || | ||
1410 | (prop->h > IMG_MAX_SIZE) || | ||
1367 | (IMG_TOO_BIG(prop->w, prop->h))) | 1411 | (IMG_TOO_BIG(prop->w, prop->h))) |
1368 | { | 1412 | { |
1369 | jpeg_destroy_decompress(&cinfo); | 1413 | jpeg_destroy_decompress(&cinfo); |
@@ -1423,8 +1467,10 @@ _emile_jpeg_head(Emile_Image *image, | |||
1423 | opts->h = load_opts_h; | 1467 | opts->h = load_opts_h; |
1424 | } | 1468 | } |
1425 | } | 1469 | } |
1426 | if (prop->w < 1) prop->w = 1; | 1470 | if (prop->w < 1) |
1427 | if (prop->h < 1) prop->h = 1; | 1471 | prop->w = 1; |
1472 | if (prop->h < 1) | ||
1473 | prop->h = 1; | ||
1428 | 1474 | ||
1429 | if ((prop->w != cinfo.output_width) || (prop->h != cinfo.output_height)) | 1475 | if ((prop->w != cinfo.output_width) || (prop->h != cinfo.output_height)) |
1430 | { | 1476 | { |
@@ -1432,15 +1478,22 @@ _emile_jpeg_head(Emile_Image *image, | |||
1432 | scaleh = cinfo.output_height / prop->h; | 1478 | scaleh = cinfo.output_height / prop->h; |
1433 | 1479 | ||
1434 | prop->scale = scalew; | 1480 | prop->scale = scalew; |
1435 | if (scaleh < scalew) prop->scale = scaleh; | 1481 | if (scaleh < scalew) |
1482 | prop->scale = scaleh; | ||
1436 | 1483 | ||
1437 | if (prop->scale > 8) prop->scale = 8; | 1484 | if (prop->scale > 8) |
1438 | else if (prop->scale < 1) prop->scale = 1; | 1485 | prop->scale = 8; |
1486 | else if (prop->scale < 1) | ||
1487 | prop->scale = 1; | ||
1439 | 1488 | ||
1440 | if (prop->scale == 3) prop->scale = 2; | 1489 | if (prop->scale == 3) |
1441 | else if (prop->scale == 5) prop->scale = 4; | 1490 | prop->scale = 2; |
1442 | else if (prop->scale == 6) prop->scale = 4; | 1491 | else if (prop->scale == 5) |
1443 | else if (prop->scale == 7) prop->scale = 4; | 1492 | prop->scale = 4; |
1493 | else if (prop->scale == 6) | ||
1494 | prop->scale = 4; | ||
1495 | else if (prop->scale == 7) | ||
1496 | prop->scale = 4; | ||
1444 | } | 1497 | } |
1445 | 1498 | ||
1446 | if (prop->scale > 1) | 1499 | if (prop->scale > 1) |
@@ -1473,13 +1526,18 @@ _emile_jpeg_head(Emile_Image *image, | |||
1473 | /* be nice and clip region to image. if its totally outside, fail load */ | 1526 | /* be nice and clip region to image. if its totally outside, fail load */ |
1474 | if ((opts->region.w > 0) && (opts->region.h > 0)) | 1527 | if ((opts->region.w > 0) && (opts->region.h > 0)) |
1475 | { | 1528 | { |
1476 | unsigned int load_region_x = opts->region.x, load_region_y = opts->region.y; | 1529 | unsigned int load_region_x = opts->region.x; |
1477 | unsigned int load_region_w = opts->region.w, load_region_h = opts->region.h; | 1530 | unsigned int load_region_y = opts->region.y; |
1531 | unsigned int load_region_w = opts->region.w; | ||
1532 | unsigned int load_region_h = opts->region.h; | ||
1478 | if (prop->rotated) | 1533 | if (prop->rotated) |
1479 | { | 1534 | { |
1480 | _rotate_region(&load_region_x, &load_region_y, &load_region_w, &load_region_h, | 1535 | _rotate_region(&load_region_x, &load_region_y, |
1481 | opts->region.x, opts->region.y, opts->region.w, opts->region.h, | 1536 | &load_region_w, &load_region_h, |
1482 | prop->w, prop->h, degree, prop->flipped); | 1537 | opts->region.x, opts->region.y, |
1538 | opts->region.w, opts->region.h, | ||
1539 | prop->w, prop->h, | ||
1540 | degree, prop->flipped); | ||
1483 | } | 1541 | } |
1484 | RECTS_CLIP_TO_RECT(load_region_x, load_region_y, | 1542 | RECTS_CLIP_TO_RECT(load_region_x, load_region_y, |
1485 | load_region_w, load_region_h, | 1543 | load_region_w, load_region_h, |
@@ -1530,7 +1588,8 @@ _emile_jpeg_data(Emile_Image *image, | |||
1530 | int region = 0; | 1588 | int region = 0; |
1531 | /* rotation setting */ | 1589 | /* rotation setting */ |
1532 | unsigned int ie_w = 0, ie_h = 0; | 1590 | unsigned int ie_w = 0, ie_h = 0; |
1533 | struct { | 1591 | struct |
1592 | { | ||
1534 | unsigned int x, y, w, h; | 1593 | unsigned int x, y, w, h; |
1535 | } opts_region; | 1594 | } opts_region; |
1536 | volatile int degree = 0; | 1595 | volatile int degree = 0; |
@@ -1538,11 +1597,12 @@ _emile_jpeg_data(Emile_Image *image, | |||
1538 | Eina_Bool line_done = EINA_FALSE; | 1597 | Eina_Bool line_done = EINA_FALSE; |
1539 | unsigned int length; | 1598 | unsigned int length; |
1540 | 1599 | ||
1541 | if (sizeof (Emile_Image_Property) != property_size) | 1600 | if (sizeof(Emile_Image_Property) != property_size) |
1542 | return EINA_FALSE; | 1601 | return EINA_FALSE; |
1543 | 1602 | ||
1544 | m = _emile_image_file_source_map(image, &length); | 1603 | m = _emile_image_file_source_map(image, &length); |
1545 | if (!m) return EINA_FALSE; | 1604 | if (!m) |
1605 | return EINA_FALSE; | ||
1546 | 1606 | ||
1547 | if (image->load_opts) | 1607 | if (image->load_opts) |
1548 | opts = &image->opts; | 1608 | opts = &image->opts; |
@@ -1591,6 +1651,7 @@ _emile_jpeg_data(Emile_Image *image, | |||
1591 | { | 1651 | { |
1592 | case JCS_UNKNOWN: | 1652 | case JCS_UNKNOWN: |
1593 | break; | 1653 | break; |
1654 | |||
1594 | case JCS_GRAYSCALE: | 1655 | case JCS_GRAYSCALE: |
1595 | if (prop->cspace == EMILE_COLORSPACE_GRY8 || | 1656 | if (prop->cspace == EMILE_COLORSPACE_GRY8 || |
1596 | prop->cspace == EMILE_COLORSPACE_AGRY88) | 1657 | prop->cspace == EMILE_COLORSPACE_AGRY88) |
@@ -1598,14 +1659,17 @@ _emile_jpeg_data(Emile_Image *image, | |||
1598 | cinfo.out_color_space = JCS_GRAYSCALE; | 1659 | cinfo.out_color_space = JCS_GRAYSCALE; |
1599 | break; | 1660 | break; |
1600 | } | 1661 | } |
1662 | |||
1601 | case JCS_RGB: | 1663 | case JCS_RGB: |
1602 | case JCS_YCbCr: | 1664 | case JCS_YCbCr: |
1603 | cinfo.out_color_space = JCS_RGB; | 1665 | cinfo.out_color_space = JCS_RGB; |
1604 | break; | 1666 | break; |
1667 | |||
1605 | case JCS_CMYK: | 1668 | case JCS_CMYK: |
1606 | case JCS_YCCK: | 1669 | case JCS_YCCK: |
1607 | cinfo.out_color_space = JCS_CMYK; | 1670 | cinfo.out_color_space = JCS_CMYK; |
1608 | break; | 1671 | break; |
1672 | |||
1609 | default: | 1673 | default: |
1610 | cinfo.out_color_space = JCS_RGB; | 1674 | cinfo.out_color_space = JCS_RGB; |
1611 | break; | 1675 | break; |
@@ -1648,8 +1712,10 @@ _emile_jpeg_data(Emile_Image *image, | |||
1648 | load_region_w = opts->region.w; | 1712 | load_region_w = opts->region.w; |
1649 | load_region_h = opts->region.h; | 1713 | load_region_h = opts->region.h; |
1650 | 1714 | ||
1651 | _rotate_region(&opts_region.x, &opts_region.y, &opts_region.w, &opts_region.h, | 1715 | _rotate_region(&opts_region.x, &opts_region.y, |
1652 | load_region_x, load_region_y, load_region_w, load_region_h, | 1716 | &opts_region.w, &opts_region.h, |
1717 | load_region_x, load_region_y, | ||
1718 | load_region_w, load_region_h, | ||
1653 | w, h, degree, prop->flipped); | 1719 | w, h, degree, prop->flipped); |
1654 | } | 1720 | } |
1655 | #ifdef BUILD_LOADER_JPEG_REGION | 1721 | #ifdef BUILD_LOADER_JPEG_REGION |
@@ -1664,8 +1730,7 @@ _emile_jpeg_data(Emile_Image *image, | |||
1664 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; | 1730 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; |
1665 | goto on_error; | 1731 | goto on_error; |
1666 | } | 1732 | } |
1667 | if ((region) && | 1733 | if ((region) && ((ie_w != opts_region.w) || (ie_h != opts_region.h))) |
1668 | ((ie_w != opts_region.w) || (ie_h != opts_region.h))) | ||
1669 | { | 1734 | { |
1670 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; | 1735 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; |
1671 | goto on_error; | 1736 | goto on_error; |
@@ -1675,24 +1740,26 @@ _emile_jpeg_data(Emile_Image *image, | |||
1675 | { | 1740 | { |
1676 | case EMILE_COLORSPACE_GRY8: | 1741 | case EMILE_COLORSPACE_GRY8: |
1677 | case EMILE_COLORSPACE_AGRY88: | 1742 | case EMILE_COLORSPACE_AGRY88: |
1678 | if (!(cinfo.out_color_space == JCS_GRAYSCALE && | 1743 | if (!(cinfo.out_color_space == JCS_GRAYSCALE && |
1679 | cinfo.output_components == 1)) | 1744 | cinfo.output_components == 1)) |
1680 | { | 1745 | { |
1681 | *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; | 1746 | *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; |
1682 | goto on_error; | 1747 | goto on_error; |
1683 | } | 1748 | } |
1684 | break; | 1749 | break; |
1750 | |||
1685 | case EMILE_COLORSPACE_ARGB8888: | 1751 | case EMILE_COLORSPACE_ARGB8888: |
1686 | if (!((cinfo.out_color_space == JCS_RGB && cinfo.output_components == 3) || | 1752 | if (!((cinfo.out_color_space == JCS_RGB && cinfo.output_components == 3) || |
1687 | (cinfo.out_color_space == JCS_CMYK && cinfo.output_components == 4))) | 1753 | (cinfo.out_color_space == JCS_CMYK && cinfo.output_components == 4))) |
1688 | { | 1754 | { |
1689 | *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; | 1755 | *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; |
1690 | goto on_error; | 1756 | goto on_error; |
1691 | } | 1757 | } |
1692 | break; | 1758 | break; |
1759 | |||
1693 | default: | 1760 | default: |
1694 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; | 1761 | *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; |
1695 | goto on_error; | 1762 | goto on_error; |
1696 | } | 1763 | } |
1697 | 1764 | ||
1698 | /* end head decoding */ | 1765 | /* end head decoding */ |
@@ -1743,7 +1810,8 @@ _emile_jpeg_data(Emile_Image *image, | |||
1743 | { | 1810 | { |
1744 | jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); | 1811 | jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); |
1745 | scans = cinfo.rec_outbuf_height; | 1812 | scans = cinfo.rec_outbuf_height; |
1746 | if ((h - l) < scans) scans = h - l; | 1813 | if ((h - l) < scans) |
1814 | scans = h - l; | ||
1747 | ptr = data; | 1815 | ptr = data; |
1748 | if (!region) | 1816 | if (!region) |
1749 | { | 1817 | { |
@@ -1754,7 +1822,7 @@ _emile_jpeg_data(Emile_Image *image, | |||
1754 | for (x = 0; x < w; x++) | 1822 | for (x = 0; x < w; x++) |
1755 | { | 1823 | { |
1756 | /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */ | 1824 | /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */ |
1757 | /* that is C is replaces by 255 - C, etc...*/ | 1825 | /* that is C is replaces by 255 - C, etc... */ |
1758 | /* See the comment below for the computation of RGB values from CMYK ones. */ | 1826 | /* See the comment below for the computation of RGB values from CMYK ones. */ |
1759 | *ptr2 = | 1827 | *ptr2 = |
1760 | (0xff000000) | | 1828 | (0xff000000) | |
@@ -1801,18 +1869,16 @@ _emile_jpeg_data(Emile_Image *image, | |||
1801 | /* if rotation flag is set , we have to rotate image */ | 1869 | /* if rotation flag is set , we have to rotate image */ |
1802 | goto done; | 1870 | goto done; |
1803 | /*jpeg_destroy_decompress(&cinfo); | 1871 | /*jpeg_destroy_decompress(&cinfo); |
1804 | _emile_jpeg_membuf_src_term(&cinfo); | 1872 | _emile_jpeg_membuf_src_term(&cinfo); |
1805 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; | 1873 | * error = EMILE_IMAGE_LOAD_ERROR_NONE; |
1806 | return EINA_FALSE;*/ | 1874 | return EINA_FALSE; */ |
1807 | } | 1875 | } |
1808 | /* else if scan block intersects region start or later */ | 1876 | /* else if scan block intersects region start or later */ |
1809 | else if ((l + scans) > | 1877 | else if ((l + scans) > (opts_region.y)) |
1810 | (opts_region.y)) | ||
1811 | { | 1878 | { |
1812 | for (y = 0; y < scans; y++) | 1879 | for (y = 0; y < scans; y++) |
1813 | { | 1880 | { |
1814 | if (((y + l) >= opts_region.y) && | 1881 | if (((y + l) >= opts_region.y) && ((y + l) < (opts_region.y + opts_region.h))) |
1815 | ((y + l) < (opts_region.y + opts_region.h))) | ||
1816 | { | 1882 | { |
1817 | ptr += opts_region.x; | 1883 | ptr += opts_region.x; |
1818 | if (cinfo.saw_Adobe_marker) | 1884 | if (cinfo.saw_Adobe_marker) |
@@ -1820,7 +1886,7 @@ _emile_jpeg_data(Emile_Image *image, | |||
1820 | for (x = 0; x < opts_region.w; x++) | 1886 | for (x = 0; x < opts_region.w; x++) |
1821 | { | 1887 | { |
1822 | /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */ | 1888 | /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */ |
1823 | /* that is C is replaces by 255 - C, etc...*/ | 1889 | /* that is C is replaces by 255 - C, etc... */ |
1824 | /* See the comment below for the computation of RGB values from CMYK ones. */ | 1890 | /* See the comment below for the computation of RGB values from CMYK ones. */ |
1825 | *ptr2 = | 1891 | *ptr2 = |
1826 | (0xff000000) | | 1892 | (0xff000000) | |
@@ -1890,7 +1956,8 @@ _emile_jpeg_data(Emile_Image *image, | |||
1890 | { | 1956 | { |
1891 | jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); | 1957 | jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); |
1892 | scans = cinfo.rec_outbuf_height; | 1958 | scans = cinfo.rec_outbuf_height; |
1893 | if ((h - l) < scans) scans = h - l; | 1959 | if ((h - l) < scans) |
1960 | scans = h - l; | ||
1894 | ptr = data; | 1961 | ptr = data; |
1895 | if (!region) | 1962 | if (!region) |
1896 | { | 1963 | { |
@@ -1915,8 +1982,7 @@ _emile_jpeg_data(Emile_Image *image, | |||
1915 | goto done; | 1982 | goto done; |
1916 | } | 1983 | } |
1917 | /* else if scan block intersects region start or later */ | 1984 | /* else if scan block intersects region start or later */ |
1918 | else if ((l + scans) > | 1985 | else if ((l + scans) > (opts_region.y)) |
1919 | (opts_region.y)) | ||
1920 | { | 1986 | { |
1921 | for (y = 0; y < scans; y++) | 1987 | for (y = 0; y < scans; y++) |
1922 | { | 1988 | { |
@@ -1952,7 +2018,8 @@ _emile_jpeg_data(Emile_Image *image, | |||
1952 | { | 2018 | { |
1953 | jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); | 2019 | jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); |
1954 | scans = cinfo.rec_outbuf_height; | 2020 | scans = cinfo.rec_outbuf_height; |
1955 | if ((h - l) < scans) scans = h - l; | 2021 | if ((h - l) < scans) |
2022 | scans = h - l; | ||
1956 | ptr = data; | 2023 | ptr = data; |
1957 | if (!region) | 2024 | if (!region) |
1958 | { | 2025 | { |
@@ -1988,13 +2055,12 @@ _emile_jpeg_data(Emile_Image *image, | |||
1988 | /* if rotation flag is set , we have to rotate image */ | 2055 | /* if rotation flag is set , we have to rotate image */ |
1989 | goto done; | 2056 | goto done; |
1990 | /*jpeg_destroy_decompress(&cinfo); | 2057 | /*jpeg_destroy_decompress(&cinfo); |
1991 | _emile_jpeg_membuf_src_term(&cinfo); | 2058 | _emile_jpeg_membuf_src_term(&cinfo); |
1992 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; | 2059 | * error = EMILE_IMAGE_LOAD_ERROR_NONE; |
1993 | return EINA_TRUE;*/ | 2060 | return EINA_TRUE; */ |
1994 | } | 2061 | } |
1995 | /* else if scan block intersects region start or later */ | 2062 | /* else if scan block intersects region start or later */ |
1996 | else if ((l + scans) > | 2063 | else if ((l + scans) > (opts_region.y)) |
1997 | (opts_region.y)) | ||
1998 | { | 2064 | { |
1999 | for (y = 0; y < scans; y++) | 2065 | for (y = 0; y < scans; y++) |
2000 | { | 2066 | { |
@@ -2070,6 +2136,7 @@ done: | |||
2070 | _rotate_change_wh(to + h - 1, ptr_rotate, w, h, -hw - 1, h); | 2136 | _rotate_change_wh(to + h - 1, ptr_rotate, w, h, -hw - 1, h); |
2071 | } | 2137 | } |
2072 | break; | 2138 | break; |
2139 | |||
2073 | case 180: | 2140 | case 180: |
2074 | if (prop->cspace == EMILE_COLORSPACE_GRY8) | 2141 | if (prop->cspace == EMILE_COLORSPACE_GRY8) |
2075 | { | 2142 | { |
@@ -2093,6 +2160,7 @@ done: | |||
2093 | _rotate_180(to, w, h); | 2160 | _rotate_180(to, w, h); |
2094 | } | 2161 | } |
2095 | break; | 2162 | break; |
2163 | |||
2096 | case 270: | 2164 | case 270: |
2097 | if (prop->cspace == EMILE_COLORSPACE_GRY8) | 2165 | if (prop->cspace == EMILE_COLORSPACE_GRY8) |
2098 | { | 2166 | { |
@@ -2116,6 +2184,7 @@ done: | |||
2116 | _rotate_change_wh(to + hw - h, ptr_rotate, w, h, hw + 1, -h); | 2184 | _rotate_change_wh(to + hw - h, ptr_rotate, w, h, hw + 1, -h); |
2117 | } | 2185 | } |
2118 | break; | 2186 | break; |
2187 | |||
2119 | default: | 2188 | default: |
2120 | if (prop->flipped) | 2189 | if (prop->flipped) |
2121 | { | 2190 | { |
@@ -2147,7 +2216,7 @@ done: | |||
2147 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; | 2216 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; |
2148 | return EINA_TRUE; | 2217 | return EINA_TRUE; |
2149 | 2218 | ||
2150 | on_error: | 2219 | on_error: |
2151 | jpeg_destroy_decompress(&cinfo); | 2220 | jpeg_destroy_decompress(&cinfo); |
2152 | _emile_jpeg_membuf_src_term(&cinfo); | 2221 | _emile_jpeg_membuf_src_term(&cinfo); |
2153 | return EINA_FALSE; | 2222 | return EINA_FALSE; |
@@ -2162,25 +2231,16 @@ _emile_jpeg_close(Emile_Image *image EINA_UNUSED) | |||
2162 | /* Generic helper to instantiate a new Emile_Image */ | 2231 | /* Generic helper to instantiate a new Emile_Image */ |
2163 | 2232 | ||
2164 | static Emile_Image * | 2233 | static Emile_Image * |
2165 | _emile_image_new(Eina_Bool (*bind) (Emile_Image *image, | 2234 | _emile_image_new(Eina_Bool (*bind)(Emile_Image *image, Emile_Image_Load_Opts *opts, Emile_Image_Animated *animated, Emile_Image_Load_Error *error), |
2166 | Emile_Image_Load_Opts *opts, | 2235 | Eina_Bool (*head)(Emile_Image *image, Emile_Image_Property *prop, unsigned int property_size, Emile_Image_Load_Error *error), |
2167 | Emile_Image_Animated *animated, | 2236 | Eina_Bool (*data)(Emile_Image *image, Emile_Image_Property *prop, unsigned int property_size, void *pixels, Emile_Image_Load_Error *error), |
2168 | Emile_Image_Load_Error *error), | ||
2169 | Eina_Bool (*head)(Emile_Image *image, | ||
2170 | Emile_Image_Property *prop, | ||
2171 | unsigned int property_size, | ||
2172 | Emile_Image_Load_Error *error), | ||
2173 | Eina_Bool (*data)(Emile_Image *image, | ||
2174 | Emile_Image_Property *prop, | ||
2175 | unsigned int property_size, | ||
2176 | void *pixels, | ||
2177 | Emile_Image_Load_Error *error), | ||
2178 | void (*close)(Emile_Image *image)) | 2237 | void (*close)(Emile_Image *image)) |
2179 | { | 2238 | { |
2180 | Emile_Image *ei; | 2239 | Emile_Image *ei; |
2181 | 2240 | ||
2182 | ei = calloc(1, sizeof (Emile_Image)); | 2241 | ei = calloc(1, sizeof(Emile_Image)); |
2183 | if (!ei) return NULL; | 2242 | if (!ei) |
2243 | return NULL; | ||
2184 | 2244 | ||
2185 | ei->bind = bind; | 2245 | ei->bind = bind; |
2186 | ei->head = head; | 2246 | ei->head = head; |
@@ -2240,7 +2300,8 @@ emile_image_tgv_memory_open(Eina_Binbuf *source, | |||
2240 | _emile_tgv_head, | 2300 | _emile_tgv_head, |
2241 | _emile_tgv_data, | 2301 | _emile_tgv_data, |
2242 | _emile_tgv_close); | 2302 | _emile_tgv_close); |
2243 | if (!ei) return NULL; | 2303 | if (!ei) |
2304 | return NULL; | ||
2244 | 2305 | ||
2245 | _emile_image_binbuf_set(ei, source); | 2306 | _emile_image_binbuf_set(ei, source); |
2246 | return _emile_image_bind(ei, opts, animated, error); | 2307 | return _emile_image_bind(ei, opts, animated, error); |
@@ -2258,7 +2319,8 @@ emile_image_tgv_file_open(Eina_File *source, | |||
2258 | _emile_tgv_head, | 2319 | _emile_tgv_head, |
2259 | _emile_tgv_data, | 2320 | _emile_tgv_data, |
2260 | _emile_tgv_close); | 2321 | _emile_tgv_close); |
2261 | if (!ei) return NULL; | 2322 | if (!ei) |
2323 | return NULL; | ||
2262 | 2324 | ||
2263 | _emile_image_file_set(ei, source); | 2325 | _emile_image_file_set(ei, source); |
2264 | return _emile_image_bind(ei, opts, animated, error); | 2326 | return _emile_image_bind(ei, opts, animated, error); |
@@ -2276,7 +2338,8 @@ emile_image_jpeg_memory_open(Eina_Binbuf *source, | |||
2276 | _emile_jpeg_head, | 2338 | _emile_jpeg_head, |
2277 | _emile_jpeg_data, | 2339 | _emile_jpeg_data, |
2278 | _emile_jpeg_close); | 2340 | _emile_jpeg_close); |
2279 | if (!ei) return NULL; | 2341 | if (!ei) |
2342 | return NULL; | ||
2280 | 2343 | ||
2281 | _emile_image_binbuf_set(ei, source); | 2344 | _emile_image_binbuf_set(ei, source); |
2282 | return _emile_image_bind(ei, opts, animated, error); | 2345 | return _emile_image_bind(ei, opts, animated, error); |
@@ -2294,7 +2357,8 @@ emile_image_jpeg_file_open(Eina_File *source, | |||
2294 | _emile_jpeg_head, | 2357 | _emile_jpeg_head, |
2295 | _emile_jpeg_data, | 2358 | _emile_jpeg_data, |
2296 | _emile_jpeg_close); | 2359 | _emile_jpeg_close); |
2297 | if (!ei) return NULL; | 2360 | if (!ei) |
2361 | return NULL; | ||
2298 | 2362 | ||
2299 | _emile_image_file_set(ei, source); | 2363 | _emile_image_file_set(ei, source); |
2300 | return _emile_image_bind(ei, opts, animated, error); | 2364 | return _emile_image_bind(ei, opts, animated, error); |
@@ -2303,7 +2367,8 @@ emile_image_jpeg_file_open(Eina_File *source, | |||
2303 | EAPI void | 2367 | EAPI void |
2304 | emile_image_close(Emile_Image *image) | 2368 | emile_image_close(Emile_Image *image) |
2305 | { | 2369 | { |
2306 | if (!image) return ; | 2370 | if (!image) |
2371 | return; | ||
2307 | 2372 | ||
2308 | _emile_image_file_source_unmap(image); | 2373 | _emile_image_file_source_unmap(image); |
2309 | if (!image->bin_source) | 2374 | if (!image->bin_source) |
@@ -2318,7 +2383,8 @@ emile_image_head(Emile_Image *image, | |||
2318 | unsigned int property_size, | 2383 | unsigned int property_size, |
2319 | Emile_Image_Load_Error *error) | 2384 | Emile_Image_Load_Error *error) |
2320 | { | 2385 | { |
2321 | if (!image) return EINA_FALSE; | 2386 | if (!image) |
2387 | return EINA_FALSE; | ||
2322 | 2388 | ||
2323 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; | 2389 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; |
2324 | return image->head(image, prop, property_size, error); | 2390 | return image->head(image, prop, property_size, error); |
@@ -2331,7 +2397,8 @@ emile_image_data(Emile_Image *image, | |||
2331 | void *pixels, | 2397 | void *pixels, |
2332 | Emile_Image_Load_Error *error) | 2398 | Emile_Image_Load_Error *error) |
2333 | { | 2399 | { |
2334 | if (!image) return EINA_FALSE; | 2400 | if (!image) |
2401 | return EINA_FALSE; | ||
2335 | 2402 | ||
2336 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; | 2403 | *error = EMILE_IMAGE_LOAD_ERROR_NONE; |
2337 | return image->data(image, prop, property_size, pixels, error); | 2404 | return image->data(image, prop, property_size, pixels, error); |
@@ -2344,19 +2411,25 @@ emile_load_error_str(Emile_Image *source EINA_UNUSED, | |||
2344 | switch (error) | 2411 | switch (error) |
2345 | { | 2412 | { |
2346 | case EMILE_IMAGE_LOAD_ERROR_NONE: | 2413 | case EMILE_IMAGE_LOAD_ERROR_NONE: |
2347 | return "No error"; | 2414 | return "No error"; |
2415 | |||
2348 | case EMILE_IMAGE_LOAD_ERROR_GENERIC: | 2416 | case EMILE_IMAGE_LOAD_ERROR_GENERIC: |
2349 | return "Generic error encountered while loading image."; | 2417 | return "Generic error encountered while loading image."; |
2418 | |||
2350 | case EMILE_IMAGE_LOAD_ERROR_DOES_NOT_EXIST: | 2419 | case EMILE_IMAGE_LOAD_ERROR_DOES_NOT_EXIST: |
2351 | return "File does not exist."; | 2420 | return "File does not exist."; |
2421 | |||
2352 | case EMILE_IMAGE_LOAD_ERROR_PERMISSION_DENIED: | 2422 | case EMILE_IMAGE_LOAD_ERROR_PERMISSION_DENIED: |
2353 | return "Permission to open file denied."; | 2423 | return "Permission to open file denied."; |
2424 | |||
2354 | case EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED: | 2425 | case EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED: |
2355 | return "Not enough memory to open file."; | 2426 | return "Not enough memory to open file."; |
2427 | |||
2356 | case EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE: | 2428 | case EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE: |
2357 | return "File is corrupted."; | 2429 | return "File is corrupted."; |
2430 | |||
2358 | case EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT: | 2431 | case EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT: |
2359 | return "Unexpected file format."; | 2432 | return "Unexpected file format."; |
2360 | } | 2433 | } |
2361 | return NULL; | 2434 | return NULL; |
2362 | } | 2435 | } |
diff --git a/src/lib/emile/emile_image.h b/src/lib/emile/emile_image.h index 7060cefbf4..bee101da91 100644 --- a/src/lib/emile/emile_image.h +++ b/src/lib/emile/emile_image.h | |||
@@ -33,14 +33,14 @@ typedef enum _Emile_Colorspace | |||
33 | EMILE_COLORSPACE_AGRY88 = 8, /**< AY 8bits Alpha and 8bits Grey, accessed 1 16bits at a time */ | 33 | EMILE_COLORSPACE_AGRY88 = 8, /**< AY 8bits Alpha and 8bits Grey, accessed 1 16bits at a time */ |
34 | EMILE_COLORSPACE_ETC1 = 9, /**< OpenGL ETC1 encoding of RGB texture (4 bit per pixel) @since 1.10 */ | 34 | EMILE_COLORSPACE_ETC1 = 9, /**< OpenGL ETC1 encoding of RGB texture (4 bit per pixel) @since 1.10 */ |
35 | EMILE_COLORSPACE_RGB8_ETC2 = 10, /**< OpenGL GL_COMPRESSED_RGB8_ETC2 texture compression format (4 bit per pixel) @since 1.10 */ | 35 | EMILE_COLORSPACE_RGB8_ETC2 = 10, /**< OpenGL GL_COMPRESSED_RGB8_ETC2 texture compression format (4 bit per pixel) @since 1.10 */ |
36 | EMILE_COLORSPACE_RGBA8_ETC2_EAC = 11, /**< OpenGL GL_COMPRESSED_RGBA8_ETC2_EAC texture compression format, supports alpha (8 bit per pixel) @since 1.10 */ | 36 | EMILE_COLORSPACE_RGBA8_ETC2_EAC = 11, /**< OpenGL GL_COMPRESSED_RGBA8_ETC2_EAC texture compression format, supports alpha (8 bit per pixel) @since 1.10 */ |
37 | EMILE_COLORSPACE_ETC1_ALPHA = 12, /**< ETC1 with alpha support using two planes: ETC1 RGB and ETC1 grey for alpha @since 1.11 */ | 37 | EMILE_COLORSPACE_ETC1_ALPHA = 12, /**< ETC1 with alpha support using two planes: ETC1 RGB and ETC1 grey for alpha @since 1.11 */ |
38 | EMILE_COLORSPACE_RGB_S3TC_DXT1 = 13, /**< OpenGL COMPRESSED_RGB_S3TC_DXT1_EXT format with RGB only. @since 1.11 */ | 38 | EMILE_COLORSPACE_RGB_S3TC_DXT1 = 13, /**< OpenGL COMPRESSED_RGB_S3TC_DXT1_EXT format with RGB only. @since 1.11 */ |
39 | EMILE_COLORSPACE_RGBA_S3TC_DXT1 = 14, /**< OpenGL COMPRESSED_RGBA_S3TC_DXT1_EXT format with RGBA punchthrough. @since 1.11 */ | 39 | EMILE_COLORSPACE_RGBA_S3TC_DXT1 = 14, /**< OpenGL COMPRESSED_RGBA_S3TC_DXT1_EXT format with RGBA punchthrough. @since 1.11 */ |
40 | EMILE_COLORSPACE_RGBA_S3TC_DXT2 = 15, /**< DirectDraw DXT2 format with premultiplied RGBA. Not supported by OpenGL itself. @since 1.11 */ | 40 | EMILE_COLORSPACE_RGBA_S3TC_DXT2 = 15, /**< DirectDraw DXT2 format with premultiplied RGBA. Not supported by OpenGL itself. @since 1.11 */ |
41 | EMILE_COLORSPACE_RGBA_S3TC_DXT3 = 16, /**< OpenGL COMPRESSED_RGBA_S3TC_DXT3_EXT format with RGBA. @since 1.11 */ | 41 | EMILE_COLORSPACE_RGBA_S3TC_DXT3 = 16, /**< OpenGL COMPRESSED_RGBA_S3TC_DXT3_EXT format with RGBA. @since 1.11 */ |
42 | EMILE_COLORSPACE_RGBA_S3TC_DXT4 = 17, /**< DirectDraw DXT4 format with premultiplied RGBA. Not supported by OpenGL itself. @since 1.11 */ | 42 | EMILE_COLORSPACE_RGBA_S3TC_DXT4 = 17, /**< DirectDraw DXT4 format with premultiplied RGBA. Not supported by OpenGL itself. @since 1.11 */ |
43 | EMILE_COLORSPACE_RGBA_S3TC_DXT5 = 18 /**< OpenGL COMPRESSED_RGBA_S3TC_DXT5_EXT format with RGBA. @since 1.11 */ | 43 | EMILE_COLORSPACE_RGBA_S3TC_DXT5 = 18 /**< OpenGL COMPRESSED_RGBA_S3TC_DXT5_EXT format with RGBA. @since 1.11 */ |
44 | } Emile_Colorspace; | 44 | } Emile_Colorspace; |
45 | 45 | ||
46 | /** | 46 | /** |
@@ -106,13 +106,13 @@ typedef enum _Emile_Image_Animated_Loop_Hint | |||
106 | */ | 106 | */ |
107 | typedef enum _Emile_Image_Load_Error | 107 | typedef enum _Emile_Image_Load_Error |
108 | { | 108 | { |
109 | EMILE_IMAGE_LOAD_ERROR_NONE = 0, /**< No error on load */ | 109 | EMILE_IMAGE_LOAD_ERROR_NONE = 0, /**< No error on load */ |
110 | EMILE_IMAGE_LOAD_ERROR_GENERIC = 1, /**< A non-specific error occurred */ | 110 | EMILE_IMAGE_LOAD_ERROR_GENERIC = 1, /**< A non-specific error occurred */ |
111 | EMILE_IMAGE_LOAD_ERROR_DOES_NOT_EXIST = 2, /**< File (or file path) does not exist */ | 111 | EMILE_IMAGE_LOAD_ERROR_DOES_NOT_EXIST = 2, /**< File (or file path) does not exist */ |
112 | EMILE_IMAGE_LOAD_ERROR_PERMISSION_DENIED = 3, /**< Permission denied to an existing file (or path) */ | 112 | EMILE_IMAGE_LOAD_ERROR_PERMISSION_DENIED = 3, /**< Permission denied to an existing file (or path) */ |
113 | EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED = 4, /**< Allocation of resources failure prevented load */ | 113 | EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED = 4, /**< Allocation of resources failure prevented load */ |
114 | EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE = 5, /**< File corrupt (but was detected as a known format) */ | 114 | EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE = 5, /**< File corrupt (but was detected as a known format) */ |
115 | EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT = 6 /**< File is not a known format */ | 115 | EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT = 6 /**< File is not a known format */ |
116 | } Emile_Image_Load_Error; /**< Emile image load error codes one can get - see emile_load_error_str() too. */ | 116 | } Emile_Image_Load_Error; /**< Emile image load error codes one can get - see emile_load_error_str() too. */ |
117 | 117 | ||
118 | /** | 118 | /** |
@@ -153,61 +153,63 @@ typedef struct _Emile_Image_Property Emile_Image_Property; | |||
153 | 153 | ||
154 | struct _Emile_Image_Property | 154 | struct _Emile_Image_Property |
155 | { | 155 | { |
156 | struct { | 156 | struct |
157 | unsigned char l, r, t, b; | 157 | { |
158 | } borders; | 158 | unsigned char l, r, t, b; |
159 | } borders; | ||
159 | 160 | ||
160 | const Emile_Colorspace *cspaces; | 161 | const Emile_Colorspace *cspaces; |
161 | Emile_Colorspace cspace; | 162 | Emile_Colorspace cspace; |
162 | 163 | ||
163 | Emile_Image_Encoding encoding; | 164 | Emile_Image_Encoding encoding; |
164 | 165 | ||
165 | unsigned int w; | 166 | unsigned int w; |
166 | unsigned int h; | 167 | unsigned int h; |
167 | unsigned int row_stride; | 168 | unsigned int row_stride; |
168 | 169 | ||
169 | unsigned char scale; | 170 | unsigned char scale; |
170 | 171 | ||
171 | Eina_Bool rotated; | 172 | Eina_Bool rotated; |
172 | Eina_Bool alpha; | 173 | Eina_Bool alpha; |
173 | Eina_Bool premul; | 174 | Eina_Bool premul; |
174 | Eina_Bool alpha_sparse; | 175 | Eina_Bool alpha_sparse; |
175 | 176 | ||
176 | Eina_Bool flipped; | 177 | Eina_Bool flipped; |
177 | Eina_Bool comp; | 178 | Eina_Bool comp; |
178 | }; | 179 | }; |
179 | 180 | ||
180 | struct _Emile_Image_Animated | 181 | struct _Emile_Image_Animated |
181 | { | 182 | { |
182 | Eina_List *frames; | 183 | Eina_List *frames; |
183 | 184 | ||
184 | Emile_Image_Animated_Loop_Hint loop_hint; | 185 | Emile_Image_Animated_Loop_Hint loop_hint; |
185 | 186 | ||
186 | int frame_count; | 187 | int frame_count; |
187 | int loop_count; | 188 | int loop_count; |
188 | int cur_frame; | 189 | int cur_frame; |
189 | 190 | ||
190 | Eina_Bool animated; | 191 | Eina_Bool animated; |
191 | }; | 192 | }; |
192 | 193 | ||
193 | struct _Emile_Image_Load_Opts | 194 | struct _Emile_Image_Load_Opts |
194 | { | 195 | { |
195 | Eina_Rectangle region; | 196 | Eina_Rectangle region; |
196 | struct { | 197 | struct |
197 | int src_x, src_y, src_w, src_h; | 198 | { |
198 | int dst_w, dst_h; | 199 | int src_x, src_y, src_w, src_h; |
199 | int smooth; | 200 | int dst_w, dst_h; |
200 | 201 | int smooth; | |
201 | /* This should have never been part of this structure, but we keep it | 202 | |
202 | for ABI/API compability with Evas_Loader */ | 203 | /* This should have never been part of this structure, but we keep it |
203 | Emile_Image_Scale_Hint scale_hint; | 204 | for ABI/API compability with Evas_Loader */ |
204 | } scale_load; | 205 | Emile_Image_Scale_Hint scale_hint; |
205 | double dpi; | 206 | } scale_load; |
206 | unsigned int w, h; | 207 | double dpi; |
207 | unsigned int degree; | 208 | unsigned int w, h; |
208 | int scale_down_by; | 209 | unsigned int degree; |
209 | 210 | int scale_down_by; | |
210 | Eina_Bool orientation; | 211 | |
212 | Eina_Bool orientation; | ||
211 | }; | 213 | }; |
212 | 214 | ||
213 | // FIXME: should we set region at load time, instead of head time | 215 | // FIXME: should we set region at load time, instead of head time |
@@ -224,11 +226,7 @@ struct _Emile_Image_Load_Opts | |||
224 | * | 226 | * |
225 | * @since 1.14 | 227 | * @since 1.14 |
226 | */ | 228 | */ |
227 | EAPI Emile_Image * | 229 | EAPI Emile_Image *emile_image_tgv_memory_open(Eina_Binbuf * source, Emile_Image_Load_Opts * opts, Emile_Image_Animated * animated, Emile_Image_Load_Error * error); |
228 | emile_image_tgv_memory_open(Eina_Binbuf *source, | ||
229 | Emile_Image_Load_Opts *opts, | ||
230 | Emile_Image_Animated *animated, | ||
231 | Emile_Image_Load_Error *error); | ||
232 | 230 | ||
233 | /** | 231 | /** |
234 | * Open a TGV image from a file. | 232 | * Open a TGV image from a file. |
@@ -241,11 +239,7 @@ emile_image_tgv_memory_open(Eina_Binbuf *source, | |||
241 | * | 239 | * |
242 | * @since 1.14 | 240 | * @since 1.14 |
243 | */ | 241 | */ |
244 | EAPI Emile_Image * | 242 | EAPI Emile_Image *emile_image_tgv_file_open(Eina_File * source, Emile_Image_Load_Opts * opts, Emile_Image_Animated * animated, Emile_Image_Load_Error * error); |
245 | emile_image_tgv_file_open(Eina_File *source, | ||
246 | Emile_Image_Load_Opts *opts, | ||
247 | Emile_Image_Animated *animated, | ||
248 | Emile_Image_Load_Error *error); | ||
249 | 243 | ||
250 | 244 | ||
251 | /** | 245 | /** |
@@ -259,11 +253,7 @@ emile_image_tgv_file_open(Eina_File *source, | |||
259 | * | 253 | * |
260 | * @since 1.14 | 254 | * @since 1.14 |
261 | */ | 255 | */ |
262 | EAPI Emile_Image * | 256 | EAPI Emile_Image *emile_image_jpeg_memory_open(Eina_Binbuf * source, Emile_Image_Load_Opts * opts, Emile_Image_Animated * animated, Emile_Image_Load_Error * error); |
263 | emile_image_jpeg_memory_open(Eina_Binbuf *source, | ||
264 | Emile_Image_Load_Opts *opts, | ||
265 | Emile_Image_Animated *animated, | ||
266 | Emile_Image_Load_Error *error); | ||
267 | 257 | ||
268 | /** | 258 | /** |
269 | * Open a JPEG image from file. | 259 | * Open a JPEG image from file. |
@@ -276,11 +266,7 @@ emile_image_jpeg_memory_open(Eina_Binbuf *source, | |||
276 | * | 266 | * |
277 | * @since 1.14 | 267 | * @since 1.14 |
278 | */ | 268 | */ |
279 | EAPI Emile_Image * | 269 | EAPI Emile_Image *emile_image_jpeg_file_open(Eina_File * source, Emile_Image_Load_Opts * opts, Emile_Image_Animated * animated, Emile_Image_Load_Error * error); |
280 | emile_image_jpeg_file_open(Eina_File *source, | ||
281 | Emile_Image_Load_Opts *opts, | ||
282 | Emile_Image_Animated *animated, | ||
283 | Emile_Image_Load_Error *error); | ||
284 | 270 | ||
285 | /** | 271 | /** |
286 | * Read the header of an image to fill Emile_Image_Property. | 272 | * Read the header of an image to fill Emile_Image_Property. |
@@ -293,11 +279,7 @@ emile_image_jpeg_file_open(Eina_File *source, | |||
293 | * | 279 | * |
294 | * @since 1.14 | 280 | * @since 1.14 |
295 | */ | 281 | */ |
296 | EAPI Eina_Bool | 282 | EAPI Eina_Bool emile_image_head(Emile_Image * image, Emile_Image_Property * prop, unsigned int property_size, Emile_Image_Load_Error * error); |
297 | emile_image_head(Emile_Image *image, | ||
298 | Emile_Image_Property *prop, | ||
299 | unsigned int property_size, | ||
300 | Emile_Image_Load_Error *error); | ||
301 | 283 | ||
302 | /** | 284 | /** |
303 | * Read the pixels from an image file. | 285 | * Read the pixels from an image file. |
@@ -311,12 +293,7 @@ emile_image_head(Emile_Image *image, | |||
311 | * | 293 | * |
312 | * @since 1.14 | 294 | * @since 1.14 |
313 | */ | 295 | */ |
314 | EAPI Eina_Bool | 296 | EAPI Eina_Bool emile_image_data(Emile_Image * image, Emile_Image_Property * prop, unsigned int property_size, void *pixels, Emile_Image_Load_Error * error); |
315 | emile_image_data(Emile_Image *image, | ||
316 | Emile_Image_Property *prop, | ||
317 | unsigned int property_size, | ||
318 | void *pixels, | ||
319 | Emile_Image_Load_Error *error); | ||
320 | 297 | ||
321 | /** | 298 | /** |
322 | * Close an opened image handler. | 299 | * Close an opened image handler. |
@@ -325,8 +302,7 @@ emile_image_data(Emile_Image *image, | |||
325 | * | 302 | * |
326 | * @since 1.14 | 303 | * @since 1.14 |
327 | */ | 304 | */ |
328 | EAPI void | 305 | EAPI void emile_image_close(Emile_Image * source); |
329 | emile_image_close(Emile_Image *source); | ||
330 | 306 | ||
331 | /** | 307 | /** |
332 | * Convert an error code related to an image handler into a meaningful string. | 308 | * Convert an error code related to an image handler into a meaningful string. |
@@ -337,9 +313,7 @@ emile_image_close(Emile_Image *source); | |||
337 | * | 313 | * |
338 | * @since 1.14 | 314 | * @since 1.14 |
339 | */ | 315 | */ |
340 | EAPI const char * | 316 | EAPI const char *emile_load_error_str(Emile_Image * source, Emile_Image_Load_Error error); |
341 | emile_load_error_str(Emile_Image *source, | ||
342 | Emile_Image_Load_Error error); | ||
343 | 317 | ||
344 | /** | 318 | /** |
345 | * @} | 319 | * @} |
diff --git a/src/lib/emile/emile_main.c b/src/lib/emile/emile_main.c index a082304656..d55782e17a 100644 --- a/src/lib/emile/emile_main.c +++ b/src/lib/emile/emile_main.c | |||
@@ -1,17 +1,17 @@ | |||
1 | #ifdef HAVE_CONFIG_H | 1 | #ifdef HAVE_CONFIG_H |
2 | # include <config.h> | 2 | #include <config.h> |
3 | #endif /* ifdef HAVE_CONFIG_H */ | 3 | #endif /* ifdef HAVE_CONFIG_H */ |
4 | 4 | ||
5 | #ifdef HAVE_GNUTLS | 5 | #ifdef HAVE_GNUTLS |
6 | # include <gnutls/gnutls.h> | 6 | #include <gnutls/gnutls.h> |
7 | # include <gnutls/x509.h> | 7 | #include <gnutls/x509.h> |
8 | # include <gcrypt.h> | 8 | #include <gcrypt.h> |
9 | #endif /* ifdef HAVE_GNUTLS */ | 9 | #endif /* ifdef HAVE_GNUTLS */ |
10 | 10 | ||
11 | #ifdef HAVE_OPENSSL | 11 | #ifdef HAVE_OPENSSL |
12 | # include <openssl/ssl.h> | 12 | #include <openssl/ssl.h> |
13 | # include <openssl/err.h> | 13 | #include <openssl/err.h> |
14 | # include <openssl/evp.h> | 14 | #include <openssl/evp.h> |
15 | #endif /* ifdef HAVE_OPENSSL */ | 15 | #endif /* ifdef HAVE_OPENSSL */ |
16 | 16 | ||
17 | #include <Eina.h> | 17 | #include <Eina.h> |
@@ -26,9 +26,11 @@ int _emile_log_dom_global = -1; | |||
26 | EAPI Eina_Bool | 26 | EAPI Eina_Bool |
27 | emile_cipher_init(void) | 27 | emile_cipher_init(void) |
28 | { | 28 | { |
29 | if (_emile_cipher_inited) return EINA_TRUE; | 29 | if (_emile_cipher_inited) |
30 | return EINA_TRUE; | ||
30 | 31 | ||
31 | if (!_emile_cipher_init()) return EINA_FALSE; | 32 | if (!_emile_cipher_init()) |
33 | return EINA_FALSE; | ||
32 | 34 | ||
33 | _emile_cipher_inited = EINA_TRUE; | 35 | _emile_cipher_inited = EINA_TRUE; |
34 | 36 | ||
@@ -65,13 +67,11 @@ emile_init(void) | |||
65 | goto shutdown_eina; | 67 | goto shutdown_eina; |
66 | } | 68 | } |
67 | 69 | ||
68 | eina_log_timing(_emile_log_dom_global, | 70 | eina_log_timing(_emile_log_dom_global, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); |
69 | EINA_LOG_STATE_STOP, | ||
70 | EINA_LOG_STATE_INIT); | ||
71 | 71 | ||
72 | return _emile_init_count; | 72 | return _emile_init_count; |
73 | 73 | ||
74 | shutdown_eina: | 74 | shutdown_eina: |
75 | eina_shutdown(); | 75 | eina_shutdown(); |
76 | 76 | ||
77 | return --_emile_init_count; | 77 | return --_emile_init_count; |
@@ -83,9 +83,7 @@ emile_shutdown(void) | |||
83 | if (--_emile_init_count != 0) | 83 | if (--_emile_init_count != 0) |
84 | return _emile_init_count; | 84 | return _emile_init_count; |
85 | 85 | ||
86 | eina_log_timing(_emile_log_dom_global, | 86 | eina_log_timing(_emile_log_dom_global, EINA_LOG_STATE_START, EINA_LOG_STATE_SHUTDOWN); |
87 | EINA_LOG_STATE_START, | ||
88 | EINA_LOG_STATE_SHUTDOWN); | ||
89 | 87 | ||
90 | if (_emile_cipher_inited) | 88 | if (_emile_cipher_inited) |
91 | { | 89 | { |
@@ -122,13 +120,7 @@ emile_shutdown(void) | |||
122 | /* For the moment, we have just one function shared accross both cipher | 120 | /* For the moment, we have just one function shared accross both cipher |
123 | * backend, so here it is. */ | 121 | * backend, so here it is. */ |
124 | Eina_Bool | 122 | Eina_Bool |
125 | emile_pbkdf2_sha1(const char *key, | 123 | emile_pbkdf2_sha1(const char *key, unsigned int key_len, const unsigned char *salt, unsigned int salt_len, unsigned int iter, unsigned char *res, unsigned int res_len) |
126 | unsigned int key_len, | ||
127 | const unsigned char *salt, | ||
128 | unsigned int salt_len, | ||
129 | unsigned int iter, | ||
130 | unsigned char *res, | ||
131 | unsigned int res_len) | ||
132 | { | 124 | { |
133 | Eina_Binbuf *step1, *step2; | 125 | Eina_Binbuf *step1, *step2; |
134 | unsigned char *buf; | 126 | unsigned char *buf; |
@@ -140,12 +132,15 @@ emile_pbkdf2_sha1(const char *key, | |||
140 | unsigned int i, j, k; | 132 | unsigned int i, j, k; |
141 | 133 | ||
142 | buf = alloca(salt_len + 4); | 134 | buf = alloca(salt_len + 4); |
143 | if (!buf) return EINA_FALSE; | 135 | if (!buf) |
136 | return EINA_FALSE; | ||
144 | 137 | ||
145 | step1 = eina_binbuf_manage_new(buf, salt_len + 4, EINA_TRUE); | 138 | step1 = eina_binbuf_manage_new(buf, salt_len + 4, EINA_TRUE); |
146 | if (!step1) return EINA_FALSE; | 139 | if (!step1) |
140 | return EINA_FALSE; | ||
147 | step2 = eina_binbuf_manage_new(digest, 20, EINA_TRUE); | 141 | step2 = eina_binbuf_manage_new(digest, 20, EINA_TRUE); |
148 | if (!step2) return EINA_FALSE; | 142 | if (!step2) |
143 | return EINA_FALSE; | ||
149 | 144 | ||
150 | for (i = 1; len; len -= tmp_len, p += tmp_len, i++) | 145 | for (i = 1; len; len -= tmp_len, p += tmp_len, i++) |
151 | { | 146 | { |
@@ -178,3 +173,4 @@ emile_pbkdf2_sha1(const char *key, | |||
178 | 173 | ||
179 | return EINA_TRUE; | 174 | return EINA_TRUE; |
180 | } | 175 | } |
176 | |||