Boost logo

Boost :

Subject: Re: [boost] [gil] What is the status of the Gil extension numeric?
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-03-14 14:15:06


2013/3/14 Christian Henning <chhenning_at_[hidden]>

> > My patch attached. I didn't write any tests (yet?).
>
> Could you give me a short description what this patch does.
> Thanks!
> Christian
>

Sure:

 Index: boost/gil/extension/numeric/sampler.hpp
===================================================================
--- boost/gil/extension/numeric/sampler.hpp (revision 796)
+++ boost/gil/extension/numeric/sampler.hpp (working copy)

### This fixed a compile error on platforms, where ptrdiff_t isn't int:
@@ -45,7 +45,7 @@
  template <typename DstP, typename SrcView, typename F>
 bool sample(nearest_neighbor_sampler, const SrcView& src, const point2<F>&
p, DstP& result) {
- point2<int> center(iround(p));
+ typename SrcView::point_t center(iround(p));
     if (center.x>=0 && center.y>=0 && center.x<src.width() &&
center.y<src.height()) {
         result=src(center.x,center.y);
         return true;

### Here some comments were wrong, and border cases were handled
incorrectly:
@@ -118,33 +118,35 @@
     {
  if (p0.y == -1)
         {
### Added comment
+ // the top-left corner pixel
  ++loc.y();
### corrected the formula; the old one caused a dark line in the
destination image
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x * frac.y ,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], 1 ,mp);
  }
         else if (p0.y+1<src.height())
         {
### wrong comment and formula;
- // most common case - inside the image, not on the last row or column
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x *(1-frac.y),mp);
+ // on the first column, but not the top-left nor bottom-left
corner pixel
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], (1-frac.y),mp);
  ++loc.y();
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x * frac.y ,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.y ,mp);
  }
         else
         {
### wrong comment and formula
- // on the last row, but not the bottom-right corner pixel
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x ,mp);
+ // the bottom-left corner pixel
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], 1 ,mp);
  }
  }
     else if (p0.x+1<src.width())
     {
  if (p0.y == -1)
         {
### lacking comment, wrong formula
+ // on the first row, but not the top-left nor top-right corner pixel
  ++loc.y();
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.x)* frac.y ,mp);
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x * frac.y ,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.x) ,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x ,mp);
  }
         else if (p0.y+1<src.height())
         {
### comment slightly elaborated
- // most common case - inside the image, not on the last row or column
+ // most common case - inside the image, not on the frist nor last
row/column
  detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.x)*(1-frac.y),mp);
  detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x *(1-frac.y),mp);
  ++loc.y();
@@ -153,24 +155,30 @@
  }
         else
         {
### comment elaborated a bit, and formula unchanged, reformated only
- // on the last row, but not the bottom-right corner pixel
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.x),mp);
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x ,mp);
+ // on the last row, but not the bottom-left nor bottom-right corner pixel
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.x) ,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(loc.x()[1], frac.x ,mp);
  }
  }
     else
     {
### added the top-right corner pixel case
- if (p0.y+1<src.height())
+ if (p0.y == -1)
         {
- // on the last column, but not the bottom-right corner pixel
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.y),mp);
+ // the top-right corner pixel
+ ++loc.y();
+
 detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, 1 ,mp);
+ }
### elaborated the comment and the formula unchanged (formated only)
+ else if (p0.y+1<src.height())
+ {
+ // on the last column, but not the top-right nor bottom-right corner pixel
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, (1-frac.y),mp);
  ++loc.y();
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, frac.y ,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, frac.y ,mp);
  }
         else
         {
  // the bottom-right corner pixel
### formated only
- detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc,1,mp);
+ detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value>
> >()(*loc, 1 ,mp);
  }
  }

Regards,
Kris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk