summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_image.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-09-01 21:46:42 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-09-06 16:54:53 +0900
commit8ee431572da636f0199f25b525c39094b7760cdf (patch)
tree99eb37e2370c554793f5b37e15fb5b92e580e688 /src/tests/evas/evas_test_image.c
parent1773ba5d827ae3b07aafed5532075d779efddb48 (diff)
evas: Switch EO APIs to Eina_Slice for gfx buffers (map)
This adds a plane and eina slice argument to the map/unmap functions, instead of void_ptr + length.
Diffstat (limited to 'src/tests/evas/evas_test_image.c')
-rw-r--r--src/tests/evas/evas_test_image.c94
1 files changed, 43 insertions, 51 deletions
diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index 3d2f240680..8743e05b85 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -659,15 +659,13 @@ START_TEST(evas_object_image_map_unmap)
659{ 659{
660 Evas *e = _setup_evas(); 660 Evas *e = _setup_evas();
661 Evas_Object *o, *o2; 661 Evas_Object *o, *o2;
662 void *data; 662 int stride, w, h, rx, ry, rw, rh;
663 int len, stride;
664 int w, h, rx, ry, rw, rh;
665 Efl_Gfx_Colorspace cs; 663 Efl_Gfx_Colorspace cs;
666 Eina_Tmpstr *tmp; 664 Eina_Tmpstr *tmp;
667 int fd; 665 int fd;
668 uint32_t *data32; 666 uint32_t *data32;
669 uint8_t *data8;
670 Eina_Bool all_white = 1, all_transparent = 1; 667 Eina_Bool all_white = 1, all_transparent = 1;
668 Eina_Rw_Slice slice;
671 669
672 const char *imgpath = TESTS_IMG_DIR "/Pic4.png"; 670 const char *imgpath = TESTS_IMG_DIR "/Pic4.png";
673 671
@@ -682,26 +680,23 @@ START_TEST(evas_object_image_map_unmap)
682 rh = (h / 2) & ~3; 680 rh = (h / 2) & ~3;
683 681
684 // same cspace, full image 682 // same cspace, full image
685 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, cs, &stride); 683 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, cs, 0, &stride));
686 fail_if(!data); 684 fail_if(!slice.len || !slice.mem);
687 fail_if(!len);
688 fail_if(!stride); 685 fail_if(!stride);
689 efl_gfx_buffer_unmap(o, data, len); 686 efl_gfx_buffer_unmap(o, &slice);
690 687
691 // same cspace, partial image 688 // same cspace, partial image
692 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, cs, &stride); 689 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, cs, 0, &stride));
693 fail_if(!data); 690 fail_if(!slice.len || !slice.mem);
694 fail_if(!len);
695 fail_if(!stride); 691 fail_if(!stride);
696 efl_gfx_buffer_unmap(o, data, len); 692 efl_gfx_buffer_unmap(o, &slice);
697 693
698 // argb cspace, full image 694 // argb cspace, full image
699 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, &stride); 695 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride));
700 fail_if(!data); 696 fail_if(!slice.len || !slice.mem);
701 fail_if(!len);
702 fail_if(!stride); 697 fail_if(!stride);
703 data32 = data; 698 data32 = slice.mem;
704 for (int k = 0; (k < len) && (all_white || all_transparent); k++) 699 for (int k = 0; (k < slice.len) && (all_white || all_transparent); k++)
705 { 700 {
706 if (data32[k]) 701 if (data32[k])
707 all_transparent = 0; 702 all_transparent = 0;
@@ -709,49 +704,45 @@ START_TEST(evas_object_image_map_unmap)
709 all_white = 0; 704 all_white = 0;
710 } 705 }
711 fail_if(all_white || all_transparent); 706 fail_if(all_white || all_transparent);
712 efl_gfx_buffer_unmap(o, data, len); 707 efl_gfx_buffer_unmap(o, &slice);
713 708
714 // argb cspace, partial image 709 // argb cspace, partial image
715 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, EFL_GFX_COLORSPACE_ARGB8888, &stride); 710 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride));
716 fail_if(!data); 711 fail_if(!slice.len || !slice.mem);
717 fail_if(!len);
718 fail_if(!stride); 712 fail_if(!stride);
719 efl_gfx_buffer_unmap(o, data, len); 713 efl_gfx_buffer_unmap(o, &slice);
720 714
721 // argb cspace, partial image, write 715 // argb cspace, partial image, write
722 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_WRITE, rx, ry, rw, rh, EFL_GFX_COLORSPACE_ARGB8888, &stride); 716 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_WRITE, rx, ry, rw, rh, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride));
723 fail_if(!data); 717 fail_if(!slice.len || !slice.mem);
724 fail_if(!len);
725 fail_if(!stride); 718 fail_if(!stride);
726 data32 = data; 719 data32 = slice.mem;
727 for (int y = 0; y < rh; y += 2) 720 for (int y = 0; y < rh; y += 2)
728 for (int x = 0; x < rw; x++) 721 for (int x = 0; x < rw; x++)
729 { 722 {
730 data32[y*stride/4 + x] = 0xFF00FF00; 723 data32[y*stride/4 + x] = 0xFF00FF00;
731 data32[(y+1)*stride/4 + x] = 0xFFFF0000; 724 data32[(y+1)*stride/4 + x] = 0xFFFF0000;
732 } 725 }
733 efl_gfx_buffer_unmap(o, data, len); 726 efl_gfx_buffer_unmap(o, &slice);
734 727
735 // argb cspace, partial image, write 728 // argb cspace, partial image, write
736 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ| EFL_GFX_BUFFER_ACCESS_MODE_WRITE, 729 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ| EFL_GFX_BUFFER_ACCESS_MODE_WRITE,
737 rx, ry, rw, rh / 2, EFL_GFX_COLORSPACE_GRY8, &stride); 730 rx, ry, rw, rh / 2, EFL_GFX_COLORSPACE_GRY8, 0, &stride));
738 fail_if(!data); 731 fail_if(!slice.len || !slice.mem);
739 fail_if(!len);
740 fail_if(!stride); 732 fail_if(!stride);
741 data8 = data;
742 for (int y = 0; y < rh / 4; y++) 733 for (int y = 0; y < rh / 4; y++)
743 for (int x = 0; x < rw; x++) 734 for (int x = 0; x < rw; x++)
744 data8[y*stride + x] = x & 0xFF; 735 slice.bytes[y*stride + x] = x & 0xFF;
745 efl_gfx_buffer_unmap(o, data, len); 736 efl_gfx_buffer_unmap(o, &slice);
746 737
747 // save file, verify its pixels 738 // save file, verify its pixels
748 fd = eina_file_mkstemp("/tmp/evas-test.XXXXXX.png", &tmp); 739 fd = eina_file_mkstemp("/tmp/evas-test.XXXXXX.png", &tmp);
749 close(fd); 740 close(fd);
750 if (efl_file_save(o, tmp, NULL, NULL)) 741 if (efl_file_save(o, tmp, NULL, NULL))
751 { 742 {
752 int w2, h2, stride2, len2; 743 Eina_Rw_Slice sorig, sdest;
753 uint32_t *data2, *orig; 744 int w2, h2, stride2, x, y;
754 int x, y; 745 uint32_t *dest, *orig;
755 746
756 o2 = efl_add(EFL_CANVAS_IMAGE_CLASS, e); 747 o2 = efl_add(EFL_CANVAS_IMAGE_CLASS, e);
757 efl_file_set(o2, tmp, NULL); 748 efl_file_set(o2, tmp, NULL);
@@ -763,20 +754,21 @@ START_TEST(evas_object_image_map_unmap)
763 fail_if(w2 != w); 754 fail_if(w2 != w);
764 fail_if(h2 != h); 755 fail_if(h2 != h);
765 756
766 orig = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, &stride); 757 fail_if(!efl_gfx_buffer_map(o, &sorig, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride));
767 fail_if(!orig); 758 fail_if(!sorig.len || !sorig.mem);
768 fail_if(!len);
769 fail_if(!stride); 759 fail_if(!stride);
770 760
771 data2 = efl_gfx_buffer_map(o2, &len2, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w2, h2, EFL_GFX_COLORSPACE_ARGB8888, &stride2); 761 fail_if(!efl_gfx_buffer_map(o2, &sdest, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w2, h2, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride2));
772 fail_if(!data2); 762 fail_if(sorig.len != sdest.len);
773 fail_if(len2 != len);
774 fail_if(stride2 != stride); 763 fail_if(stride2 != stride);
775 764
765 dest = sdest.mem;
766 orig = sorig.mem;
767
776 // first quarter: same image 768 // first quarter: same image
777 for (y = 0; y < h / 4; y++) 769 for (y = 0; y < h / 4; y++)
778 for (x = 0; x < w; x++) 770 for (x = 0; x < w; x++)
779 fail_if(orig[y*stride/4 + x] != data2[y*stride2/4+x], "pixels differ [1]"); 771 fail_if(orig[y*stride/4 + x] != dest[y*stride2/4+x], "pixels differ [1]");
780 772
781 // middle zone top: grey gradient 773 // middle zone top: grey gradient
782 for (y = ry; y < (ry + rh / 4); y++) 774 for (y = ry; y < (ry + rh / 4); y++)
@@ -784,28 +776,28 @@ START_TEST(evas_object_image_map_unmap)
784 { 776 {
785 uint32_t c = (x - rx) & 0xFF; 777 uint32_t c = (x - rx) & 0xFF;
786 c = 0xFF000000 | (c << 16) | (c << 8) | c; 778 c = 0xFF000000 | (c << 16) | (c << 8) | c;
787 fail_if(data2[y*stride/4 + x] != c, "pixels differ [2]"); 779 fail_if(dest[y*stride/4 + x] != c, "pixels differ [2]");
788 } 780 }
789 781
790 // middle zone: grey image 782 // middle zone: grey image
791 for (y = (ry + rh / 4 + 1); y < (ry + rh / 2); y++) 783 for (y = (ry + rh / 4 + 1); y < (ry + rh / 2); y++)
792 for (x = rx; x < rx + rw; x++) 784 for (x = rx; x < rx + rw; x++)
793 { 785 {
794 uint32_t c = data2[y*stride/4 + x] & 0xFF; 786 uint32_t c = dest[y*stride/4 + x] & 0xFF;
795 c = 0xFF000000 | (c << 16) | (c << 8) | c; 787 c = 0xFF000000 | (c << 16) | (c << 8) | c;
796 fail_if(data2[y*stride/4 + x] != c, "pixels differ [2bis]"); 788 fail_if(dest[y*stride/4 + x] != c, "pixels differ [2bis]");
797 } 789 }
798 790
799 // next lines: green & red 791 // next lines: green & red
800 y = ry + rh / 2; 792 y = ry + rh / 2;
801 for (x = rx; x < rx + rw; x++) 793 for (x = rx; x < rx + rw; x++)
802 { 794 {
803 fail_if(data2[y*stride/4 + x] != 0xFF00FF00, "pixels differ [3]"); 795 fail_if(dest[y*stride/4 + x] != 0xFF00FF00, "pixels differ [3]");
804 fail_if(data2[(y+1)*stride/4 + x] != 0xFFFF0000, "pixels differ [4]"); 796 fail_if(dest[(y+1)*stride/4 + x] != 0xFFFF0000, "pixels differ [4]");
805 } 797 }
806 798
807 efl_gfx_buffer_unmap(o, orig, len); 799 efl_gfx_buffer_unmap(o, &sorig);
808 efl_gfx_buffer_unmap(o2, data2, len2); 800 efl_gfx_buffer_unmap(o2, &sdest);
809 } 801 }
810 else unlink(tmp); 802 else unlink(tmp);
811 eina_tmpstr_del(tmp); 803 eina_tmpstr_del(tmp);