summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_image.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-09-18 19:59:11 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-09-19 10:51:48 +0900
commit2df8ad36b4b0068ae5ae3f547d2ece4d3c741a76 (patch)
treee8821395cdc6cca75f968d2e7e7decab42f5a94c /src/tests/evas/evas_test_image.c
parent1f242afdefd27cc11eb71bc598f4e7903ceb5ea9 (diff)
evas: Use Eina.Slice on the stack (gfx.buffer)
Diffstat (limited to 'src/tests/evas/evas_test_image.c')
-rw-r--r--src/tests/evas/evas_test_image.c69
1 files changed, 36 insertions, 33 deletions
diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index 5cbfa015fc..2d715f0021 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -667,13 +667,14 @@ START_TEST(evas_object_image_map_unmap)
667{ 667{
668 Evas *e = _setup_evas(); 668 Evas *e = _setup_evas();
669 Evas_Object *o, *o2; 669 Evas_Object *o, *o2;
670 int stride, w, h, rx, ry, rw, rh; 670 int stride, w, h;
671 Efl_Gfx_Colorspace cs; 671 Efl_Gfx_Colorspace cs;
672 Eina_Tmpstr *tmp; 672 Eina_Tmpstr *tmp;
673 int fd; 673 int fd;
674 uint32_t *data32; 674 uint32_t *data32;
675 Eina_Bool all_white = 1, all_transparent = 1; 675 Eina_Bool all_white = 1, all_transparent = 1;
676 Eina_Rw_Slice slice; 676 Eina_Rw_Slice slice;
677 Eina_Rect r, r2;
677 678
678 const char *imgpath = TESTS_IMG_DIR "/Pic4.png"; 679 const char *imgpath = TESTS_IMG_DIR "/Pic4.png";
679 680
@@ -682,25 +683,25 @@ START_TEST(evas_object_image_map_unmap)
682 efl_gfx_view_size_get(o, &w, &h); 683 efl_gfx_view_size_get(o, &w, &h);
683 cs = efl_gfx_buffer_colorspace_get(o); 684 cs = efl_gfx_buffer_colorspace_get(o);
684 685
685 rx = (w / 4) & ~3; 686 r.x = (w / 4) & ~3;
686 ry = (h / 4) & ~3; 687 r.y = (h / 4) & ~3;
687 rw = (w / 2) & ~3; 688 r.w = (w / 2) & ~3;
688 rh = (h / 2) & ~3; 689 r.h = (h / 2) & ~3;
689 690
690 // same cspace, full image 691 // same cspace, full image
691 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, cs, 0, &stride)); 692 slice = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_READ, NULL, cs, 0, &stride);
692 fail_if(!slice.len || !slice.mem); 693 fail_if(!slice.len || !slice.mem);
693 fail_if(!stride); 694 fail_if(!stride);
694 efl_gfx_buffer_unmap(o, &slice); 695 efl_gfx_buffer_unmap(o, slice);
695 696
696 // same cspace, partial image 697 // same cspace, partial image
697 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, cs, 0, &stride)); 698 slice = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_READ, &r, cs, 0, &stride);
698 fail_if(!slice.len || !slice.mem); 699 fail_if(!slice.len || !slice.mem);
699 fail_if(!stride); 700 fail_if(!stride);
700 efl_gfx_buffer_unmap(o, &slice); 701 efl_gfx_buffer_unmap(o, slice);
701 702
702 // argb cspace, full image 703 // argb cspace, full image
703 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride)); 704 slice = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_READ, NULL, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride);
704 fail_if(!slice.len || !slice.mem); 705 fail_if(!slice.len || !slice.mem);
705 fail_if(!stride); 706 fail_if(!stride);
706 data32 = slice.mem; 707 data32 = slice.mem;
@@ -712,36 +713,38 @@ START_TEST(evas_object_image_map_unmap)
712 all_white = 0; 713 all_white = 0;
713 } 714 }
714 fail_if(all_white || all_transparent); 715 fail_if(all_white || all_transparent);
715 efl_gfx_buffer_unmap(o, &slice); 716 efl_gfx_buffer_unmap(o, slice);
716 717
717 // argb cspace, partial image 718 // argb cspace, partial image
718 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride)); 719 slice = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_READ, &r, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride);
719 fail_if(!slice.len || !slice.mem); 720 fail_if(!slice.len || !slice.mem);
720 fail_if(!stride); 721 fail_if(!stride);
721 efl_gfx_buffer_unmap(o, &slice); 722 efl_gfx_buffer_unmap(o, slice);
722 723
723 // argb cspace, partial image, write 724 // argb cspace, partial image, write
724 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_WRITE, rx, ry, rw, rh, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride)); 725 slice = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_WRITE, &r, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride);
725 fail_if(!slice.len || !slice.mem); 726 fail_if(!slice.len || !slice.mem);
726 fail_if(!stride); 727 fail_if(!stride);
727 data32 = slice.mem; 728 data32 = slice.mem;
728 for (int y = 0; y < rh; y += 2) 729 for (int y = 0; y < r.h; y += 2)
729 for (int x = 0; x < rw; x++) 730 for (int x = 0; x < r.w; x++)
730 { 731 {
731 data32[y*stride/4 + x] = 0xFF00FF00; 732 data32[y*stride/4 + x] = 0xFF00FF00;
732 data32[(y+1)*stride/4 + x] = 0xFFFF0000; 733 data32[(y+1)*stride/4 + x] = 0xFFFF0000;
733 } 734 }
734 efl_gfx_buffer_unmap(o, &slice); 735 efl_gfx_buffer_unmap(o, slice);
735 736
736 // argb cspace, partial image, write 737 // argb cspace, partial image, write
737 fail_if(!efl_gfx_buffer_map(o, &slice, EFL_GFX_BUFFER_ACCESS_MODE_READ| EFL_GFX_BUFFER_ACCESS_MODE_WRITE, 738 r2 = r;
738 rx, ry, rw, rh / 2, EFL_GFX_COLORSPACE_GRY8, 0, &stride)); 739 r2.h = r.h / 2;
740 slice = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_READ | EFL_GFX_BUFFER_ACCESS_MODE_WRITE,
741 &r2, EFL_GFX_COLORSPACE_GRY8, 0, &stride);
739 fail_if(!slice.len || !slice.mem); 742 fail_if(!slice.len || !slice.mem);
740 fail_if(!stride); 743 fail_if(!stride);
741 for (int y = 0; y < rh / 4; y++) 744 for (int y = 0; y < r.h / 4; y++)
742 for (int x = 0; x < rw; x++) 745 for (int x = 0; x < r.w; x++)
743 slice.bytes[y*stride + x] = x & 0xFF; 746 slice.bytes[y*stride + x] = x & 0xFF;
744 efl_gfx_buffer_unmap(o, &slice); 747 efl_gfx_buffer_unmap(o, slice);
745 748
746 // save file, verify its pixels 749 // save file, verify its pixels
747 fd = eina_file_mkstemp("/tmp/evas-test.XXXXXX.png", &tmp); 750 fd = eina_file_mkstemp("/tmp/evas-test.XXXXXX.png", &tmp);
@@ -762,11 +765,11 @@ START_TEST(evas_object_image_map_unmap)
762 fail_if(w2 != w); 765 fail_if(w2 != w);
763 fail_if(h2 != h); 766 fail_if(h2 != h);
764 767
765 fail_if(!efl_gfx_buffer_map(o, &sorig, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride)); 768 sorig = efl_gfx_buffer_map(o, EFL_GFX_BUFFER_ACCESS_MODE_READ, NULL, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride);
766 fail_if(!sorig.len || !sorig.mem); 769 fail_if(!sorig.len || !sorig.mem);
767 fail_if(!stride); 770 fail_if(!stride);
768 771
769 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 sdest = efl_gfx_buffer_map(o2, EFL_GFX_BUFFER_ACCESS_MODE_READ, NULL, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride2);
770 fail_if(sorig.len != sdest.len); 773 fail_if(sorig.len != sdest.len);
771 fail_if(stride2 != stride); 774 fail_if(stride2 != stride);
772 775
@@ -779,17 +782,17 @@ START_TEST(evas_object_image_map_unmap)
779 fail_if(orig[y*stride/4 + x] != dest[y*stride2/4+x], "pixels differ [1]"); 782 fail_if(orig[y*stride/4 + x] != dest[y*stride2/4+x], "pixels differ [1]");
780 783
781 // middle zone top: grey gradient 784 // middle zone top: grey gradient
782 for (y = ry; y < (ry + rh / 4); y++) 785 for (y = r.y; y < (r.y + r.h / 4); y++)
783 for (x = rx; x < rx + rw; x++) 786 for (x = r.x; x < r.x + r.w; x++)
784 { 787 {
785 uint32_t c = (x - rx) & 0xFF; 788 uint32_t c = (x - r.x) & 0xFF;
786 c = 0xFF000000 | (c << 16) | (c << 8) | c; 789 c = 0xFF000000 | (c << 16) | (c << 8) | c;
787 fail_if(dest[y*stride/4 + x] != c, "pixels differ [2]"); 790 fail_if(dest[y*stride/4 + x] != c, "pixels differ [2]");
788 } 791 }
789 792
790 // middle zone: grey image 793 // middle zone: grey image
791 for (y = (ry + rh / 4 + 1); y < (ry + rh / 2); y++) 794 for (y = (r.y + r.h / 4 + 1); y < (r.y + r.h / 2); y++)
792 for (x = rx; x < rx + rw; x++) 795 for (x = r.x; x < r.x + r.w; x++)
793 { 796 {
794 uint32_t c = dest[y*stride/4 + x] & 0xFF; 797 uint32_t c = dest[y*stride/4 + x] & 0xFF;
795 c = 0xFF000000 | (c << 16) | (c << 8) | c; 798 c = 0xFF000000 | (c << 16) | (c << 8) | c;
@@ -797,15 +800,15 @@ START_TEST(evas_object_image_map_unmap)
797 } 800 }
798 801
799 // next lines: green & red 802 // next lines: green & red
800 y = ry + rh / 2; 803 y = r.y + r.h / 2;
801 for (x = rx; x < rx + rw; x++) 804 for (x = r.x; x < r.x + r.w; x++)
802 { 805 {
803 fail_if(dest[y*stride/4 + x] != 0xFF00FF00, "pixels differ [3]"); 806 fail_if(dest[y*stride/4 + x] != 0xFF00FF00, "pixels differ [3]");
804 fail_if(dest[(y+1)*stride/4 + x] != 0xFFFF0000, "pixels differ [4]"); 807 fail_if(dest[(y+1)*stride/4 + x] != 0xFFFF0000, "pixels differ [4]");
805 } 808 }
806 809
807 efl_gfx_buffer_unmap(o, &sorig); 810 efl_gfx_buffer_unmap(o, sorig);
808 efl_gfx_buffer_unmap(o2, &sdest); 811 efl_gfx_buffer_unmap(o2, sdest);
809 } 812 }
810 else unlink(tmp); 813 else unlink(tmp);
811 eina_tmpstr_del(tmp); 814 eina_tmpstr_del(tmp);