TuttleOFX
1
|
00001 #ifndef _blend_hpp_ 00002 #define _blend_hpp_ 00003 00004 #include <boost/gil/gil_all.hpp> 00005 00006 struct alpha24_blend 00007 { 00008 short alpha; 00009 alpha24_blend(short alpha) : alpha(alpha){} 00010 00011 template <typename T> 00012 void operator()(T& dst, const T src) 00013 { 00014 dst = ((dst + 1) * alpha >> 8) - 00015 ((src + 1) * alpha >> 8) + 00016 src; 00017 } 00018 }; 00019 00020 template <typename blend_t, typename pixel_t, typename grayview_t, typename view_t> inline 00021 void copy(pixel_t pixel, const grayview_t& grayview, const view_t& view) 00022 { 00023 using namespace boost::gil; 00024 BOOST_ASSERT(grayview.width() == view.width()); 00025 00026 typedef typename view_t::x_iterator x_iterator_t; 00027 typedef typename grayview_t::x_iterator x_iterator2_t; 00028 00029 for (int y = 0; y < view.height(); ++y) 00030 { 00031 x_iterator_t it_view = view.row_begin(y); 00032 x_iterator2_t it_gray = grayview.row_begin(y); 00033 for (int x = 0; x < view.width(); ++x) 00034 { 00035 pixel_t dst = pixel; 00036 static_for_each(dst, it_view[x], blend_t(it_gray[x])); 00037 it_view[x] = dst; 00038 } 00039 } 00040 } 00041 00042 template <typename blend_t, typename grayview_t, typename view_t> inline 00043 void copy(const grayview_t& gray, const view_t& bottom, const view_t& top) 00044 { 00045 using namespace boost::gil; 00046 BOOST_ASSERT(gray.width() == bottom.width()); 00047 BOOST_ASSERT(bottom.width() == top.width()); 00048 00049 typedef typename view_t::x_iterator x_iterator_t; 00050 typedef typename grayview_t::x_iterator x_iterator2_t; 00051 typedef typename view_t::value_type value_type_t; 00052 00053 for (int y = 0; y < top.height(); ++y) 00054 { 00055 x_iterator_t it_top = top.row_begin(y); 00056 x_iterator_t it_bot = bottom.row_begin(y); 00057 x_iterator2_t it_gray = gray.row_begin(y); 00058 for (int x = 0; x < top.width(); ++x) 00059 { 00060 value_type_t dst = it_bot[x]; 00061 static_for_each(dst, it_top[x], blend_t(it_gray[x])); 00062 it_top[x] = dst; 00063 } 00064 } 00065 } 00066 00067 #endif