Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60880 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2010-03-27 14:21:40


Author: psiha
Date: 2010-03-27 14:21:39 EDT (Sat, 27 Mar 2010)
New Revision: 60880
URL: http://svn.boost.org/trac/boost/changeset/60880

Log:
Added support for packed pixel formats to the GDI+ backend.
Fixed the view_gp_format<> metafunction.
Added the get_raw_data() helper function to replace interleaved_view_get_raw_data() because it does not work with packed pixel views.
Added IDs for the JPG, TIFF, GIF and BMP codecs.
Fixed the gp_bitmap::convert_to_target() member function to use the read locking mode after all (otherwise no data is received but the call still succeeds.
Text files modified:
   sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp | 58 +++++++++++++++++++++++++++++++--------
   1 files changed, 45 insertions(+), 13 deletions(-)

Modified: sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp 2010-03-27 14:21:39 EDT (Sat, 27 Mar 2010)
@@ -96,12 +96,14 @@
     };
 };
 
+
 template <class View>
 struct view_gp_format
     :
- mpl::eval_if
+ mpl::eval_if_c
     <
- is_reference<typename View::reference>,
+ // Err, an 'official' way to detect this?
+ ( mpl::size<typename View::value_type::layout_t::channel_mapping_t>::value <= sizeof( typename View::value_type ) ),
         mpl::identity<unpacked_view_gp_format>,
         mpl::identity< packed_view_gp_format>
>::type::apply<View>::type
@@ -261,7 +263,6 @@
     template <class View>
     explicit gp_bitmap( View & view )
     {
- BOOST_STATIC_ASSERT( is_supported<view_gp_format<View>::value>::value );
         // http://msdn.microsoft.com/en-us/library/ms536315(VS.85).aspx
         // stride has to be a multiple of 4 bytes
         BOOST_ASSERT( !( view.pixels().row_size() % sizeof( Gdiplus::ARGB ) ) );
@@ -274,7 +275,7 @@
                 view.height(),
                 view.pixels().row_size(),
                 view_gp_format<View>::value,
- interleaved_view_get_raw_data( view ),
+ get_raw_data( view ),
                 &pBitmap_
             )
         );
@@ -335,8 +336,6 @@
     template <typename View, typename CC>
     void convert_to_prepared_view( View const & view, CC const & converter ) const
     {
- BOOST_STATIC_ASSERT( is_supported<view_gp_format<View>::value>::value );
-
         BOOST_ASSERT( !dimensions_mismatch( view ) );
 
         using namespace Gdiplus;
@@ -409,14 +408,47 @@
         convert_to_prepared_view( view );
     }
 
- void save_to_png( char const * const pFilename ) const { save_to( pFilename, png_encoder() ); }
- void save_to_png( wchar_t const * const pFilename ) const { save_to( pFilename, png_encoder() ); }
+ void save_to_png( char const * const pFilename ) const { save_to( pFilename, png_codec() ); }
+ void save_to_png( wchar_t const * const pFilename ) const { save_to( pFilename, png_codec() ); }
 
 private:
- static CLSID const & png_encoder()
+ static CLSID const & png_codec()
+ {
+ static CLSID const clsid = { 0x557cf406, 0x1a04, 0x11d3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
+ return clsid;
+ }
+ static CLSID const & jpg_codec()
+ {
+ static CLSID const clsid = { 0x557CF401, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
+ return clsid;
+ }
+ static CLSID const & tiff_codec()
+ {
+ static CLSID const clsid = { 0x557CF405, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
+ return clsid;
+ }
+ static CLSID const & gif_codec()
     {
- static CLSID const PNG_CLSID = { 0x557cf406, 0x1a04, 0x11d3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
- return PNG_CLSID;
+ static CLSID const clsid = { 0x557CF402, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
+ return clsid;
+ }
+ static CLSID const & bmp_codec()
+ {
+ static CLSID const clsid = { 0x557CF400, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
+ return clsid;
+ }
+
+ template <typename View>
+ static BYTE * get_raw_data( View const & view )
+ {
+ // A private implementation of interleaved_view_get_raw_data() that
+ // works with packed pixel views.
+ BOOST_STATIC_ASSERT((!is_planar<View>::value /*&& view_is_basic<View>::value*/));
+ BOOST_STATIC_ASSERT((boost::is_pointer<typename View::x_iterator>::value));
+
+ BOOST_STATIC_ASSERT( is_supported<view_gp_format<View>::value>::value );
+
+ return static_cast<BYTE *>( &gil::at_c<0>( view( 0, 0 ) ) );
     }
 
     template <typename View>
@@ -430,7 +462,7 @@
             view.height(),
             view.pixels().row_size(),
             view_gp_format<View>::value,
- interleaved_view_get_raw_data( view ),
+ get_raw_data( view ),
             0
         };
         return bitmapData;
@@ -452,7 +484,7 @@
             (
                 pBitmap_,
                 0,
- ImageLockModeUserInputBuf /* | ImageLockModeRead */,
+ ImageLockModeRead | ImageLockModeUserInputBuf,
                 bitmapData.PixelFormat,
                 pMutableBitmapData
             )


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