TuttleOFX  1
pattern.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 _pattern_hpp_
00006 #define _pattern_hpp_
00007 
00008 #include <boost/gil/gil_all.hpp>
00009 #include <blend.hpp>
00010 
00011 namespace layer
00012 {
00013 
00014 template <typename view_t>
00015 struct pattern
00016 {
00017         view_t v2;
00018         pattern(view_t v2) : v2(v2){}
00019                 
00020         void operator()(view_t& view)
00021         {
00022                 using namespace boost::gil;
00023 
00024                 int h = v2.height();
00025                 int w = v2.width();
00026                 if (h > view.height() || w > view.width())
00027                         return;
00028                 
00029                 int n = 0;
00030                 for (int x = 0; x < view.width(); x+=w)
00031                 {
00032                         for (int y = 0; y < view.height(); y+=h)
00033                         {
00034                                 int aw = w;
00035                                 if (x+w > view.width())
00036                                 {
00037                                         int t = x+w-view.width();
00038                                         aw = w-t;       
00039                                 }
00040 
00041                                 int ah = h;
00042                                 if (y+h > view.height())
00043                                 {
00044                                         int t = y+h-view.height();
00045                                         ah = h-t;       
00046                                 }
00047 
00048                                 view_t v3 = subimage_view(view,x,y,aw,ah);
00049                                 view_t v4 = subimage_view(v2,0,0,aw,ah);
00050                                 boost::gil::copy_pixels(v4,v3);
00051                         }
00052                 }
00053         }
00054 };
00055 
00056 }
00057 
00058 #endif