TuttleOFX  1
aligned.tests.cpp
Go to the documentation of this file.
00001 #include <boost/test/included/unit_test.hpp>
00002 
00003 #include <aligned.hpp>
00004 
00005 using boost::unit_test::test_suite;
00006 using namespace boost::gil;
00007 
00008 //g++ aligned.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\377\377\377\377\377\377"
00020   "\377\377\377\377\377\377\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\377\377\377\377\377\377"
00022   "\377\377\377\377\377\377\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\377\377\377\377\377\377"
00024   "\377\377\377\377\377\377\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\277\277\277\177\177\177"
00026   "\0\0\0\0\0\0\0\0\0\177\177\177\277\277\277\377\377\377\377\377\377\377\377"
00027   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\277\277"
00028   "\277\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\277\277\277\377\377\377\377"
00029   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\277\277\277\0\0"
00030   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\277\277\277\377\377\377"
00031   "\377\377\377\377\377\377\377\377\377\377\377\377\177\177\177\0\0\0\0\0\0"
00032   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\177\177\177\377\377\377\377\377"
00033   "\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
00034   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377"
00035   "\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
00036   "\0\0\0\0\0\0\0\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\0\0\0\0\0\0\0\0\0\377\377"
00038   "\377\377\377\377\377\377\377\377\377\377\377\377\377\177\177\177\0\0\0\0"
00039   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\177\177\177\377\377\377\377"
00040   "\377\377\377\377\377\377\377\377\377\377\377\277\277\277\0\0\0\0\0\0\0\0"
00041   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\277\277\277\377\377\377\377\377\377"
00042   "\377\377\377\377\377\377\377\377\377\377\377\377\277\277\277\0\0\0\0\0\0"
00043   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\277\277\277\377\377\377\377\377\377\377\377"
00044   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\277\277"
00045   "\277\177\177\177\0\0\0\0\0\0\0\0\0\177\177\177\277\277\277\377\377\377\377"
00046   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
00047   "\377\377\377\377\377\377\377\377\377\377\377\377\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\377\377\377\377\377\377\377\377\377\377\377\377"
00051   "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377",
00052 };
00053 
00054 struct test1
00055 {
00056         void operator()()
00057         {
00058                 int width = 200;
00059                 int height = 200;
00060                 unsigned char* buffer = new unsigned char[width * height * 3];
00061                 memset(buffer, 255, width * height * 3);        
00062                 rgb8_view_t view = interleaved_view(width,height,(rgb8_pixel_t*)buffer,width*3);
00063 
00064                 rgb8_view_t view2 = interleaved_view(gimp_image.width,gimp_image.height,
00065                         (rgb8_pixel_t*)gimp_image.pixel_data,gimp_image.width*gimp_image.bytes_per_pixel);
00066 
00067                 typedef layer::aligned<rgb8_view_t> aligned_t;
00068                 aligned_t aligned(view2,aligned_t::center|aligned_t::middle);
00069                 aligned(view);
00070 
00071                 aligned.align = aligned_t::left|aligned_t::top;
00072                 aligned(view);
00073 
00074                 FILE* fd = fopen("aligned.ppm", "wb");
00075                 fprintf(fd, "P6\n# CREATOR: reportbase\n%d %d\n255\n", width, height);
00076                 fwrite(buffer, 1, width*height*3, fd);
00077                 fclose(fd);
00078                 delete [] buffer;
00079         }
00080 };
00081 
00082 test_suite* init_unit_test_suite( int argc, char** argv)
00083 {
00084         test_suite* test= BOOST_TEST_SUITE( "aligned tests" );
00085         test->add( BOOST_TEST_CASE(test1()), 0);
00086         return test;
00087 }