Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83883 - in trunk: boost/gil/extension/toolbox/image_types libs/gil/toolbox/test
From: chhenning_at_[hidden]
Date: 2013-04-13 17:32:51


Author: chhenning
Date: 2013-04-13 17:32:49 EDT (Sat, 13 Apr 2013)
New Revision: 83883
URL: http://svn.boost.org/trac/boost/changeset/83883

Log:
Added sub-image factors as template parameters.
Text files modified:
   trunk/boost/gil/extension/toolbox/image_types/subchroma_image.hpp | 187 +++++++++++++++++++--------------------
   trunk/libs/gil/toolbox/test/subchroma_image.cpp | 33 ++++--
   2 files changed, 109 insertions(+), 111 deletions(-)

Modified: trunk/boost/gil/extension/toolbox/image_types/subchroma_image.hpp
==============================================================================
--- trunk/boost/gil/extension/toolbox/image_types/subchroma_image.hpp (original)
+++ trunk/boost/gil/extension/toolbox/image_types/subchroma_image.hpp 2013-04-13 17:32:49 EDT (Sat, 13 Apr 2013)
@@ -19,6 +19,8 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 
+#include <boost/mpl/vector_c.hpp>
+
 #include <boost/gil/image.hpp>
 
 namespace boost{ namespace gil {
@@ -31,12 +33,14 @@
 /// \brief Used for virtual_2D_locator
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
-template< typename Locator >
+template< typename Locator
+ , typename Factors
+ >
 struct subchroma_image_deref_fn
 {
     typedef gray8_view_t::locator plane_locator_t;
 
- typedef subchroma_image_deref_fn const_t;
+ typedef subchroma_image_deref_fn const_t;
     typedef typename Locator::value_type value_type;
     typedef value_type reference;
     typedef value_type const_reference;
@@ -49,29 +53,21 @@
     subchroma_image_deref_fn() {}
 
     /// constructor
- subchroma_image_deref_fn( const plane_locator_t& y_locator
- , const plane_locator_t& v_locator
- , const plane_locator_t& u_locator
- , const std::size_t ux_ssfactor
- , const std::size_t uy_ssfactor
- , const std::size_t vx_ssfactor
- , const std::size_t vy_ssfactor
+ subchroma_image_deref_fn( const plane_locator_t& y_locator
+ , const plane_locator_t& v_locator
+ , const plane_locator_t& u_locator
                              )
- : _y_locator ( y_locator )
- , _v_locator ( v_locator )
- , _u_locator ( u_locator )
- , _ux_ssfactor( ux_ssfactor )
- , _uy_ssfactor( uy_ssfactor )
- , _vx_ssfactor( vx_ssfactor )
- , _vy_ssfactor( vy_ssfactor )
+ : _y_locator( y_locator )
+ , _v_locator( v_locator )
+ , _u_locator( u_locator )
     {}
 
     /// operator()
     typename result_type operator()( const point_t& p ) const
     {
         plane_locator_t y = _y_locator.xy_at( p );
- plane_locator_t v = _v_locator.xy_at( p.x / _ux_ssfactor, p.y / _uy_ssfactor );
- plane_locator_t u = _u_locator.xy_at( p.x / _vx_ssfactor, p.y / _vy_ssfactor );
+ plane_locator_t v = _v_locator.xy_at( p.x / mpl::at_c<Factors, 0>::type::value, p.y / mpl::at_c<Factors, 1>::type::value);
+ plane_locator_t u = _u_locator.xy_at( p.x / mpl::at_c<Factors, 2>::type::value, p.y / mpl::at_c<Factors, 3>::type::value);
 
         return value_type( at_c<0>( *y )
                          , at_c<0>( *v )
@@ -84,21 +80,11 @@
     const plane_locator_t& v_locator() const { return _v_locator; }
     const plane_locator_t& u_locator() const { return _u_locator; }
 
- const std::size_t ux_ssfactor() const { return ux_ssfactor; }
- const std::size_t uy_ssfactor() const { return uy_ssfactor; }
- const std::size_t vx_ssfactor() const { return vx_ssfactor; }
- const std::size_t vy_ssfactor() const { return vy_ssfactor; }
-
 private:
     
     plane_locator_t _y_locator;
     plane_locator_t _v_locator;
     plane_locator_t _u_locator;
-
- std::size_t _ux_ssfactor;
- std::size_t _uy_ssfactor;
- std::size_t _vx_ssfactor;
- std::size_t _vy_ssfactor;
 };
 
 
@@ -108,11 +94,15 @@
 /// \brief
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
-template< typename Locator >
+template< typename Locator
+ , typename Factors
+ >
 struct subchroma_image_locator
 {
- typedef virtual_2d_locator< subchroma_image_deref_fn< Locator > // Deref
- , false // IsTransposed
+ typedef virtual_2d_locator< subchroma_image_deref_fn< Locator
+ , Factors
+ > // Deref
+ , false // IsTransposed
> type;
 };
 
@@ -123,7 +113,9 @@
 /// \brief A lightweight object that interprets a subsampled image.Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
-template< typename Locator > // subchroma_image_locator< ... >::type
+template< typename Locator
+ , typename Factors = mpl::vector_c< int, 2, 2, 2, 2 >
+ >
 class subchroma_image_view : public image_view< Locator >
 {
 public:
@@ -180,7 +172,7 @@
 
 private:
 
- template< typename Locator > friend class subchroma_image_view;
+ template< typename Locator, typename Factors > friend class subchroma_image_view;
 
     point_t _y_dimensions;
     point_t _v_dimensions;
@@ -196,6 +188,7 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 template< typename Pixel
+ , typename Factors = mpl::vector_c< int, 2, 2, 2, 2 >
         , typename Allocator = std::allocator< unsigned char >
>
 class subchroma_image
@@ -214,33 +207,26 @@
     typedef typename view_type_from_pixel< Pixel >::type pixel_view_t;
     typedef typename pixel_view_t::locator pixel_locator_t;
 
- typedef typename subchroma_image_locator< pixel_locator_t >::type locator_t;
+ typedef typename subchroma_image_locator< pixel_locator_t
+ , Factors
+ >::type locator_t;
 
     typedef typename plane_image_t::coord_t x_coord_t;
     typedef typename plane_image_t::coord_t y_coord_t;
 
- typedef subchroma_image_view< locator_t > view_t;
- typedef typename view_t::const_t const_view_t;
+ typedef subchroma_image_view< locator_t, Factors > view_t;
+ typedef typename view_t::const_t const_view_t;
 
 
     /// constructor
- subchroma_image( const x_coord_t y_width
- , const y_coord_t y_height
- , const std::size_t vx_ssfactor = 2
- , const std::size_t vy_ssfactor = 2
- , const std::size_t ux_ssfactor = 2
- , const std::size_t uy_ssfactor = 2
- )
- : _y_plane( y_width, y_height, 0, Allocator() )
- , _v_plane( y_width / vx_ssfactor, y_height / vy_ssfactor, 0, Allocator() )
- , _u_plane( y_width / ux_ssfactor, y_height / uy_ssfactor, 0, Allocator() )
+ subchroma_image( const x_coord_t y_width
+ , const y_coord_t y_height
+ )
+ : _y_plane( y_width, y_height, 0, Allocator() )
+ , _v_plane( y_width / mpl::at_c<Factors, 0>::type::value, y_height / mpl::at_c<Factors, 1>::type::value, 0, Allocator() )
+ , _u_plane( y_width / mpl::at_c<Factors, 2>::type::value, y_height / mpl::at_c<Factors, 3>::type::value, 0, Allocator() )
     {
- init( point_t( y_width, y_height )
- , vx_ssfactor
- , vy_ssfactor
- , ux_ssfactor
- , uy_ssfactor
- );
+ init( point_t( y_width, y_height ) );
     }
 
 public:
@@ -249,22 +235,15 @@
 
 private:
 
- void init( const point_t& y_dimensions
- , const std::size_t vx_ssfactor
- , const std::size_t vy_ssfactor
- , const std::size_t ux_ssfactor
- , const std::size_t uy_ssfactor
- )
+ void init( const point_t& y_dimensions )
     {
- typedef subchroma_image_deref_fn< pixel_locator_t > defer_fn_t;
+ typedef subchroma_image_deref_fn< pixel_locator_t
+ , Factors
+ > defer_fn_t;
 
         defer_fn_t deref_fn( view( _y_plane ).xy_at( 0, 0 )
                            , view( _v_plane ).xy_at( 0, 0 )
                            , view( _u_plane ).xy_at( 0, 0 )
- , vx_ssfactor
- , vy_ssfactor
- , ux_ssfactor
- , uy_ssfactor
                            );
 
         // init a virtual_2d_locator
@@ -294,18 +273,22 @@
 /// \ingroup ImageModel
 /// \brief Returns the non-constant-pixel view of an image
 /////////////////////////////////////////////////////////////////////////////////////////
-template< typename Pixel >
+template< typename Pixel
+ , typename Factors
+ >
 inline
-const typename subchroma_image< Pixel >::view_t& view( subchroma_image< Pixel >& img )
+const typename subchroma_image< Pixel, Factors >::view_t& view( subchroma_image< Pixel, Factors >& img )
 {
     return img._view;
 }
 
-template< typename Pixel >
+template< typename Pixel
+ , typename Factors
+ >
 inline
-const typename subchroma_image< Pixel >::const_view_t const_view( subchroma_image< Pixel >& img )
+const typename subchroma_image< Pixel, Factors >::const_view_t const_view( subchroma_image< Pixel, Factors >& img )
 {
- return static_cast< const typename subchroma_image< Pixel >::const_view_t>( img._view );
+ return static_cast< const typename subchroma_image< Pixel, Factors >::const_view_t>( img._view );
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -313,13 +296,14 @@
 /// \brief std::fill for subchroma_image views
 /////////////////////////////////////////////////////////////////////////////////////////
 template< typename Locator
+ , typename Factors
         , typename Pixel
>
-void fill_pixels( const subchroma_image_view< Locator >& view
- , const Pixel& value
+void fill_pixels( const subchroma_image_view< Locator, Factors >& view
+ , const Pixel& value
                 )
 {
- typedef typename subchroma_image<Pixel>::plane_view_t::value_type channel_t;
+ typedef typename subchroma_image< Pixel, Factors >::plane_view_t::value_type channel_t;
 
     fill_pixels( view.y_plane_view(), channel_t( at_c<0>( value )));
     fill_pixels( view.v_plane_view(), channel_t( at_c<1>( value )));
@@ -330,23 +314,25 @@
 /// \ingroup ImageViewConstructors
 /// \brief Creates a subsampled view from a raw memory
 /////////////////////////////////////////////////////////////////////////////////////////
-template< typename Pixel >
-typename subchroma_image< Pixel >::view_t subsampled_view( std::size_t y_width
- , std::size_t y_height
- , unsigned char* y_base
- , std::size_t vx_ssfactor = 2
- , std::size_t vy_ssfactor = 2
- , std::size_t ux_ssfactor = 2
- , std::size_t uy_ssfactor = 2
- )
+template< typename Pixel
+ , typename Factors
+ >
+typename subchroma_image< Pixel
+ , Factors
+ >::view_t subsampled_view( std::size_t y_width
+ , std::size_t y_height
+ , unsigned char* y_base
+ )
 {
     std::size_t y_channel_size = 1;
     std::size_t u_channel_size = 1;
 
     unsigned char* u_base = y_base + ( y_width * y_height * y_channel_size );
- unsigned char* v_base = u_base + ( y_width / ux_ssfactor ) * ( y_height / uy_ssfactor ) * u_channel_size;
+ unsigned char* v_base = u_base + ( y_width / mpl::at_c<Factors, 2>::type::value )
+ * ( y_height / mpl::at_c<Factors, 3>::type::value )
+ * u_channel_size;
 
- typedef subchroma_image< Pixel >::plane_view_t plane_view_t;
+ typedef subchroma_image< Pixel, Factors >::plane_view_t plane_view_t;
 
     plane_view_t y_plane = interleaved_view( y_width
                                            , y_height
@@ -354,39 +340,46 @@
                                            , y_width // rowsize_in_bytes
                                            );
 
- plane_view_t v_plane = interleaved_view( y_width / vx_ssfactor
- , y_height / vy_ssfactor
+ plane_view_t v_plane = interleaved_view( y_width / mpl::at_c<Factors, 0>::type::value
+ , y_height / mpl::at_c<Factors, 1>::type::value
                                            , (plane_view_t::value_type*) v_base // pixels
                                            , y_width // rowsize_in_bytes
                                            );
 
- plane_view_t u_plane = interleaved_view( y_width / ux_ssfactor
- , y_height / uy_ssfactor
+ plane_view_t u_plane = interleaved_view( y_width / mpl::at_c<Factors, 2>::type::value
+ , y_height / mpl::at_c<Factors, 3>::type::value
                                            , (plane_view_t::value_type*) u_base // pixels
                                            , y_width // rowsize_in_bytes
                                            );
 
- typedef subchroma_image_deref_fn< typename subchroma_image< Pixel >::pixel_locator_t > defer_fn_t;
+ typedef subchroma_image_deref_fn< typename subchroma_image< Pixel
+ , Factors
+ >::pixel_locator_t
+ , Factors
+ > defer_fn_t;
+
     defer_fn_t deref_fn( y_plane.xy_at( 0, 0 )
                        , v_plane.xy_at( 0, 0 )
                        , u_plane.xy_at( 0, 0 )
- , vx_ssfactor
- , vy_ssfactor
- , ux_ssfactor
- , uy_ssfactor
                        );
     
 
- typedef subchroma_image< Pixel >::locator_t locator_t;
+ typedef subchroma_image< Pixel
+ , Factors
+ >::locator_t locator_t;
+
     locator_t locator( point_t( 0, 0 ) // p
                      , point_t( 1, 1 ) // step
                      , deref_fn
                      );
 
- typedef subchroma_image< Pixel >::view_t view_t;
- return view_t( point_t( y_width, y_height )
- , point_t( y_width / vx_ssfactor, y_height / vy_ssfactor )
- , point_t( y_width / ux_ssfactor, y_height / uy_ssfactor )
+ typedef subchroma_image< Pixel
+ , Factors
+ >::view_t view_t;
+
+ return view_t( point_t( y_width, y_height )
+ , point_t( y_width / mpl::at_c<Factors, 0>::type::value, y_height / mpl::at_c<Factors, 1>::type::value )
+ , point_t( y_width / mpl::at_c<Factors, 2>::type::value, y_height / mpl::at_c<Factors, 3>::type::value )
                  , locator
                  );
 }
@@ -394,4 +387,4 @@
 } // namespace gil
 } // namespace boost
 
-#endif // BOOST_GIL_EXTENSION_TOOLBOX_IMAGE_TYPES_SUBSAMPLED_IMAGE_HPP
\ No newline at end of file
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_IMAGE_TYPES_SUBSAMPLED_IMAGE_HPP

Modified: trunk/libs/gil/toolbox/test/subchroma_image.cpp
==============================================================================
--- trunk/libs/gil/toolbox/test/subchroma_image.cpp (original)
+++ trunk/libs/gil/toolbox/test/subchroma_image.cpp 2013-04-13 17:32:49 EDT (Sat, 13 Apr 2013)
@@ -45,30 +45,35 @@
     }
 
     {
+ typedef rgb8_pixel_t pixel_t;
+ typedef mpl::vector_c< int, 1, 1, 1, 1 > factors_t;
+ typedef subchroma_image< pixel_t, factors_t > image_t;
+
+ image_t img( 640, 480 );
+
+ fill_pixels( view( img )
+ , pixel_t( 10, 20, 30 )
+ );
+ }
+
+ {
         typedef ycbcr_601_8_pixel_t pixel_t;
+ typedef mpl::vector_c< int, 2, 2, 2, 2 > factors_t;
         typedef subchroma_image< pixel_t > image_t;
 
         std::size_t y_width = 640;
         std::size_t y_height = 480;
- std::size_t vx_ssfactor = 2;
- std::size_t vy_ssfactor = 2;
- std::size_t ux_ssfactor = 2;
- std::size_t uy_ssfactor = 2;
 
         std::size_t image_size = ( y_width * y_height )
- + ( y_width / vx_ssfactor ) * ( y_height / vy_ssfactor )
- + ( y_width / ux_ssfactor ) * ( y_height / uy_ssfactor );
+ + ( y_width / mpl::at_c<factors_t, 0>::type::value ) * ( y_height / mpl::at_c<factors_t, 1>::type::value )
+ + ( y_width / mpl::at_c<factors_t, 2>::type::value ) * ( y_height / mpl::at_c<factors_t, 3>::type::value );
 
         vector< unsigned char > data( image_size );
 
- image_t::view_t v = subsampled_view< pixel_t >( y_width
- , y_height
- , &data.front()
- , vx_ssfactor
- , vy_ssfactor
- , ux_ssfactor
- , uy_ssfactor
- );
+ image_t::view_t v = subsampled_view< pixel_t, factors_t >( y_width
+ , y_height
+ , &data.front()
+ );
         rgb8_pixel_t p = *v.xy_at( 0, 0 );
     }
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk