Example #1
0
inline void boost::gil::rescale_rows(const SrcView& src, const DstView& dst, const Filter& filter)
{
  typedef typename SrcView::value_type src_pixel_t;
  typedef typename gil::detail::create_accum_pixel_type<src_pixel_t>::type accum_pixel_t;

  if (src.width() != dst.width())
  {
    throw std::runtime_error("rescale_rows: width of source and destination views must match");
  }

  detail::weight_table weights;
  weights.reset(filter, src.height(), dst.height());

  detail::weight_table::const_iterator const table_begin = weights.begin();
  detail::weight_table::const_iterator const table_end   = weights.end();

  typedef typename DstView::coord_t coord_t;
  coord_t const width = dst.width();

  for (coord_t x=0; x<width; x++)
  {
    detail::rescale_line<accum_pixel_t>(
        src.col_begin(x)
      , dst.col_begin(x)
      , table_begin
      , table_end
      );
  }
}
Example #2
0
inline void boost::gil::rescale(const SrcView& src, const DstView& dst, const Filter& filter)
{
  typedef typename SrcView::value_type src_pixel_t;
  typedef typename gil::detail::create_accum_pixel_type<src_pixel_t>::type accum_pixel_t;

  // construct weights tables

  detail::weight_table horizontal_weights;
  horizontal_weights.reset(filter, src.width(), dst.width());

  detail::weight_table vertical_weights;
  vertical_weights.reset(filter, src.height(), dst.height());

  // allocate intermediary pixels row

  std::vector<accum_pixel_t> intermediate_row( src.width() );

  typedef typename DstView::coord_t coord_t;
  coord_t const src_width  = src.width();
  coord_t const dst_height = dst.height();

  for (coord_t y=0; y<dst_height; y++)
  {
    // create the intermediate row by vertically sampling the source image pixels

    detail::weight_table::const_iterator const vtable_begin = vertical_weights.begin() + y;
    detail::weight_table::const_iterator const vtable_end   = vtable_begin + 1;

    for (coord_t x=0; x<src_width; x++)
    {
      detail::rescale_line<accum_pixel_t>(
          src.col_begin(x)
        , intermediate_row.begin() + x
        , vtable_begin
        , vtable_end
        );
    }

    // scale horizontally the intermediate row into the destination row

    detail::weight_table::const_iterator const htable_begin = horizontal_weights.begin();
    detail::weight_table::const_iterator const htable_end   = horizontal_weights.end();

    detail::rescale_line<accum_pixel_t>(
        intermediate_row.begin()
      , dst.row_begin(y)
      , htable_begin
      , htable_end
      );
  }
}