root/gilx/trunk/src/test/test_palette_view.cpp

Revision 7, 2.6 KB (checked in by anonymous, 13 months ago)

removed FS dependancies.

I was using Boost.Filesystem to create an output directory if none existed. I now use SVN to make sure the directory exists. I also partially switched from using the Boost.Test library in order to use my own ad-hoc testing macros. The idea is that I can remove the dependency on the unit test libraries if that is necessary.

  • Property svn:mime-type set to text/plain
Line 
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
25using namespace i3dea;
26
27namespace boost{ namespace gil{
28std::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
38template<class XfmView, class Fn, class SrcView >
39static
40inline
41void test_view(XfmView result, Fn f, SrcView src){
42    I3DEA_CHECK( result(5, 5) == f(src(5,5)));
43}
44
45int 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}
Note: See TracBrowser for help on using the browser.