8 #ifndef BOOST_GIL_IMAGE_PROCESSING_SCALING_HPP
9 #define BOOST_GIL_IMAGE_PROCESSING_SCALING_HPP
11 #include <boost/gil/image_view.hpp>
12 #include <boost/gil/rgb.hpp>
13 #include <boost/gil/pixel.hpp>
14 #include <boost/gil/image_processing/numeric.hpp>
16 namespace boost {
namespace gil {
36 template <
typename ImageView>
39 ImageView output_view,
40 typename ImageView::x_coord_t source_x,
41 typename ImageView::y_coord_t source_y,
42 typename ImageView::x_coord_t target_x,
43 typename ImageView::y_coord_t target_y,
46 using x_coord_t =
typename ImageView::x_coord_t;
47 using y_coord_t =
typename ImageView::y_coord_t;
48 using pixel_t =
typename std::remove_reference<decltype(std::declval<ImageView>()(0, 0))>::type;
51 using channel_t =
typename std::remove_reference
53 decltype(std::declval<pixel_t>().at(std::integral_constant<int, 0>{}))
57 static_transform(result_pixel, result_pixel, [](channel_t) {
58 return static_cast<channel_t
>(0);
60 auto x_zero =
static_cast<x_coord_t
>(0);
61 auto x_one =
static_cast<x_coord_t
>(1);
62 auto y_zero =
static_cast<y_coord_t
>(0);
63 auto y_one =
static_cast<y_coord_t
>(1);
65 for (y_coord_t y_i = (std::max)(source_y -
static_cast<y_coord_t
>(a) + y_one, y_zero);
66 y_i <= (std::min)(source_y + static_cast<y_coord_t>(a), input_view.height() - y_one);
69 for (x_coord_t x_i = (std::max)(source_x -
static_cast<x_coord_t
>(a) + x_one, x_zero);
70 x_i <= (std::min)(source_x + static_cast<x_coord_t>(a), input_view.width() - x_one);
73 double lanczos_response =
lanczos(source_x - x_i, a) *
lanczos(source_y - y_i, a);
74 auto op = [lanczos_response](channel_t prev, channel_t next)
76 return static_cast<channel_t
>(prev + next * lanczos_response);
78 static_transform(result_pixel, input_view(source_x, source_y), result_pixel, op);
82 output_view(target_x, target_y) = result_pixel;
94 template <
typename ImageView>
95 void scale_lanczos(ImageView input_view, ImageView output_view, std::ptrdiff_t a)
97 double scale_x = (
static_cast<double>(output_view.width()))
98 /
static_cast<double>(input_view.width());
99 double scale_y = (
static_cast<double>(output_view.height()))
100 /
static_cast<double>(input_view.height());
102 using x_coord_t =
typename ImageView::x_coord_t;
103 using y_coord_t =
typename ImageView::y_coord_t;
104 for (y_coord_t y = 0; y < output_view.height(); ++y)
106 for (x_coord_t x = 0; x < output_view.width(); ++x)
108 lanczos_at(input_view, output_view, x / scale_x, y / scale_y, x, y, a);
void scale_lanczos(ImageView input_view, ImageView output_view, std::ptrdiff_t a)
Complete Lanczos algorithm.
Definition: scaling.hpp:95
double lanczos(double x, std::ptrdiff_t a)
Lanczos response at point x.
Definition: numeric.hpp:46
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36