$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r67797 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2011-01-08 16:02:28
Author: psiha
Date: 2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
New Revision: 67797
URL: http://svn.boost.org/trac/boost/changeset/67797
Log:
Added can_do_*_access() query member functions to all backends.
Renamed the format_size() member function(s) to cached_format_size() to better emphasize their intended use and made them private. Instead added public pixel_size(), row_size() and (libtiff specific) tile_size() member functions.
(Re)sorted and cleaned up some public-private sections of the interface(s).
Text files modified: 
   sandbox/gil/boost/gil/extension/io2/formatted_image.hpp |    54 ++++++++++-----                         
   sandbox/gil/boost/gil/extension/io2/gp_image.hpp        |   138 ++++++++++++++++++++------------------- 
   sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp   |    88 +++++++++++-------------                
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp    |    12 +-                                      
   sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp   |    20 +++--                                   
   sandbox/gil/boost/gil/extension/io2/wic_image.hpp       |    59 ++++++++--------                        
   6 files changed, 196 insertions(+), 175 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	2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
@@ -334,11 +334,18 @@
     typedef unsigned int image_type_id;
     static image_type_id const unsupported_format = static_cast<image_type_id>( -1 );
 
+public: // Low-level (row, strip, tile) access
     struct sequential_row_access_state { BOOST_STATIC_CONSTANT( bool, throws_on_error = true ); };
 
-public:
     static sequential_row_access_state begin_sequential_row_access() { return sequential_row_access_state(); }
 
+    static bool can_do_row_access  () { return true ; }
+    static bool can_do_strip_access() { return false; }
+    static bool can_do_tile_access () { return false; }
+
+    static bool can_do_roi_access         () { return false; }
+    static bool can_do_vertical_roi_access() { return true ; }
+
 protected:
     static bool dimensions_mismatch( dimensions_t const & mine, dimensions_t const & other ) { return mine != other; }
     template <class View>
@@ -523,19 +530,19 @@
     typedef typename formatted_image_traits<Impl>::roi_t                     roi;
     typedef typename roi::offset_t                                           offset_t;
 
-    template <typename PixelType, typename IsPlanar>
+    template <typename PixelType, bool IsPlanar>
     struct native_format
-        : formatted_image_traits<Impl>::gil_to_native_format:: BOOST_NESTED_TEMPLATE apply<PixelType, IsPlanar::value>::type
+        : formatted_image_traits<Impl>::gil_to_native_format:: BOOST_NESTED_TEMPLATE apply<PixelType, IsPlanar>::type
     {};
 
     template <typename PixelType, typename IsPlanar>
-    struct get_native_format<mpl::pair<PixelType, IsPlanar> > : native_format<PixelType, IsPlanar> {};
+    struct get_native_format<mpl::pair<PixelType, IsPlanar> > : native_format<PixelType, IsPlanar::value> {};
 
     template <typename PixelType, bool IsPlanar>
-    struct get_native_format<image<PixelType, IsPlanar> > : native_format<PixelType, mpl::bool_<IsPlanar> > {};
+    struct get_native_format<image<PixelType, IsPlanar> > : native_format<PixelType, IsPlanar > {};
 
     template <typename Locator>
-    struct get_native_format<image_view<Locator> > : native_format<typename image_view<Locator>::value_type, is_planar<image_view<Locator> > > {};
+    struct get_native_format<image_view<Locator> > : native_format<typename image_view<Locator>::value_type, is_planar<image_view<Locator> >::value> {};
 
     template <class View>
     struct has_supported_format
@@ -722,18 +729,7 @@
     template <typename View>
     bool can_do_inplace_transform( typename formatted_image_traits<Impl>::format_t const my_format ) const
     {
-        return ( impl().format_size( my_format ) == static_cast<std::size_t>( memunit_step( get_original_view_t<View>::type::x_iterator() ) ) );
-    }
-
-    // A generic implementation...impl classes are encouraged to provide more
-    // efficient overrides...
-    static image_type_id image_format_id( format_t const closest_gil_supported_format )
-    {
-        // This (linear search) will be transformed into a switch...
-        image_id_finder finder( closest_gil_supported_format );
-        mpl::for_each<valid_type_id_range_t>( ref( finder ) );
-        BOOST_ASSERT( finder.image_id_ != unsupported_format );
-        return finder.image_id_;
+        return ( impl().cached_format_size( my_format ) == static_cast<std::size_t>( memunit_step( get_original_view_t<View>::type::x_iterator() ) ) );
     }
 
     template <typename View>
@@ -761,6 +757,28 @@
         );
     }
 
+public: // Low-level (row, strip, tile) access
+    std::size_t pixel_size() const
+    {
+        return impl().cached_format_size( impl().format() );
+    }
+
+    std::size_t row_size() const
+    {
+        return impl().pixel_size() * impl().dimensions().x;
+    }
+
+    // A generic implementation...impl classes are encouraged to provide more
+    // efficient overrides...
+    static image_type_id image_format_id( format_t const closest_gil_supported_format )
+    {
+        // This (linear search) will be transformed into a switch...
+        image_id_finder finder( closest_gil_supported_format );
+        mpl::for_each<valid_type_id_range_t>( ref( finder ) );
+        BOOST_ASSERT( finder.image_id_ != unsupported_format );
+        return finder.image_id_;
+    }
+
 public: // Views...
     template <typename View>
     void copy_to( View const & view, assert_dimensions_match, assert_formats_match ) const
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	2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
@@ -394,73 +394,6 @@
         return point2<std::ptrdiff_t>( static_cast<std::ptrdiff_t>( width ), static_cast<std::ptrdiff_t>( height ) );
     }
 
-    static std::size_t format_size( format_t const format )
-    {
-        return Gdiplus::GetPixelFormatSize( format );
-    }
-
-public: // Low-level (row, strip, tile) access
-    class sequential_row_access_state
-        :
-        private detail::cumulative_result
-    {
-    public:
-        using detail::cumulative_result::failed;
-        void throw_if_error() const { detail::cumulative_result::throw_if_error( "GDI+ failure" ); }
-
-        BOOST_STATIC_CONSTANT( bool, throws_on_error = false );
-
-    private:
-        sequential_row_access_state( gp_image const & source_image )
-            :
-            roi_( 0, 0, source_image.dimensions().x, 1 )
-        {
-            bitmapData_.Width  = roi_.Width;
-            bitmapData_.Height = 1;
-            bitmapData_.PixelFormat = source_image.format();
-            bitmapData_.Stride = bitmapData_.Width * source_image.format_size( bitmapData_.PixelFormat );
-            bitmapData_.Reserved = 0;
-        }
-
-    private: friend gp_image;
-        Gdiplus::Rect       roi_       ;
-        Gdiplus::BitmapData bitmapData_;
-    };
-
-    sequential_row_access_state begin_sequential_row_access() const { return sequential_row_access_state( *this ); }
-
-    /// \todo Kill duplication with raw_convert_to_prepared_view().
-    ///                                       (04.01.2011.) (Domagoj Saric)
-    void read_row( sequential_row_access_state & state, unsigned char * const p_row_storage ) const
-    {
-        using namespace detail ;
-        using namespace Gdiplus;
-
-        state.bitmapData_.Scan0 = p_row_storage;
-
-        state.accumulate_equal
-        (
-            DllExports::GdipBitmapLockBits
-            (
-                pBitmap_,
-                &state.roi_,
-                ImageLockModeRead | ImageLockModeUserInputBuf,
-                state.bitmapData_.PixelFormat,
-                &state.bitmapData_
-            ),
-            Gdiplus::Ok
-        );
-        verify_result( DllExports::GdipBitmapUnlockBits( pBitmap_, &state.bitmapData_ ) );
-
-        ++state.roi_.Y;
-    }
-
-    ::Gdiplus::GpBitmap       & lib_object()       { return *pBitmap_; }
-    ::Gdiplus::GpBitmap const & lib_object() const { return const_cast<gp_image &>( *this ).lib_object(); }
-
-private: // Private formatted_image_base interface.
-    friend base_t;
-
     format_t format() const
     {
         format_t pixel_format;
@@ -532,7 +465,70 @@
         }
     }
 
-private:
+public: // Low-level (row, strip, tile) access
+    static bool can_do_roi_access() { return true; }
+
+    class sequential_row_access_state
+        :
+        private detail::cumulative_result
+    {
+    public:
+        using detail::cumulative_result::failed;
+        void throw_if_error() const { detail::cumulative_result::throw_if_error( "GDI+ failure" ); }
+
+        BOOST_STATIC_CONSTANT( bool, throws_on_error = false );
+
+    private:
+        sequential_row_access_state( gp_image const & source_image )
+            :
+            roi_( 0, 0, source_image.dimensions().x, 1 )
+        {
+            bitmapData_.Width  = roi_.Width;
+            bitmapData_.Height = 1;
+            bitmapData_.PixelFormat = source_image.format();
+            bitmapData_.Stride = bitmapData_.Width * source_image.cached_format_size( bitmapData_.PixelFormat );
+            bitmapData_.Reserved = 0;
+        }
+
+    private: friend gp_image;
+        Gdiplus::Rect       roi_       ;
+        Gdiplus::BitmapData bitmapData_;
+    };
+
+    sequential_row_access_state begin_sequential_row_access() const { return sequential_row_access_state( *this ); }
+
+    /// \todo Kill duplication with raw_convert_to_prepared_view().
+    ///                                       (04.01.2011.) (Domagoj Saric)
+    void read_row( sequential_row_access_state & state, unsigned char * const p_row_storage ) const
+    {
+        using namespace detail ;
+        using namespace Gdiplus;
+
+        state.bitmapData_.Scan0 = p_row_storage;
+
+        state.accumulate_equal
+        (
+            DllExports::GdipBitmapLockBits
+            (
+                pBitmap_,
+                &state.roi_,
+                ImageLockModeRead | ImageLockModeUserInputBuf,
+                state.bitmapData_.PixelFormat,
+                &state.bitmapData_
+            ),
+            Gdiplus::Ok
+        );
+        verify_result( DllExports::GdipBitmapUnlockBits( pBitmap_, &state.bitmapData_ ) );
+
+        ++state.roi_.Y;
+    }
+
+    ::Gdiplus::GpBitmap       & lib_object()       { return *pBitmap_; }
+    ::Gdiplus::GpBitmap const & lib_object() const { return const_cast<gp_image &>( *this ).lib_object(); }
+
+private: // Private formatted_image_base interface.
+    friend base_t;
+
     template <class MyView, class TargetView, class Converter>
     void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const
     {
@@ -609,6 +605,12 @@
         raw_convert_to_prepared_view( view_data );
     }
 
+
+    static std::size_t cached_format_size( format_t const format )
+    {
+        return Gdiplus::GetPixelFormatSize( format );
+    }
+
 private:
     template <Gdiplus::PixelFormat desired_format>
     void pre_palettized_conversion( mpl::true_ /*is_indexed*/ )
Modified: sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp	(original)
+++ sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp	2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
@@ -509,34 +509,28 @@
         }
     }
 
-    static std::size_t format_size( format_t const format )
+    point2<std::ptrdiff_t> dimensions() const
     {
-        switch ( format )
+        // Implementation note:
+        //   A user might have setup output image scaling through the low-level
+        // lib_object accessor.
+        //                                    (17.10.2010.) (Domagoj Saric)
+        if ( dirty_output_dimensions_ )
         {
-            case JCS_RGB:
-            case JCS_YCbCr:
-                return 3;
-            case JCS_CMYK:
-            case JCS_YCCK:
-                return 4;
-            case JCS_GRAYSCALE:
-                return 1;
-
-            default:
-                BOOST_ASSERT( !"Invalid or unknown format specified." );
-                BF_UNREACHABLE_CODE
-                return 0;
+            jpeg_calc_output_dimensions( &const_cast<libjpeg_image &>( *this ).lib_object() );
+            dirty_output_dimensions_ = false;
         }
+        return point2<std::ptrdiff_t>( decompressor().output_width, decompressor().output_height );
     }
 
-    //...zzz...
-    //std::size_t format_size( format_t const format ) const
-    //{
-    //    BOOST_ASSERT( format_size( format ) == decompressor().output_components );
-    //    BOOST_ASSERT( decompressor().out_color_components == decompressor().output_components );
-    //    ignore_unused_variable_warning( format );
-    //    return decompressor().output_components;
-    //}
+public: // Low-level (row, strip, tile) access
+    void read_row( sequential_row_access_state, unsigned char * const p_row_storage ) const
+    {
+        read_scanline( p_row_storage );
+    }
+
+    jpeg_decompress_struct       & lib_object()       { dirty_output_dimensions_ = true; return decompressor(); }
+    jpeg_decompress_struct const & lib_object() const {                                  return decompressor(); }
 
 public: /// \ingroup Construction
     explicit libjpeg_image( memory_chunk_t & memory_chunk )
@@ -567,32 +561,9 @@
         read_header();
     }
 
-public:
-    point2<std::ptrdiff_t> dimensions() const
-    {
-        // Implementation note:
-        //   A user might have setup output image scaling through the low-level
-        // lib_object accessor.
-        //                                    (17.10.2010.) (Domagoj Saric)
-        if ( dirty_output_dimensions_ )
-        {
-            jpeg_calc_output_dimensions( &const_cast<libjpeg_image &>( *this ).lib_object() );
-            dirty_output_dimensions_ = false;
-        }
-        return point2<std::ptrdiff_t>( decompressor().output_width, decompressor().output_height );
-    }
-
-public: // Low-level (row, strip, tile) access
-    void read_row( sequential_row_access_state, unsigned char * const p_row_storage ) const
-    {
-        read_scanline( p_row_storage );
-    }
-
-    jpeg_decompress_struct       & lib_object()       { dirty_output_dimensions_ = true; return decompressor(); }
-    jpeg_decompress_struct const & lib_object() const {                                  return decompressor(); }
-
 private: // Private interface for the base formatted_image<> class.
     friend base_t;
+
     void raw_convert_to_prepared_view( detail::view_data_t const & view_data ) const throw(...)
     {
         setup_decompression( view_data );
@@ -634,6 +605,7 @@
         }
     }
 
+
     template <class MyView, class TargetView, class Converter>
     void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const
     {
@@ -683,6 +655,7 @@
         }
     }
 
+
     void raw_copy_to_prepared_view( detail::view_data_t const & view_data ) const
     {
         BOOST_ASSERT( view_data.width_  == static_cast<unsigned int>( dimensions().x ) );
@@ -691,6 +664,27 @@
         raw_convert_to_prepared_view( view_data );
     }
 
+
+    static std::size_t cached_format_size( format_t const format )
+    {
+        switch ( format )
+        {
+            case JCS_RGB:
+            case JCS_YCbCr:
+                return 3;
+            case JCS_CMYK:
+            case JCS_YCCK:
+                return 4;
+            case JCS_GRAYSCALE:
+                return 1;
+
+            default:
+                BOOST_ASSERT( !"Invalid or unknown format specified." );
+                BF_UNREACHABLE_CODE
+                return 0;
+        }
+    }
+
 private:
     void setup_decompression( detail::decompression_setup_data_t const & view_data ) const throw(...)
     {
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	2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
@@ -465,12 +465,7 @@
         }
     }
 
-    std::size_t format_size( format_t const format ) const
-    {
-        return number_of_channels() * format_bit_depth( format ) / 8;
-    }
-
-    std::size_t format_size() const
+    std::size_t pixel_size() const
     {
         return number_of_channels() * bit_depth() / 8;
     }
@@ -650,6 +645,11 @@
         }
     }
 
+    std::size_t cached_format_size( format_t const format ) const
+    {
+        return number_of_channels() * format_bit_depth( format ) / 8;
+    }
+
 private:
     #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
         jmp_buf & error_handler_target() const { return png_object().jmpbuf; }
Modified: sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp	(original)
+++ sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp	2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
@@ -543,13 +543,13 @@
     format_t const & format                      () const { return format_.number; }
     format_t const & closest_gil_supported_format() const { return format()      ; }
 
-    static std::size_t format_size( format_t const format )
-    {
-        full_format_t::format_bitfield const & bits( reinterpret_cast<full_format_t const &>( format ).bits );
-        return bits.bits_per_sample * ( ( bits.planar_configuration == PLANARCONFIG_CONTIG ) ? bits.samples_per_pixel : 1 ) / 8;
-    }
-
 public: // Low-level (row, strip, tile) access
+    bool can_do_row_access  () const { return !can_do_tile_access(); }
+    bool can_do_strip_access() const { return /*...yet to implement...can_do_row_access();*/ false; }
+    bool can_do_tile_access () const { return ::TIFFIsTiled( &lib_object() ) != 0; }
+
+    std::size_t tile_size() const { return ::TIFFTileSize( &lib_object() ); }
+
     class sequential_row_access_state
         :
         private detail::libtiff_base::cumulative_result
@@ -735,7 +735,7 @@
     {
         cumulative_result result;
 
-        if ( ::TIFFIsTiled( &lib_object() ) )
+        if ( can_do_tile_access() )
         {
             tile_setup_t setup( *this, view_data.dimensions_, view_data.offset_, false );
 
@@ -1098,6 +1098,12 @@
         result.throw_if_error();
     }
 
+    static std::size_t cached_format_size( format_t const format )
+    {
+        full_format_t::format_bitfield const & bits( reinterpret_cast<full_format_t const &>( format ).bits );
+        return bits.bits_per_sample * ( ( bits.planar_configuration == PLANARCONFIG_CONTIG ) ? bits.samples_per_pixel : 1 ) / 8;
+    }
+
 private:
     template <typename View>
     static typename nth_channel_view_type<View>::type
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	2011-01-08 16:02:27 EST (Sat, 08 Jan 2011)
@@ -418,21 +418,24 @@
         return result;
     }
 
-    static std::size_t format_size( format_t /*const*/ format )
+    /*format_t*/WICPixelFormatGUID format() const
     {
-        using namespace detail;
-        com_scoped_ptr<IWICComponentInfo> p_component_info;
-        ensure_result( wic_factory::singleton().CreateComponentInfo( format, &p_component_info ) );
-        //com_scoped_ptr<IWICPixelFormatInfo> p_pixel_format_info;
-        //p_component_info->QueryInterface( );IID_IWICPixelFormatInfo
-        com_scoped_ptr<IWICPixelFormatInfo> const p_pixel_format_info( *p_component_info );
-        io_error_if_not( p_pixel_format_info, "WIC failure" );
-        unsigned int bits_per_pixel;
-        verify_result( p_pixel_format_info->GetBitsPerPixel( &bits_per_pixel ) );
-        return bits_per_pixel;
+        WICPixelFormatGUID pixel_format;
+        detail::verify_result( frame_decoder().GetPixelFormat( &pixel_format ) );
+        //...zzz...check that it is a supported format...
+        return pixel_format;
+    }
+
+    /*format_t*/WICPixelFormatGUID closest_gil_supported_format() const { return format(); }
+
+    image_type_id current_image_format_id() const
+    {
+        return image_format_id( closest_gil_supported_format() );
     }
 
 public: // Low-level (row, strip, tile) access
+    static bool can_do_roi_access() { return true; }
+
     class sequential_row_access_state
         :
         private detail::cumulative_result
@@ -447,7 +450,7 @@
         sequential_row_access_state( wic_image const & source_image )
             :
             roi_   ( 0, 0, source_image.dimensions().x, 1 ),
-            stride_( roi_.X * source_image.format_size( source_image.format() ) )
+            stride_( roi_.X * source_image.pixel_size()   )
         {}
 
     private: friend wic_image;
@@ -478,23 +481,6 @@
 private: // Private formatted_image_base interface.
     friend base_t;
 
-    //...zzz...cleanup...
-    /*format_t*/WICPixelFormatGUID format() const
-    {
-        WICPixelFormatGUID pixel_format;
-        detail::verify_result( frame_decoder().GetPixelFormat( &pixel_format ) );
-        //...zzz...check that it is a supported format...
-        return pixel_format;
-    }
-
-    /*format_t*/WICPixelFormatGUID closest_gil_supported_format() const { return format(); }
-
-    image_type_id current_image_format_id() const
-    {
-        return image_format_id( closest_gil_supported_format() );
-    }
-
-
     template <class MyView, class TargetView, class Converter>
     void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const
     {
@@ -568,6 +554,21 @@
         );
     }
 
+
+    static std::size_t cached_format_size( format_t const format )
+    {
+        using namespace detail;
+        com_scoped_ptr<IWICComponentInfo> p_component_info;
+        ensure_result( wic_factory::singleton().CreateComponentInfo( format, &p_component_info ) );
+        //com_scoped_ptr<IWICPixelFormatInfo> p_pixel_format_info;
+        //p_component_info->QueryInterface( );IID_IWICPixelFormatInfo
+        com_scoped_ptr<IWICPixelFormatInfo> const p_pixel_format_info( *p_component_info );
+        io_error_if_not( p_pixel_format_info, "WIC failure" );
+        unsigned int bits_per_pixel;
+        verify_result( p_pixel_format_info->GetBitsPerPixel( &bits_per_pixel ) );
+        return bits_per_pixel;
+    }
+
 private:
     IWICBitmapFrameDecode & frame_decoder() const { return *lib_object_.first ; }
     IWICBitmapDecoder     & wic_decoder  () const { return *lib_object_.second; }