Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67750 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2011-01-07 03:50:11


Author: psiha
Date: 2011-01-07 03:50:03 EST (Fri, 07 Jan 2011)
New Revision: 67750
URL: http://svn.boost.org/trac/boost/changeset/67750

Log:
Refactored the various GIL<->native format related metafunctions to work with pixel formats directly instead of through View types.

Added raw tile access for the libtiff_image class.

Cleaned up and fixed the libpng_view_data_t and libpng_writer classes.
Text files modified:
   sandbox/gil/boost/gil/extension/io2/formatted_image.hpp | 53 +++++++++++++++++++-----------
   sandbox/gil/boost/gil/extension/io2/gp_image.hpp | 29 ++++++++--------
   sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp | 25 ++++++++------
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp | 67 ++++++++++++++++++---------------------
   sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp | 43 +++++++++++++++++--------
   5 files changed, 121 insertions(+), 96 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-07 03:50:03 EST (Fri, 07 Jan 2011)
@@ -536,6 +536,21 @@
 
     template <typename Locator>
     struct gil_to_native_format<image_view<Locator> > : gil_to_native_format_aux<typename image_view<Locator>::value_type, is_planar<image_view<Locator> > > {};
+
+ template <class View>
+ struct has_supported_format
+ {
+ private:
+ typedef typename get_original_view_t<View>::type original_view_t;
+
+ public:
+ typedef typename formatted_image_traits<Impl>:: BOOST_NESTED_TEMPLATE is_supported
+ <
+ typename original_view_t::value_type,
+ is_planar<original_view_t>::value
+ > type;
+ BOOST_STATIC_CONSTANT( bool, value = type::value );
+ };
     
     typedef any_image<supported_pixel_formats> dynamic_image_t;
 
@@ -557,29 +572,29 @@
         BOOST_STATIC_CONSTANT( bool , single_format = mpl::size <supported_image_formats>::value == 1 );
 
         typedef typename mpl::at
- <
- typename formatted_image_traits<Impl>::writers,
- Target
- >::type base_writer_t;
+ <
+ typename formatted_image_traits<Impl>::writers,
+ Target
+ >::type base_writer_t;
 
         // The backend does not seem to provide a writer for the specified target...
         BOOST_STATIC_ASSERT(( !is_same<base_writer_t, mpl::void_>::value ));
 
         typedef typename mpl::if_c
- <
- single_format,
- typename base_writer_t:: BOOST_NESTED_TEMPLATE single_format_writer_wrapper<base_writer_t, Target, default_format>,
- base_writer_t
- >::type first_layer_wrapper;
+ <
+ single_format,
+ typename base_writer_t:: BOOST_NESTED_TEMPLATE single_format_writer_wrapper<base_writer_t, Target, default_format>,
+ base_writer_t
+ >::type first_layer_wrapper;
 
     public:
         typedef typename base_writer_t::wrapper
- <
- first_layer_wrapper,
- Target,
- typename formatted_image_traits<Impl>::writer_view_data_t,
- default_format
- > type;
+ <
+ first_layer_wrapper,
+ Target,
+ typename formatted_image_traits<Impl>::writer_view_data_t,
+ default_format
+ > type;
     };
 
     BOOST_STATIC_CONSTANT( bool, has_full_roi = (is_same<roi::offset_t, roi::point_t>::value) );
@@ -589,15 +604,13 @@
 
     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>
     {
     private:
         typedef make_dynamic_image<Images> base;
+
     public:
         typedef void result_type;
 
@@ -635,7 +648,7 @@
     struct write_is_supported
     {
         template <typename View>
- struct apply : public is_supported<View> {};
+ struct apply : public has_supported_format<View> {};
     };
 
     typedef mpl::range_c<std::size_t, 0, mpl::size<supported_pixel_formats>::value> valid_type_id_range_t;
@@ -753,7 +766,7 @@
     void copy_to( View const & view, assert_dimensions_match, assert_formats_match ) const
     {
         BOOST_STATIC_ASSERT( get_original_view_t<View>::type::value_type::is_mutable );
- BOOST_STATIC_ASSERT( is_supported<View>::value );
+ BOOST_STATIC_ASSERT( has_supported_format<View>::value );
         BOOST_ASSERT( !impl().dimensions_mismatch( view ) );
         BOOST_ASSERT( !impl().formats_mismatch<View>() );
         impl().raw_copy_to_prepared_view( get_view_data( 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-07 03:50:03 EST (Fri, 07 Jan 2011)
@@ -57,10 +57,8 @@
 typedef bgra_layout_t gp_alpha_layout_t;
 typedef bgr_layout_t gp_layout_t;
 
-
 typedef packed_pixel_type<uint16_t, mpl::vector3_c<unsigned,5,6,5>, gp_layout_t>::type gp_bgr565_pixel_t;
 
-
 template <typename Pixel, bool IsPlanar>
 struct gil_to_gp_format : mpl::integral_c<Gdiplus::PixelFormat, PixelFormatUndefined> {};
 
@@ -75,6 +73,10 @@
 #endif // (GDIPVER >= 0x0110)
 
 
+template <typename Pixel, bool IsPlanar>
+struct gp_is_supported : is_supported<gil_to_gp_format<Pixel, IsPlanar>::value>{};
+
+
 typedef mpl::
 #if (GDIPVER >= 0x0110)
     vector4
@@ -91,13 +93,6 @@
> gp_supported_pixel_formats;
 
 
-struct view_gp_format
-{
- template <typename Pixel, bool IsPlanar>
- struct apply : gil_to_gp_format<Pixel, IsPlanar> {};
-};
-
-
 typedef iterator_range<TCHAR const *> string_chunk_t;
 
 
@@ -182,7 +177,7 @@
     template <class View>
     explicit gp_writer( View & view )
     {
- BOOST_STATIC_ASSERT( is_supported<view_gp_format::apply<View>::value>::value );
+ BOOST_STATIC_ASSERT(( gp_is_supported<typename View::value_type, is_planar<View>::value>::value ));
 
         // http://msdn.microsoft.com/en-us/library/ms536315(VS.85).aspx
         // stride has to be a multiple of 4 bytes
@@ -195,7 +190,7 @@
                 view.width (),
                 view.height(),
                 view.pixels().row_size(),
- view_gp_format::apply<View>::value,
+ gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value,
                 formatted_image_base::get_raw_data( view ),
                 &lib_object().first
             )
@@ -274,10 +269,14 @@
 
     typedef detail::gp_roi roi_t;
 
- typedef detail::view_gp_format gil_to_native_format;
+ struct gil_to_native_format
+ {
+ template <typename Pixel, bool IsPlanar>
+ struct apply : detail::gil_to_gp_format<Pixel, IsPlanar> {};
+ };
 
     template <typename Pixel, bool IsPlanar>
- struct is_supported : detail::is_supported<gil_to_native_format:: BOOST_NESTED_TEMPLATE apply<Pixel, IsPlanar>::value> {};
+ struct is_supported : detail::gp_is_supported<Pixel, IsPlanar> {};
 
     typedef mpl::map5
     <
@@ -324,12 +323,12 @@
         {
             using namespace detail;
 
- BOOST_STATIC_ASSERT( is_supported<typename get_original_view_t<View>::type>::value );
+ BOOST_STATIC_ASSERT(( is_supported<typename View::value_type, is_planar<View>::value>::value ));
 
             Width = view.width ();
             Height = view.height();
             Stride = view.pixels().row_size();
- PixelFormat = gil_to_native_format<View>::value;
+ PixelFormat = detail::gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value;
             Scan0 = formatted_image_base::get_raw_data( view );
             Reserved = 0;
         }

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-07 03:50:03 EST (Fri, 07 Jan 2011)
@@ -54,11 +54,8 @@
 template <> struct gil_to_libjpeg_format<cmyk8_pixel_t, false> : mpl::integral_c<J_COLOR_SPACE, JCS_CMYK > {};
 
 
-struct view_libjpeg_format
-{
- template <typename Pixel, bool IsPlanar>
- struct apply : gil_to_libjpeg_format<Pixel, IsPlanar> {};
-};
+template <typename Pixel, bool IsPlanar>
+struct libjpeg_is_supported : mpl::bool_<gil_to_libjpeg_format<Pixel, IsPlanar>::value != JCS_UNKNOWN> {};
 
 
 typedef mpl::vector3
@@ -215,7 +212,7 @@
         :
         decompression_setup_data_t
         (
- view_libjpeg_format::apply<View>::value,
+ gil_to_libjpeg_format<typename View::value_type, is_planar<View>::value>::value,
             formatted_image_base::get_raw_data( view ),
             offset
         ),
@@ -224,7 +221,7 @@
         stride_( view.pixels().row_size() ),
         number_of_channels_( num_channels<View>::value )
     {
- BOOST_STATIC_ASSERT( view_libjpeg_format::apply<View>::value != JCS_UNKNOWN );
+ BOOST_STATIC_ASSERT(( libjpeg_is_supported<typename View::value_type, is_planar<View>::value>::value ));
     }
 
     void set_format( J_COLOR_SPACE const format ) { format_ = format; }
@@ -417,11 +414,16 @@
     typedef ::J_COLOR_SPACE format_t;
     typedef detail::libjpeg_supported_pixel_formats supported_pixel_formats_t;
     typedef detail::libjpeg_roi roi_t;
- typedef detail::view_libjpeg_format gil_to_native_format;
     typedef detail::view_data_t view_data_t;
 
+ struct gil_to_native_format
+ {
+ template <typename Pixel, bool IsPlanar>
+ struct apply : detail::gil_to_libjpeg_format<Pixel, IsPlanar> {};
+ };
+
     template <typename Pixel, bool IsPlanar>
- struct is_supported : mpl::bool_<gil_to_native_format::apply<Pixel, IsPlanar>::value != JCS_UNKNOWN> {};
+ struct is_supported : detail::libjpeg_is_supported<Pixel, IsPlanar> {};
 
     typedef mpl::map3
             <
@@ -643,12 +645,13 @@
         JSAMPROW scanline ( p_scanline_buffer.get() );
         JSAMPROW const scanline_end( scanline + scanline_length );
 
- BOOST_ASSERT( closest_gil_supported_format() == view_libjpeg_format::apply<MyView>::value );
+ format_t const my_format( gil_to_libjpeg_format<typename MyView::value_type, is_planar<MyView>::value>::value );
+ BOOST_ASSERT( this->closest_gil_supported_format() == my_format );
         setup_decompression
         (
             decompression_setup_data_t
             (
- view_libjpeg_format::apply<MyView>::value,
+ my_format,
                 scanline,
                 detail::get_offset<offset_t>( view )
             )

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-07 03:50:03 EST (Fri, 07 Jan 2011)
@@ -41,28 +41,24 @@
 //------------------------------------------------------------------------------
 
 template <typename Pixel, bool isPlanar>
-struct gil_to_libpng_format : mpl::integral_c<int, -1> {};
+struct gil_to_libpng_format : mpl::integral_c<unsigned int, formatted_image_base::unsupported_format> {};
 
 /// \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 )> {};
-template <> struct gil_to_libpng_format<rgb16_pixel_t , false> : mpl::integral_c<int, PNG_COLOR_TYPE_RGB | ( 16 << 16 )> {};
-template <> struct gil_to_libpng_format<rgba16_pixel_t, false> : mpl::integral_c<int, PNG_COLOR_TYPE_RGB_ALPHA | ( 16 << 16 )> {};
-template <> struct gil_to_libpng_format<gray16_pixel_t, false> : mpl::integral_c<int, PNG_COLOR_TYPE_GRAY | ( 16 << 16 )> {};
-
-
-struct view_libpng_format
-{
- template <typename Pixel, bool IsPlanar>
- struct apply : gil_to_libpng_format<Pixel, IsPlanar> {};
-};
+template <> struct gil_to_libpng_format<rgb8_pixel_t , false> : mpl::integral_c<unsigned int, PNG_COLOR_TYPE_RGB | ( 8 << 16 )> {};
+template <> struct gil_to_libpng_format<rgba8_pixel_t , false> : mpl::integral_c<unsigned int, PNG_COLOR_TYPE_RGB_ALPHA | ( 8 << 16 )> {};
+template <> struct gil_to_libpng_format<gray8_pixel_t , false> : mpl::integral_c<unsigned int, PNG_COLOR_TYPE_GRAY | ( 8 << 16 )> {};
+template <> struct gil_to_libpng_format<rgb16_pixel_t , false> : mpl::integral_c<unsigned int, PNG_COLOR_TYPE_RGB | ( 16 << 16 )> {};
+template <> struct gil_to_libpng_format<rgba16_pixel_t, false> : mpl::integral_c<unsigned int, PNG_COLOR_TYPE_RGB_ALPHA | ( 16 << 16 )> {};
+template <> struct gil_to_libpng_format<gray16_pixel_t, false> : mpl::integral_c<unsigned int, PNG_COLOR_TYPE_GRAY | ( 16 << 16 )> {};
 
 
 template <typename Pixel, bool IsPlanar>
-struct is_view_supported : mpl::bool_<view_libpng_format::apply<Pixel, IsPlanar>::value != -1> {};
+struct libpng_is_supported : mpl::bool_<gil_to_libpng_format<Pixel, IsPlanar>::value != -1> {};
+
+template <typename View>
+struct libpng_is_view_supported : libpng_is_supported<typename View::value_type, is_planar<View>::value> {};
 
 
 typedef mpl::vector6
@@ -86,29 +82,27 @@
     template <class View>
     /*explicit*/ libpng_view_data_t( View const & view, libpng_roi::offset_t const offset = 0 )
         :
- format_( view_libpng_format::apply<View>::value ),
+ format_( gil_to_libpng_format<typename View::value_type, is_planar<View>::value>::value ),
         buffer_( formatted_image_base::get_raw_data( view ) ),
- offset_( offset ),
+ offset_( offset ),
         height_( view.height() ),
         width_ ( view.width () ),
         stride_( view.pixels().row_size() ),
         number_of_channels_( num_channels<View>::value )
     {
- BOOST_STATIC_ASSERT( is_view_supported<View>::value );
+ BOOST_STATIC_ASSERT( libpng_is_view_supported<View>::value );
     }
 
     void set_format( unsigned int const format ) { format_ = format; }
 
     format_t /*const*/ format_;
- unsigned int /*const*/ colour_type_;
- unsigned int /*const*/ bits_per_pixel_;
- png_byte * /*const*/ buffer_;
- libpng_roi::offset_t /*const*/ offset_;
-
- unsigned int /*const*/ height_;
- unsigned int /*const*/ width_ ;
- unsigned int /*const*/ stride_;
- unsigned int number_of_channels_;
+ png_byte * const buffer_;
+ libpng_roi::offset_t const offset_;
+
+ unsigned int const height_;
+ unsigned int const width_ ;
+ unsigned int const stride_;
+ unsigned int const number_of_channels_;
 };
 
 
@@ -267,7 +261,7 @@
             format_colour_type( view.format_ ),
             PNG_INTERLACE_NONE ,
             PNG_COMPRESSION_TYPE_DEFAULT ,
- PNG_INTRAPIXEL_DIFFERENCING
+ PNG_FILTER_TYPE_DEFAULT
         );
 
         //::png_set_invert_alpha( &png_object() );
@@ -329,10 +323,6 @@
     {
         ::png_set_write_fn( &png_object(), p_target_object, write_data_fn, output_flush_fn );
     }
-
-private:
- jpeg_destination_mgr destination_manager_;
- array<unsigned char, 4096> write_buffer_ ;
 };
 
 
@@ -383,20 +373,25 @@
 template <>
 struct formatted_image_traits<libpng_image>
 {
- typedef int format_t;
     typedef detail::libpng_supported_pixel_formats supported_pixel_formats_t;
     typedef detail::libpng_roi roi_t;
- typedef detail::view_libpng_format gil_to_native_format;
     typedef detail::libpng_view_data_t view_data_t;
+ typedef detail::libpng_view_data_t::format_t format_t;
+
+ struct gil_to_native_format
+ {
+ template <typename Pixel, bool IsPlanar>
+ struct apply : detail::gil_to_libpng_format<Pixel, IsPlanar> {};
+ };
 
     template <typename Pixel, bool IsPlanar>
- struct is_supported : detail::is_view_supported<Pixel, IsPlanar> {};
+ struct is_supported : detail::libpng_is_supported<Pixel, IsPlanar> {};
 
     typedef mpl::map3
             <
                 mpl::pair<memory_chunk_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> >
+ mpl::pair<char const *, detail::input_c_str_for_mmap_extender <libpng_image> >
> readers;
 
     typedef mpl::map2

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-07 03:50:03 EST (Fri, 07 Jan 2011)
@@ -114,13 +114,6 @@
 {};
 
 
-struct view_libtiff_format
-{
- template <typename Pixel, bool IsPlanar>
- struct apply : gil_to_libtiff_format<Pixel, IsPlanar> {};
-};
-
-
 typedef mpl::vector35
 <
     image<rgb8_pixel_t , false>,
@@ -263,7 +256,7 @@
         stride_ ( view.pixels().row_size() ),
         offset_ ( offset )
         #ifdef _DEBUG
- ,format_id_( view_libtiff_format::apply<typename View::value_type, is_planar<View>::value>::value )
+ ,format_id_( gil_to_libtiff_format<typename View::value_type, is_planar<View>::value>::value )
         #endif
     {
         set_buffers( view, is_planar<View>() );
@@ -314,7 +307,7 @@
         :
         tiff_view_data_t( view, 0 )
     {
- format_.number = view_libtiff_format::apply<View>::value;
+ format_.number = gil_to_libtiff_format<typename View::value_type, is_planar<View>::value>::value;
     }
 
     full_format_t format_;
@@ -483,11 +476,15 @@
 
     typedef detail::generic_vertical_roi roi_t;
 
- typedef detail::view_libtiff_format gil_to_native_format;
-
     typedef detail::tiff_view_data_t view_data_t;
 
- template <class View>
+ struct gil_to_native_format
+ {
+ template <typename Pixel, bool IsPlanar>
+ struct apply : detail::gil_to_libtiff_format<Pixel, IsPlanar> {};
+ };
+
+ template <typename Pixel, bool IsPlanar>
     struct is_supported : mpl::true_ {}; //...zzz...
 
     typedef mpl::map2
@@ -563,16 +560,34 @@
 
         BOOST_STATIC_CONSTANT( bool, throws_on_error = false );
 
- friend libtiff_image;
+ private: friend libtiff_image;
+ sequential_row_access_state() : position_( 0 ) {}
+
+ unsigned int position_;
     };
 
+
     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 ) ),
+ ::TIFFReadScanline( &lib_object(), p_row_storage, state.position_++, static_cast<tsample_t>( plane ) ),
+ 0
+ );
+ }
+
+
+ typedef sequential_row_access_state sequential_tile_access_state;
+
+ static sequential_tile_access_state begin_sequential_tile_access() { return begin_sequential_row_access(); }
+
+ void read_tile( sequential_row_access_state & state, unsigned char * const p_tile_storage ) const
+ {
+ state.accumulate_greater
+ (
+ ::TIFFReadEncodedTile( &lib_object(), state.position_++, p_tile_storage, -1 ),
             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