$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r67660 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2011-01-04 17:29:00
Author: psiha
Date: 2011-01-04 17:28:52 EST (Tue, 04 Jan 2011)
New Revision: 67660
URL: http://svn.boost.org/trac/boost/changeset/67660
Log:
Added low level row access to all backends.
Minor other refactoring and stylistic changes.
Text files modified: 
   sandbox/gil/boost/gil/extension/io2/formatted_image.hpp |     7 +++                                     
   sandbox/gil/boost/gil/extension/io2/gp_image.hpp        |    61 ++++++++++++++++++++++++++++++++++++++- 
   sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp   |     6 +++                                     
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp    |    14 ++++++--                                
   sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp   |    25 ++++++++++++++++                        
   sandbox/gil/boost/gil/extension/io2/wic_image.hpp       |    55 ++++++++++++++++++++++++++++++++---     
   6 files changed, 155 insertions(+), 13 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-04 17:28:52 EST (Tue, 04 Jan 2011)
@@ -326,7 +326,7 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 
-class formatted_image_base : public /*khm private seems to bug MSVC++ 10 with the libtiff backend....*/ noncopyable
+class formatted_image_base : noncopyable
 {
 public:
     typedef point2<std::ptrdiff_t> dimensions_t;
@@ -334,6 +334,11 @@
     typedef unsigned int image_type_id;
     static image_type_id const unsupported_format = static_cast<image_type_id>( -1 );
 
+    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(); }
+
 protected:
     static bool dimensions_mismatch( dimensions_t const & mine, dimensions_t const & other ) { return mine != other; }
     template <class View>
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-04 17:28:52 EST (Tue, 04 Jan 2011)
@@ -245,7 +245,7 @@
             { 0x557CF400, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // BMP
             { 0x557CF402, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // GIF
             { 0x557CF401, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // JPEG
-            { 0x557cf406, 0x1a04, 0x11d3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // PNG
+            { 0x557CF406, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // PNG
             { 0x557CF405, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // TIFF
             CLSID_NULL // TGA
         };
@@ -326,7 +326,7 @@
 
             BOOST_STATIC_ASSERT( is_supported<typename get_original_view_t<View>::type>::value );
 
-            Width       = view.width();
+            Width       = view.width ();
             Height      = view.height();
             Stride      = view.pixels().row_size();
             PixelFormat = gil_to_native_format<View>::value;
@@ -400,6 +400,62 @@
         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(); }
 
@@ -517,6 +573,7 @@
         verify_result( DllExports::GdipBitmapUnlockBits( pBitmap_, &bitmapData ) );
     }
 
+
     void raw_convert_to_prepared_view( view_data_t const & view_data ) const
     {
         BOOST_ASSERT( view_data.Scan0 );
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-04 17:28:52 EST (Tue, 04 Jan 2011)
@@ -580,6 +580,12 @@
         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(); }
 
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-04 17:28:52 EST (Tue, 04 Jan 2011)
@@ -518,10 +518,16 @@
     point2<std::ptrdiff_t> dimensions() const
     {
         return point2<std::ptrdiff_t>
-               (
-                   ::png_get_image_width ( &png_object(), &info_object() ),
-                   ::png_get_image_height( &png_object(), &info_object() )
-               );
+        (
+            ::png_get_image_width ( &png_object(), &info_object() ),
+            ::png_get_image_height( &png_object(), &info_object() )
+        );
+    }
+
+public: // Low-level (row, strip, tile) access
+    void read_row( sequential_row_access_state, unsigned char * const p_row_storage ) const
+    {
+        read_row( p_row_storage );
     }
 
     png_struct & lib_object() const { return png_object(); }
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-04 17:28:52 EST (Tue, 04 Jan 2011)
@@ -554,6 +554,31 @@
         return bits.bits_per_sample * ( ( bits.planar_configuration == PLANARCONFIG_CONTIG ) ? bits.samples_per_pixel : 1 ) / 8;
     }
 
+public: // Low-level (row, strip, tile) access
+    class sequential_row_access_state
+        :
+        private detail::libtiff_base::cumulative_result
+    {
+    public:
+        using detail::libtiff_base::cumulative_result::failed;
+        using detail::libtiff_base::cumulative_result::throw_if_error;
+
+        BOOST_STATIC_CONSTANT( bool, throws_on_error = false );
+
+        friend libtiff_image;
+    };
+
+    static sequential_row_access_state begin_sequential_row_access() { return sequential_row_access_state(); }
+
+    void read_row( sequential_row_access_state & state, unsigned char * const p_row_storage, unsigned int const plane = 0 ) const
+    {
+        state.accumulate_greater
+        (
+            ::TIFFReadScanline( &lib_object(), p_row_storage, ::TIFFCurrentRow( &lib_object() ), static_cast<tsample_t>( plane ) ),
+            0
+        );
+    }
+
 private:
     template <typename T>
     T get_field( ttag_t const tag ) const
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-04 17:28:52 EST (Tue, 04 Jan 2011)
@@ -118,12 +118,14 @@
 public:
     wic_roi( value_type const x, value_type const y, value_type const width, value_type const height )
     {
-        X = x; Y = y; Width = width; Height = height;
+        X = x; Y = y;
+        Width = width; Height = height;
     }
 
-    wic_roi( offset_t const offset, value_type const width, value_type const height )
+    wic_roi( offset_t const top_left, value_type const width, value_type const height )
     {
-        X = offset.x; Y = offset.y; Width = width; Height = height;
+        X = top_left.x; Y = top_left.y;
+        Width = width; Height = height;
     }
 
     wic_roi( offset_t const top_left, offset_t const bottom_right )
@@ -151,7 +153,7 @@
     template <typename View>
     wic_view_data_t( View const & view )
         :
-        p_roi_ ( 0                                   ),
+        p_roi_ ( 0                                                                                ),
         format_( view_wic_format::apply<typename View::value_type, is_planar<View>::value>::value )
     {
         set_bitmapdata_for_view( view );
@@ -413,8 +415,6 @@
     //    create_first_frame_decoder();
     //}
 
-    lib_object_t & lib_object() { return lib_object_; }
-
 public:
     point2<std::ptrdiff_t> dimensions() const
     {
@@ -441,6 +441,49 @@
         return bits_per_pixel;
     }
 
+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( "WIC failure" ); }
+
+        BOOST_STATIC_CONSTANT( bool, throws_on_error = false );
+
+    private:
+        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() ) )
+        {}
+
+    private: friend wic_image;
+        detail::wic_roi       roi_   ;
+        UINT            const stride_;
+    };
+
+    sequential_row_access_state begin_sequential_row_access() const { return sequential_row_access_state( *this ); }
+
+    void read_row( sequential_row_access_state & state, unsigned char * const p_row_storage ) const
+    {
+        state.accumulate_equal
+        (
+            frame_decoder().CopyPixels
+            (
+                &state.roi_,
+                state.stride_,
+                state.stride_,
+                p_row_storage
+            ),
+            S_OK
+        );
+        ++state.roi_.Y;
+    }
+
+    lib_object_t & lib_object() { return lib_object_; }
+
 private: // Private formatted_image_base interface.
     friend base_t;