TuttleOFX  1
shrink.hpp
Go to the documentation of this file.
00001 // Copyright Tom Brinkman 2008. Distributed under the Boost
00002 // Software License, Version 1.0. (See accompanying
00003 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00004 
00005 #ifndef _shrink_hpp_
00006 #define _shrink_hpp_
00007 
00008 #include <boost/gil/gil_all.hpp>
00009 #include <boost/function.hpp>
00010 
00011 namespace layer
00012 {
00013 
00014 template <typename view_t>
00015 struct shrink
00016 {
00017         typedef boost::function<void (view_t&)> funct_t;
00018 
00019         double left;
00020         double top;
00021         double right;
00022         double bottom;
00023         funct_t funct;
00024 
00025         shrink(funct_t funct, double left=5, double top=5,
00026                 double right=5, double bottom=5) :
00027                         funct(funct), left(left), top(top), 
00028                                 right(right), bottom(bottom){}
00029 
00030         void operator()(view_t& view)
00031         {
00032                 if (left < 1.0) left *= view.width();
00033                 if (right < 1.0) right *= view.width();
00034                 if (top < 1.0) top *= view.height();
00035                 if (bottom < 1.0) bottom *= view.height();
00036 
00037                 double width = view.width()-left-right;
00038                 double height = view.height()-top-bottom;
00039                 view_t view2 = boost::gil::subimage_view(view,(int)left,(int)top,(int)width,(int)height);
00040                 funct(view2);
00041         }
00042 };      
00043 
00044 }
00045 
00046 #endif