$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r85336 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2013-08-13 18:08:26
Author: psiha
Date: 2013-08-13 18:08:26 EDT (Tue, 13 Aug 2013)
New Revision: 85336
URL: http://svn.boost.org/trac/boost/changeset/85336
Log:
Minor refactoring and cleanup (moving the GDI+, LibJPEG and LibPNG backends toward the new architecture).
Text files modified: 
   sandbox/gil/boost/gil/extension/io2/gp_image.hpp      |    35 +++++++++++++++--------------           
   sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp |    41 +++++++++++++++++++----------------     
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp  |    46 ++++++++++++++++++++--------------------
   3 files changed, 63 insertions(+), 59 deletions(-)
Modified: sandbox/gil/boost/gil/extension/io2/gp_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/gp_image.hpp	Tue Aug 13 17:39:57 2013	(r85335)
+++ sandbox/gil/boost/gil/extension/io2/gp_image.hpp	2013-08-13 18:08:26 EDT (Tue, 13 Aug 2013)	(r85336)
@@ -5,9 +5,10 @@
 ///
 /// Base IO interface GDI+ implementation.
 ///
-/// Copyright (c) Domagoj Saric 2010.
+/// Copyright (c) 2010.-2013. Domagoj Saric
 ///
-///  Use, modification and distribution is subject to the Boost Software License, Version 1.0.
+///  Use, modification and distribution is subject to the
+///  Boost Software License, Version 1.0.
 ///  (See accompanying file LICENSE_1_0.txt or copy at
 ///  http://www.boost.org/LICENSE_1_0.txt)
 ///
@@ -23,7 +24,7 @@
 #include "detail/gp_extern_lib_guard.hpp"
 #include "detail/windows_shared.hpp"
 #include "detail/windows_shared_istreams.hpp"
-#include "formatted_image.hpp"
+#include "backend.hpp"
 
 #include <boost/array.hpp>
 #include <boost/mpl/eval_if.hpp>
@@ -191,7 +192,7 @@
                 view.height(),
                 view.pixels().row_size(),
                 gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value,
-                formatted_image_base::get_raw_data( view ),
+                backend_base::get_raw_data( view ),
                 &lib_object().first
             )
         );
@@ -261,7 +262,7 @@
 class gp_image;
 
 template <>
-struct formatted_image_traits<gp_image>
+struct backend_traits<gp_image>
 {
     typedef Gdiplus::PixelFormat format_t;
 
@@ -284,8 +285,8 @@
         mpl::pair<wchar_t        const *,                                           gp_image  >,
         mpl::pair<IStream               ,                                           gp_image  >,
         mpl::pair<FILE                  , detail::input_FILE_for_IStream_extender  <gp_image> >,
-        mpl::pair<memory_chunk_t        , detail::memory_chunk_for_IStream_extender<gp_image> >
-    > readers;
+        mpl::pair<memory_range_t        , detail::memory_chunk_for_IStream_extender<gp_image> >
+    > native_sources;
 
     typedef mpl::map4
     <
@@ -293,7 +294,7 @@
         mpl::pair<wchar_t const *, detail::gp_writer>,
         mpl::pair<IStream        , detail::gp_writer>,
         mpl::pair<FILE           , detail::gp_writer>
-    > writers;
+    > native_sinks;
 
     typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
 
@@ -329,7 +330,7 @@
             Height      = view.height();
             Stride      = view.pixels().row_size();
             PixelFormat = detail::gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value;
-            Scan0       = formatted_image_base::get_raw_data( view );
+            Scan0       = backend_base::get_raw_data( view );
             Reserved    = 0;
         }
 
@@ -354,7 +355,7 @@
 class gp_image
     :
     private detail::gp_guard,
-    public  detail::formatted_image<gp_image>
+    public  detail::backend<gp_image>
 {
 public:
     typedef detail::gp_user_guard guard;
@@ -468,7 +469,7 @@
 public: // Low-level (row, strip, tile) access
     static bool can_do_roi_access() { return true; }
 
-    class sequential_row_access_state
+    class sequential_row_read_state
         :
         private detail::cumulative_result
     {
@@ -479,7 +480,7 @@
         BOOST_STATIC_CONSTANT( bool, throws_on_error = false );
 
     private:
-        sequential_row_access_state( gp_image const & source_image )
+        sequential_row_read_state( gp_image const & source_image )
             :
             roi_( 0, 0, source_image.dimensions().x, 1 )
         {
@@ -495,11 +496,11 @@
         Gdiplus::BitmapData bitmapData_;
     };
 
-    sequential_row_access_state begin_sequential_row_access() const { return sequential_row_access_state( *this ); }
+    sequential_row_read_state begin_sequential_row_read() const { return sequential_row_read_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
+    void read_row( sequential_row_read_state & state, unsigned char * const p_row_storage ) const
     {
         using namespace detail ;
         using namespace Gdiplus;
@@ -526,7 +527,7 @@
     ::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.
+private: // Private backend_base interface.
     friend class base_t;
 
     template <class MyView, class TargetView, class Converter>
@@ -770,8 +771,8 @@
 //...mhmh...to be implemented...
 //template <class Impl, class SupportedPixelFormats, class ROI>
 //inline
-//typename formatted_image<Impl, SupportedPixelFormats, ROI>::view_t
-//view( formatted_image<Impl, SupportedPixelFormats, ROI> & img );// { return img._view; }
+//typename backend<Impl, SupportedPixelFormats, ROI>::view_t
+//view( backend<Impl, SupportedPixelFormats, ROI> & img );// { return img._view; }
 
 //------------------------------------------------------------------------------
 } // namespace detail
Modified: sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp	Tue Aug 13 17:39:57 2013	(r85335)
+++ sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp	2013-08-13 18:08:26 EDT (Tue, 13 Aug 2013)	(r85336)
@@ -17,7 +17,7 @@
 #ifndef libjpeg_image_hpp__7C5F6951_A00F_4E0D_9783_488A49B1CA2B
 #define libjpeg_image_hpp__7C5F6951_A00F_4E0D_9783_488A49B1CA2B
 //------------------------------------------------------------------------------
-#include "formatted_image.hpp"
+#include "backend.hpp"
 #include "detail/io_error.hpp"
 #include "detail/libx_shared.hpp"
 #include "detail/shared.hpp"
@@ -221,7 +221,7 @@
         decompression_setup_data_t
         (
             gil_to_libjpeg_format<typename View::value_type, is_planar<View>::value>::value,
-            formatted_image_base::get_raw_data( view ),
+            backend_base::get_raw_data( view ),
             offset
         ),
         height_( view.height()            ),
@@ -246,6 +246,9 @@
     private libjpeg_base,
     public  configure_on_write_writer
 {
+protected:
+    BOOST_STATIC_CONSTANT( bool, auto_closes_device = true );
+
 public:
     explicit libjpeg_writer( char const * const p_target_file_name )
         :
@@ -298,7 +301,7 @@
         compressor().in_color_space   = view.format_;
     }
 
-    void do_write( view_data_t const & view ) BOOST_GIL_CAN_THROW //...zzz...a plain throw(...) would be enough here but it chokes GCC...
+    void do_write( view_data_t const & view ) BOOST_GIL_CAN_THROW
     {
         BOOST_ASSERT( view.format_ != JCS_UNKNOWN );
 
@@ -460,7 +463,7 @@
 class libjpeg_image;
 
 template <>
-struct formatted_image_traits<libjpeg_image>
+struct backend_traits<libjpeg_image>
 {
     typedef       ::J_COLOR_SPACE                   format_t;
     typedef detail::libjpeg_supported_pixel_formats supported_pixel_formats_t;
@@ -478,16 +481,16 @@
 
     typedef mpl::map3
             <
-                mpl::pair<memory_chunk_t        , detail::seekable_input_memory_range_extender<libjpeg_image> >,
+                mpl::pair<memory_range_t        , detail::seekable_input_memory_range_extender<libjpeg_image> >,
                 mpl::pair<FILE                  ,                                              libjpeg_image  >,
                 mpl::pair<char           const *, detail::input_c_str_for_mmap_extender       <libjpeg_image> >
-            > readers;
+            > native_sources;
 
     typedef mpl::map2
             <
                 mpl::pair<FILE        , detail::libjpeg_writer>,
                 mpl::pair<char const *, detail::libjpeg_writer>
-            > writers;
+            > native_sinks;
 
     typedef mpl::vector1_c<format_tag, jpeg> supported_image_formats;
 
@@ -507,7 +510,7 @@
 class libjpeg_image
     :
     public detail::libjpeg_base,
-    public detail::formatted_image<libjpeg_image>
+    public detail::backend<libjpeg_image>
 {
 public:
     struct guard {};
@@ -575,7 +578,7 @@
     }
 
 public: // Low-level (row, strip, tile) access
-    void read_row( sequential_row_access_state, unsigned char * const p_row_storage ) const
+    void read_row( sequential_row_read_state, unsigned char * const p_row_storage ) const
     {
         read_scanline( p_row_storage );
     }
@@ -584,7 +587,7 @@
     jpeg_decompress_struct const & lib_object() const {                                  return decompressor(); }
 
 public: /// \ingroup Construction
-    explicit libjpeg_image( memory_chunk_t & memory_chunk )
+    explicit libjpeg_image( memory_range_t & memory_chunk )
         :
         libjpeg_base( for_decompressor() )
     {
@@ -612,15 +615,15 @@
         read_header();
     }
 
-private: // Private interface for the base formatted_image<> class.
+private: // Private interface for the base backend<> class.
     // Implementation note:
     //   MSVC 10 accepts friend base_t and friend class base_t, Clang 2.8
     // accepts friend class base_t, Apple Clang 1.6 and GCC (4.2 and 4.6) accept
     // neither.
     //                                        (13.01.2011.) (Domagoj Saric)
-    friend class detail::formatted_image<libjpeg_image>;
+    friend class detail::backend<libjpeg_image>;
 
-    void raw_convert_to_prepared_view( detail::view_data_t const & view_data ) const BOOST_GIL_CAN_THROW //...zzz...a plain throw(...) would be enough here but it chokes GCC...
+    void raw_convert_to_prepared_view( detail::view_data_t const & view_data ) const BOOST_GIL_CAN_THROW
     {
         setup_decompression( view_data );
 
@@ -721,7 +724,7 @@
     }
 
 
-    static std::size_t cached_format_size( format_t const format )
+    static unsigned int cached_format_size( format_t const format )
     {
         switch ( format )
         {
@@ -742,7 +745,7 @@
     }
 
 private:
-    void setup_decompression( detail::decompression_setup_data_t const & view_data ) const BOOST_GIL_CAN_THROW //...zzz...a plain throw(...) would be enough here but it chokes GCC...
+    void setup_decompression( detail::decompression_setup_data_t const & view_data ) const BOOST_GIL_CAN_THROW
     {
         unsigned int const state       ( decompressor().global_state );
         unsigned int       rows_to_skip( view_data.offset_           );
@@ -786,9 +789,9 @@
         mutable_this().decompressor().raw_data_out = true;
         mutable_this().decompressor().global_state = DSTATE_RAW_OK;
 
-        std::size_t const max_number_of_components( 4 ); // CMYK
-        std::size_t const max_sampling_factor     ( 2 ); // Documentation
-        std::size_t const mcu_row_size            ( max_sampling_factor * DCTSIZE ); // Documentation
+        unsigned int const max_number_of_components( 4 ); // CMYK
+        unsigned int const max_sampling_factor     ( 2 ); // Documentation
+        unsigned int const mcu_row_size            ( max_sampling_factor * DCTSIZE ); // Documentation
         BOOST_ASSERT( decompressor().num_components    <= max_number_of_components );
         BOOST_ASSERT( decompressor().max_v_samp_factor <= max_sampling_factor      );
 
@@ -885,7 +888,7 @@
         decompressor().src = &source_manager_;
     }
 
-    void setup_source( memory_chunk_t & memory_chunk )
+    void setup_source( memory_range_t & memory_chunk )
     {
         setup_source();
 
Modified: sandbox/gil/boost/gil/extension/io2/libpng_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libpng_image.hpp	Tue Aug 13 17:39:57 2013	(r85335)
+++ sandbox/gil/boost/gil/extension/io2/libpng_image.hpp	2013-08-13 18:08:26 EDT (Tue, 13 Aug 2013)	(r85336)
@@ -13,11 +13,11 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
-#pragma once
 #ifndef libpng_image_hpp__9E0C99E6_EAE8_4D71_844B_93518FFCB5CE
 #define libpng_image_hpp__9E0C99E6_EAE8_4D71_844B_93518FFCB5CE
+#pragma once
 //------------------------------------------------------------------------------
-#include "formatted_image.hpp"
+#include "backend.hpp"
 #include "detail/platform_specifics.hpp"
 #include "detail/io_error.hpp"
 #include "detail/libx_shared.hpp"
@@ -43,7 +43,7 @@
 //------------------------------------------------------------------------------
 
 template <typename Pixel, bool isPlanar>
-struct gil_to_libpng_format : mpl::integral_c<unsigned int, formatted_image_base::unsupported_format> {};
+struct gil_to_libpng_format : mpl::integral_c<unsigned int, backend_base::unsupported_format> {};
 
 /// \todo Add bgr-layout formats as LibPNG actually supports them through
 /// png_set_bgr().
@@ -85,7 +85,7 @@
     /*explicit*/ libpng_view_data_t( View const & view, libpng_roi::offset_t const offset = 0 )
         :
         format_( gil_to_libpng_format<typename View::value_type, is_planar<View>::value>::value ),
-        buffer_( formatted_image_base::get_raw_data( view ) ),
+        buffer_( backend_base::get_raw_data( view ) ),
         offset_( offset                   ),
         height_( view.height()            ),
         width_ ( view.width ()            ),
@@ -250,8 +250,6 @@
 ///
 /// \class libpng_writer
 ///
-/// \brief
-///
 ////////////////////////////////////////////////////////////////////////////////
 
 class libpng_writer
@@ -280,7 +278,7 @@
         write( view );
     }
 
-    void write( libpng_view_data_t const & view ) BOOST_GIL_CAN_THROW //...zzz...a plain throw(...) would be enough here but it chokes GCC...
+    void write( libpng_view_data_t const & view ) BOOST_GIL_CAN_THROW
     {
         BOOST_ASSERT( view.format_ != JCS_UNKNOWN );
 
@@ -382,7 +380,7 @@
 class libpng_image;
 
 template <>
-struct formatted_image_traits<libpng_image>
+struct backend_traits<libpng_image>
 {
     typedef detail::libpng_supported_pixel_formats supported_pixel_formats_t;
     typedef detail::libpng_roi                     roi_t;
@@ -400,16 +398,16 @@
 
     typedef mpl::map3
             <
-                mpl::pair<memory_chunk_t        , detail::seekable_input_memory_range_extender<libpng_image> >,
+                mpl::pair<memory_range_t        , detail::seekable_input_memory_range_extender<libpng_image> >,
                 mpl::pair<FILE                  ,                                              libpng_image  >,
                 mpl::pair<char           const *, detail::input_c_str_for_mmap_extender       <libpng_image> >
-            > readers;
+            > native_sources;
 
     typedef mpl::map2
             <
                 mpl::pair<FILE        ,                                          detail::libpng_writer_FILE  >,
                 mpl::pair<char const *, detail::output_c_str_for_c_file_extender<detail::libpng_writer_FILE> >
-            > writers;
+            > native_sinks;
 
     typedef mpl::vector1_c<format_tag, png> supported_image_formats;
 
@@ -430,7 +428,7 @@
 
 class libpng_image
     :
-    public  detail::formatted_image<libpng_image>,
+    public  detail::backend<libpng_image>,
     private detail::libpng_base
 {
 public:
@@ -450,8 +448,8 @@
         {
             default: return current_format;
 
-            case PNG_COLOR_TYPE_PALETTE   : return PNG_COLOR_TYPE_RGB  | ( 8 << 16 );
-            case PNG_COLOR_TYPE_GRAY_ALPHA: return PNG_COLOR_TYPE_RGBA | ( ( ( current_format >> 16 ) & 0xFF ) << 16 );
+            case PNG_COLOR_TYPE_PALETTE   : return PNG_COLOR_TYPE_RGB  | ( 8 << 16 ); // 8-bit RGB
+            case PNG_COLOR_TYPE_GRAY_ALPHA: return PNG_COLOR_TYPE_RGBA | ( ( ( current_format >> 16 ) & 0xFF ) << 16 ); // (bits of current_format) RGBA
         }
     }
 
@@ -498,7 +496,7 @@
         init();
     }
 
-    explicit libpng_image( memory_chunk_t & in_memory_image )
+    explicit libpng_image( memory_range_t & in_memory_image )
         :
         libpng_base( ::png_create_read_struct_2( PNG_LIBPNG_VER_STRING, NULL, &detail::png_error_function, &detail::png_warning_function, NULL, NULL, NULL ) )
     {
@@ -526,20 +524,20 @@
     }
 
 public: // Low-level (row, strip, tile) access
-    void read_row( sequential_row_access_state, unsigned char * const p_row_storage ) const
+    void read_row( sequential_row_read_state, unsigned char * const p_row_storage ) const
     {
         read_row( p_row_storage );
     }
 
     png_struct & lib_object() const { return png_object(); }
 
-private: // Private formatted_image_base interface.
+private: // Private backend_base interface.
     // Implementation note:
     //   MSVC 10 accepts friend base_t and friend class base_t, Clang 2.8
     // accepts friend class base_t, Apple Clang 1.6 and GCC (4.2 and 4.6) accept
     // neither.
     //                                        (13.01.2011.) (Domagoj Saric)
-    friend class detail::formatted_image<libpng_image>;
+    friend class detail::backend<libpng_image>;
 
     template <class MyView, class TargetView, class Converter>
     void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const BOOST_GIL_CAN_THROW //...zzz...a plain throw(...) would be enough here but it chokes GCC...
@@ -598,8 +596,13 @@
             ::png_set_palette_to_rgb( &png_object() );
         }
         else
-        if ( colour_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8 )
+        if ( ( colour_type == PNG_COLOR_TYPE_GRAY ) && ( bit_depth < 8 ) )
+        {
             ::png_set_expand_gray_1_2_4_to_8( &png_object() );
+        }
+
+        if ( !( colour_type & PNG_COLOR_MASK_ALPHA ) )
+            ::png_set_strip_alpha( &png_object() );
 
         if ( ::png_get_valid( &png_object(), &info_object(), PNG_INFO_tRNS ) )
             ::png_set_tRNS_to_alpha( &png_object() );
@@ -607,9 +610,6 @@
         if ( bit_depth == 8 )
             ::png_set_strip_16( &png_object() );
 
-        if ( !( colour_type & PNG_COLOR_MASK_ALPHA ) )
-            ::png_set_strip_alpha( &png_object() );
-
         //...zzz...
 
         //if (color_type == PNG_COLOR_TYPE_RGB ||
@@ -738,7 +738,7 @@
         BOOST_ASSERT( png_ptr         );
         BOOST_ASSERT( png_ptr->io_ptr );
 
-        memory_chunk_t & memory_chunk( *static_cast<memory_chunk_t *>( png_ptr->io_ptr ) );
+        memory_range_t & memory_chunk( *static_cast<memory_range_t *>( png_ptr->io_ptr ) );
 
         if ( length <= static_cast<std::size_t>( memory_chunk.size() ) )
         {