📄 reduce.hpp
字号:
}; template <typename Vec, int Basis> struct type_vec_to_integer_impl<Vec,Basis,0> { static const int value=0; }; template <typename Vec, int Basis=10> struct type_vec_to_integer { static const int value = type_vec_to_integer_impl<Vec,Basis, mpl::size<Vec>::value>::value; }; // Given two color spaces and the mapping of the channels between them, returns the reduced pair of color spaces // The default version performs no reduction template <typename SrcColorSpace, typename DstColorSpace, int Mapping> struct reduce_color_spaces_impl { typedef SrcColorSpace first_t; typedef DstColorSpace second_t; }; // 012: RGB-RGB, bgr-bgr, lab-lab, hsb-hsb template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,12> { typedef rgb_t first_t; typedef rgb_t second_t; }; // 210: RGB-bgr, bgr-RGB template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,210> { typedef rgb_t first_t; typedef bgr_t second_t; }; // 0123: RGBA-RGBA, bgra-bgra, argb-argb, abgr-abgr cmyk-cmyk template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,123> { typedef rgba_t first_t; typedef rgba_t second_t; }; // 3210: RGBA-abgr, bgra-argb, argb-bgra, abgr-RGBA template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,3210> { typedef rgba_t first_t; typedef abgr_t second_t; }; // 1230: RGBA-argb, bgra-abgr template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,1230> { typedef rgba_t first_t; typedef argb_t second_t; }; // 2103: RGBA-bgra, bgra-RGBA (uses subclass to ensure that base color space is not reduced to derived) template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,2103> { typedef rgba_t first_t; typedef bgra_t second_t; }; // 3012: argb-RGBA, abgr-bgra template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,3012> { typedef argb_t first_t; typedef rgba_t second_t; }; // 0321: argb-abgr, abgr-argb template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,321> { typedef argb_t first_t; typedef abgr_t second_t; }; template <typename SrcColorSpace, typename DstColorSpace> struct reduce_color_spaces { typedef typename channel_order<SrcColorSpace>::type src_order_t; typedef typename channel_order<DstColorSpace>::type dst_order_t; typedef typename mpl::transform<src_order_t, type_to_index<dst_order_t,mpl::_1> >::type mapping; static const int mapping_val = type_vec_to_integer<mapping>::value; typedef typename reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,mapping_val>::first_t _first_t; typedef typename reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,mapping_val>::second_t _second_t; typedef typename mpl::and_<color_space_is_base<DstColorSpace>, mpl::not_< color_space_is_base<_second_t> > > swap_t; public: typedef typename mpl::if_<swap_t, _second_t, _first_t>::type first_t; typedef typename mpl::if_<swap_t, _first_t, _second_t>::type second_t; };*/// TODO: Use the old code for reduce_color_spaces above to do color layout reduction template <typename SrcLayout, typename DstLayout> struct reduce_color_layouts { typedef SrcLayout first_t; typedef DstLayout second_t; }; //////////////////////////////////////////////////////// //// //// Reduce for copy_pixels //// //////////////////////////////////////////////////////// struct copy_pixels_fn; /* // 1D reduce for copy_pixels reduces the channel to mutable and the color space to its base with same dimensions template <typename View> struct reduce_view_basic<copy_pixels_fn,View,true> { private: typedef typename reduce_color_space<typename View::color_space_t>::type Cs; // reduce the color space typedef layout<Cs, typename View::channel_mapping_t> layout_t; public: typedef typename derived_view_type<View, use_default, layout_t, use_default, use_default, mpl::true_>::type type; };*/ // Incompatible views cannot be used in copy_pixels - will throw std::bad_cast template <typename V1, typename V2, bool Compatible> struct reduce_copy_pixop_compat { typedef error_t type; }; // For compatible basic views, reduce their color spaces based on their channel mapping. // Make the source immutable and the destination mutable (they should already be that way) template <typename V1, typename V2> struct reduce_copy_pixop_compat<V1,V2,true> { typedef layout<typename V1::color_space_t, typename V1::channel_mapping_t> layout1; typedef layout<typename V2::color_space_t, typename V2::channel_mapping_t> layout2; typedef typename reduce_color_layouts<layout1,layout2>::first_t L1; typedef typename reduce_color_layouts<layout1,layout2>::second_t L2; typedef typename derived_view_type<V1, use_default, L1, use_default, use_default, use_default, mpl::false_>::type DV1; typedef typename derived_view_type<V2, use_default, L2, use_default, use_default, use_default, mpl::true_ >::type DV2; typedef std::pair<const DV1*, const DV2*> type; }; // The general 2D version branches into compatible and incompatible views template <typename V1, typename V2> struct reduce_views_basic<copy_pixels_fn, V1, V2, true> : public reduce_copy_pixop_compat<V1, V2, mpl::and_<views_are_compatible<V1,V2>, view_is_mutable<V2> >::value > { }; //////////////////////////////////////////////////////// //// //// Reduce for variant destructor (basic views have no destructor) //// //////////////////////////////////////////////////////// struct destructor_op; template <typename View> struct reduce_view_basic<destructor_op,View,true> { typedef gray8_view_t type; }; //////////////////////////////////////////////////////// //// //// Reduce for get_dimensions (basic views and images have the same structure and the dimensions are contained at the beginning) //// //////////////////////////////////////////////////////// struct any_type_get_dimensions; template <typename View> struct reduce_view_basic<any_type_get_dimensions,View,true> { typedef gray8_view_t type; }; template <typename Img> struct reduce_image_basic<any_type_get_dimensions,Img,true> { typedef gray8_image_t type; }; //////////////////////////////////////////////////////// //// //// Reduce for get_num_channels (only color space matters) //// //////////////////////////////////////////////////////// struct any_type_get_num_channels; template <typename View> struct reduce_view_basic<any_type_get_num_channels,View,true> { typedef typename View::color_space_t::base Cs; typedef typename view_type<bits8,typename reduce_color_space<Cs>::type>::type type; }; template <typename Img> struct reduce_image_basic<any_type_get_num_channels,Img,true> { typedef typename Img::color_space_t::base Cs; typedef typename image_type<bits8,typename reduce_color_space<Cs>::type>::type type; }; //////////////////////////////////////////////////////// //// //// Reduce for resample_pixels (same as copy_pixels) //// //////////////////////////////////////////////////////// template <typename Sampler, typename MapFn> struct resample_pixels_fn; template <typename S, typename M, typename V, bool IsBasic> struct reduce_view_basic<resample_pixels_fn<S,M>, V, IsBasic> : public reduce_view_basic<copy_pixels_fn, V, IsBasic> {}; template <typename S, typename M, typename V1, typename V2, bool IsBasic> struct reduce_views_basic<resample_pixels_fn<S,M>, V1, V2, IsBasic> : public reduce_views_basic<copy_pixels_fn, V1, V2, IsBasic> {}; //////////////////////////////////////////////////////// //// //// Reduce for copy_and_convert_pixels //// (the only reduction could be made when views are compatible and have the same mapping, planarity and stepness) //// //////////////////////////////////////////////////////// template <typename CC> class copy_and_convert_pixels_fn; // the only thing for 1D reduce is making them all mutable... template <typename CC, typename View, bool IsBasic> struct reduce_view_basic<copy_and_convert_pixels_fn<CC>, View, IsBasic> : public derived_view_type<View, use_default, use_default, use_default, use_default, mpl::true_> { }; // For 2D reduce, if they have the same channels and color spaces (i.e. the same pixels) then copy_and_convert is just copy. // In this case, reduce their common color space. In general make the first immutable and the second mutable template <typename CC, typename V1, typename V2, bool AreBasic> struct reduce_views_basic<copy_and_convert_pixels_fn<CC>, V1, V2, AreBasic> { typedef is_same<typename V1::pixel_t, typename V2::pixel_t> Same; typedef reduce_color_space<typename V1::color_space_t::base> CsR; typedef typename mpl::if_<Same, typename CsR::type, typename V1::color_space_t>::type Cs1; typedef typename mpl::if_<Same, typename CsR::type, typename V2::color_space_t>::type Cs2; typedef typename derived_view_type<V1, use_default, layout<Cs1, typename V1::channel_mapping_t>, use_default, use_default, mpl::false_>::type DV1; typedef typename derived_view_type<V2, use_default, layout<Cs2, typename V2::channel_mapping_t>, use_default, use_default, mpl::true_ >::type DV2; typedef std::pair<const DV1*, const DV2*> type; }; //integral_image_generator //resize_clobber_image_fnobj //image_default_construct_fnobj //fill_converted_pixels_fn //bind(gil::detail::copy_pixels_fn(), _1, dst) //bind(gil::detail::copy_pixels_fn(), src,_1) //bind(detail::copy_and_convert_pixels_fn(), _1, dst) //bind(detail::copy_and_convert_pixels_fn(), src, _1) //gil::detail::fill_pixels_fn<Value>(val) //detail::copy_construct_in_place_fn<base_t> //detail::equal_to_fn<typename variant<Types>::base_t> //detail::any_image_get_view<typename any_image<Types>::view_t> //detail::any_image_get_const_view<typename any_image<Types>::view_t> //detail::flipped_up_down_view_fn<any_image_view<ViewTypes> > //detail::flipped_left_right_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t> //detail::tranposed_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t> //detail::rotated90cw_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t> //detail::rotated90ccw_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t> //detail::rotated180_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t> //detail::subimage_view_fn<any_image_view<ViewTypes> > //detail::subsampled_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t> //detail::nth_channel_view_fn<typename nth_channel_view_type<any_image_view<ViewTypes> > //detail::color_converted_view_fn<DstP,typename color_convert_view_type<any_image_view<ViewTypes>, DstP>::type >}} } // namespace boost::gil#endif // GIL_REDUCE_CODE_BLOAT#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -