TuttleOFX  1
pattern.tests.cpp
Go to the documentation of this file.
00001 #include <boost/test/included/unit_test.hpp>
00002 
00003 #include <pattern.hpp>
00004 
00005 using boost::unit_test::test_suite;
00006 using namespace boost::gil;
00007 
00008 //g++ pattern.tests.cpp -I /home/scott/project/boost_1_36_0 -I .
00009 
00010 static const struct {
00011   int    width;
00012   int    height;
00013   int    bytes_per_pixel; /* 3:RGB, 4:RGBA */ 
00014   char   pixel_data[16 * 16 * 3 + 1];
00015 } gimp_image = {
00016   16, 16, 3,
00017   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00018   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00019   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00020   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00021   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00022   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00023   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00024   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00025   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00026   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00027   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00028   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00029   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00030   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00031   "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
00032   "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
00033   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00034   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00035   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00036   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00037   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00038   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00039   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00040   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00041   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00042   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00043   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00044   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00045   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00046   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00047   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377"
00048   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00049   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00050   "\377\377\377\377\377\377",
00051 };
00052 
00053 struct test1
00054 {
00055         void operator()()
00056         {
00057                 int rows = 4;
00058                 int cols = 7;
00059                 int extra = 5;
00060                 int width = gimp_image.width*cols+extra;
00061                 int height = gimp_image.height*rows+extra;
00062                 unsigned char* buffer = new unsigned char[width * height * gimp_image.bytes_per_pixel];
00063                 memset(buffer, 255, width * height * gimp_image.bytes_per_pixel);       
00064                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*gimp_image.bytes_per_pixel);
00065 
00066                 rgb8_view_t view2 = interleaved_view(gimp_image.width,gimp_image.height,
00067                         (rgb8_pixel_t*)gimp_image.pixel_data,gimp_image.width*gimp_image.bytes_per_pixel);
00068 
00069                 layer::pattern<rgb8_view_t> pattern(view2);
00070                 pattern(view);
00071                 
00072                 FILE* fd = fopen("pattern.ppm", "wb");
00073                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00074                 fwrite(buffer, 1, width*height*3, fd);
00075                 fclose(fd);
00076                 delete [] buffer;
00077         }
00078 };
00079 
00080 test_suite* init_unit_test_suite( int argc, char** argv)
00081 {
00082         test_suite* test= BOOST_TEST_SUITE( "pattern tests" );
00083         test->add( BOOST_TEST_CASE(test1()), 0);
00084         return test;
00085 }