summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_image.c
diff options
context:
space:
mode:
authorWonguk Jeong <wonguk.jeong@samsung.com>2014-06-29 13:04:16 +0200
committerCedric BAIL <c.bail@partner.samsung.com>2014-06-29 13:04:16 +0200
commit573f477272fb842f2ed3f1c951fd1c77d6936b59 (patch)
treec78a8b7bf464e56728b3f6f0fd921252d84b7d33 /src/tests/evas/evas_test_image.c
parent2c97212736d1d30eba8b499cc4eed93fee27b95a (diff)
jpeg laoder: exif orientation test added
Summary: currently, normal orientation tests are only added. I'm going to add flipped orientation tests as well after I put related code in jpeg loader (currently it's not supported) Reviewers: raster, cedric, jpeg CC: seoz, cedric Differential Revision: https://phab.enlightenment.org/D1098
Diffstat (limited to 'src/tests/evas/evas_test_image.c')
-rw-r--r--src/tests/evas/evas_test_image.c119
1 files changed, 117 insertions, 2 deletions
diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index 1f71399b22..bd7b5450e9 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -9,13 +9,15 @@
9#include "Evas.h" 9#include "Evas.h"
10#include "evas_tests_helpers.h" 10#include "evas_tests_helpers.h"
11 11
12#define TESTS_IMG_DIR TESTS_SRC_DIR"/images"
13
12#if 0 14#if 0
13static const char * 15static const char *
14_test_image_get(const char *name) 16_test_image_get(const char *name)
15{ 17{
16 static char filename[PATH_MAX]; 18 static char filename[PATH_MAX];
17 19
18 snprintf(filename, PATH_MAX, TESTS_SRC_DIR"/images/%s", name); 20 snprintf(filename, PATH_MAX, TESTS_IMG_DIR"/%s", name);
19 21
20 return filename; 22 return filename;
21} 23}
@@ -30,7 +32,7 @@ START_TEST(evas_object_image_loader)
30 32
31 o = evas_object_image_add(e); 33 o = evas_object_image_add(e);
32 34
33 it = eina_file_direct_ls(TESTS_SRC_DIR"/images/"); 35 it = eina_file_direct_ls(TESTS_IMG_DIR);
34 EINA_ITERATOR_FOREACH(it, file) 36 EINA_ITERATOR_FOREACH(it, file)
35 { 37 {
36 int w, h; 38 int w, h;
@@ -49,7 +51,120 @@ START_TEST(evas_object_image_loader)
49} 51}
50END_TEST 52END_TEST
51 53
54typedef struct _orientation_Test_Res {
55 const char *img;
56 int flag;
57 int (*compare_func)(const uint32_t *d1, const uint32_t *d2, int w2, int h2);
58} Orientation_Test_Res;
59
60static int _compare_img(const uint32_t *d1, const uint32_t *d2, int w2, int h2)
61{
62 return memcmp(d1, d2, w2 * h2 * 4);
63}
64
65static int _compare_img_90(const uint32_t *d1, const uint32_t *d2, int w2, int h2)
66{
67 int x, y;
68 int r;
69
70 for (x = w2 - 1; x >= 0; x--)
71 {
72 for (y = 0; y < h2; y++)
73 {
74 r = *d1 - *(d2 + x + y * w2);
75 if (r != 0) return r;
76 d1++;
77 }
78 }
79
80 return 0;
81}
82
83static int _compare_img_180(const uint32_t *d1, const uint32_t *d2, int w2, int h2)
84{
85 int x, y;
86 int r;
87
88 for (y = h2 - 1; y >= 0; y--)
89 {
90 for (x = w2 - 1; x >= 0; x--)
91 {
92 r = *d1 - *(d2 + x + y * w2);
93 if (r != 0) return r;
94 d1++;
95 }
96 }
97
98 return 0;
99}
100
101static int _compare_img_270(const uint32_t *d1, const uint32_t *d2, int w2, int h2)
102{
103 int x, y;
104 int r;
105
106 for (x = 0; x < w2; x++)
107 {
108 for (y = h2 - 1; y >= 0; y--)
109 {
110 r = *d1 - *(d2 + x + y * w2);
111 if (r != 0) return r;
112 d1++;
113 }
114 }
115
116 return 0;
117}
118
119/* TODO: flip test code for 2, 4, 5, 7 */
120START_TEST(evas_object_image_loader_orientation)
121{
122 Evas *e = _setup_evas();
123 Evas_Object *orig, *rot;
124 Orientation_Test_Res res[] = {
125 {TESTS_IMG_DIR"/Light_exif.jpg", 1, _compare_img},
126 {TESTS_IMG_DIR"/Light_exif_90.jpg", 6, _compare_img_90},
127 {TESTS_IMG_DIR"/Light_exif_180.jpg", 3, _compare_img_180},
128 {TESTS_IMG_DIR"/Light_exif_270.jpg", 8, _compare_img_270},
129 {NULL, 0, NULL}
130 };
131 int w, h, r_w, r_h;
132 const uint32_t *d, *r_d;
133 int i;
134
135 orig = evas_object_image_add(e);
136 evas_object_image_file_set(orig, TESTS_IMG_DIR"/Light.jpg", NULL);
137 fail_if(evas_object_image_load_error_get(orig) != EVAS_LOAD_ERROR_NONE);
138 evas_object_image_size_get(orig, &w, &h);
139 fail_if(w == 0 || h == 0);
140 d = evas_object_image_data_get(orig, EINA_FALSE);
141
142 rot = evas_object_image_add(e);
143 evas_object_image_load_orientation_set(rot, EINA_TRUE);
144
145 for (i = 0; res[i].img; i++)
146 {
147 evas_object_image_file_set(rot, res[i].img, NULL);
148 fail_if(evas_object_image_load_error_get(rot) != EVAS_LOAD_ERROR_NONE);
149 evas_object_image_size_get(rot, &r_w, &r_h);
150 fail_if(w * h != r_w * r_h);
151
152 r_d = evas_object_image_data_get(rot, EINA_FALSE);
153
154 fail_if(res[i].compare_func(d, r_d, r_w, r_h),
155 "Image orientation test failed: exif orientation flag: %d\n", res[i].flag);
156 }
157
158 evas_object_del(orig);
159 evas_object_del(rot);
160
161 evas_free(e);
162 evas_shutdown();
163}
164END_TEST
165
52void evas_test_image_object(TCase *tc) 166void evas_test_image_object(TCase *tc)
53{ 167{
54 tcase_add_test(tc, evas_object_image_loader); 168 tcase_add_test(tc, evas_object_image_loader);
169 tcase_add_test(tc, evas_object_image_loader_orientation);
55} 170}