14 #ifndef GIL_RESAMPLE_HPP 15 #define GIL_RESAMPLE_HPP 17 #include <boost/lambda/lambda.hpp> 18 #include <boost/lambda/bind.hpp> 19 #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp> 32 namespace boost {
namespace gil {
40 template <
typename MapFn>
struct mapping_traits {};
46 template <
typename Sampler,
50 void resample_pixels(
const SrcView& src_view,
const DstView& dst_view,
const MapFn& dst_to_src, Sampler sampler=Sampler()) {
51 typename DstView::point_t dst_dims=dst_view.dimensions();
52 typename DstView::point_t dst_p;
55 for (dst_p.y=0; dst_p.y<dst_dims.y; ++dst_p.y) {
56 typename DstView::x_iterator xit = dst_view.row_begin(dst_p.y);
57 for (dst_p.x=0; dst_p.x<dst_dims.x; ++dst_p.x) {
58 sample(sampler, src_view, transform(dst_to_src, dst_p), xit[dst_p.x]);
70 template <
typename Sampler,
typename MapFn>
71 struct resample_pixels_fn :
public binary_operation_obj<resample_pixels_fn<Sampler,MapFn> > {
74 resample_pixels_fn(
const MapFn& dst_to_src,
const Sampler& sampler) : _dst_to_src(dst_to_src), _sampler(sampler) {}
76 template <
typename SrcView,
typename DstView>
void apply_compatible(
const SrcView& src,
const DstView& dst)
const {
85 template <
typename Sampler,
typename Types1,
typename V2,
typename MapFn>
86 void resample_pixels(
const any_image_view<Types1>& src,
const V2& dst,
const MapFn& dst_to_src, Sampler sampler=Sampler()) {
87 apply_operation(src,bind(detail::resample_pixels_fn<Sampler,MapFn>(dst_to_src,sampler), _1, dst));
93 template <
typename Sampler,
typename V1,
typename Types2,
typename MapFn>
94 void resample_pixels(
const V1& src,
const any_image_view<Types2>& dst,
const MapFn& dst_to_src, Sampler sampler=Sampler()) {
95 apply_operation(dst,bind(detail::resample_pixels_fn<Sampler,MapFn>(dst_to_src,sampler), src, _1));
101 template <
typename Sampler,
typename SrcTypes,
typename DstTypes,
typename MapFn>
102 void resample_pixels(
const any_image_view<SrcTypes>& src,
const any_image_view<DstTypes>& dst,
const MapFn& dst_to_src, Sampler sampler=Sampler()) {
103 apply_operation(src,dst,detail::resample_pixels_fn<Sampler,MapFn>(dst_to_src,sampler));
115 template <
typename Sampler,
typename SrcMetaView,
typename DstMetaView>
116 void resample_subimage(
const SrcMetaView& src,
const DstMetaView& dst,
117 double src_min_x,
double src_min_y,
118 double src_max_x,
double src_max_y,
119 double angle,
const Sampler& sampler=Sampler()) {
120 double src_width = std::max<double>(src_max_x - src_min_x - 1,1);
121 double src_height = std::max<double>(src_max_y - src_min_y - 1,1);
122 double dst_width = std::max<double>((double)(dst.width()-1),1);
123 double dst_height = std::max<double>((double)(dst.height()-1),1);
139 template <
typename Sampler,
typename SrcMetaView,
typename DstMetaView>
140 void resize_view(
const SrcMetaView& src,
const DstMetaView& dst,
const Sampler& sampler=Sampler()) {
141 resample_subimage(src,dst,0.0,0.0,(
double)src.width(),(double)src.height(),0.0,sampler);
support for affine transformations
void resample_pixels(const SrcView &src_view, const DstView &dst_view, const MapFn &dst_to_src, Sampler sampler=Sampler())
Set each pixel in the destination view as the result of a sampling function over the transformed coor...
Define affine mapping that transforms the source coordinates by the affine transformation.