summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_image.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-03-23 17:43:07 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-03-28 16:40:02 +0900
commitba4ffba8c164400acf662eea7b7a715093812f12 (patch)
tree13ed2f9e2d52cf2af8b252817493e83902b77c22 /src/tests/evas/evas_test_image.c
parent488854af2bbae2e18624fec235599de6e191a812 (diff)
Evas: Add a test case for image buffer_map.
This: 1. opens a file 2. maps its data and vaguely verifies it 3. writes data to it 4. writes data to it with a GRY8 map 5. verifies that the final image has all the proper pixels
Diffstat (limited to 'src/tests/evas/evas_test_image.c')
-rw-r--r--src/tests/evas/evas_test_image.c167
1 files changed, 167 insertions, 0 deletions
diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index 3414fb26a4..7f90754872 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -654,6 +654,172 @@ START_TEST(evas_object_image_defaults)
654} 654}
655END_TEST 655END_TEST
656 656
657// FIXME: belongs to another file
658START_TEST(evas_object_image_map_unmap)
659{
660 Evas *e = _setup_evas();
661 Evas_Object *o, *o2;
662 void *data;
663 int len, stride;
664 int w, h, rx, ry, rw, rh;
665 Efl_Gfx_Colorspace cs;
666 Eina_Tmpstr *tmp;
667 int fd;
668 uint32_t *data32;
669 uint8_t *data8;
670 Eina_Bool all_white = 1, all_transparent = 1;
671
672 const char *imgpath = TESTS_IMG_DIR "/Pic4.png";
673
674 o = eo_add(EFL_CANVAS_IMAGE_CLASS, e);
675 efl_file_set(o, imgpath, NULL);
676 efl_gfx_view_size_get(o, &w, &h);
677 cs = efl_gfx_buffer_colorspace_get(o);
678
679 rx = (w / 4) & ~3;
680 ry = (h / 4) & ~3;
681 rw = (w / 2) & ~3;
682 rh = (h / 2) & ~3;
683
684 // same cspace, full image
685 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, cs, &stride);
686 fail_if(!data);
687 fail_if(!len);
688 fail_if(!stride);
689 efl_gfx_buffer_unmap(o, data, len);
690
691 // same cspace, partial image
692 data = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, rx, ry, rw, rh, cs, &stride);
693 fail_if(!data);
694 fail_if(!len);
695 fail_if(!stride);
696 efl_gfx_buffer_unmap(o, data, len);
697
698 // 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);
700 fail_if(!data);
701 fail_if(!len);
702 fail_if(!stride);
703 data32 = data;
704 for (int k = 0; (k < len) && (all_white || all_transparent); k++)
705 {
706 if (data32[k])
707 all_transparent = 0;
708 if (data32[k] != 0xFFFFFFFF)
709 all_white = 0;
710 }
711 fail_if(all_white || all_transparent);
712 efl_gfx_buffer_unmap(o, data, len);
713
714 // 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);
716 fail_if(!data);
717 fail_if(!len);
718 fail_if(!stride);
719 efl_gfx_buffer_unmap(o, data, len);
720
721 // 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);
723 fail_if(!data);
724 fail_if(!len);
725 fail_if(!stride);
726 data32 = data;
727 for (int y = 0; y < rh; y += 2)
728 for (int x = 0; x < rw; x++)
729 {
730 data32[y*stride/4 + x] = 0xFF00FF00;
731 data32[(y+1)*stride/4 + x] = 0xFFFF0000;
732 }
733 efl_gfx_buffer_unmap(o, data, len);
734
735 // 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,
737 rx, ry, rw, rh / 2, EFL_GFX_COLORSPACE_GRY8, &stride);
738 fail_if(!data);
739 fail_if(!len);
740 fail_if(!stride);
741 data8 = data;
742 for (int y = 0; y < rh / 4; y++)
743 for (int x = 0; x < rw; x++)
744 data8[y*stride + x] = x & 0xFF;
745 efl_gfx_buffer_unmap(o, data, len);
746
747 // save file, verify its pixels
748 fd = eina_file_mkstemp("/tmp/evas-test.XXXXXX.png", &tmp);
749 close(fd);
750 if (efl_file_save(o, tmp, NULL, NULL))
751 {
752 Efl_Gfx_Colorspace cs2;
753 int w2, h2, stride2, len2;
754 uint32_t *data2, *orig;
755 int x, y;
756
757 o2 = eo_add(EFL_CANVAS_IMAGE_CLASS, e);
758 efl_file_set(o2, tmp, NULL);
759 efl_gfx_view_size_get(o, &w2, &h2);
760 cs2 = efl_gfx_buffer_colorspace_get(o2);
761
762 // unlink now to not leave any crap after failing the test
763 unlink(tmp);
764
765 fail_if(w2 != w);
766 fail_if(h2 != h);
767
768 orig = efl_gfx_buffer_map(o, &len, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, &stride);
769 fail_if(!orig);
770 fail_if(!len);
771 fail_if(!stride);
772
773 data2 = efl_gfx_buffer_map(o2, &len2, EFL_GFX_BUFFER_ACCESS_MODE_READ, 0, 0, w2, h2, EFL_GFX_COLORSPACE_ARGB8888, &stride2);
774 fail_if(!data2);
775 fail_if(len2 != len);
776 fail_if(stride2 != stride);
777
778 // first quarter: same image
779 for (y = 0; y < h / 4; y++)
780 for (x = 0; x < w; x++)
781 fail_if(orig[y*stride/4 + x] != data2[y*stride2/4+x], "pixels differ [1]");
782
783 // middle zone top: grey gradient
784 for (y = ry; y < (ry + rh / 4); y++)
785 for (x = rx; x < rx + rw; x++)
786 {
787 uint32_t c = (x - rx) & 0xFF;
788 c = 0xFF000000 | (c << 16) | (c << 8) | c;
789 fail_if(data2[y*stride/4 + x] != c, "pixels differ [2]");
790 }
791
792 // middle zone: grey image
793 for (y = (ry + rh / 4 + 1); y < (ry + rh / 2); y++)
794 for (x = rx; x < rx + rw; x++)
795 {
796 uint32_t c = data2[y*stride/4 + x] & 0xFF;
797 c = 0xFF000000 | (c << 16) | (c << 8) | c;
798 fail_if(data2[y*stride/4 + x] != c, "pixels differ [2bis]");
799 }
800
801 // next lines: green & red
802 y = ry + rh / 2;
803 for (x = rx; x < rx + rw; x++)
804 {
805 fail_if(data2[y*stride/4 + x] != 0xFF00FF00, "pixels differ [3]");
806 fail_if(data2[(y+1)*stride/4 + x] != 0xFFFF0000, "pixels differ [4]");
807 }
808
809 efl_gfx_buffer_unmap(o, orig, len);
810 efl_gfx_buffer_unmap(o2, data2, len2);
811 }
812 else unlink(tmp);
813 eina_tmpstr_del(tmp);
814
815 // TODO: test copy-on-write
816 // TODO: test more color conversions
817
818 evas_free(e);
819 evas_shutdown();
820}
821END_TEST
822
657void evas_test_image_object(TCase *tc) 823void evas_test_image_object(TCase *tc)
658{ 824{
659 tcase_add_test(tc, evas_object_image_defaults); 825 tcase_add_test(tc, evas_object_image_defaults);
@@ -666,6 +832,7 @@ void evas_test_image_object(TCase *tc)
666#if BUILD_LOADER_PNG 832#if BUILD_LOADER_PNG
667 tcase_add_test(tc, evas_object_image_all_loader_data); 833 tcase_add_test(tc, evas_object_image_all_loader_data);
668 tcase_add_test(tc, evas_object_image_buggy); 834 tcase_add_test(tc, evas_object_image_buggy);
835 tcase_add_test(tc, evas_object_image_map_unmap);
669#endif 836#endif
670 tcase_add_test(tc, evas_object_image_partially_load_orientation); 837 tcase_add_test(tc, evas_object_image_partially_load_orientation);
671} 838}