summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_image.c
diff options
context:
space:
mode:
authorjiin.moon <jiin.moon@samsung.com>2015-06-03 10:57:27 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-06-03 13:46:44 +0200
commit63a12d7d26f53b22b7794eb61897de930614bac7 (patch)
tree707c69c48c78d36524828931cf029cfd9edd54b2 /src/tests/evas/evas_test_image.c
parent0c729faf688a518f10f75a890e7364d4f1e76939 (diff)
emile: fix region load for jpeg image with orientation different set.
Summary: If you try to load the jpeg image with an orientation mode defined using elm_photocam, you can see the broken image(in canse of 90 degree) or even segmentation fault can happen (in case of 180,270 degree) @fix Test Plan: photocam menu on elementary_test Reviewers: Hermet, cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2593 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/evas/evas_test_image.c')
-rw-r--r--src/tests/evas/evas_test_image.c138
1 files changed, 126 insertions, 12 deletions
diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index ca7a0cbbf9..cfb0f9402c 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -100,11 +100,13 @@ START_TEST(evas_object_image_loader)
100} 100}
101END_TEST 101END_TEST
102 102
103typedef struct _orientation_Test_Res { 103typedef struct _Orientation_Test_Res Orientation_Test_Res;
104struct _Orientation_Test_Res {
104 const char *img; 105 const char *img;
105 const char *desc; 106 const char *desc;
107 Evas_Image_Orient orient;
106 int (*compare_func)(const uint32_t *d1, const uint32_t *d2, int w2, int h2); 108 int (*compare_func)(const uint32_t *d1, const uint32_t *d2, int w2, int h2);
107} Orientation_Test_Res; 109};
108 110
109typedef struct _orient_Test { 111typedef struct _orient_Test {
110 Evas_Image_Orient orient; 112 Evas_Image_Orient orient;
@@ -247,16 +249,16 @@ START_TEST(evas_object_image_loader_orientation)
247{ 249{
248 Evas *e = _setup_evas(); 250 Evas *e = _setup_evas();
249 Evas_Object *orig, *rot; 251 Evas_Object *orig, *rot;
250 Orientation_Test_Res res[] = { 252 static const Orientation_Test_Res res[] = {
251 {TESTS_IMG_DIR"/Light_exif.jpg", "Original", _compare_img}, 253 { TESTS_IMG_DIR"/Light_exif.jpg", "Original", EVAS_IMAGE_ORIENT_NONE, _compare_img },
252 {TESTS_IMG_DIR"/Light_exif_flip_h.jpg", "Flip horizontally", _compare_img_flip_h}, 254 { TESTS_IMG_DIR"/Light_exif_flip_h.jpg", "Flip horizontally", EVAS_IMAGE_FLIP_HORIZONTAL, _compare_img_flip_h },
253 {TESTS_IMG_DIR"/Light_exif_180.jpg", "Rotate 180° CW", _compare_img_180}, 255 { TESTS_IMG_DIR"/Light_exif_180.jpg", "Rotate 180° CW", EVAS_IMAGE_ORIENT_180, _compare_img_180 },
254 {TESTS_IMG_DIR"/Light_exif_flip_v.jpg", "Flip vertically", _compare_img_flip_v}, 256 { TESTS_IMG_DIR"/Light_exif_flip_v.jpg", "Flip vertically", EVAS_IMAGE_FLIP_VERTICAL, _compare_img_flip_v },
255 {TESTS_IMG_DIR"/Light_exif_transpose.jpg", "Transpose", _compare_img_transpose}, 257 { TESTS_IMG_DIR"/Light_exif_transpose.jpg", "Transpose", EVAS_IMAGE_FLIP_TRANSPOSE, _compare_img_transpose },
256 {TESTS_IMG_DIR"/Light_exif_90.jpg", "Rotate 90° CW", _compare_img_90}, 258 { TESTS_IMG_DIR"/Light_exif_90.jpg", "Rotate 90° CW", EVAS_IMAGE_ORIENT_90, _compare_img_90 },
257 {TESTS_IMG_DIR"/Light_exif_transverse.jpg", "Transverse", _compare_img_transverse}, 259 { TESTS_IMG_DIR"/Light_exif_transverse.jpg", "Transverse", EVAS_IMAGE_FLIP_TRANSVERSE, _compare_img_transverse },
258 {TESTS_IMG_DIR"/Light_exif_270.jpg", "Rotate 90° CCW", _compare_img_270}, 260 { TESTS_IMG_DIR"/Light_exif_270.jpg", "Rotate 90° CCW", EVAS_IMAGE_ORIENT_270, _compare_img_270 },
259 {NULL, NULL, NULL} 261 { NULL, NULL, EVAS_IMAGE_ORIENT_NONE, NULL }
260 }; 262 };
261 int w, h, r_w, r_h; 263 int w, h, r_w, r_h;
262 const uint32_t *d, *r_d; 264 const uint32_t *d, *r_d;
@@ -528,6 +530,117 @@ START_TEST(evas_object_image_buggy)
528} 530}
529END_TEST 531END_TEST
530 532
533static void check_rotate_region(Evas_Image_Orient orientation, int *r_x, int *r_y, int *r_w, int *r_h, int w, int h)
534{
535 int tmp;
536
537 switch (orientation)
538 {
539 case EVAS_IMAGE_FLIP_HORIZONTAL:
540 *r_x = w - *r_w;
541 break;
542 case EVAS_IMAGE_FLIP_VERTICAL:
543 *r_y = h - *r_h;
544 break;
545 case EVAS_IMAGE_ORIENT_180:
546 *r_x = w - *r_w;
547 *r_y = h - *r_h;
548 break;
549 case EVAS_IMAGE_ORIENT_90:
550 tmp = *r_x;
551 *r_x = w - (*r_y + *r_h);
552 *r_y = tmp;
553 tmp = *r_w;
554 *r_w = *r_h;
555 *r_h = tmp;
556 break;
557 case EVAS_IMAGE_ORIENT_270:
558 tmp = *r_y;
559 *r_y = h - (*r_x + *r_w);
560 *r_x = tmp;
561 tmp = *r_w;
562 *r_w = *r_h;
563 *r_h = tmp;
564 break;
565 case EVAS_IMAGE_FLIP_TRANSPOSE:
566 tmp = *r_x;
567 *r_x = *r_y;
568 *r_y = tmp;
569 tmp = *r_w;
570 *r_w = *r_h;
571 *r_h = tmp;
572 break;
573 case EVAS_IMAGE_FLIP_TRANSVERSE:
574 tmp = *r_x;
575 *r_x = w - (*r_y + *r_h);
576 *r_y = h - (tmp + *r_w);
577 tmp = *r_w;
578 *r_w = *r_h;
579 *r_h = tmp;
580 break;
581 case EVAS_IMAGE_ORIENT_0:
582 break;
583 }
584}
585
586
587START_TEST(evas_object_image_partially_load_orientation)
588{
589 static const Orientation_Test_Res res[] = {
590 { TESTS_IMG_DIR"/Light_exif.jpg", "Original", EVAS_IMAGE_ORIENT_NONE, _compare_img },
591 { TESTS_IMG_DIR"/Light_exif_flip_h.jpg", "Flip horizontally", EVAS_IMAGE_FLIP_HORIZONTAL, _compare_img_flip_h },
592 { TESTS_IMG_DIR"/Light_exif_180.jpg", "Rotate 180° CW", EVAS_IMAGE_ORIENT_180, _compare_img_180 },
593 { TESTS_IMG_DIR"/Light_exif_flip_v.jpg", "Flip vertically", EVAS_IMAGE_FLIP_VERTICAL, _compare_img_flip_v },
594 { TESTS_IMG_DIR"/Light_exif_transpose.jpg", "Transpose", EVAS_IMAGE_FLIP_TRANSPOSE, _compare_img_transpose },
595 { TESTS_IMG_DIR"/Light_exif_90.jpg", "Rotate 90° CW", EVAS_IMAGE_ORIENT_90, _compare_img_90 },
596 { TESTS_IMG_DIR"/Light_exif_transverse.jpg", "Transverse", EVAS_IMAGE_FLIP_TRANSVERSE, _compare_img_transverse },
597 { TESTS_IMG_DIR"/Light_exif_270.jpg", "Rotate 90° CCW", EVAS_IMAGE_ORIENT_270, _compare_img_270 },
598 { NULL, NULL, EVAS_IMAGE_ORIENT_NONE, NULL }
599 };
600
601 Evas *e = _setup_evas();
602 Evas_Object *orig, *rot;
603 int x, y, w, h, r_w, r_h;
604 int region_x, region_y, region_w, region_h;
605 const uint32_t *d, *r_d;
606 int i;
607
608 orig = evas_object_image_add(e);
609 evas_object_image_file_set(orig, TESTS_IMG_DIR"/Light.jpg", NULL);
610 fail_if(evas_object_image_load_error_get(orig) != EVAS_LOAD_ERROR_NONE);
611 evas_object_image_size_get(orig, &w, &h);
612 x = 0; y = 0; w = w / 2; h = h / 2;;
613 evas_object_image_load_region_set(orig, x, y, w, h);
614 evas_object_image_size_get(orig, &w, &h);
615 d = evas_object_image_data_get(orig, EINA_FALSE);
616 for (i = 0; res[i].img; i++)
617 {
618 region_x = x;
619 region_y = y;
620 region_w = w;
621 region_h = h;
622 rot = evas_object_image_add(e);
623 evas_object_image_load_orientation_set(rot, EINA_TRUE);
624 evas_object_image_file_set(rot, res[i].img, NULL);
625 fail_if(evas_object_image_load_error_get(rot) != EVAS_LOAD_ERROR_NONE);
626 evas_object_image_size_get(rot, &r_w, &r_h);
627 check_rotate_region(res[i].orient, &region_x, &region_y, &region_w, &region_h, r_w, r_h);
628 evas_object_image_load_region_set(rot, region_x, region_y, region_w, region_h);
629 evas_object_image_size_get(rot, &r_w, &r_h);
630 fail_if(w * h != r_w * r_h);
631 r_d = evas_object_image_data_get(rot, EINA_FALSE);
632 fail_if(res[i].compare_func(d, r_d, r_w, r_h),
633 "Image orientation partially load test failed: exif orientation flag: %s\n", res[i].desc);
634 evas_object_del(rot);
635 }
636
637 evas_object_del(orig);
638
639 evas_free(e);
640 evas_shutdown();
641}
642END_TEST
643
531void evas_test_image_object(TCase *tc) 644void evas_test_image_object(TCase *tc)
532{ 645{
533 tcase_add_test(tc, evas_object_image_loader); 646 tcase_add_test(tc, evas_object_image_loader);
@@ -540,4 +653,5 @@ void evas_test_image_object(TCase *tc)
540 tcase_add_test(tc, evas_object_image_all_loader_data); 653 tcase_add_test(tc, evas_object_image_all_loader_data);
541 tcase_add_test(tc, evas_object_image_buggy); 654 tcase_add_test(tc, evas_object_image_buggy);
542#endif 655#endif
656 tcase_add_test(tc, evas_object_image_partially_load_orientation);
543} 657}