9#ifndef BOOST_GIL_ALGORITHM_HPP
10#define BOOST_GIL_ALGORITHM_HPP
12#include <boost/gil/metafunctions.hpp>
13#include <boost/gil/pixel_iterator.hpp>
14#include <boost/gil/pixel_numeric_operations.hpp>
15#include <boost/gil/image.hpp>
16#include <boost/gil/bit_aligned_pixel_iterator.hpp>
17#include <boost/gil/color_base_algorithm.hpp>
18#include <boost/gil/concepts.hpp>
19#include <boost/gil/image_view.hpp>
20#include <boost/gil/image_view_factory.hpp>
21#include <boost/gil/detail/mp11.hpp>
22#include <boost/gil/detail/type_traits.hpp>
24#include <boost/assert.hpp>
25#include <boost/config.hpp>
36namespace boost {
namespace gil {
39template <
typename ChannelPtr,
typename ColorSpace>
40struct planar_pixel_iterator;
41template <
typename Iterator>
42class memory_based_step_iterator;
43template <
typename StepIterator>
44class memory_based_2d_locator;
86template <
typename Derived,
typename Result=
void>
89 using result_type = Result;
91 template <
typename V1,
typename V2> BOOST_FORCEINLINE
92 auto operator()(
const std::pair<const V1*,const V2*>& p)
const -> result_type {
96 template <
typename V1,
typename V2> BOOST_FORCEINLINE
97 auto operator()(
const V1& v1,
const V2& v2)
const -> result_type {
101 auto operator()(
const error_t&)
const -> result_type {
throw std::bad_cast(); }
105 template <
typename V1,
typename V2>
107 auto apply(V1
const& v1, V2
const& v2, std::false_type)
const -> result_type
109 return ((
const Derived*)
this)->apply_incompatible(v1, v2);
113 template <
typename V1,
typename V2>
115 auto apply(V1
const& v1, V2
const& v2, std::true_type)
const -> result_type
117 return ((
const Derived*)
this)->apply_compatible(v1, v2);
121 template <
typename V1,
typename V2>
123 auto apply_incompatible(V1
const& , V2
const& )
const -> result_type
125 throw std::bad_cast();
143template<
typename T,
typename CS>
151 auto p = std::copy((
unsigned char*)first, (
unsigned char*)last, (
unsigned char*)dst);
157template<
typename T,
typename CS>
166namespace boost {
namespace gil {
168template <
typename I,
typename O>
struct copy_fn {
169 BOOST_FORCEINLINE I operator()(I first, I last, O dst)
const {
return std::copy(first,last,dst); }
177template<
typename CS,
typename IC1,
typename IC2> BOOST_FORCEINLINE
180 boost::gil::gil_function_requires<boost::gil::ChannelsCompatibleConcept<typename std::iterator_traits<IC1>::value_type,
typename std::iterator_traits<IC2>::value_type>>();
181 static_for_each(first,last,dst,boost::gil::detail::copy_fn<IC1,IC2>());
182 return dst+(last-first);
186namespace boost {
namespace gil {
190template <
typename I,
typename O>
192 BOOST_FORCEINLINE
void operator()(I src,
typename std::iterator_traits<I>::difference_type n, O dst)
const {
195 std::copy(src, src + n, dst);
200template <
typename IL,
typename O>
202 using diff_t =
typename std::iterator_traits<iterator_from_2d<IL>>::difference_type;
204 gil_function_requires<PixelLocatorConcept<IL>>();
205 gil_function_requires<MutablePixelIteratorConcept<O>>();
207 diff_t l=src.width()-src.x_pos();
208 diff_t numToCopy=(n<l ? n:l);
209 detail::copy_n(src.x(), numToCopy, dst);
218template <
typename I,
typename OL>
220 using diff_t =
typename std::iterator_traits<I>::difference_type;
222 gil_function_requires<PixelIteratorConcept<I>>();
223 gil_function_requires<MutablePixelLocatorConcept<OL>>();
225 diff_t l=dst.width()-dst.x_pos();
226 diff_t numToCopy=(n<l ? n:l);
227 detail::copy_n(src, numToCopy, dst.x());
236template <
typename IL,
typename OL>
238 using diff_t =
typename iterator_from_2d<IL>::difference_type;
240 gil_function_requires<PixelLocatorConcept<IL>>();
241 gil_function_requires<MutablePixelLocatorConcept<OL>>();
242 if (src.x_pos()!=dst.x_pos() || src.width()!=dst.width()) {
248 diff_t l=dst.width()-dst.x_pos();
249 diff_t numToCopy=(n<l ? n : l);
250 detail::copy_n(src.x(), numToCopy, dst.x());
258template <
typename SrcIterator,
typename DstIterator>
259BOOST_FORCEINLINE
auto copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) -> DstIterator {
260 using src_x_iterator =
typename SrcIterator::x_iterator;
261 using dst_x_iterator =
typename DstIterator::x_iterator;
263 typename SrcIterator::difference_type n = last - first;
265 if (first.is_1d_traversable()) {
266 if (dst.is_1d_traversable())
271 if (dst.is_1d_traversable())
272 copier_n<SrcIterator,dst_x_iterator>()(first,n, dst.x());
274 copier_n<SrcIterator,DstIterator>()(first,n,dst);
284template <
typename IL,
typename OL>
287 return boost::gil::detail::copy_with_2d_iterators(first,last,dst);
292namespace boost {
namespace gil {
295template <
typename View1,
typename View2> BOOST_FORCEINLINE
298 BOOST_ASSERT(src.dimensions() == dst.dimensions());
299 detail::copy_with_2d_iterators(src.begin(),src.end(),dst.begin());
313template <
typename CC>
314class copy_and_convert_pixels_fn :
public binary_operation_obj<copy_and_convert_pixels_fn<CC>>
319 using result_type =
typename binary_operation_obj<copy_and_convert_pixels_fn<default_color_converter>>::result_type;
320 copy_and_convert_pixels_fn() {}
321 copy_and_convert_pixels_fn(CC cc_in) : _cc(cc_in) {}
323 template <
typename V1,
typename V2> BOOST_FORCEINLINE
324 auto apply_incompatible(
const V1& src,
const V2& dst)
const -> result_type {
325 copy_pixels(color_converted_view<typename V2::value_type>(src,_cc),dst);
329 template <
typename V1,
typename V2> BOOST_FORCEINLINE
330 auto apply_compatible(
const V1& src,
const V2& dst)
const -> result_type {
337template <
typename V1,
typename V2,
typename CC>
339void copy_and_convert_pixels(
const V1& src,
const V2& dst,CC cc) {
340 detail::copy_and_convert_pixels_fn<CC> ccp(cc);
344struct default_color_converter;
347template <
typename View1,
typename View2>
349void copy_and_convert_pixels(
const View1& src,
const View2& dst) {
350 detail::copy_and_convert_pixels_fn<default_color_converter> ccp;
372template <
typename IL,
typename V>
374 boost::gil::gil_function_requires<boost::gil::MutablePixelLocatorConcept<IL>>();
375 if (first.is_1d_traversable()) {
379 std::ptrdiff_t n=last-first;
381 std::ptrdiff_t numToDo=std::min<const std::ptrdiff_t>(n,(std::ptrdiff_t)(first.width()-first.x_pos()));
382 std::fill_n(first.x(), numToDo, val);
390namespace boost {
namespace gil {
396 template <
typename It,
typename P>
397 void operator()(It first, It last,
const P& p_in) {
403template <
typename It,
typename P>
405void fill_aux(It first, It last, P
const& p, std::true_type)
407 static_for_each(first, last, p,
std_fill_t());
411template <
typename It,
typename P>
413void fill_aux(It first, It last, P
const& p, std::false_type)
422template <
typename View,
typename Value>
426 if (
view.is_1d_traversable())
429 view.begin().x(),
view.end().x(), value, is_planar<View>());
433 for (std::ptrdiff_t y = 0; y <
view.height(); ++y)
435 view.row_begin(y),
view.row_end(y), value, is_planar<View>());
448template <
typename Iterator>
450void destruct_range_impl(Iterator first, Iterator last,
451 typename std::enable_if
455 std::is_pointer<Iterator>,
458 detail::is_trivially_destructible<
typename std::iterator_traits<Iterator>::value_type>
463 while (first != last)
470template <
typename Iterator>
472void destruct_range_impl(Iterator , Iterator ,
473 typename std::enable_if
477 mp11::mp_not<std::is_pointer<Iterator>>,
478 detail::is_trivially_destructible<
typename std::iterator_traits<Iterator>::value_type>
484template <
typename Iterator>
486void destruct_range(Iterator first, Iterator last)
488 destruct_range_impl(first, last);
493 template <
typename Iterator>
494 void operator()(Iterator first, Iterator last)
const
496 destruct_range(first,last);
501template <
typename It>
503void destruct_aux(It first, It last, std::true_type)
505 static_for_each(first,last,std_destruct_t());
509template <
typename It>
511void destruct_aux(It first, It last, std::false_type)
513 destruct_range(first,last);
520template <
typename View>
524 if (
view.is_1d_traversable())
526 detail::destruct_aux(
527 view.begin().x(),
view.end().x(), is_planar<View>());
531 for (std::ptrdiff_t y = 0; y <
view.height(); ++y)
532 detail::destruct_aux(
533 view.row_begin(y),
view.row_end(y), is_planar<View>());
549template <
typename It,
typename P>
551void uninitialized_fill_aux(It first, It last, P
const& p, std::true_type)
553 std::size_t channel = 0;
556 using pixel_t =
typename std::iterator_traits<It>::value_type;
557 while (channel < num_channels<pixel_t>::value)
559 std::uninitialized_fill(
560 dynamic_at_c(first,channel),
561 dynamic_at_c(last,channel),
562 dynamic_at_c(p,channel));
569 for (std::size_t c = 0; c < channel; ++c)
570 destruct_range(dynamic_at_c(first, c), dynamic_at_c(last, c));
577template <
typename It,
typename P>
579void uninitialized_fill_aux(It first, It last, P
const& p, std::false_type)
581 std::uninitialized_fill(first,last,p);
590template <
typename View,
typename Value>
592 if (
view.is_1d_traversable())
593 detail::uninitialized_fill_aux(
view.begin().x(),
view.end().x(),
594 val,is_planar<View>());
596 typename View::y_coord_t y = 0;
598 for (y=0; y<
view.height(); ++y)
599 detail::uninitialized_fill_aux(
view.row_begin(y),
view.row_end(y),
600 val,is_planar<View>());
602 for (
typename View::y_coord_t y0=0; y0<y; ++y0)
603 detail::destruct_aux(
view.row_begin(y0),
view.row_end(y0), is_planar<View>());
618template <
typename It> BOOST_FORCEINLINE
619void default_construct_range_impl(It first, It last, std::true_type)
624 using value_t =
typename std::iterator_traits<It>::value_type;
625 while (first != last)
627 new (first) value_t();
633 destruct_range(first1, first);
638template <
typename It>
640void default_construct_range_impl(It, It, std::false_type) {}
642template <
typename It>
644void default_construct_range(It first, It last)
646 default_construct_range_impl(first, last,
typename std::is_pointer<It>::type());
650template <
typename It>
652void default_construct_aux(It first, It last, std::true_type)
654 std::size_t channel = 0;
657 using pixel_t =
typename std::iterator_traits<It>::value_type;
658 while (channel < num_channels<pixel_t>::value)
660 default_construct_range(dynamic_at_c(first, channel), dynamic_at_c(last, channel));
666 for (std::size_t c = 0; c < channel; ++c)
667 destruct_range(dynamic_at_c(first, c), dynamic_at_c(last, c));
673template <
typename It>
675void default_construct_aux(It first, It last, std::false_type)
677 default_construct_range(first, last);
680template <
typename View,
bool IsPlanar>
681struct has_trivial_pixel_constructor
682 : detail::is_trivially_default_constructible<typename View::value_type>
685template <
typename View>
686struct has_trivial_pixel_constructor<View, true>
687 : detail::is_trivially_default_constructible<typename channel_type<View>::type>
690template<
typename View,
bool IsTriviallyConstructible>
692void default_construct_pixels_impl(
694 std::enable_if<!IsTriviallyConstructible>* =
nullptr)
696 if (
view.is_1d_traversable())
698 detail::default_construct_aux(
699 view.begin().x(),
view.end().x(), is_planar<View>());
703 typename View::y_coord_t y = 0;
706 for( y = 0; y <
view.height(); ++y )
707 detail::default_construct_aux(
708 view.row_begin(y),
view.row_end(y), is_planar<View>());
712 for (
typename View::y_coord_t y0 = 0; y0 < y; ++y0 )
713 detail::destruct_aux(
714 view.row_begin(y0),
view.row_end(y0), is_planar<View>());
727template <
typename View>
730 detail::default_construct_pixels_impl
733 detail::has_trivial_pixel_constructor
736 is_planar<View>::value
751enum class copy_planarity_condition
754 interleaved_to_planar,
758using planar_to_planar_type =
759 std::integral_constant
761 copy_planarity_condition, copy_planarity_condition::planar_to_planar
763using interleaved_to_planar_type =
764 std::integral_constant
766 copy_planarity_condition, copy_planarity_condition::interleaved_to_planar
768using mixed_to_interleaved_type =
769 std::integral_constant
771 copy_planarity_condition, copy_planarity_condition::mixed_to_interleaved
775template <
typename It1,
typename It2>
777void uninitialized_copy_aux(It1 first1, It1 last1, It2 first2, It2 last2, planar_to_planar_type)
779 std::size_t channel=0;
781 using pixel_t =
typename std::iterator_traits<It1>::value_type;
782 while (channel < num_channels<pixel_t>::value)
784 std::uninitialized_copy(
785 dynamic_at_c(first1, channel),
786 dynamic_at_c(last1, channel),
787 dynamic_at_c(first2, channel));
794 std::advance(last2, std::distance(first1, last1));
795 for (std::size_t c = 0; c < channel; ++c)
796 destruct_range(dynamic_at_c(first2, c), dynamic_at_c(last2, c));
802template <
typename It1,
typename It2>
804void uninitialized_copy_aux(It1 first1, It1 last1, It2 first2, It2, mixed_to_interleaved_type)
806 std::uninitialized_copy(first1, last1, first2);
810template <
typename It1,
typename It2>
812void uninitialized_copy_aux(It1 first1, It1, It2 first2, It2 last2,
813interleaved_to_planar_type)
815 default_construct_aux(first2, last2, std::true_type());
817 typename It2::difference_type n = last2 - first2;
818 copier_n<It1,It2>()(first1, n, first2);
826template <
typename View1,
typename View2>
829 using copy_planarity_condition = detail::copy_planarity_condition;
830 using copy_planarity_condition_type =
831 std::integral_constant
833 copy_planarity_condition,
834 !is_planar<View2>::value
835 ? copy_planarity_condition::mixed_to_interleaved
836 : (is_planar<View1>::value
837 ? copy_planarity_condition::planar_to_planar
838 : copy_planarity_condition::interleaved_to_planar)
840 BOOST_ASSERT(view1.dimensions() == view2.dimensions());
842 if (view1.is_1d_traversable() && view2.is_1d_traversable())
844 detail::uninitialized_copy_aux(
845 view1.begin().x(), view1.end().x(), view2.begin().x(), view2.end().x(),
846 copy_planarity_condition_type());
850 typename View1::y_coord_t y = 0;
853 for (y = 0; y < view1.height(); ++y)
854 detail::uninitialized_copy_aux(
855 view1.row_begin(y), view1.row_end(y), view2.row_begin(y), view2.row_end(y),
856 copy_planarity_condition_type());
860 for (
typename View1::y_coord_t y0 = 0; y0 < y; ++y0)
861 detail::destruct_aux(view2.row_begin(y0), view2.row_end(y0), is_planar<View2>());
881template <
typename View,
typename F>
882F for_each_pixel(View
const&
view, F fun)
884 if (
view.is_1d_traversable())
886 return std::for_each(
view.begin().x(),
view.end().x(), fun);
890 for (std::ptrdiff_t y = 0; y <
view.height(); ++y)
891 for (
auto begin =
view.row_begin(y), end =
view.row_end(y); begin != end; ++begin)
902template <
typename View,
typename F>
903F for_each_pixel_position(View
const&
view, F fun)
905 typename View::xy_locator loc =
view.xy_at(0, 0);
906 for (std::ptrdiff_t y = 0; y <
view.height(); ++y)
908 for (std::ptrdiff_t x = 0; x <
view.width(); ++x, ++loc.x())
910 loc.x() -=
view.width(); ++loc.y();
925template <
typename View,
typename F>
928 if (
view.is_1d_traversable())
930 std::generate(
view.begin().x(),
view.end().x(), fun);
934 for (std::ptrdiff_t y = 0; y <
view.height(); ++y)
935 std::generate(
view.row_begin(y),
view.row_end(y), fun);
947template <
typename I1,
typename I2>
949bool equal_n(I1 i1, std::ptrdiff_t n, I2 i2);
953template <
typename I1,
typename I2>
957 bool operator()(I1 i1, std::ptrdiff_t n, I2 i2)
const
965template<
typename T,
typename CS>
975template<
typename T,
typename CS>
983template<
typename IC,
typename CS>
990 constexpr std::ptrdiff_t byte_size = n *
sizeof(
typename std::iterator_traits<IC>::value_type);
991 for (std::ptrdiff_t i = 0; i < mp11::mp_size<CS>::value; ++i)
993 if (memcmp(dynamic_at_c(i1, i), dynamic_at_c(i2, i), byte_size) != 0)
1003template <
typename Loc,
typename It>
1009 gil_function_requires<boost::gil::PixelLocatorConcept<Loc>>();
1010 gil_function_requires<boost::gil::PixelIteratorConcept<It>>();
1013 std::ptrdiff_t
const num = std::min<std::ptrdiff_t>(n, i1.width() - i1.x_pos());
1014 if (!equal_n(i1.x(), num, i2))
1027template <
typename It,
typename Loc>
1033 gil_function_requires<boost::gil::PixelIteratorConcept<It>>();
1034 gil_function_requires<boost::gil::PixelLocatorConcept<Loc>>();
1037 std::ptrdiff_t
const num = std::min<std::ptrdiff_t>(n, i2.width() - i2.x_pos());
1038 if (!equal_n(i1, num, i2.x()))
1049template <
typename Loc1,
typename Loc2>
1052 gil_function_requires<boost::gil::PixelLocatorConcept<Loc1>>();
1053 gil_function_requires<boost::gil::PixelLocatorConcept<Loc2>>();
1054 if (i1.x_pos()!=i2.x_pos() || i1.width()!=i2.width()) {
1056 if (*i1++!=*i2++)
return false;
1060 std::ptrdiff_t num=std::min<const std::ptrdiff_t>(n,i2.width()-i2.x_pos());
1061 if (!equal_n(i1.x(), num, i2.x()))
1072template <
typename I1,
typename I2> BOOST_FORCEINLINE
1073bool equal_n(I1 i1, std::ptrdiff_t n, I2 i2) {
1074 return detail::equal_n_fn<I1,I2>()(i1,n,i2);
1090template <
typename Loc1,
typename Loc2> BOOST_FORCEINLINE
1092 boost::gil::gil_function_requires<boost::gil::PixelLocatorConcept<Loc1>>();
1093 boost::gil::gil_function_requires<boost::gil::PixelLocatorConcept<Loc2>>();
1094 std::ptrdiff_t n=last-first;
1095 if (first.is_1d_traversable()) {
1096 if (first2.is_1d_traversable())
1097 return boost::gil::detail::equal_n_fn<typename Loc1::x_iterator,typename Loc2::x_iterator>()(first.x(),n, first2.x());
1099 return boost::gil::detail::equal_n_fn<typename Loc1::x_iterator,boost::gil::iterator_from_2d<Loc2>>()(first.x(),n, first2);
1101 if (first2.is_1d_traversable())
1109namespace boost {
namespace gil {
1112template <
typename View1,
typename View2> BOOST_FORCEINLINE
1114 BOOST_ASSERT(v1.dimensions() == v2.dimensions());
1115 return std::equal(v1.begin(),v1.end(),v2.begin());
1130template <
typename View1,
typename View2,
typename F> BOOST_FORCEINLINE
1132 BOOST_ASSERT(src.dimensions() == dst.dimensions());
1133 for (std::ptrdiff_t y=0; y<src.height(); ++y) {
1134 typename View1::x_iterator srcIt=src.row_begin(y);
1135 typename View2::x_iterator dstIt=dst.row_begin(y);
1136 for (std::ptrdiff_t x=0; x<src.width(); ++x)
1137 dstIt[x]=fun(srcIt[x]);
1144template <
typename View1,
typename View2,
typename View3,
typename F> BOOST_FORCEINLINE
1146 for (std::ptrdiff_t y=0; y<dst.height(); ++y) {
1147 typename View1::x_iterator srcIt1=src1.row_begin(y);
1148 typename View2::x_iterator srcIt2=src2.row_begin(y);
1149 typename View3::x_iterator dstIt=dst.row_begin(y);
1150 for (std::ptrdiff_t x=0; x<dst.width(); ++x)
1151 dstIt[x]=fun(srcIt1[x],srcIt2[x]);
1162template <
typename View1,
typename View2,
typename F> BOOST_FORCEINLINE
1164 BOOST_ASSERT(src.dimensions() == dst.dimensions());
1165 typename View1::xy_locator loc=src.xy_at(0,0);
1166 for (std::ptrdiff_t y=0; y<src.height(); ++y) {
1167 typename View2::x_iterator dstIt=dst.row_begin(y);
1168 for (std::ptrdiff_t x=0; x<src.width(); ++x, ++loc.x())
1170 loc.x()-=src.width(); ++loc.y();
1177template <
typename View1,
typename View2,
typename View3,
typename F> BOOST_FORCEINLINE
1179 BOOST_ASSERT(src1.dimensions() == dst.dimensions());
1180 BOOST_ASSERT(src2.dimensions() == dst.dimensions());
1181 typename View1::xy_locator loc1=src1.xy_at(0,0);
1182 typename View2::xy_locator loc2=src2.xy_at(0,0);
1183 for (std::ptrdiff_t y=0; y<src1.height(); ++y) {
1184 typename View3::x_iterator dstIt=dst.row_begin(y);
1185 for (std::ptrdiff_t x=0; x<src1.width(); ++x, ++loc1.x(), ++loc2.x())
1186 dstIt[x]=fun(loc1,loc2);
1187 loc1.x()-=src1.width(); ++loc1.y();
1188 loc2.x()-=src2.width(); ++loc2.y();
1200template <
typename T>
1204template <
typename Iterator1,
typename Iterator2,
typename BinaryFunction>
1205BinaryFunction for_each(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryFunction f)
1207 while (first1 != last1)
1208 f(*first1++, *first2++);
1212template <
typename SrcIterator,
typename DstIterator>
1214auto assign_pixels(SrcIterator src, SrcIterator src_end, DstIterator dst) -> DstIterator
1216 for_each(src, src_end, dst,
1219 typename pixel_proxy<
typename std::iterator_traits<SrcIterator>::value_type>::type,
1220 typename pixel_proxy<
typename std::iterator_traits<DstIterator>::value_type>::type
1222 return dst + (src_end - src);
1227template <std::
size_t Size>
1228struct inner_product_k_t
1232 class InputIterator1,
1233 class InputIterator2,
1235 class BinaryOperation1,
1236 class BinaryOperation2
1239 InputIterator1 first1,
1240 InputIterator2 first2, T init,
1241 BinaryOperation1 binary_op1,
1242 BinaryOperation2 binary_op2)
1244 init = binary_op1(init, binary_op2(*first1, *first2));
1245 return inner_product_k_t<Size - 1>::apply(
1246 first1 + 1, first2 + 1, init, binary_op1, binary_op2);
1251struct inner_product_k_t<0>
1255 class InputIterator1,
1256 class InputIterator2,
1258 class BinaryOperation1,
1259 class BinaryOperation2
1262 InputIterator1 first1,
1263 InputIterator2 first2,
1265 BinaryOperation1 binary_op1,
1266 BinaryOperation2 binary_op2)
1278 class InputIterator1,
1279 class InputIterator2,
1281 class BinaryOperation1,
1282 class BinaryOperation2
1286 InputIterator1 first1,
1287 InputIterator2 first2,
1289 BinaryOperation1 binary_op1,
1290 BinaryOperation2 binary_op2)
1292 return detail::inner_product_k_t<Size>::apply(
1293 first1, first2, init, binary_op1, binary_op2);
1299 typename PixelAccum,
1300 typename SrcIterator,
1301 typename KernelIterator,
1303 typename DstIterator
1306auto correlate_pixels_n(
1307 SrcIterator src_begin,
1308 SrcIterator src_end,
1309 KernelIterator kernel_begin,
1311 DstIterator dst_begin)
1314 using src_pixel_ref_t =
typename pixel_proxy
1316 typename std::iterator_traits<SrcIterator>::value_type
1318 using dst_pixel_ref_t =
typename pixel_proxy
1320 typename std::iterator_traits<DstIterator>::value_type
1322 using kernel_value_t =
typename std::iterator_traits<KernelIterator>::value_type;
1324 PixelAccum accum_zero;
1325 pixel_zeros_t<PixelAccum>()(accum_zero);
1326 while (src_begin != src_end)
1328 pixel_assigns_t<PixelAccum, dst_pixel_ref_t>()(
1331 src_begin + kernel_size,
1334 pixel_plus_t<PixelAccum, PixelAccum, PixelAccum>(),
1335 pixel_multiplies_scalar_t<src_pixel_ref_t, kernel_value_t, PixelAccum>()),
1348 typename PixelAccum,
1349 typename SrcIterator,
1350 typename KernelIterator,
1351 typename DstIterator
1354auto correlate_pixels_k(
1355 SrcIterator src_begin,
1356 SrcIterator src_end,
1357 KernelIterator kernel_begin,
1358 DstIterator dst_begin)
1361 using src_pixel_ref_t =
typename pixel_proxy
1363 typename std::iterator_traits<SrcIterator>::value_type
1365 using dst_pixel_ref_t =
typename pixel_proxy
1367 typename std::iterator_traits<DstIterator>::value_type
1369 using kernel_type =
typename std::iterator_traits<KernelIterator>::value_type;
1371 PixelAccum accum_zero;
1372 pixel_zeros_t<PixelAccum>()(accum_zero);
1373 while (src_begin != src_end)
1375 pixel_assigns_t<PixelAccum, dst_pixel_ref_t>()(
1376 inner_product_k<Size>(
1380 pixel_plus_t<PixelAccum, PixelAccum, PixelAccum>(),
1381 pixel_multiplies_scalar_t<src_pixel_ref_t, kernel_type, PixelAccum>()),
1394template <
typename PixelAccum,
typename SrcView,
typename Scalar,
typename DstView>
1396void view_multiplies_scalar(SrcView
const& src_view, Scalar
const& scalar, DstView
const& dst_view)
1398 static_assert(std::is_scalar<Scalar>::value,
"Scalar is not scalar");
1399 BOOST_ASSERT(src_view.dimensions() == dst_view.dimensions());
1400 using src_pixel_ref_t =
typename pixel_proxy<typename SrcView::value_type>::type;
1401 using dst_pixel_ref_t =
typename pixel_proxy<typename DstView::value_type>::type;
1402 using y_coord_t =
typename SrcView::y_coord_t;
1404 y_coord_t
const height = src_view.height();
1405 for (y_coord_t y = 0; y < height; ++y)
1407 typename SrcView::x_iterator it_src = src_view.row_begin(y);
1408 typename DstView::x_iterator it_dst = dst_view.row_begin(y);
1409 typename SrcView::x_iterator it_src_end = src_view.row_end(y);
1410 while (it_src != it_src_end)
1412 pixel_assigns_t<PixelAccum, dst_pixel_ref_t>()(
1413 pixel_multiplies_scalar_t<src_pixel_ref_t, Scalar, PixelAccum>()(*it_src, scalar),
1425enum class boundary_option
1437template <
typename SrcView,
typename RltView>
1438void extend_row_impl(
1439 SrcView
const& src_view,
1440 RltView result_view,
1441 std::size_t extend_count,
1442 boundary_option option)
1444 std::ptrdiff_t extend_count_ =
static_cast<std::ptrdiff_t
>(extend_count);
1446 if (option == boundary_option::extend_constant)
1448 for (std::ptrdiff_t i = 0; i < result_view.height(); i++)
1450 if(i >= extend_count_ && i < extend_count_ + src_view.height())
1453 src_view.row_begin(i - extend_count_),
1454 src_view.row_end(i - extend_count_),
1455 result_view.row_begin(i)
1458 else if(i < extend_count_)
1460 assign_pixels(src_view.row_begin(0), src_view.row_end(0), result_view.row_begin(i));
1465 src_view.row_begin(src_view.height() - 1),
1466 src_view.row_end(src_view.height() - 1),
1467 result_view.row_begin(i)
1473 else if (option == boundary_option::extend_zero)
1475 typename SrcView::value_type acc_zero;
1476 pixel_zeros_t<typename SrcView::value_type>()(acc_zero);
1478 for (std::ptrdiff_t i = 0; i < result_view.height(); i++)
1480 if (i >= extend_count_ && i < extend_count_ + src_view.height())
1483 src_view.row_begin(i - extend_count_),
1484 src_view.row_end(i - extend_count_),
1485 result_view.row_begin(i)
1490 std::fill_n(result_view.row_begin(i), result_view.width(), acc_zero);
1494 else if (option == boundary_option::extend_padded)
1496 auto original_view = subimage_view(
1501 src_view.height() + (2 * extend_count)
1503 for (std::ptrdiff_t i = 0; i < result_view.height(); i++)
1506 original_view.row_begin(i),
1507 original_view.row_end(i),
1508 result_view.row_begin(i)
1514 BOOST_ASSERT_MSG(
false,
"Invalid boundary option");
1527template <
typename SrcView>
1529 SrcView
const& src_view,
1530 std::size_t extend_count,
1531 boundary_option option
1532) ->
typename gil::image<typename SrcView::value_type>
1534 typename gil::image<typename SrcView::value_type>
1535 result_img(src_view.width(), src_view.height() + (2 * extend_count));
1537 auto result_view =
view(result_img);
1538 detail::extend_row_impl(src_view, result_view, extend_count, option);
1549template <
typename SrcView>
1551 SrcView
const& src_view,
1552 std::size_t extend_count,
1553 boundary_option option
1554) ->
typename gil::image<typename SrcView::value_type>
1556 auto src_view_rotate = rotated90cw_view(src_view);
1558 typename gil::image<typename SrcView::value_type>
1559 result_img(src_view.width() + (2 * extend_count), src_view.height());
1561 auto result_view = rotated90cw_view(
view(result_img));
1562 detail::extend_row_impl(src_view_rotate, result_view, extend_count, option);
1572template <
typename SrcView>
1573auto extend_boundary(
1574 SrcView
const& src_view,
1575 std::size_t extend_count,
1576 boundary_option option
1577) ->
typename gil::image<typename SrcView::value_type>
1579 if (option == boundary_option::extend_padded)
1581 typename gil::image<typename SrcView::value_type>
1582 result_img(src_view.width()+(2 * extend_count), src_view.height()+(2 * extend_count));
1583 typename gil::image<typename SrcView::value_type>::view_t result_view =
view(result_img);
1585 auto original_view = subimage_view(
1589 src_view.width() + (2 * extend_count),
1590 src_view.height() + (2 * extend_count)
1593 for (std::ptrdiff_t i = 0; i < result_view.height(); i++)
1596 original_view.row_begin(i),
1597 original_view.row_end(i),
1598 result_view.row_begin(i)
1605 auto auxilary_img = extend_col(src_view, extend_count, option);
1606 return extend_row(
view(auxilary_img), extend_count, option);
Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept,...
Definition iterator_from_2d.hpp:49
auto view(image< Pixel, IsPlanar, Alloc > &img) -> typename image< Pixel, IsPlanar, Alloc >::view_t const &
Returns the non-constant-pixel view of an image.
Definition image.hpp:565
BOOST_FORCEINLINE void copy_pixels(const View1 &src, const View2 &dst)
std::copy for image views
Definition algorithm.hpp:296
void default_construct_pixels(View const &view)
Invokes the in-place default constructor on every pixel of the (uninitialized) view....
Definition algorithm.hpp:728
BOOST_FORCEINLINE void destruct_pixels(View const &view)
Invokes the in-place destructor on every pixel of the view.
Definition algorithm.hpp:522
BOOST_FORCEINLINE bool equal_pixels(const View1 &v1, const View2 &v2)
std::equal for image views
Definition algorithm.hpp:1113
BOOST_FORCEINLINE void fill_pixels(View const &view, Value const &value)
std::fill for image views
Definition algorithm.hpp:424
void generate_pixels(View const &view, F fun)
std::generate for image views
Definition algorithm.hpp:926
void uninitialized_copy_pixels(View1 const &view1, View2 const &view2)
std::uninitialized_copy for image views. Does not support planar heterogeneous views....
Definition algorithm.hpp:827
void uninitialized_fill_pixels(const View &view, const Value &val)
std::uninitialized_fill for image views. Does not support planar heterogeneous views....
Definition algorithm.hpp:591
void fill(boost::gil::iterator_from_2d< IL > first, boost::gil::iterator_from_2d< IL > last, const V &val)
std::fill(I,I,V) with I being a iterator_from_2d
Definition algorithm.hpp:373
BOOST_FORCEINLINE bool equal(boost::gil::iterator_from_2d< Loc1 > first, boost::gil::iterator_from_2d< Loc1 > last, boost::gil::iterator_from_2d< Loc2 > first2)
std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
Definition algorithm.hpp:1091
BOOST_FORCEINLINE auto copy1(boost::gil::iterator_from_2d< IL > first, boost::gil::iterator_from_2d< IL > last, boost::gil::iterator_from_2d< OL > dst) -> boost::gil::iterator_from_2d< OL >
std::copy(I1,I1,I2) with I1 and I2 being a iterator_from_2d
Definition algorithm.hpp:285
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
A generic binary operation on views.
Definition algorithm.hpp:88
Definition algorithm.hpp:191
struct to do std::fill
Definition algorithm.hpp:395
Reference proxy associated with a type that has a "reference" member type alias.
Definition algorithm.hpp:1201
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept,...
Definition pixel.hpp:106
An iterator over planar pixels. Models HomogeneousColorBaseConcept, PixelIteratorConcept,...
Definition planar_pixel_iterator.hpp:59
Returns whether two views are compatible.
Definition concepts/image_view.hpp:524