From 443eaa5faee8976fafaafa8c2aff273f5d966b0f Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Fri, 7 Dec 2018 16:00:17 +0100 Subject: [PATCH] Fix compilation of subchroma_image.hpp as self-contained headers (#176) Rename `Scaling_Factors` to lower-case, as well as its template parameters. Move `scaling_factors` to namespace `detail` and before it is use. Fix access to `scaling_factors` members in derived classes. Add missing `typename`. Remove superfluous thus incorrect `typename`. Remove `subchroma_image_view` implicit friends with self - Fixes template parameter aliasing for Locator and Factors. Subset of fixes from pending PR #164 --- .../toolbox/image_types/subchroma_image.hpp | 120 +++++++++--------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp b/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp index be2a7baa8..9883288f0 100644 --- a/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp +++ b/include/boost/gil/extension/toolbox/image_types/subchroma_image.hpp @@ -9,8 +9,11 @@ #define BOOST_GIL_EXTENSION_TOOLBOX_IMAGE_TYPES_SUBCHROMA_IMAGE_HPP #include +#include #include +#include +#include #include #include #include @@ -21,7 +24,47 @@ #include #include -namespace boost{ namespace gil { +namespace boost { namespace gil { + +namespace detail { + +template< int J, int A, int B> +struct scaling_factors +{ + BOOST_STATIC_ASSERT(( mpl::equal_to< mpl::int_< J >, mpl::int_< 4 > >::type::value )); + + BOOST_STATIC_ASSERT(( mpl::or_< mpl::equal_to< mpl::int_, mpl::int_< 4 > > + , mpl::or_< mpl::equal_to< mpl::int_, mpl::int_< 2 > > + , mpl::equal_to< mpl::int_, mpl::int_< 1 > > + > + >::type::value + )); + + BOOST_STATIC_ASSERT(( mpl::or_< mpl::equal_to< mpl::int_, mpl::int_< 4 > > + , mpl::or_< mpl::equal_to< mpl::int_, mpl::int_< 2 > > + , mpl::or_< mpl::equal_to< mpl::int_, mpl::int_< 1 > > + , mpl::equal_to< mpl::int_, mpl::int_< 0 > > + > + > + >::type::value + )); + + BOOST_STATIC_CONSTANT( int, ss_X = ( mpl::divides< mpl::int_< J > + , mpl::int_ + >::type::value ) + ); + + BOOST_STATIC_CONSTANT( int, ss_Y = ( mpl::if_< mpl::equal_to< mpl::int_, mpl::int_< 0 > > + , mpl::int_< 2 > + , mpl::if_< mpl::equal_to< mpl::int_, mpl::int_ > + , mpl::int_< 1 > + , mpl::int_< 4 > + > + >::type::value ) + ); +}; + +} // namespace detail //////////////////////////////////////////////////////////////////////////////////////// /// \class subchroma_image_deref_fn @@ -61,7 +104,7 @@ struct subchroma_image_deref_fn /// operator() result_type operator()( const point_t& p ) const { - typedef Scaling_Factors< mpl::at_c< Factors, 0 >::type::value + typedef detail::scaling_factors< mpl::at_c< Factors, 0 >::type::value , mpl::at_c< Factors, 1 >::type::value , mpl::at_c< Factors, 2 >::type::value > scaling_factors_t; @@ -173,7 +216,7 @@ class subchroma_image_view : public image_view< Locator > { public: - typedef typename Locator locator; + typedef Locator locator; typedef typename locator::deref_fn_t deref_fn_t; typedef typename deref_fn_t::plane_locator_t plane_locator_t; @@ -227,8 +270,6 @@ private: private: - template< typename Locator, typename Factors > friend class subchroma_image_view; - point_t _y_dimensions; point_t _v_dimensions; point_t _u_dimensions; @@ -285,49 +326,6 @@ struct transposed_type< subchroma_image_view< Locator, Factors > > typedef image_view< typename transposed_type< Locator >::type > type; }; - -///////////////////////////////////////////////////////////// -template< int J - , int a - , int b - > -struct Scaling_Factors -{ - BOOST_STATIC_ASSERT(( mpl::equal_to< mpl::int_< J >, mpl::int_< 4 > >::type::value )); - - BOOST_STATIC_ASSERT(( mpl::or_< mpl::equal_to< mpl::int_< a >, mpl::int_< 4 > > - , mpl::or_< mpl::equal_to< mpl::int_< a >, mpl::int_< 2 > > - , mpl::equal_to< mpl::int_< a >, mpl::int_< 1 > > - > - >::type::value - )); - - BOOST_STATIC_ASSERT(( mpl::or_< mpl::equal_to< mpl::int_< b >, mpl::int_< 4 > > - , mpl::or_< mpl::equal_to< mpl::int_< b >, mpl::int_< 2 > > - , mpl::or_< mpl::equal_to< mpl::int_< b >, mpl::int_< 1 > > - , mpl::equal_to< mpl::int_< b >, mpl::int_< 0 > > - > - > - >::type::value - )); - - BOOST_STATIC_CONSTANT( int, ss_X = ( mpl::divides< mpl::int_< J > - , mpl::int_< a > - >::type::value ) - ); - - BOOST_STATIC_CONSTANT( int, ss_Y = ( mpl::if_< mpl::equal_to< mpl::int_< b >, mpl::int_< 0 > > - , mpl::int_< 2 > - , mpl::if_< mpl::equal_to< mpl::int_< a >, mpl::int_< b > > - , mpl::int_< 1 > - , mpl::int_< 4 > - >::type - >::type::value ) - ); -}; - - - //////////////////////////////////////////////////////////////////////////////////////// /// \ingroup ImageModel PixelBasedModel /// \brief container interface over image view. Models ImageConcept, PixelBasedConcept @@ -339,12 +337,18 @@ template< typename Pixel , typename Factors = mpl::vector_c< int, 4, 4, 4 > , typename Allocator = std::allocator< unsigned char > > -class subchroma_image : public Scaling_Factors< mpl::at_c< Factors, 0 >::type::value +class subchroma_image : public detail::scaling_factors< mpl::at_c< Factors, 0 >::type::value , mpl::at_c< Factors, 1 >::type::value , mpl::at_c< Factors, 2 >::type::value > { +private: + using parent_t = detail::scaling_factors< mpl::at_c< Factors, 0 >::type::value + , mpl::at_c< Factors, 1 >::type::value + , mpl::at_c< Factors, 2 >::type::value + >; + public: typedef typename channel_type< Pixel >::type channel_t; @@ -375,8 +379,8 @@ public: , const y_coord_t y_height ) : _y_plane( y_width, y_height, 0, Allocator() ) - , _v_plane( y_width / ss_X, y_height / ss_Y, 0, Allocator() ) - , _u_plane( y_width / ss_X, y_height / ss_Y, 0, Allocator() ) + , _v_plane( y_width / parent_t::ss_X, y_height / parent_t::ss_Y, 0, Allocator() ) + , _u_plane( y_width / parent_t::ss_X, y_height / parent_t::ss_Y, 0, Allocator() ) { init(); } @@ -498,7 +502,7 @@ typename subchroma_image< Pixel , unsigned char* y_base ) { - typedef Scaling_Factors< mpl::at_c< Factors, 0 >::type::value + typedef detail::scaling_factors< mpl::at_c< Factors, 0 >::type::value , mpl::at_c< Factors, 1 >::type::value , mpl::at_c< Factors, 2 >::type::value > scaling_factors_t; @@ -510,23 +514,23 @@ typename subchroma_image< Pixel unsigned char* v_base = u_base + ( y_width / scaling_factors_t::ss_X ) * u_channel_size; - typedef subchroma_image< Pixel, Factors >::plane_view_t plane_view_t; + typedef typename subchroma_image< Pixel, Factors >::plane_view_t plane_view_t; plane_view_t y_plane = interleaved_view( y_width , y_height - , (plane_view_t::value_type*) y_base // pixels + , (typename plane_view_t::value_type*) y_base // pixels , y_width // rowsize_in_bytes ); plane_view_t v_plane = interleaved_view( y_width / scaling_factors_t::ss_X , y_height / scaling_factors_t::ss_Y - , (plane_view_t::value_type*) v_base // pixels + , (typename plane_view_t::value_type*) v_base // pixels , y_width // rowsize_in_bytes ); plane_view_t u_plane = interleaved_view( y_width / scaling_factors_t::ss_X , y_height / scaling_factors_t::ss_Y - , (plane_view_t::value_type*) u_base // pixels + , (typename plane_view_t::value_type*) u_base // pixels , y_width // rowsize_in_bytes ); @@ -542,7 +546,7 @@ typename subchroma_image< Pixel ); - typedef subchroma_image< Pixel + typedef typename subchroma_image< Pixel , Factors >::locator_t locator_t; @@ -551,7 +555,7 @@ typename subchroma_image< Pixel , deref_fn ); - typedef subchroma_image< Pixel + typedef typename subchroma_image< Pixel , Factors >::view_t view_t;