Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85675 - in sandbox/gil: boost/gil/extension/io2/backends/gp boost/gil/extension/io2/backends/libjpeg boost/gil/extension/io2/backends/libpng boost/gil/extension/io2/backends/libtiff boost/gil/extension/io2/backends/wic libs/gil/io2/test
From: dsaritz_at_[hidden]
Date: 2013-09-15 09:55:24


Author: psiha
Date: 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013)
New Revision: 85675
URL: http://svn.boost.org/trac/boost/changeset/85675

Log:
(Mostly) Finished transition to the new backend-reader-writer hierarchy for GDI+
Moved pieces of shared functionality from reader and writer implementation classes to the respective base/backend classes.
Added more sanity checks.
Minor other refactoring and stylistic changes.

Text files modified:
   sandbox/gil/boost/gil/extension/io2/backends/gp/backend.hpp | 109 ++++-
   sandbox/gil/boost/gil/extension/io2/backends/gp/reader.hpp | 442 +-----------------------
   sandbox/gil/boost/gil/extension/io2/backends/gp/writer.hpp | 712 +--------------------------------------
   sandbox/gil/boost/gil/extension/io2/backends/libjpeg/backend.hpp | 71 +++
   sandbox/gil/boost/gil/extension/io2/backends/libjpeg/reader.hpp | 90 +---
   sandbox/gil/boost/gil/extension/io2/backends/libjpeg/writer.hpp | 33 -
   sandbox/gil/boost/gil/extension/io2/backends/libpng/backend.hpp | 60 ++
   sandbox/gil/boost/gil/extension/io2/backends/libpng/reader.hpp | 62 ---
   sandbox/gil/boost/gil/extension/io2/backends/libpng/writer.hpp | 13
   sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp | 15
   sandbox/gil/boost/gil/extension/io2/backends/libtiff/writer.hpp | 2
   sandbox/gil/boost/gil/extension/io2/backends/wic/backend.hpp | 12
   sandbox/gil/boost/gil/extension/io2/backends/wic/reader.hpp | 54 +-
   sandbox/gil/boost/gil/extension/io2/backends/wic/writer.hpp | 21
   sandbox/gil/libs/gil/io2/test/CMakeLists.txt | 30 +
   15 files changed, 377 insertions(+), 1349 deletions(-)

Modified: sandbox/gil/boost/gil/extension/io2/backends/gp/backend.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/gp/backend.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/gp/backend.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -79,7 +79,7 @@
 
 
 typedef mpl::
-#if (GDIPVER >= 0x0110)
+#if ( GDIPVER >= 0x0110 )
     vector4
 #else
     vector3
@@ -88,16 +88,13 @@
     image<bgr8_pixel_t , false>,
     image<bgra8_pixel_t , false>,
     image<gp_bgr565_pixel_t, false>
- #if (GDIPVER >= 0x0110)
+ #if ( GDIPVER >= 0x0110 )
     ,image<cmyk8_pixel_t , false>
     #endif
> gp_supported_pixel_formats;
 
 
-typedef iterator_range<TCHAR const *> string_chunk_t;
-
-
-/*string_chunk_t*/char const * error_string( Gdiplus::GpStatus const status )
+char const * error_string( Gdiplus::GpStatus const status )
 {
     using namespace Gdiplus;
     switch ( status )
@@ -119,12 +116,12 @@
         case UnsupportedGdiplusVersion : return "Unsupported GDI+ version";
         case PropertyNotFound : return "Specified property does not exist in the image";
         case PropertyNotSupported : return "Specified property not supported by the format of the image";
- #if (GDIPVER >= 0x0110)
+ #if ( GDIPVER >= 0x0110 )
         case ProfileNotFound : return "Profile required to save an image in CMYK format not found";
         #endif //(GDIPVER >= 0x0110)
     }
 
- // Programmer errors:
+ // Programmer errors or GIL::IO2 bugs:
     switch ( status )
     {
         case Ok : BOOST_ASSERT( !"Should not be called for no error" ); BF_UNREACHABLE_CODE break;
@@ -139,7 +136,7 @@
 inline void ensure_result( Gdiplus::GpStatus const result )
 {
     if ( result != Gdiplus::Ok )
- io_error( error_string( result )/*.begin()*/ );
+ io_error( error_string( result ) );
 }
 
 inline void verify_result( Gdiplus::GpStatus const result )
@@ -165,7 +162,7 @@
 
     gp_roi( offset_t const top_left, offset_t const bottom_right )
         : Gdiplus::Rect( Gdiplus::Point( top_left.x, top_left.y ), Gdiplus::Size( bottom_right.x - top_left.x, bottom_right.y - top_left.y ) ) {}
-};
+}; // class gp_roi
 
 class gp_view_base;
 
@@ -251,13 +248,13 @@
 
     private:
         aligned_storage<sizeof( roi_t ), alignment_of<roi_t>::value>::type optional_roi_;
- };
+ }; // class view_data_t
 
     typedef view_data_t writer_view_data_t;
 
     BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( Gdiplus::ARGB ) );
     BOOST_STATIC_CONSTANT( bool , builtin_conversion = true );
-};
+}; // struct backend_traits<gp_image>
 
 
 #if defined( BOOST_MSVC )
@@ -273,19 +270,33 @@
 public:
     typedef detail::gp_user_guard guard;
 
-public: /// \ingroup Construction
+protected: /// \ingroup Construction
     ~gp_image()
     {
         detail::verify_result( Gdiplus::DllExports::GdipDisposeImage( pBitmap_ ) );
     }
 
-public:
- point2<std::ptrdiff_t> dimensions() const
+public: /// \ingroup Information
+ typedef point2<unsigned int> dimensions_t;
+
+ dimensions_t dimensions() const
     {
         using namespace Gdiplus;
- REAL width, height;
- detail::verify_result( DllExports::GdipGetImageDimension( const_cast<GpBitmap *>( pBitmap_ ), &width, &height ) );
- return point2<std::ptrdiff_t>( static_cast<std::ptrdiff_t>( width ), static_cast<std::ptrdiff_t>( height ) );
+ REAL width_float, height_float;
+ detail::verify_result( DllExports::GdipGetImageDimension( const_cast<GpBitmap *>( pBitmap_ ), &width_float, &height_float ) );
+ #ifndef NDEBUG
+ BOOST_ASSERT( static_cast<unsigned int>( width_float ) == width_float );
+ BOOST_ASSERT( static_cast<unsigned int>( height_float ) == height_float );
+ UINT width ; detail::verify_result( DllExports::GetWidth ( const_cast<GpBitmap *>( pBitmap_ ), &width ) );
+ UINT height; detail::verify_result( DllExports::GetHeight( const_cast<GpBitmap *>( pBitmap_ ), &height ) );
+ BOOST_ASSERT( width_float == width );
+ BOOST_ASSERT( height_float == height );
+ #endif // NDEBUG
+ return dimensions_t
+ (
+ static_cast<dimensions_t::value_type>( width_float ),
+ static_cast<dimensions_t::value_type>( height_float )
+ );
     }
 
     format_t format() const
@@ -295,14 +306,61 @@
         return pixel_format;
     }
 
- static image_type_id image_format_id( format_t const closest_gil_supported_format )
+ format_t closest_gil_supported_format() const
+ {
+ //http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2008-01/msg00044.html
+ switch ( format() )
+ {
+ case PixelFormat16bppGrayScale:
+ case PixelFormat48bppRGB :
+ case PixelFormat32bppRGB :
+ case PixelFormat24bppRGB :
+ return
+ PixelFormat24bppRGB;
+
+ case PixelFormat64bppPARGB :
+ case PixelFormat32bppPARGB :
+ case PixelFormat64bppARGB :
+ case PixelFormat32bppARGB :
+ case PixelFormat16bppARGB1555 :
+ return
+ PixelFormat32bppARGB;
+
+ case PixelFormat16bppRGB565 :
+ case PixelFormat16bppRGB555 :
+ case PixelFormat8bppIndexed :
+ case PixelFormat4bppIndexed :
+ case PixelFormat1bppIndexed :
+ return
+ PixelFormat16bppRGB565;
+
+ case PixelFormat32bppCMYK:
+ return
+ #if ( GDIPVER >= 0x0110 )
+ PixelFormat32bppCMYK;
+ #else
+ PixelFormat24bppRGB;
+ #endif // GDIPVER >= 0x0110
+
+ default:
+ BF_UNREACHABLE_CODE
+ return PixelFormatUndefined;
+ }
+ }
+
+ image_type_id_t current_image_format_id() const
+ {
+ return image_format_id( closest_gil_supported_format() );
+ }
+
+ static image_type_id_t image_format_id( format_t const closest_gil_supported_format )
     {
         switch ( closest_gil_supported_format )
         {
             case PixelFormat24bppRGB : return 0;
             case PixelFormat32bppARGB : return 1;
             case PixelFormat16bppRGB565 : return 2;
- #if (GDIPVER >= 0x0110)
+ #if ( GDIPVER >= 0x0110 )
             case PixelFormat32bppCMYK : return 3;
             #endif
 
@@ -312,14 +370,17 @@
         }
     }
 
- ::Gdiplus::GpBitmap & lib_object() { return *pBitmap_; }
- ::Gdiplus::GpBitmap const & lib_object() const { return const_cast<gp_image &>( *this ).lib_object(); }
+public: /// \ingroup Low level access
+ typedef ::Gdiplus::GpBitmap lib_object_t;
+
+ lib_object_t & lib_object() { return *pBitmap_; }
+ lib_object_t const & lib_object() const { return const_cast<gp_image &>( *this ).lib_object(); }
 
 private:
     friend class detail::gp_view_base;
 
- Gdiplus::GpBitmap * /*const*/ pBitmap_;
-};
+ lib_object_t * /*const*/ pBitmap_;
+}; // class gp_image
 
 #if defined( BOOST_MSVC )
 # pragma warning( pop )

Modified: sandbox/gil/boost/gil/extension/io2/backends/gp/reader.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/gp/reader.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/gp/reader.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -1,7 +1,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \file gp_image.hpp
-/// ------------------
+/// \file gp/reader.hpp
+/// -------------------
 ///
 /// Base IO interface GDI+ implementation.
 ///
@@ -16,24 +16,11 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
+#ifndef reader_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
+#define reader_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
 #pragma once
-#ifndef gp_private_base_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
-#define gp_private_base_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
 //------------------------------------------------------------------------------
-#include "detail/io_error.hpp"
-#include "detail/gp_extern_lib_guard.hpp"
-#include "detail/windows_shared.hpp"
-#include "detail/windows_shared_istreams.hpp"
 #include "backend.hpp"
-
-#include <boost/array.hpp>
-#include <boost/mpl/eval_if.hpp>
-#include <boost/mpl/integral_c.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/type_traits/is_pod.hpp>
-
-#include <algorithm>
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -45,329 +32,30 @@
 {
 //------------------------------------------------------------------------------
 
-template <Gdiplus::PixelFormat gp_format> struct is_canonical : mpl::bool_ <(gp_format & PixelFormatCanonical) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct is_extended : mpl::bool_ <(gp_format & PixelFormatExtended ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct is_indexed : mpl::bool_ <(gp_format & PixelFormatIndexed ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct has_alpha : mpl::bool_ <(gp_format & PixelFormatAlpha ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct has_premultiplied_alpha : mpl::bool_ <(gp_format & PixelFormatPAlpha ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct is_supported : mpl::bool_ <(gp_format & PixelFormatGDI ) != 0 || ( ( gp_format == PixelFormat32bppCMYK ) && ( GDIPVER >= 0x0110 ) )> {};
-template <Gdiplus::PixelFormat gp_format> struct pixel_size : mpl::size_t<( gp_format >> 8 ) & 0xff > {};
-
-
-/// @see GdiplusPixelFormats.h: ARGB -> little endian BGRA
-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> {};
-
-template <> struct gil_to_gp_format<gp_bgr565_pixel_t, false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat16bppRGB565 > {};
-template <> struct gil_to_gp_format<bgr8_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat24bppRGB > {};
-template <> struct gil_to_gp_format<bgra8_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat32bppARGB > {};
-template <> struct gil_to_gp_format<gray16_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat16bppGrayScale> {};
-template <> struct gil_to_gp_format<bgr16_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat48bppRGB > {};
-template <> struct gil_to_gp_format<bgra16_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat64bppARGB > {};
-#if (GDIPVER >= 0x0110)
-template <> struct gil_to_gp_format<cmyk8_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat32bppCMYK > {};
-#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
-#else
- vector3
-#endif
-<
- image<bgr8_pixel_t , false>,
- image<bgra8_pixel_t , false>,
- image<gp_bgr565_pixel_t, false>
- #if (GDIPVER >= 0x0110)
- ,image<cmyk8_pixel_t , false>
- #endif
-> gp_supported_pixel_formats;
-
-
-typedef iterator_range<TCHAR const *> string_chunk_t;
-
-
-/*string_chunk_t*/char const * error_string( Gdiplus::GpStatus const status )
-{
- using namespace Gdiplus;
- switch ( status )
- {
- case GenericError : return "Generic GDI+ error";
- case OutOfMemory : return "Out of memory";
- case ObjectBusy : return "Object busy";
- case InsufficientBuffer : return "Insufficient buffer";
- case NotImplemented : return "Not implemented";
- case Win32Error : return "Win32 subsystem failure";
- case Aborted : return "Aborted";
- case FileNotFound : return "File not found";
- case ValueOverflow : return "Numeric overflow";
- case AccessDenied : return "Access denied";
- case UnknownImageFormat : return "Unknown image format";
- case FontFamilyNotFound : return "Font family not found";
- case FontStyleNotFound : return "Font style not found";
- case NotTrueTypeFont : return "A non TrueType font specified";
- case UnsupportedGdiplusVersion : return "Unsupported GDI+ version";
- case PropertyNotFound : return "Specified property does not exist in the image";
- case PropertyNotSupported : return "Specified property not supported by the format of the image";
- #if (GDIPVER >= 0x0110)
- case ProfileNotFound : return "Profile required to save an image in CMYK format not found";
- #endif //(GDIPVER >= 0x0110)
- }
-
- // Programmer errors:
- switch ( status )
- {
- case Ok : BOOST_ASSERT( !"Should not be called for no error" ); BF_UNREACHABLE_CODE break;
- case InvalidParameter : BOOST_ASSERT( !"Invalid parameter" ); BF_UNREACHABLE_CODE break;
- case WrongState : BOOST_ASSERT( !"Object in wrong state" ); BF_UNREACHABLE_CODE break;
- case GdiplusNotInitialized : BOOST_ASSERT( !"GDI+ not initialized" ); BF_UNREACHABLE_CODE break;
-
- default: BOOST_ASSERT( !"Unknown GDI+ status code." ); BF_UNREACHABLE_CODE break;
- }
-}
-
-inline void ensure_result( Gdiplus::GpStatus const result )
-{
- if ( result != Gdiplus::Ok )
- io_error( error_string( result )/*.begin()*/ );
-}
-
-inline void verify_result( Gdiplus::GpStatus const result )
-{
- BOOST_VERIFY( result == Gdiplus::Ok );
-}
-
-
-class gp_roi : public Gdiplus::Rect
-{
-public:
- typedef INT value_type;
- typedef point2<value_type> point_t ;
-
- typedef point_t offset_t ;
-
-public:
- gp_roi( value_type const x, value_type const y, value_type const width, value_type const height )
- : Gdiplus::Rect( x, y, width, height ) {}
-
- gp_roi( offset_t const offset, value_type const width, value_type const height )
- : Gdiplus::Rect( Gdiplus::Point( offset.x, offset.y ), Gdiplus::Size( width, height ) ) {}
-
- gp_roi( offset_t const top_left, offset_t const bottom_right )
- : Gdiplus::Rect( Gdiplus::Point( top_left.x, top_left.y ), Gdiplus::Size( bottom_right.x - top_left.x, bottom_right.y - top_left.y ) ) {}
-};
-
-
-class gp_writer : public open_on_write_writer
-{
-public:
- typedef std::pair<Gdiplus::GpBitmap *, Gdiplus::EncoderParameters *> lib_object_t;
-
- // The passed View object must outlive the GpBitmap object (GDI+ uses lazy
- // evaluation).
- template <class View>
- explicit gp_writer( View & view )
- {
- 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
- BOOST_ASSERT( !( view.pixels().row_size() % sizeof( Gdiplus::ARGB ) ) );
-
- ensure_result
- (
- Gdiplus::DllExports::GdipCreateBitmapFromScan0
- (
- view.width (),
- view.height(),
- view.pixels().row_size(),
- gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value,
- backend_base::get_raw_data( view ),
- &lib_object().first
- )
- );
- BOOST_ASSERT( lib_object().first );
- }
-
- ~gp_writer()
- {
- detail::verify_result( Gdiplus::DllExports::GdipDisposeImage( lib_object().first ) );
- }
-
- template <typename Target>
- void write_default( Target const & target, format_tag const format )
- {
- BOOST_ASSERT( lib_object().second == NULL );
- write( target, format );
- }
-
- void write( char const * const pFilename, format_tag const format ) const
- {
- write( detail::wide_path( pFilename ), format );
- }
-
- void write( wchar_t const * const pFilename, format_tag const format ) const
- {
- detail::ensure_result
- (
- Gdiplus::DllExports::GdipSaveImageToFile
- (
- lib_object().first,
- pFilename,
- &encoder_id( format ),
- lib_object().second
- )
- );
- }
-
- lib_object_t & lib_object() { return lib_instance_; }
- lib_object_t const & lib_object() const { return lib_instance_; }
-
-private:
- static CLSID const & encoder_id( format_tag const format )
- {
- static CLSID const ids[ number_of_known_formats ] =
- {
- { 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
- { 0x557CF405, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E }, // TIFF
- CLSID_NULL // TGA
- };
- BOOST_ASSERT( ids[ format ] != CLSID_NULL );
- return ids[ format ];
- }
-
-private:
- lib_object_t lib_instance_;
-};
-
-
-class gp_view_base;
-
 //------------------------------------------------------------------------------
 } // namespace detail
 
-class gp_image;
-
-template <>
-struct backend_traits<gp_image>
-{
- typedef Gdiplus::PixelFormat format_t;
-
- typedef detail::gp_supported_pixel_formats supported_pixel_formats_t;
-
- typedef detail::gp_roi roi_t;
-
- 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::gp_is_supported<Pixel, IsPlanar> {};
-
- typedef mpl::map5
- <
- mpl::pair<char const *, gp_image >,
- 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_range_t , detail::memory_chunk_for_IStream_extender<gp_image> >
- > native_sources;
-
- typedef mpl::map4
- <
- mpl::pair<char const *, detail::gp_writer>,
- mpl::pair<wchar_t const *, detail::gp_writer>,
- mpl::pair<IStream , detail::gp_writer>,
- mpl::pair<FILE , detail::gp_writer>
- > native_sinks;
-
- typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
-
- class view_data_t : public Gdiplus::BitmapData
- {
- public:
- template <typename View>
- view_data_t( View const & view ) : p_roi_( 0 ) { set_bitmapdata_for_view( view ); }
-
- template <typename View>
- view_data_t( View const & view, roi_t::offset_t const & offset )
- :
- p_roi_( static_cast<roi_t const *>( optional_roi_.address() ) )
- {
- set_bitmapdata_for_view( view );
- new ( optional_roi_.address() ) roi_t( offset, Width, Height );
- }
-
- void set_format( format_t const format ) { PixelFormat = format; }
-
- public:
- Gdiplus::Rect const * const p_roi_;
-
- private:
- template <typename View>
- void set_bitmapdata_for_view( View const & view )
- {
- using namespace detail;
-
- 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 = detail::gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value;
- Scan0 = backend_base::get_raw_data( view );
- Reserved = 0;
- }
-
- void operator=( view_data_t const & );
-
- private:
- aligned_storage<sizeof( roi_t ), alignment_of<roi_t>::value>::type optional_roi_;
- };
-
- typedef view_data_t writer_view_data_t;
-
- BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( Gdiplus::ARGB ) );
- BOOST_STATIC_CONSTANT( bool , builtin_conversion = true );
-};
-
-
 #if defined(BOOST_MSVC)
 # pragma warning( push )
 # pragma warning( disable : 4127 ) // "conditional expression is constant"
 #endif
 
-class gp_image
+class gp_image::native_reader
     :
- private detail::gp_guard,
- public detail::backend<gp_image>
+ public gp_image,
+ public detail::backend_reader<gp_image>
 {
 public:
     typedef detail::gp_user_guard guard;
 
 public: /// \ingroup Construction
- explicit gp_image( wchar_t const * const filename )
+ explicit native_reader( wchar_t const * const filename )
     {
         detail::ensure_result( Gdiplus::DllExports::GdipCreateBitmapFromFile( filename, &pBitmap_ ) );
         BOOST_ASSERT( pBitmap_ );
     }
 
- explicit gp_image( char const * const filename )
+ explicit native_reader( char const * const filename )
     {
         detail::ensure_result( Gdiplus::DllExports::GdipCreateBitmapFromFile( detail::wide_path( filename ), &pBitmap_ ) );
         BOOST_ASSERT( pBitmap_ );
@@ -375,97 +63,12 @@
 
     // The passed IStream object must outlive the GpBitmap object (GDI+ uses
     // lazy evaluation).
- explicit gp_image( IStream & stream )
+ explicit native_reader( IStream & stream )
     {
         detail::ensure_result( Gdiplus::DllExports::GdipCreateBitmapFromStream( &stream, &pBitmap_ ) );
         BOOST_ASSERT( pBitmap_ );
     }
 
- ~gp_image()
- {
- detail::verify_result( Gdiplus::DllExports::GdipDisposeImage( pBitmap_ ) );
- }
-
-public:
- point2<std::ptrdiff_t> dimensions() const
- {
- using namespace Gdiplus;
- REAL width, height;
- detail::verify_result( DllExports::GdipGetImageDimension( const_cast<GpBitmap *>( pBitmap_ ), &width, &height ) );
- return point2<std::ptrdiff_t>( static_cast<std::ptrdiff_t>( width ), static_cast<std::ptrdiff_t>( height ) );
- }
-
- format_t format() const
- {
- format_t pixel_format;
- detail::verify_result( Gdiplus::DllExports::GdipGetImagePixelFormat( pBitmap_, &pixel_format ) );
- return pixel_format;
- }
-
- format_t closest_gil_supported_format() const
- {
- //http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2008-01/msg00044.html
- switch ( format() )
- {
- case PixelFormat16bppGrayScale:
- case PixelFormat48bppRGB :
- case PixelFormat32bppRGB :
- case PixelFormat24bppRGB :
- return
- PixelFormat24bppRGB;
-
- case PixelFormat64bppPARGB :
- case PixelFormat32bppPARGB :
- case PixelFormat64bppARGB :
- case PixelFormat32bppARGB :
- case PixelFormat16bppARGB1555 :
- return
- PixelFormat32bppARGB;
-
- case PixelFormat16bppRGB565 :
- case PixelFormat16bppRGB555 :
- case PixelFormat8bppIndexed :
- case PixelFormat4bppIndexed :
- case PixelFormat1bppIndexed :
- return
- PixelFormat16bppRGB565;
-
- case PixelFormat32bppCMYK:
- return
- #if (GDIPVER >= 0x0110)
- PixelFormat32bppCMYK;
- #else
- PixelFormat24bppRGB;
- #endif // (GDIPVER >= 0x0110)
-
- default:
- BF_UNREACHABLE_CODE
- return PixelFormatUndefined;
- }
- }
-
- image_type_id current_image_format_id() const
- {
- return image_format_id( closest_gil_supported_format() );
- }
-
- static image_type_id image_format_id( format_t const closest_gil_supported_format )
- {
- switch ( closest_gil_supported_format )
- {
- case PixelFormat24bppRGB : return 0;
- case PixelFormat32bppARGB : return 1;
- case PixelFormat16bppRGB565 : return 2;
- #if (GDIPVER >= 0x0110)
- case PixelFormat32bppCMYK : return 3;
- #endif
-
- default:
- BF_UNREACHABLE_CODE
- return unsupported_format;
- }
- }
-
 public: // Low-level (row, strip, tile) access
     static bool can_do_roi_access() { return true; }
 
@@ -494,7 +97,7 @@
     private: friend gp_image;
         Gdiplus::Rect roi_ ;
         Gdiplus::BitmapData bitmapData_;
- };
+ }; // class sequential_row_read_state
 
     sequential_row_read_state begin_sequential_row_read() const { return sequential_row_read_state( *this ); }
 
@@ -524,9 +127,6 @@
         ++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 backend_base interface.
     friend class base_t;
 
@@ -608,7 +208,7 @@
     }
 
 
- static std::size_t cached_format_size( format_t const format )
+ static unsigned int cached_format_size( format_t const format )
     {
         return Gdiplus::GetPixelFormatSize( format );
     }
@@ -617,17 +217,17 @@
     template <Gdiplus::PixelFormat desired_format>
     void pre_palettized_conversion( mpl::true_ /*is_indexed*/ )
     {
- #if (GDIPVER >= 0x0110)
+ #if ( GDIPVER >= 0x0110 )
         // A GDI+ 1.1 (a non-distributable version, distributed with MS Office
         // 2003 and MS Windows Vista and MS Windows 7) 'enhanced'/'tuned'
         // version of the conversion routine for indexed/palettized image
         // formats. Unless/until proven useful, pretty much still a GDI+ 1.1
         // tester...
-
+
         BOOST_ASSERT( !has_alpha<desired_format>::value && "Is this possible for indexed formats?" );
- std::size_t const number_of_pixel_bits ( pixel_size<desired_format>::value );
- std::size_t const number_of_palette_colours( static_cast<std::size_t>( ( 2 << ( number_of_pixel_bits - 1 ) ) - 1 ) );
- std::size_t const palette_size ( sizeof( ColorPalette ) + number_of_palette_colours * sizeof( ARGB ) );
+ unsigned int const number_of_pixel_bits ( pixel_size<desired_format>::value );
+ unsigned int const number_of_palette_colours( static_cast<unsigned int>( ( 2 << ( number_of_pixel_bits - 1 ) ) - 1 ) );
+ unsigned int const palette_size ( sizeof( ColorPalette ) + number_of_palette_colours * sizeof( ARGB ) );
         aligned_storage
         <
            palette_size,
@@ -662,7 +262,7 @@
                 50
             )
         );
- #endif // (GDIPVER >= 0x0110)
+ #endif // GDIPVER >= 0x0110
     }
 
     template <Gdiplus::PixelFormat desired_format>
@@ -672,7 +272,7 @@
     friend class detail::gp_view_base;
 
     Gdiplus::GpBitmap * /*const*/ pBitmap_;
-};
+}; // class gp_image::native_reader
 
 #if defined(BOOST_MSVC)
 # pragma warning( pop )
@@ -727,7 +327,7 @@
 private:
     Gdiplus::GpBitmap & bitmap_ ;
     Gdiplus::BitmapData bitmapData_;
-};
+}; // class gp_view_base
 
 
 
@@ -781,4 +381,4 @@
 //------------------------------------------------------------------------------
 } // namespace boost
 //------------------------------------------------------------------------------
-#endif // gp_private_base_hpp
+#endif // reader_hpp

Modified: sandbox/gil/boost/gil/extension/io2/backends/gp/writer.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/gp/writer.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/gp/writer.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -1,7 +1,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \file gp_image.hpp
-/// ------------------
+/// \file gp/writer.hpp
+/// -------------------
 ///
 /// Base IO interface GDI+ implementation.
 ///
@@ -16,24 +16,11 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
+#ifndef writer_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
+#define writer_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
 #pragma once
-#ifndef gp_private_base_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
-#define gp_private_base_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
 //------------------------------------------------------------------------------
-#include "detail/io_error.hpp"
-#include "detail/gp_extern_lib_guard.hpp"
-#include "detail/windows_shared.hpp"
-#include "detail/windows_shared_istreams.hpp"
 #include "backend.hpp"
-
-#include <boost/array.hpp>
-#include <boost/mpl/eval_if.hpp>
-#include <boost/mpl/integral_c.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/type_traits/is_pod.hpp>
-
-#include <algorithm>
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -41,142 +28,32 @@
 namespace gil
 {
 //------------------------------------------------------------------------------
-namespace detail
-{
-//------------------------------------------------------------------------------
-
-template <Gdiplus::PixelFormat gp_format> struct is_canonical : mpl::bool_ <(gp_format & PixelFormatCanonical) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct is_extended : mpl::bool_ <(gp_format & PixelFormatExtended ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct is_indexed : mpl::bool_ <(gp_format & PixelFormatIndexed ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct has_alpha : mpl::bool_ <(gp_format & PixelFormatAlpha ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct has_premultiplied_alpha : mpl::bool_ <(gp_format & PixelFormatPAlpha ) != 0> {};
-template <Gdiplus::PixelFormat gp_format> struct is_supported : mpl::bool_ <(gp_format & PixelFormatGDI ) != 0 || ( ( gp_format == PixelFormat32bppCMYK ) && ( GDIPVER >= 0x0110 ) )> {};
-template <Gdiplus::PixelFormat gp_format> struct pixel_size : mpl::size_t<( gp_format >> 8 ) & 0xff > {};
-
-
-/// @see GdiplusPixelFormats.h: ARGB -> little endian BGRA
-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> {};
-
-template <> struct gil_to_gp_format<gp_bgr565_pixel_t, false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat16bppRGB565 > {};
-template <> struct gil_to_gp_format<bgr8_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat24bppRGB > {};
-template <> struct gil_to_gp_format<bgra8_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat32bppARGB > {};
-template <> struct gil_to_gp_format<gray16_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat16bppGrayScale> {};
-template <> struct gil_to_gp_format<bgr16_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat48bppRGB > {};
-template <> struct gil_to_gp_format<bgra16_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat64bppARGB > {};
-#if (GDIPVER >= 0x0110)
-template <> struct gil_to_gp_format<cmyk8_pixel_t , false> : mpl::integral_c<Gdiplus::PixelFormat, PixelFormat32bppCMYK > {};
-#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
-#else
- vector3
-#endif
-<
- image<bgr8_pixel_t , false>,
- image<bgra8_pixel_t , false>,
- image<gp_bgr565_pixel_t, false>
- #if (GDIPVER >= 0x0110)
- ,image<cmyk8_pixel_t , false>
- #endif
-> gp_supported_pixel_formats;
-
-
-typedef iterator_range<TCHAR const *> string_chunk_t;
-
-
-/*string_chunk_t*/char const * error_string( Gdiplus::GpStatus const status )
-{
- using namespace Gdiplus;
- switch ( status )
- {
- case GenericError : return "Generic GDI+ error";
- case OutOfMemory : return "Out of memory";
- case ObjectBusy : return "Object busy";
- case InsufficientBuffer : return "Insufficient buffer";
- case NotImplemented : return "Not implemented";
- case Win32Error : return "Win32 subsystem failure";
- case Aborted : return "Aborted";
- case FileNotFound : return "File not found";
- case ValueOverflow : return "Numeric overflow";
- case AccessDenied : return "Access denied";
- case UnknownImageFormat : return "Unknown image format";
- case FontFamilyNotFound : return "Font family not found";
- case FontStyleNotFound : return "Font style not found";
- case NotTrueTypeFont : return "A non TrueType font specified";
- case UnsupportedGdiplusVersion : return "Unsupported GDI+ version";
- case PropertyNotFound : return "Specified property does not exist in the image";
- case PropertyNotSupported : return "Specified property not supported by the format of the image";
- #if (GDIPVER >= 0x0110)
- case ProfileNotFound : return "Profile required to save an image in CMYK format not found";
- #endif //(GDIPVER >= 0x0110)
- }
-
- // Programmer errors:
- switch ( status )
- {
- case Ok : BOOST_ASSERT( !"Should not be called for no error" ); BF_UNREACHABLE_CODE break;
- case InvalidParameter : BOOST_ASSERT( !"Invalid parameter" ); BF_UNREACHABLE_CODE break;
- case WrongState : BOOST_ASSERT( !"Object in wrong state" ); BF_UNREACHABLE_CODE break;
- case GdiplusNotInitialized : BOOST_ASSERT( !"GDI+ not initialized" ); BF_UNREACHABLE_CODE break;
-
- default: BOOST_ASSERT( !"Unknown GDI+ status code." ); BF_UNREACHABLE_CODE break;
- }
-}
-
-inline void ensure_result( Gdiplus::GpStatus const result )
-{
- if ( result != Gdiplus::Ok )
- io_error( error_string( result )/*.begin()*/ );
-}
-
-inline void verify_result( Gdiplus::GpStatus const result )
-{
- BOOST_VERIFY( result == Gdiplus::Ok );
-}
 
-
-class gp_roi : public Gdiplus::Rect
-{
-public:
- typedef INT value_type;
- typedef point2<value_type> point_t ;
-
- typedef point_t offset_t ;
-
-public:
- gp_roi( value_type const x, value_type const y, value_type const width, value_type const height )
- : Gdiplus::Rect( x, y, width, height ) {}
-
- gp_roi( offset_t const offset, value_type const width, value_type const height )
- : Gdiplus::Rect( Gdiplus::Point( offset.x, offset.y ), Gdiplus::Size( width, height ) ) {}
-
- gp_roi( offset_t const top_left, offset_t const bottom_right )
- : Gdiplus::Rect( Gdiplus::Point( top_left.x, top_left.y ), Gdiplus::Size( bottom_right.x - top_left.x, bottom_right.y - top_left.y ) ) {}
-};
-
-
-class gp_writer : public open_on_write_writer
-{
-public:
- typedef std::pair<Gdiplus::GpBitmap *, Gdiplus::EncoderParameters *> lib_object_t;
+class gp_writer
+ :
+ public gp_image,
+ public detail::backend_writer<gp_image>,
+ public open_on_write_writer
+{
+public:
+ typedef std::pair
+ <
+ Gdiplus::GpBitmap *,
+ Gdiplus::EncoderParameters *
+ > lib_object_t;
+
+ typedef std::pair
+ <
+ lib_object_t::first_type const,
+ lib_object_t::second_type const
+ > const_lib_object_t;
 
     // The passed View object must outlive the GpBitmap object (GDI+ uses lazy
     // evaluation).
     template <class View>
     explicit gp_writer( View & view )
+ :
+ p_encoder_parameters_( NULL )
     {
         BOOST_STATIC_ASSERT(( gp_is_supported<typename View::value_type, is_planar<View>::value>::value ));
 
@@ -193,7 +70,7 @@
                 view.pixels().row_size(),
                 gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value,
                 backend_base::get_raw_data( view ),
- &lib_object().first
+ &gp_image::lib_object()
             )
         );
         BOOST_ASSERT( lib_object().first );
@@ -211,11 +88,7 @@
         write( target, format );
     }
 
- void write( char const * const pFilename, format_tag const format ) const
- {
- write( detail::wide_path( pFilename ), format );
- }
-
+ void write( char const * const pFilename, format_tag const format ) const { write( detail::wide_path( pFilename ), format ); }
     void write( wchar_t const * const pFilename, format_tag const format ) const
     {
         detail::ensure_result
@@ -230,8 +103,8 @@
         );
     }
 
- lib_object_t & lib_object() { return lib_instance_; }
- lib_object_t const & lib_object() const { return lib_instance_; }
+ lib_object_t lib_object() { return lib_object_t ( &gp_image::lib_object(), p_encoder_parameters_ ); }
+ const_lib_object_t lib_object() const { return const_lib_object_t( &gp_image::lib_object(), p_encoder_parameters_ ); }
 
 private:
     static CLSID const & encoder_id( format_tag const format )
@@ -250,535 +123,12 @@
     }
 
 private:
- lib_object_t lib_instance_;
-};
-
-
-class gp_view_base;
-
-//------------------------------------------------------------------------------
-} // namespace detail
-
-class gp_image;
-
-template <>
-struct backend_traits<gp_image>
-{
- typedef Gdiplus::PixelFormat format_t;
-
- typedef detail::gp_supported_pixel_formats supported_pixel_formats_t;
-
- typedef detail::gp_roi roi_t;
-
- 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::gp_is_supported<Pixel, IsPlanar> {};
-
- typedef mpl::map5
- <
- mpl::pair<char const *, gp_image >,
- 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_range_t , detail::memory_chunk_for_IStream_extender<gp_image> >
- > native_sources;
-
- typedef mpl::map4
- <
- mpl::pair<char const *, detail::gp_writer>,
- mpl::pair<wchar_t const *, detail::gp_writer>,
- mpl::pair<IStream , detail::gp_writer>,
- mpl::pair<FILE , detail::gp_writer>
- > native_sinks;
-
- typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
-
- class view_data_t : public Gdiplus::BitmapData
- {
- public:
- template <typename View>
- view_data_t( View const & view ) : p_roi_( 0 ) { set_bitmapdata_for_view( view ); }
-
- template <typename View>
- view_data_t( View const & view, roi_t::offset_t const & offset )
- :
- p_roi_( static_cast<roi_t const *>( optional_roi_.address() ) )
- {
- set_bitmapdata_for_view( view );
- new ( optional_roi_.address() ) roi_t( offset, Width, Height );
- }
-
- void set_format( format_t const format ) { PixelFormat = format; }
-
- public:
- Gdiplus::Rect const * const p_roi_;
-
- private:
- template <typename View>
- void set_bitmapdata_for_view( View const & view )
- {
- using namespace detail;
-
- 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 = detail::gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value;
- Scan0 = backend_base::get_raw_data( view );
- Reserved = 0;
- }
-
- void operator=( view_data_t const & );
-
- private:
- aligned_storage<sizeof( roi_t ), alignment_of<roi_t>::value>::type optional_roi_;
- };
-
- typedef view_data_t writer_view_data_t;
-
- BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( Gdiplus::ARGB ) );
- BOOST_STATIC_CONSTANT( bool , builtin_conversion = true );
-};
-
-
-#if defined(BOOST_MSVC)
-# pragma warning( push )
-# pragma warning( disable : 4127 ) // "conditional expression is constant"
-#endif
-
-class gp_image
- :
- private detail::gp_guard,
- public detail::backend<gp_image>
-{
-public:
- typedef detail::gp_user_guard guard;
-
-public: /// \ingroup Construction
- explicit gp_image( wchar_t const * const filename )
- {
- detail::ensure_result( Gdiplus::DllExports::GdipCreateBitmapFromFile( filename, &pBitmap_ ) );
- BOOST_ASSERT( pBitmap_ );
- }
-
- explicit gp_image( char const * const filename )
- {
- detail::ensure_result( Gdiplus::DllExports::GdipCreateBitmapFromFile( detail::wide_path( filename ), &pBitmap_ ) );
- BOOST_ASSERT( pBitmap_ );
- }
-
- // The passed IStream object must outlive the GpBitmap object (GDI+ uses
- // lazy evaluation).
- explicit gp_image( IStream & stream )
- {
- detail::ensure_result( Gdiplus::DllExports::GdipCreateBitmapFromStream( &stream, &pBitmap_ ) );
- BOOST_ASSERT( pBitmap_ );
- }
-
- ~gp_image()
- {
- detail::verify_result( Gdiplus::DllExports::GdipDisposeImage( pBitmap_ ) );
- }
-
-public:
- point2<std::ptrdiff_t> dimensions() const
- {
- using namespace Gdiplus;
- REAL width, height;
- detail::verify_result( DllExports::GdipGetImageDimension( const_cast<GpBitmap *>( pBitmap_ ), &width, &height ) );
- return point2<std::ptrdiff_t>( static_cast<std::ptrdiff_t>( width ), static_cast<std::ptrdiff_t>( height ) );
- }
-
- format_t format() const
- {
- format_t pixel_format;
- detail::verify_result( Gdiplus::DllExports::GdipGetImagePixelFormat( pBitmap_, &pixel_format ) );
- return pixel_format;
- }
-
- format_t closest_gil_supported_format() const
- {
- //http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2008-01/msg00044.html
- switch ( format() )
- {
- case PixelFormat16bppGrayScale:
- case PixelFormat48bppRGB :
- case PixelFormat32bppRGB :
- case PixelFormat24bppRGB :
- return
- PixelFormat24bppRGB;
-
- case PixelFormat64bppPARGB :
- case PixelFormat32bppPARGB :
- case PixelFormat64bppARGB :
- case PixelFormat32bppARGB :
- case PixelFormat16bppARGB1555 :
- return
- PixelFormat32bppARGB;
-
- case PixelFormat16bppRGB565 :
- case PixelFormat16bppRGB555 :
- case PixelFormat8bppIndexed :
- case PixelFormat4bppIndexed :
- case PixelFormat1bppIndexed :
- return
- PixelFormat16bppRGB565;
-
- case PixelFormat32bppCMYK:
- return
- #if (GDIPVER >= 0x0110)
- PixelFormat32bppCMYK;
- #else
- PixelFormat24bppRGB;
- #endif // (GDIPVER >= 0x0110)
-
- default:
- BF_UNREACHABLE_CODE
- return PixelFormatUndefined;
- }
- }
-
- image_type_id current_image_format_id() const
- {
- return image_format_id( closest_gil_supported_format() );
- }
-
- static image_type_id image_format_id( format_t const closest_gil_supported_format )
- {
- switch ( closest_gil_supported_format )
- {
- case PixelFormat24bppRGB : return 0;
- case PixelFormat32bppARGB : return 1;
- case PixelFormat16bppRGB565 : return 2;
- #if (GDIPVER >= 0x0110)
- case PixelFormat32bppCMYK : return 3;
- #endif
-
- default:
- BF_UNREACHABLE_CODE
- return unsupported_format;
- }
- }
-
-public: // Low-level (row, strip, tile) access
- static bool can_do_roi_access() { return true; }
-
- class sequential_row_read_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_read_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_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_read_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 backend_base interface.
- friend class base_t;
-
- template <class MyView, class TargetView, class Converter>
- void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const
- {
- BOOST_ASSERT( !dimensions_mismatch( view ) );
- //BOOST_ASSERT( !formats_mismatch ( view ) );
-
- using namespace detail ;
- using namespace Gdiplus;
-
- point2<std::ptrdiff_t> const & targetDimensions( original_view( view ).dimensions() );
- gp_roi const roi( get_offset<gp_roi::offset_t>( view ), targetDimensions.x, targetDimensions.y );
- format_t const my_format( gil_to_gp_format<typename View::value_type, is_planar<View>::value>::value );
- BitmapData bitmapData;
- ensure_result
- (
- DllExports::GdipBitmapLockBits
- (
- pBitmap_,
- &roi,
- ImageLockModeRead,
- my_format,
- &bitmapData
- )
- );
- BOOST_ASSERT( bitmapData.PixelFormat == my_format );
- copy_and_convert_pixels // This must not throw!
- (
- interleaved_view
- (
- bitmapData.Width ,
- bitmapData.Height,
- gil_reinterpret_cast_c<typename MyView::value_type const *>( bitmapData.Scan0 ),
- bitmapData.Stride
- ),
- view,
- converter
- );
- verify_result( DllExports::GdipBitmapUnlockBits( pBitmap_, &bitmapData ) );
- }
-
-
- void raw_convert_to_prepared_view( view_data_t const & view_data ) const
- {
- BOOST_ASSERT( view_data.Scan0 );
-
- using namespace detail ;
- using namespace Gdiplus;
-
- BitmapData * const pMutableBitmapData( const_cast<BitmapData *>( static_cast<BitmapData const *>( &view_data ) ) );
- GpStatus const load_result
- (
- DllExports::GdipBitmapLockBits
- (
- pBitmap_,
- view_data.p_roi_,
- ImageLockModeRead | ImageLockModeUserInputBuf,
- view_data.PixelFormat,
- pMutableBitmapData
- )
- );
- GpStatus const unlock_result( DllExports::GdipBitmapUnlockBits( pBitmap_, pMutableBitmapData ) );
- ensure_result( load_result );
- verify_result( unlock_result );
- }
-
-
- void raw_copy_to_prepared_view( view_data_t const & view_data ) const
- {
- BOOST_ASSERT( view_data.Width == static_cast<UINT>( dimensions().x ) );
- BOOST_ASSERT( view_data.Height == static_cast<UINT>( dimensions().y ) );
- //...this need not hold as it can be used to perform GDI+ default
- //internal colour conversion...maybe i'll provide another worker
- //function...
- //BOOST_ASSERT( view_data.PixelFormat == format () );
- 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*/ )
- {
- #if (GDIPVER >= 0x0110)
- // A GDI+ 1.1 (a non-distributable version, distributed with MS Office
- // 2003 and MS Windows Vista and MS Windows 7) 'enhanced'/'tuned'
- // version of the conversion routine for indexed/palettized image
- // formats. Unless/until proven useful, pretty much still a GDI+ 1.1
- // tester...
-
- BOOST_ASSERT( !has_alpha<desired_format>::value && "Is this possible for indexed formats?" );
- std::size_t const number_of_pixel_bits ( pixel_size<desired_format>::value );
- std::size_t const number_of_palette_colours( static_cast<std::size_t>( ( 2 << ( number_of_pixel_bits - 1 ) ) - 1 ) );
- std::size_t const palette_size ( sizeof( ColorPalette ) + number_of_palette_colours * sizeof( ARGB ) );
- aligned_storage
- <
- palette_size,
- alignment_of<ColorPalette>::value
- >::type palette_storage;
- ColorPalette & palette( *static_cast<ColorPalette *>( palette_storage.address() ) );
- palette.Flags = ( PaletteFlagsHasAlpha * has_alpha<desired_format>::value ) |
- ( PaletteFlagsGrayScale * is_same<typename color_space_type<View>::type, gray_t>::value );
- palette.Count = number_of_palette_colours;
-
- verify_result
- (
- DllExports::GdipInitializePalette
- (
- &palette,
- PaletteTypeOptimal,
- number_of_palette_colours,
- has_alpha<desired_format>::value,
- pBitmap_
- )
- );
+ Gdiplus::EncoderParameters * p_encoder_parameters_;
+}; // class gp_writer
 
- ensure_result
- (
- DllExports::GdipBitmapConvertFormat
- (
- pBitmap_,
- desired_format,
- DitherTypeErrorDiffusion,
- PaletteTypeOptimal,
- &palette,
- 50
- )
- );
- #endif // (GDIPVER >= 0x0110)
- }
-
- template <Gdiplus::PixelFormat desired_format>
- void pre_palettized_conversion( mpl::false_ /*not is_indexed*/ ) const {}
-
-private:
- friend class detail::gp_view_base;
-
- Gdiplus::GpBitmap * /*const*/ pBitmap_;
-};
-
-#if defined(BOOST_MSVC)
-# pragma warning( pop )
-#endif
-
-namespace detail
-{
-//------------------------------------------------------------------------------
-
-////////////////////////////////////////////////////////////////////////////////
-///
-/// \class gp_view_base
-///
-////////////////////////////////////////////////////////////////////////////////
-
-class gp_view_base : noncopyable
-{
-public:
- ~gp_view_base()
- {
- detail::verify_result( Gdiplus::DllExports::GdipBitmapUnlockBits( &bitmap_, &bitmapData_ ) );
- }
-
-protected:
- gp_view_base( gp_image & bitmap, unsigned int const lock_mode, gp_image::roi const * const p_roi = 0 )
- :
- bitmap_( *bitmap.pBitmap_ )
- {
- std::memset( &bitmapData_, 0, sizeof( bitmapData_ ) );
-
- detail::ensure_result
- (
- Gdiplus::DllExports::GdipBitmapLockBits
- (
- &bitmap_,
- p_roi,
- lock_mode,
- bitmap.format(),
- &bitmapData_
- )
- );
- }
-
- template <typename Pixel>
- typename type_from_x_iterator<Pixel *>::view_t
- get_typed_view()
- {
- //todo assert correct type...
- interleaved_view<Pixel *>( bitmapData_.Width, bitmapData_.Height, bitmapData_.Scan0, bitmapData_.Stride );
- }
-
-private:
- Gdiplus::GpBitmap & bitmap_ ;
- Gdiplus::BitmapData bitmapData_;
-};
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-///
-/// \class gp_view
-///
-////////////////////////////////////////////////////////////////////////////////
-
-template <typename Pixel>
-class gp_view
- :
- private gp_view_base,
- public type_from_x_iterator<Pixel *>::view_t
-{
-public:
- gp_view( gp_image & image, gp_image::roi const * const p_roi = 0 )
- :
- gp_view_base( image, ImageLockModeRead | ( is_const<Pixel>::value * ImageLockModeWrite ), p_roi ),
- type_from_x_iterator<Pixel *>::view_t( get_typed_view<Pixel>() )
- {}
-};
-
-
-//...mhmh...to be seen if necessary...
-//template <typename Pixel>
-//class gp_const_view
-// :
-// private gp_view_base,
-// public type_from_x_iterator<Pixel const *>::view_t
-//{
-//public:
-// gp_const_view( gp_image & image, gp_image::roi const * const p_roi = 0 )
-// :
-// gp_view_base( image, ImageLockModeRead ),
-// type_from_x_iterator<Pixel const *>::view_t( get_typed_view<Pixel const>() )
-// {}
-//};
-
-
-//...mhmh...to be implemented...
-//template <class Impl, class SupportedPixelFormats, class ROI>
-//inline
-//typename backend<Impl, SupportedPixelFormats, ROI>::view_t
-//view( backend<Impl, SupportedPixelFormats, ROI> & img );// { return img._view; }
-
-//------------------------------------------------------------------------------
-} // namespace detail
 //------------------------------------------------------------------------------
 } // namespace gil
 //------------------------------------------------------------------------------
 } // namespace boost
 //------------------------------------------------------------------------------
-#endif // gp_private_base_hpp
+#endif // writer_hpp

Modified: sandbox/gil/boost/gil/extension/io2/backends/libjpeg/backend.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libjpeg/backend.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libjpeg/backend.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -33,10 +33,6 @@
 #include "jpeglib.h"
 #undef JPEG_INTERNALS
 
-#ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
- #include <csetjmp>
-#endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
-#include <cstdlib>
 #if defined(BOOST_MSVC)
     #pragma warning( push )
     #pragma warning( disable : 4996 ) // "The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name."
@@ -44,6 +40,12 @@
     #include "sys/stat.h"
 #endif // MSVC
 #include "fcntl.h"
+
+#ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+#include <csetjmp>
+#endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+#include <cstddef>
+#include <cstdlib>
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -153,8 +155,65 @@
 public:
         struct guard {};
 
-public:
- static image_type_id image_format_id(format_t const closest_gil_supported_format)
+public: /// \ingroup Information
+ typedef point2<unsigned int> dimensions_t;
+
+ dimensions_t dimensions() const
+ {
+ BOOST_STATIC_ASSERT( offsetof( jpeg_compress_struct, image_width ) == offsetof( jpeg_decompress_struct, image_width ) );
+ BOOST_STATIC_ASSERT( offsetof( jpeg_compress_struct, image_height ) == offsetof( jpeg_decompress_struct, image_height ) );
+ return dimensions_t( decompressor().image_width, decompressor().image_height );
+ }
+
+ unsigned int number_of_channels() const
+ {
+ BOOST_STATIC_ASSERT( offsetof( jpeg_compress_struct, num_components ) == offsetof( jpeg_decompress_struct, num_components ) );
+ return decompressor().num_components;
+ }
+
+ format_t format() const
+ {
+ BOOST_STATIC_ASSERT( offsetof( jpeg_compress_struct, jpeg_color_space ) == offsetof( jpeg_decompress_struct, jpeg_color_space ) );
+ return decompressor().jpeg_color_space;
+ }
+
+ format_t closest_gil_supported_format() const
+ {
+ format_t const current_format( format() );
+ #ifdef _DEBUG
+ switch ( current_format )
+ {
+ case JCS_RGB :
+ case JCS_YCbCr :
+ case JCS_CMYK :
+ case JCS_YCCK :
+ case JCS_GRAYSCALE:
+ case JCS_UNKNOWN :
+ break;
+
+ default:
+ BOOST_ASSERT( !"Unknown format code." );
+ }
+ #endif
+
+ switch ( current_format )
+ {
+ default : return current_format;
+
+ case JCS_BG_RGB:
+ case JCS_BG_YCC:
+ case JCS_YCbCr : return JCS_RGB ;
+ case JCS_YCCK : return JCS_CMYK ;
+ }
+ }
+
+ image_type_id_t current_image_format_id() const
+ {
+ return image_format_id( closest_gil_supported_format() );
+ }
+
+
+ static image_type_id_t image_format_id( format_t const closest_gil_supported_format )
         {
                 switch ( closest_gil_supported_format )
                 {

Modified: sandbox/gil/boost/gil/extension/io2/backends/libjpeg/reader.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libjpeg/reader.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libjpeg/reader.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -30,7 +30,6 @@
 #include <boost/array.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/smart_ptr/scoped_array.hpp>
-
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -55,12 +54,12 @@
     J_COLOR_SPACE /*const*/ format_;
     JSAMPROW /*const*/ buffer_;
     libjpeg_roi::offset_t /*const*/ offset_;
-};
+}; // struct decompression_setup_data_t
 
 struct view_data_t : decompression_setup_data_t
 {
     template <class View>
- /*explicit*/ view_data_t( View const & view, libjpeg_roi::offset_t const offset = 0 )
+ explicit view_data_t( View const & view, libjpeg_roi::offset_t const offset = 0 )
         :
         decompression_setup_data_t
         (
@@ -82,7 +81,7 @@
     unsigned int /*const*/ width_ ;
     unsigned int /*const*/ stride_;
     unsigned int number_of_channels_;
-};
+}; // struct view_data_t
 
 //------------------------------------------------------------------------------
 } // namespace detail
@@ -99,54 +98,23 @@
     :
     public libjpeg_image
 {
-public:
- format_t format() const { return decompressor().jpeg_color_space; }
-
- format_t closest_gil_supported_format() const
- {
- format_t const current_format( format() );
- #ifdef _DEBUG
- switch ( current_format )
- {
- case JCS_RGB :
- case JCS_YCbCr :
- case JCS_CMYK :
- case JCS_YCCK :
- case JCS_GRAYSCALE:
- case JCS_UNKNOWN :
- break;
-
- default:
- BOOST_ASSERT( !"Unknown format code." );
- }
- #endif
-
- switch ( current_format )
- {
- case JCS_YCbCr: return JCS_RGB ;
- case JCS_YCCK : return JCS_CMYK ;
- default : return current_format;
- }
- }
-
- image_type_id current_image_format_id() const
- {
- return image_format_id( closest_gil_supported_format() );
- }
-
-
- point2<std::ptrdiff_t> dimensions() const
+public: /// \ingroup Information
+ dimensions_t dimensions() const
     {
         // Implementation note:
         // A user might have setup output image scaling through the low-level
- // lib_object accessor.
+ // lib_object accessor or the scale_image() member function so we have
+ // to use the "output" dimensions.
         // (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 );
+ return dimensions_t( decompressor().output_width, decompressor().output_height );
+ }
+
+public: /// \ingroup Backend specific - transformation
+ void scale_image( unsigned int const scale_numerator, unsigned int const scale_denominator )
+ {
+ decompressor().scale_num = scale_numerator ;
+ decompressor().scale_denom = scale_denominator;
+ jpeg_calc_output_dimensions( &const_cast<libjpeg_image &>( *this ).lib_object() );
     }
 
 public: // Low-level (row, strip, tile) access
@@ -155,8 +123,8 @@
         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(); }
+ jpeg_decompress_struct & lib_object() { return decompressor(); }
+ jpeg_decompress_struct const & lib_object() const { return decompressor(); }
 
 public: /// \ingroup Construction
         template <class Device>
@@ -164,10 +132,10 @@
         :
         libjpeg_base( for_decompressor() )
     {
- #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
- if ( setjmp( libjpeg_base::error_handler_target() ) )
- libjpeg_base::throw_jpeg_error();
- #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+ #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+ if ( setjmp( libjpeg_base::error_handler_target() ) )
+ libjpeg_base::throw_jpeg_error();
+ #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
 
         setup_source( device );
 
@@ -436,8 +404,6 @@
         decompressor().output_width = decompressor().image_width ;
         decompressor().output_height = decompressor().image_height;
 
- dirty_output_dimensions_ = false;
-
         detail::io_error_if( decompressor().data_precision != BITS_IN_JSAMPLE, "Unsupported image file data precision." );
     }
 
@@ -580,10 +546,9 @@
     }
 
 private:
- jpeg_source_mgr source_manager_ ;
- mutable bool dirty_output_dimensions_;
- array<JOCTET, 4096> read_buffer_ ;//...zzz...extract to a wrapper...not needed for in memory sources...
-};
+ jpeg_source_mgr source_manager_;
+ array<JOCTET, 4096> read_buffer_ ;//...zzz...extract to a wrapper...not needed for in memory sources...
+}; // class libjpeg_reader
 
 #if defined( BOOST_MSVC )
 # pragma warning( pop )
@@ -647,9 +612,4 @@
 //------------------------------------------------------------------------------
 } // namespace boost
 //------------------------------------------------------------------------------
-
-#if defined( BOOST_MSVC )
- #pragma warning( pop )
-#endif // MSVC
-
 #endif // reader_hpp

Modified: sandbox/gil/boost/gil/extension/io2/backends/libjpeg/writer.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libjpeg/writer.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libjpeg/writer.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -34,9 +34,6 @@
 namespace gil
 {
 //------------------------------------------------------------------------------
-namespace detail
-{
-//------------------------------------------------------------------------------
 
 class libjpeg_writer
     :
@@ -73,10 +70,10 @@
     {
         setup_compression( view );
 
- #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
- if ( setjmp( libjpeg_base::error_handler_target() ) )
- libjpeg_base::throw_jpeg_error();
- #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+ #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+ if ( setjmp( libjpeg_base::error_handler_target() ) )
+ libjpeg_base::throw_jpeg_error();
+ #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
         jpeg_set_defaults( &compressor() );
         //jpeg_set_quality( &compressor(), 100, false );
 
@@ -102,10 +99,10 @@
     {
         BOOST_ASSERT( view.format_ != JCS_UNKNOWN );
 
- #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
- if ( setjmp( libjpeg_base::error_handler_target() ) )
- libjpeg_base::throw_jpeg_error();
- #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+ #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
+ if ( setjmp( libjpeg_base::error_handler_target() ) )
+ libjpeg_base::throw_jpeg_error();
+ #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
         
         jpeg_start_compress( &compressor(), false );
 
@@ -158,7 +155,7 @@
 
         setup_destination();
 
- compressor().client_data = reinterpret_cast<void *>( file_descriptor );
+ compressor().client_data = reinterpret_cast<void *>( static_cast<std::intptr_t>( file_descriptor ) );
 
         destination_manager_.init_destination = &init_destination ;
         destination_manager_.empty_output_buffer = &empty_fd_buffer ;
@@ -194,7 +191,7 @@
         (
             /*std*/::write
             (
- reinterpret_cast<long>( compressor().client_data ),
+ static_cast<int>( reinterpret_cast<std::intptr_t>( compressor().client_data ) ),
                 write_buffer_.begin(),
                 number_of_bytes
             ) != static_cast<int>( number_of_bytes )
@@ -252,19 +249,11 @@
 private:
     jpeg_destination_mgr destination_manager_;
     array<unsigned char, 65536> write_buffer_ ;
-};
-//------------------------------------------------------------------------------
-} // namespace detail
-
+}; // class libjpeg_writer
 
 //------------------------------------------------------------------------------
 } // namespace gil
 //------------------------------------------------------------------------------
 } // namespace boost
 //------------------------------------------------------------------------------
-
-#if defined( BOOST_MSVC )
- #pragma warning( pop )
-#endif // MSVC
-
 #endif // writer_hpp

Modified: sandbox/gil/boost/gil/extension/io2/backends/libpng/backend.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libpng/backend.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libpng/backend.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -250,7 +250,7 @@
 
     BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( void * ) );
     BOOST_STATIC_CONSTANT( bool , builtin_conversion = true );
-};
+}; // struct backend_traits<libpng_image>
 
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -269,26 +269,62 @@
 public:
         struct guard {};
 
- typedef lib_object_t lib_object_t;
+public: /// \ingroup Information
+ typedef point2<unsigned int> dimensions_t;
 
- lib_object_t & lib_object() { return *this; }
+ dimensions_t dimensions() const
+ {
+ return dimensions_t
+ (
+ ::png_get_image_width ( &png_object(), &info_object() ),
+ ::png_get_image_height( &png_object(), &info_object() )
+ );
+ }
 
- static image_type_id image_format_id( format_t const closest_gil_supported_format )
+ unsigned int number_of_channels() const { return ::png_get_channels ( &png_object(), &info_object() ); }
+ unsigned int bit_depth () const { return ::png_get_bit_depth( &png_object(), &info_object() ); }
+
+ format_t format() const { return ::png_get_color_type( &png_object(), &info_object() ) | ( bit_depth() << 16 ); }
+
+ format_t closest_gil_supported_format() const
+ {
+ format_t const current_format( format() );
+
+ switch ( current_format & 0xFF )
+ {
+ default: return current_format;
+
+ 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
+ }
+ }
+
+ image_type_id_t current_image_format_id() const { return image_format_id( closest_gil_supported_format() ); }
+
+ unsigned int pixel_size() const { return number_of_channels() * bit_depth() / 8; }
+
+ static image_type_id_t image_format_id( format_t const closest_gil_supported_format )
         {
                 switch ( closest_gil_supported_format )
                 {
- case PNG_COLOR_TYPE_RGB | ( 8 << 16 ) : return 0;
- case PNG_COLOR_TYPE_RGB_ALPHA | ( 8 << 16 ) : return 1;
- case PNG_COLOR_TYPE_GRAY | ( 8 << 16 ) : return 2;
- case PNG_COLOR_TYPE_RGB | ( 16 << 16 ) : return 3;
+ case PNG_COLOR_TYPE_RGB | ( 8 << 16 ) : return 0;
+ case PNG_COLOR_TYPE_RGB_ALPHA | ( 8 << 16 ) : return 1;
+ case PNG_COLOR_TYPE_GRAY | ( 8 << 16 ) : return 2;
+ case PNG_COLOR_TYPE_RGB | ( 16 << 16 ) : return 3;
                         case PNG_COLOR_TYPE_RGB_ALPHA | ( 16 << 16 ) : return 4;
- case PNG_COLOR_TYPE_GRAY | ( 16 << 16 ) : return 5;
+ case PNG_COLOR_TYPE_GRAY | ( 16 << 16 ) : return 5;
 
                         default:
                                 return unsupported_format;
                 }
         }
 
+public:
+ typedef lib_object_t lib_object_t;
+
+ lib_object_t & lib_object() { return *this; }
+ lib_object_t const & lib_object() const { return *this; }
+
 protected:
         libpng_image( png_struct * const p_png )
                 :
@@ -298,12 +334,12 @@
         //...zzz...forced by LibPNG into either duplication or this anti-pattern...
         bool successful_creation() const { return is_valid(); }
 
- static std::size_t format_bit_depth( libpng_view_data_t::format_t const format )
+ static unsigned int format_bit_depth( libpng_view_data_t::format_t const format )
         {
                 return ( format >> 16 ) & 0xFF;
         }
 
- static std::size_t format_colour_type( libpng_view_data_t::format_t const format )
+ static unsigned int format_colour_type( libpng_view_data_t::format_t const format )
         {
                 return format & 0xFF;
         }
@@ -311,7 +347,7 @@
 #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
         jmp_buf & error_handler_target() const { return png_object().jmpbuf; }
 #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
-};
+}; // class libpng_image
 
 //------------------------------------------------------------------------------
 } // namespace gil

Modified: sandbox/gil/boost/gil/extension/io2/backends/libpng/reader.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libpng/reader.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libpng/reader.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -39,13 +39,6 @@
 namespace gil
 {
 //------------------------------------------------------------------------------
-namespace detail
-{
-//------------------------------------------------------------------------------
-
-//------------------------------------------------------------------------------
-} // namespace detail
-
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
@@ -57,46 +50,16 @@
 
 class libpng_reader
     :
- public detail::libpng_image
+ public libpng_image
 {
 public:
     struct guard {};
 
-public:
- format_t format() const
- {
- return ::png_get_color_type( &png_object(), &info_object() ) | ( bit_depth() << 16 );
- }
-
- format_t closest_gil_supported_format() const
- {
- format_t const current_format( format() );
-
- switch ( current_format & 0xFF )
- {
- default: return current_format;
-
- 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
- }
- }
-
- image_type_id current_image_format_id() const
- {
- return image_format_id( closest_gil_supported_format() );
- }
-
-
- std::size_t pixel_size() const
- {
- return number_of_channels() * bit_depth() / 8;
- }
-
 public: /// \ingroup Construction
         template <class Device>
- explicit libpng_image( Device & device )
+ explicit libpng_reader( Device & device )
         :
- libpng_base( ::png_create_read_struct_2( PNG_LIBPNG_VER_STRING, NULL, &detail::png_error_function, &detail::png_warning_function, NULL, NULL, NULL ) )
+ libpng_image( ::png_create_read_struct_2( PNG_LIBPNG_VER_STRING, NULL, &detail::png_error_function, &detail::png_warning_function, NULL, NULL, NULL ) )
     {
         if ( !successful_creation() )
             cleanup_and_throw_libpng_error();
@@ -119,24 +82,12 @@
         destroy_read_struct();
     }
 
-public:
- 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() )
- );
- }
-
 public: // Low-level (row, strip, tile) access
     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 backend_base interface.
     // Implementation note:
     // MSVC 10 accepts friend base_t and friend class base_t, Clang 2.8
@@ -267,7 +218,7 @@
         }
     }
 
- std::size_t cached_format_size( format_t const format ) const
+ unsigned int cached_format_size( format_t const format ) const
     {
         return number_of_channels() * format_bit_depth( format ) / 8;
     }
@@ -315,9 +266,6 @@
         }
     }
 
- unsigned int number_of_channels() const { return ::png_get_channels ( &png_object(), &info_object() ); }
- std::size_t bit_depth () const { return ::png_get_bit_depth( &png_object(), &info_object() ); }
-
     void destroy_read_struct() { ::png_destroy_read_struct( &png_object_for_destruction(), &info_object_for_destruction(), NULL ); }
 
     void read_row( png_byte * const p_row ) const BOOST_GIL_CAN_THROW
@@ -354,7 +302,7 @@
         else
             detail::png_error_function( png_ptr, "Read Error" );
     }
-};
+}; // class libpng_reader
 
 //------------------------------------------------------------------------------
 } // namespace gil

Modified: sandbox/gil/boost/gil/extension/io2/backends/libpng/writer.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libpng/writer.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libpng/writer.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -39,9 +39,6 @@
 namespace gil
 {
 //------------------------------------------------------------------------------
-namespace detail
-{
-//------------------------------------------------------------------------------
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
@@ -51,7 +48,7 @@
 
 class libpng_writer
     :
- public libpng_base,
+ public libpng_image,
     public configure_on_write_writer
 {
 public:
@@ -103,7 +100,7 @@
 protected:
     libpng_writer( void * const p_target_object, png_rw_ptr const write_data_fn, png_flush_ptr const output_flush_fn )
         :
- libpng_base( ::png_create_write_struct_2( PNG_LIBPNG_VER_STRING, NULL, &detail::png_error_function, &detail::png_warning_function, NULL, NULL, NULL ) )
+ libpng_image( ::png_create_write_struct_2( PNG_LIBPNG_VER_STRING, NULL, &detail::png_error_function, &detail::png_warning_function, NULL, NULL, NULL ) )
     {
         if ( !successful_creation() )
             cleanup_and_throw_libpng_error();
@@ -129,7 +126,7 @@
     {
         ::png_set_write_fn( &png_object(), p_target_object, write_data_fn, output_flush_fn );
     }
-};
+}; // class libpng_writer
 
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -168,11 +165,9 @@
 
         std::fflush( static_cast<FILE *>( png_ptr->io_ptr ) );
     }
-};
+}; // class libpng_writer_FILE
 
 //------------------------------------------------------------------------------
-} // namespace detail
-//------------------------------------------------------------------------------
 } // namespace gil
 //------------------------------------------------------------------------------
 } // namespace boost

Modified: sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -408,10 +408,15 @@
 private:
     typedef detail::full_format_t full_format_t;
 
-public:
- point2<uint32> dimensions() const
- {
- return point2<uint32>( get_field<uint32>( TIFFTAG_IMAGEWIDTH ), get_field<uint32>( TIFFTAG_IMAGELENGTH ) );
+public: /// \ingroup Information
+ typedef point2<uint32> dimensions_t;
+ dimensions_t dimensions() const
+ {
+ return dimensions_t
+ (
+ get_field<uint32>( TIFFTAG_IMAGEWIDTH ),
+ get_field<uint32>( TIFFTAG_IMAGELENGTH )
+ );
     }
 
 protected:
@@ -445,7 +450,7 @@
         return std::pair<T1, T2>( first, second );
     }
 
- static std::size_t cached_format_size( backend_traits<libtiff_image>::format_t const format )
+ static unsigned int cached_format_size( backend_traits<libtiff_image>::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;

Modified: sandbox/gil/boost/gil/extension/io2/backends/libtiff/writer.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libtiff/writer.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/libtiff/writer.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -138,7 +138,7 @@
     {
         BOOST_VERIFY( ::TIFFSetField( &lib_object(), tag, value1, value2 ) );
     }
-};
+}; // class libtiff_image::native_writer
 
 //------------------------------------------------------------------------------
 } // namespace io

Modified: sandbox/gil/boost/gil/extension/io2/backends/wic/backend.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/wic/backend.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/wic/backend.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -179,13 +179,13 @@
         set_bitmapdata_for_view( view );
     }
 
- WICRect const * const p_roi_ ;
- unsigned int /*const*/ width_ ;
- unsigned int /*const*/ height_;
- unsigned int /*const*/ stride_;
+ WICRect const * const p_roi_ ;
+ unsigned int /*const*/ width_ ;
+ unsigned int /*const*/ height_ ;
+ unsigned int /*const*/ stride_ ;
     unsigned int /*const*/ pixel_size_;
- BYTE * /*const*/ p_buffer_;
- wic_format_t const format_;
+ BYTE * /*const*/ p_buffer_ ;
+ wic_format_t const format_ ;
 
 private:
     template <typename View>

Modified: sandbox/gil/boost/gil/extension/io2/backends/wic/reader.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/wic/reader.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/wic/reader.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -5,7 +5,7 @@
 ///
 /// WIC reader.
 ///
-/// Copyright (c) Domagoj Saric 2010.-2011.
+/// Copyright (c) Domagoj Saric 2010.-2013.
 ///
 /// Use, modification and distribution is subject to the Boost Software License, Version 1.0.
 /// (See accompanying file LICENSE_1_0.txt or copy at
@@ -62,28 +62,8 @@
     public detail::backend_reader<wic_image>
 {
 public:
- // Implementation note:
- // The IWICBitmapDecoder instance is not otherwise necessary once an
- // IWICBitmapFrameDecode instance is created but we keep it here and make it
- // accessible to the user to enable the use of multi frame/page/picture
- // formats like GIF and TIFF.
- // (26.07.2010.) (Domagoj Saric)
- typedef std::pair
- <
- detail::com_scoped_ptr<IWICBitmapFrameDecode>,
- detail::com_scoped_ptr<IWICBitmapDecoder >
- > lib_object_t;
-
-public:
- explicit native_reader( wchar_t const * const filename )
- {
- create_decoder_from_filename( filename );
- }
-
- explicit native_reader( char const * const filename )
- {
- create_decoder_from_filename( detail::wide_path( filename ) );
- }
+ explicit native_reader( wchar_t const * const filename ) { create_decoder_from_filename( filename ); }
+ explicit native_reader( char const * const filename ) { create_decoder_from_filename( detail::wide_path( filename ) ); }
 
     // The passed IStream object must outlive the wic_image object (to support
     // lazy evaluation).
@@ -101,11 +81,13 @@
         create_first_frame_decoder();
     }
 
-public:
- point2<std::ptrdiff_t> dimensions() const
+public: /// \ingroup Information
+ typedef point2<UINT> dimensions_t;
+
+ dimensions_t dimensions() const
     {
         using namespace detail;
- typedef point2<std::ptrdiff_t> result_t;
+ typedef dimensions_t result_t;
         aligned_storage<sizeof( result_t ), alignment_of<result_t>::value>::type placeholder;
         result_t & result( *gil_reinterpret_cast<result_t *>( placeholder.address() ) );
         BOOST_STATIC_ASSERT( sizeof( result_t::value_type ) == sizeof( UINT ) );
@@ -123,7 +105,7 @@
 
     /*format_t*/WICPixelFormatGUID closest_gil_supported_format() const { return format(); }
 
- image_type_id current_image_format_id() const
+ image_type_id_t current_image_format_id() const
     {
         return image_format_id( closest_gil_supported_format() );
     }
@@ -149,7 +131,7 @@
     private: friend wic_image;
         detail::wic_roi roi_ ;
         UINT const stride_;
- };
+ }; // class sequential_row_read_state
 
     sequential_row_read_state begin_sequential_row_read() const { return sequential_row_read_state( *this ); }
 
@@ -169,7 +151,21 @@
         ++state.roi_.Y;
     }
 
- lib_object_t & lib_object() { return lib_object_; }
+public:
+ // Implementation note:
+ // The IWICBitmapDecoder instance is not otherwise necessary once an
+ // IWICBitmapFrameDecode instance is created but we keep it here and make it
+ // accessible to the user to enable the use of multi frame/page/picture
+ // formats like GIF and TIFF.
+ // (26.07.2010.) (Domagoj Saric)
+ typedef std::pair
+ <
+ detail::com_scoped_ptr<IWICBitmapFrameDecode>,
+ detail::com_scoped_ptr<IWICBitmapDecoder >
+ > lib_object_t;
+
+ lib_object_t & lib_object() { return lib_object_; }
+ lib_object_t const & lib_object() const { return lib_object_; }
 
 private: // Private formatted_image_base interface.
     friend class detail::backend_reader<wic_image>;

Modified: sandbox/gil/boost/gil/extension/io2/backends/wic/writer.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/wic/writer.hpp Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/boost/gil/extension/io2/backends/wic/writer.hpp 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -44,16 +44,6 @@
     public detail::configure_on_write_writer
 {
 public:
- struct lib_object_t
- {
- detail::com_scoped_ptr<IWICBitmapFrameEncode> p_frame_ ;
- detail::com_scoped_ptr<IWICBitmapEncoder > p_encoder_ ;
- IPropertyBag2 * p_frame_parameters_;
- };
-
- lib_object_t & lib_object() { return lib_object_; }
-
-public:
     native_writer( IStream & target, format_tag const format )
     {
         create_encoder( target, encoder_guid( format ) );
@@ -100,6 +90,17 @@
 
     void write( detail::wic_view_data_t const & view_data ) { write_default( view_data ); }
 
+public:
+ struct lib_object_t
+ {
+ detail::com_scoped_ptr<IWICBitmapFrameEncode> p_frame_ ;
+ detail::com_scoped_ptr<IWICBitmapEncoder > p_encoder_ ;
+ IPropertyBag2 * p_frame_parameters_;
+ }; // struct lib_object_t
+
+ lib_object_t & lib_object() { return lib_object_; }
+ lib_object_t const & lib_object() const { return lib_object_; }
+
 private:
     void create_encoder( IStream & target, GUID const & format )
     {

Modified: sandbox/gil/libs/gil/io2/test/CMakeLists.txt
==============================================================================
--- sandbox/gil/libs/gil/io2/test/CMakeLists.txt Sun Sep 15 07:05:46 2013 (r85674)
+++ sandbox/gil/libs/gil/io2/test/CMakeLists.txt 2013-09-15 09:55:24 EDT (Sun, 15 Sep 2013) (r85675)
@@ -58,6 +58,20 @@
 
 set( public_headers_path "${CMAKE_CURRENT_SOURCE_DIR}/../../../../boost/gil/extension/io2" )
 
+set( headers_libjpeg
+ ${public_headers_path}/backends/libjpeg/backend.hpp
+ ${public_headers_path}/backends/libjpeg/reader.hpp
+ ${public_headers_path}/backends/libjpeg/writer.hpp
+)
+source_group( "LibJPEG" FILES ${headers_libjpeg} )
+
+set( headers_libpng
+ ${public_headers_path}/backends/libpng/backend.hpp
+ ${public_headers_path}/backends/libpng/reader.hpp
+ ${public_headers_path}/backends/libpng/writer.hpp
+)
+source_group( "LibPNG" FILES ${headers_libpng} )
+
 set( headers_libtiff
     ${public_headers_path}/backends/libtiff/backend.hpp
     ${public_headers_path}/backends/libtiff/reader.hpp
@@ -66,6 +80,13 @@
 source_group( "LibTIFF" FILES ${headers_libtiff} )
 
 if ( WIN32 )
+set( headers_gp
+ ${public_headers_path}/backends/gp/backend.hpp
+ ${public_headers_path}/backends/gp/reader.hpp
+ ${public_headers_path}/backends/gp/writer.hpp
+)
+source_group( "GDI+" FILES ${headers_gp} )
+
 set( headers_wic
     ${public_headers_path}/backends/wic/backend.hpp
     ${public_headers_path}/backends/wic/reader.hpp
@@ -74,7 +95,14 @@
 source_group( "WIC" FILES ${headers_wic} )
 endif()
 
-add_executable( gio_io2_tester test.cpp ${headers_libtiff} ${headers_wic} )
+add_executable( gio_io2_tester
+ test.cpp
+ ${headers_libjpeg}
+ ${headers_libpng}
+ ${headers_libtiff}
+ ${headers_gp}
+ ${headers_wic}
+)
 
 #addPCH( gio_io2_tester precompiled_headers )
 


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