| 1 |
|
|---|
| 2 | /******************************************************************************
|
|---|
| 3 | * __LICENCE_BEGIN__
|
|---|
| 4 | *
|
|---|
| 5 | * __LICENCE_END__ |
|---|
| 6 | *****************************************************************************/
|
|---|
| 7 |
|
|---|
| 8 | ///@file
|
|---|
| 9 | ///@brief Test for i3dea::transform_view<>
|
|---|
| 10 | ///
|
|---|
| 11 | ///@author john.femiani@asu.edu
|
|---|
| 12 | ///
|
|---|
| 13 | ///
|
|---|
| 14 |
|
|---|
| 15 | #include <i3dea/test.hpp>
|
|---|
| 16 |
|
|---|
| 17 | #include <i3dea/gil/palette_image.hpp>
|
|---|
| 18 | #include <i3dea/gil/rgb_functions.hpp>
|
|---|
| 19 | #include <i3dea/gil/transform_view.hpp>
|
|---|
| 20 |
|
|---|
| 21 | #include <boost/gil/gil_all.hpp>
|
|---|
| 22 | #include <typeinfo>
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | using namespace i3dea;
|
|---|
| 26 |
|
|---|
| 27 | namespace boost{ namespace gil{
|
|---|
| 28 | std::ostream& operator<<(std::ostream& out,boost::gil::rgb8_pixel_t const & p)
|
|---|
| 29 | {
|
|---|
| 30 | return out << "["
|
|---|
| 31 | << boost::gil::get_color(p, boost::gil::red_t()) << " "
|
|---|
| 32 | << boost::gil::get_color(p, boost::gil::red_t()) << " "
|
|---|
| 33 | << boost::gil::get_color(p, boost::gil::red_t())
|
|---|
| 34 | << "]";
|
|---|
| 35 | }
|
|---|
| 36 | } }
|
|---|
| 37 |
|
|---|
| 38 | template<class XfmView, class Fn, class SrcView >
|
|---|
| 39 | static
|
|---|
| 40 | inline
|
|---|
| 41 | void test_view(XfmView result, Fn f, SrcView src){
|
|---|
| 42 | I3DEA_CHECK( result(5, 5) == f(src(5,5)));
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | int main(int ac, char** av){
|
|---|
| 46 | using gil::rgb8_pixel_t;
|
|---|
| 47 | using boost::is_same;
|
|---|
| 48 |
|
|---|
| 49 | gil::gray8_image_t test_(10,10, gil::gray8_pixel_t(1));
|
|---|
| 50 | gil::gray8_view_t test = view(test_);
|
|---|
| 51 |
|
|---|
| 52 | rgb8_pixel_t palette[256];
|
|---|
| 53 | palette[0] = rgb8_pixel_t(255, 255, 255);
|
|---|
| 54 | palette[1] = rgb8_pixel_t(255, 0, 0); //red
|
|---|
| 55 | palette[2] = rgb8_pixel_t(0, 255, 0); //green
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | //Compute the view type
|
|---|
| 59 | typedef result_of::make_palette_view<
|
|---|
| 60 | gil::gray8_view_t,
|
|---|
| 61 | rgb8_pixel_t const*
|
|---|
| 62 | >::type
|
|---|
| 63 | palette_view_type;
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | //Make sure the view has the proper typedefs
|
|---|
| 67 | BOOST_MPL_ASSERT((mpl::or_<
|
|---|
| 68 | is_same<palette_view_type::result_type, rgb8_pixel_t const&>,
|
|---|
| 69 | is_same<palette_view_type::result_type, rgb8_pixel_t>
|
|---|
| 70 | >));
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | BOOST_MPL_ASSERT((is_same<palette_view_type::value_type, rgb8_pixel_t > ));
|
|---|
| 74 |
|
|---|
| 75 | BOOST_MPL_ASSERT(( is_same<palette_view_type::iterator::pointer,
|
|---|
| 76 | rgb8_pixel_t const*> ));
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | //Whew, finally an image.
|
|---|
| 83 | palette_view_type result = i3dea::make_palette_view(test, &palette[0]);
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | test(5,0) = 0; //white
|
|---|
| 87 | test(5,1) = 1; //red
|
|---|
| 88 | test(5,2) = 2; //green
|
|---|
| 89 | test(5,3) = 3; //black
|
|---|
| 90 |
|
|---|
| 91 | I3DEA_CHECK_EQUAL( i3dea::make_palette_view(test, &palette[0])(5,5),
|
|---|
| 92 | palette[test(5,5)] );
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | I3DEA_CHECK( result(5,0) == palette[0]);
|
|---|
| 96 | I3DEA_CHECK( result(5,1) == palette[1]);
|
|---|
| 97 | I3DEA_CHECK( result(5,2) == palette[2]);
|
|---|
| 98 | I3DEA_CHECK( result(5,3) == palette[3]);
|
|---|
| 99 |
|
|---|
| 100 | return 0;
|
|---|
| 101 | }
|
|---|