Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65463 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2010-09-19 13:21:56


Author: psiha
Date: 2010-09-19 13:21:55 EDT (Sun, 19 Sep 2010)
New Revision: 65463
URL: http://svn.boost.org/trac/boost/changeset/65463

Log:
Fixed the offset_view_t<> class.
Fixed the offset_view<>() global utility function (it had to moved into the formatted_image<> class as a static member function).
Fixed the formatted_image<>::dimensions_mismatch<>() overload for offset views.
Added the utility is_supported<> template to the formatted_image<> class to fix certain compile-time and runtime errors while also reducing verbosity.

Fixed various offset view issues.
Text files modified:
   sandbox/gil/boost/gil/extension/io2/formatted_image.hpp | 36 ++++++++++++++++++++----------------
   sandbox/gil/boost/gil/extension/io2/gp_image.hpp | 2 +-
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp | 25 ++++++++++++++++++++-----
   sandbox/gil/boost/gil/extension/io2/wic_image.hpp | 3 ++-
   4 files changed, 43 insertions(+), 23 deletions(-)

Modified: sandbox/gil/boost/gil/extension/io2/formatted_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/formatted_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/formatted_image.hpp 2010-09-19 13:21:55 EDT (Sun, 19 Sep 2010)
@@ -188,15 +188,11 @@
     }
 
 private:
- View const & view_ ;
- typename call_traits<Offset>::param_type offset_;
+ View const & view_ ;
+ Offset offset_;
 };
 
 
-template <class View, typename Offset>
-offset_view_t<View, Offset> offset_view( View const & view, Offset const & offset ) { return offset_view_t<View, Offset>( view, offset ); }
-
-
 ////////////////////////////////////////////////////////////////////////////////
 /// \class formatted_image_traits
 /// ( forward declaration )
@@ -205,7 +201,6 @@
 template <class Impl>
 struct formatted_image_traits;
 
-
 namespace detail
 {
 //------------------------------------------------------------------------------
@@ -337,7 +332,7 @@
     static bool dimensions_mismatch( dimensions_t const & mine, offset_view_t<View, Offset> const & offset_view )
     {
         dimensions_t const other( offset_view.dimensions() );
- return !( ( mine.x >= other.x ) && ( mine.y >= other.y ) );
+ return ( other.x < mine.x ) || ( other.y < mine.y );
     }
 
     static void do_ensure_dimensions_match( dimensions_t const & mine, dimensions_t const & other )
@@ -497,6 +492,9 @@
 
     typedef typename formatted_image_traits<Impl>::view_data_t view_data_t;
 
+ template <class View>
+ struct is_supported : formatted_image_traits<Impl>:: BOOST_NESTED_TEMPLATE is_supported<get_original_view_t<View>::type> {};
+
 private:
     template <typename Images, typename dimensions_policy, typename formats_policy>
     class read_dynamic_image : make_dynamic_image<Images>
@@ -540,7 +538,7 @@
     struct write_is_supported
     {
         template<typename View>
- struct apply : public formatted_image_traits<Impl>::is_supported<View> {};
+ struct apply : public is_supported<View> {};
     };
 
     typedef mpl::range_c<std::size_t, 0, mpl::size<supported_pixel_formats>::value> valid_type_id_range_t;
@@ -596,7 +594,7 @@
     template <typename View>
     bool formats_mismatch() const
     {
- return formats_mismatch( formatted_image_traits<Impl>::view_to_native_format::apply<View>::value );
+ return formats_mismatch( formatted_image_traits<Impl>::view_to_native_format:: BOOST_NESTED_TEMPLATE apply<get_original_view_t<View>::type>::value );
     }
 
     bool formats_mismatch( typename formatted_image_traits<Impl>::format_t const other_format ) const
@@ -634,10 +632,10 @@
     template <typename View>
     void copy_to( View const & view, assert_dimensions_match, assert_formats_match ) const
     {
- BOOST_STATIC_ASSERT( View::value_type::is_mutable );
- BOOST_STATIC_ASSERT( formatted_image_traits<Impl>::is_supported<View>::value );
- BOOST_ASSERT( !impl().dimensions_mismatch( view ) );
- BOOST_ASSERT( !impl().formats_mismatch<View>() );
+ BOOST_STATIC_ASSERT( get_original_view_t<View>::type::value_type::is_mutable );
+ BOOST_STATIC_ASSERT( is_supported<View>::value );
+ BOOST_ASSERT( !impl().dimensions_mismatch( view ) );
+ BOOST_ASSERT( !impl().formats_mismatch<View>() );
         impl().raw_copy_to_prepared_view
         (
             view_data_t
@@ -682,7 +680,7 @@
         BOOST_ASSERT( !impl().dimensions_mismatch( view ) );
         bool const can_use_raw
         (
- formatted_image_traits<Impl>::is_supported<View>::value &&
+ is_supported <View>::value &&
             formatted_image_traits<Impl>::builtin_conversion
         );
         default_convert_to_worker( view, mpl::bool_<can_use_raw>() );
@@ -749,6 +747,12 @@
         );
     }
 
+public: // Offset factory
+ template <class View>
+ static
+ offset_view_t<View, offset_t>
+ offset_view( View const & view, offset_t const offset ) { return offset_view_t<View, offset_t>( view, offset ); }
+
 public: // Utility 'quick-wrappers'...
     template <class Source, class Image>
     static void read( Source const & target, Image & image )
@@ -895,7 +899,7 @@
             mpl::bool_
             <
                 is_plain_in_memory_view<typename get_original_view_t<View>::type>::value &&
- formatted_image_traits<Impl>::is_supported<View>::value
+ is_supported < View >::value
>()
         );
     }

Modified: sandbox/gil/boost/gil/extension/io2/gp_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/gp_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/gp_image.hpp 2010-09-19 13:21:55 EDT (Sun, 19 Sep 2010)
@@ -333,7 +333,7 @@
         template <typename View>
         void set_bitmapdata_for_view( View const & view )
         {
- BOOST_STATIC_ASSERT( is_supported<View>::value );
+ BOOST_STATIC_ASSERT( is_supported<typename get_original_view_t<View>::type>::value );
 
             Width = view.width();
             Height = view.height();

Modified: sandbox/gil/boost/gil/extension/io2/libpng_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libpng_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/libpng_image.hpp 2010-09-19 13:21:55 EDT (Sun, 19 Sep 2010)
@@ -42,6 +42,9 @@
 template <typename Pixel, bool isPlanar>
 struct gil_to_libpng_format : mpl::integral_c<int, -1> {};
 
+/// \todo Add bgr-layout formats as LibPNG actually supports them through
+/// png_set_bgr().
+/// (19.09.2010.) (Domagoj Saric)
 template <> struct gil_to_libpng_format<rgb8_pixel_t , false> : mpl::integral_c<int, PNG_COLOR_TYPE_RGB | ( 8 << 16 )> {};
 template <> struct gil_to_libpng_format<rgba8_pixel_t , false> : mpl::integral_c<int, PNG_COLOR_TYPE_RGB_ALPHA | ( 8 << 16 )> {};
 template <> struct gil_to_libpng_format<gray8_pixel_t , false> : mpl::integral_c<int, PNG_COLOR_TYPE_GRAY | ( 8 << 16 )> {};
@@ -514,6 +517,8 @@
     template <class MyView, class TargetView, class Converter>
     void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const throw(...)
     {
+ using namespace detail;
+
         std::size_t const row_length ( ::png_get_rowbytes( &png_object(), &info_object() ) );
         scoped_ptr<png_byte> const p_row_buffer( new png_byte[ row_length ] );
 
@@ -527,20 +532,26 @@
         BOOST_ASSERT( ( number_of_passes == 1 ) && "Missing interlaced support for the generic conversion case." );
         ignore_unused_variable_warning( number_of_passes );
 
- skip_rows( detail::get_offset<offset_t>( view ) );
+ skip_rows( get_offset<offset_t>( view ) );
 
         png_byte * const p_row ( p_row_buffer.get() );
         png_byte const * const p_row_end( p_row + row_length );
 
- unsigned int const rows_to_read( detail::original_view( view ).dimensions().y );
+ unsigned int const rows_to_read
+ (
+ ( get_offset<offset_t>( view ) == 0 )
+ ? original_view( view ).dimensions().y
+ : std::min( original_view( view ).dimensions().y, dimensions().y - get_offset<offset_t>( view ) )
+ );
         for ( unsigned int row_index( 0 ); row_index < rows_to_read; ++row_index )
         {
             read_row( p_row );
 
             typedef typename MyView::value_type pixel_t;
+ typedef typename get_original_view_t<TargetView>::type::x_iterator x_iterator;
 
- pixel_t const * p_source_pixel( gil_reinterpret_cast_c<pixel_t const *>( p_row ) );
- typename TargetView::x_iterator p_target_pixel( view.row_begin( row_index ) );
+ pixel_t const * p_source_pixel( gil_reinterpret_cast_c<pixel_t const *>( p_row ) );
+ x_iterator p_target_pixel( original_view( view ).row_begin( row_index ) );
             while ( p_source_pixel < gil_reinterpret_cast_c<pixel_t const *>( p_row_end ) )
             {
                 converter( *p_source_pixel, *p_target_pixel );
@@ -661,10 +672,14 @@
         #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
     }
 
- void skip_rows( unsigned int number_of_rows_to_skip ) const
+ void skip_rows( unsigned int const row_to_skip_to ) const
     {
+ BOOST_ASSERT( ( row_to_skip_to >= png_object().row_number ) && "No 'rewind' capability for LibPNG yet." );
+
+ unsigned int number_of_rows_to_skip( row_to_skip_to - png_object().row_number );
         while ( number_of_rows_to_skip-- )
         {
+ __assume( row_to_skip_to != 0 );
             read_row( NULL );
         }
     }

Modified: sandbox/gil/boost/gil/extension/io2/wic_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/wic_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/wic_image.hpp 2010-09-19 13:21:55 EDT (Sun, 19 Sep 2010)
@@ -141,6 +141,7 @@
     BOOST_VERIFY( result == S_OK );
 }
 
+
 struct wic_view_data_t
 {
     template <typename View>
@@ -168,7 +169,7 @@
     unsigned int /*const*/ stride_;
     unsigned int /*const*/ pixel_size_;
     BYTE * /*const*/ p_buffer_;
- wic_format_t format_;
+ wic_format_t const format_;
 
 private:
     template <typename View>


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