TuttleOFX  1
layers.tests.cpp
Go to the documentation of this file.
00001 #include <boost/test/included/unit_test.hpp>
00002 
00003 #include <layers.hpp>
00004 #include <fill.hpp>
00005 #include <shrink.hpp>
00006 
00007 using boost::unit_test::test_suite;
00008 using namespace boost::gil;
00009 
00010 //g++ layers.tests.cpp -I /home/scott/project/boost_1_36_0 -I .
00011 
00012 struct test1
00013 {
00014         void operator()()
00015         {
00016                 int width = 200;
00017                 int height = 200;
00018                 unsigned char* buffer = new unsigned char[width * height * 3];
00019                 memset(buffer, 255, width * height * 3);        
00020                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00021 
00022                 typedef boost::function<void (rgb8_view_t&)> layer_t;
00023 
00024                 layer_t a[] = 
00025                 {
00026                         layer::shrink<rgb8_view_t>(
00027                                 layer::fill<rgb8_view_t>(rgb8_view_t::value_type(255,0,255)),5,5,5,5),
00028                         layer::shrink<rgb8_view_t>(
00029                                 layer::fill<rgb8_view_t>(rgb8_view_t::value_type(255,0,0)),20,20,20,20)
00030                 };
00031 
00032                 layer::layers<rgb8_view_t> layer(a,2);
00033                 layer(view);
00034                 
00035                 FILE* fd = fopen("layers.ppm", "wb");
00036                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00037                 fwrite(buffer, 1, width*height*3, fd);
00038                 fclose(fd);
00039                 delete [] buffer;
00040         }
00041 };
00042 
00043 test_suite* init_unit_test_suite( int argc, char** argv)
00044 {
00045         test_suite* test= BOOST_TEST_SUITE( "rounded tests" );
00046         test->add( BOOST_TEST_CASE(test1()), 0);
00047         return test;
00048 }