Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65874 - in sandbox/gil/boost/gil/extension/io2: . detail
From: dsaritz_at_[hidden]
Date: 2010-10-10 11:10:12


Author: psiha
Date: 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
New Revision: 65874
URL: http://svn.boost.org/trac/boost/changeset/65874

Log:
Added the memory_mapping module and added memory mapped files (reader) functionality to all backends.

Moved the memory_chunk_t typedefs to the new memory_mapping.hpp file.

Minor stylistic changes.
Added:
   sandbox/gil/boost/gil/extension/io2/detail/memory_mapping.cpp (contents, props changed)
   sandbox/gil/boost/gil/extension/io2/detail/memory_mapping.hpp (contents, props changed)
Text files modified:
   sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp | 83 ++++++++++++++++++++++++++
   sandbox/gil/boost/gil/extension/io2/detail/shared.hpp | 5 -
   sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp | 2
   sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp | 13 +++
   sandbox/gil/boost/gil/extension/io2/gp_image.hpp | 19 +++--
   sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp | 123 ++++++++++++++++++++++++++++++++-------
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp | 47 ++++++++++++--
   sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp | 75 +++++++++++++++++++++++-
   sandbox/gil/boost/gil/extension/io2/wic_image.hpp | 18 ++--
   9 files changed, 319 insertions(+), 66 deletions(-)

Modified: sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -21,6 +21,7 @@
 //------------------------------------------------------------------------------
 #include "../../../utilities.hpp"
 #include "io_error.hpp"
+#include "memory_mapping.hpp"
 
 #include "boost/assert.hpp"
 #include "boost/noncopyable.hpp"
@@ -104,7 +105,7 @@
 class c_file_input_guard : public c_file_guard
 {
 public:
- c_file_input_guard( char const * const file_name ) : c_file_guard( file_name, "rb" ) {}
+ explicit c_file_input_guard( char const * const file_name ) : c_file_guard( file_name, "rb" ) {}
 };
 
 
@@ -117,7 +118,39 @@
 class c_file_output_guard : public c_file_guard
 {
 public:
- c_file_output_guard( char const * const file_name ) : c_file_guard( file_name, "wb" ) {}
+ explicit c_file_output_guard( char const * const file_name ) : c_file_guard( file_name, "wb" ) {}
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class mapped_input_file_guard
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class mapped_input_file_guard : private memory_mapped_source
+{
+public:
+ explicit mapped_input_file_guard( char const * const file_name )
+ :
+ memory_mapped_source( map_read_only_file( file_name ) ),
+ mutable_range_ ( memory_mapped_source::memory_range() )
+ {
+ io_error_if( memory_range().empty(), "File open failure" );
+ }
+
+ ~mapped_input_file_guard()
+ {
+ // Verify that the image class did not 'walk outside' the mapped range.
+ BOOST_ASSERT( mutable_range_.begin() <= mutable_range_.end () );
+ BOOST_ASSERT( mutable_range_.begin() >= memory_range().begin() );
+ BOOST_ASSERT( mutable_range_.end () <= memory_range().end () );
+ }
+
+ memory_chunk_t & get() { return mutable_range_; }
+
+private:
+ memory_chunk_t mutable_range_;
 };
 
 
@@ -176,6 +209,52 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
+/// \class input_c_str_for_mmap_extender
+/// \internal
+/// \brief Helper wrapper for classes that can construct from memory_chunk_t
+/// objects.
+///
+////////////////////////////////////////////////////////////////////////////////
+//...zzz...add another layer of utility templates to kill this duplication...
+template <class mmap_capable_class>
+class input_c_str_for_mmap_extender
+ :
+ private mapped_input_file_guard,
+ public mmap_capable_class
+{
+public:
+ input_c_str_for_mmap_extender( char const * const file_path )
+ :
+ mapped_input_file_guard( file_path ),
+ mmap_capable_class ( mapped_input_file_guard::get() )
+ {}
+};
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class seekable_input_memory_range_extender
+///
+////////////////////////////////////////////////////////////////////////////////
+
+template <class in_memory_capable_class>
+class seekable_input_memory_range_extender
+ :
+ private memory_chunk_t,
+ public in_memory_capable_class
+{
+public:
+ explicit seekable_input_memory_range_extender( memory_chunk_t const & memory_range )
+ :
+ memory_chunk_t ( memory_range ),
+ in_memory_capable_class( static_cast<memory_chunk_t &>( *this ) )
+ {}
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \class cumulative_result
 ///
 ////////////////////////////////////////////////////////////////////////////////

Added: sandbox/gil/boost/gil/extension/io2/detail/memory_mapping.cpp
==============================================================================
--- (empty file)
+++ sandbox/gil/boost/gil/extension/io2/detail/memory_mapping.cpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -0,0 +1,365 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file memory_mapping.cpp
+/// ------------------------
+///
+/// Copyright (c) Domagoj Saric 2010.
+///
+/// Use, modification and distribution is subject to the Boost Software License, Version 1.0.
+/// (See accompanying file LICENSE_1_0.txt or copy at
+/// http://www.boost.org/LICENSE_1_0.txt)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#include "memory_mapping.hpp"
+
+#include "boost/assert.hpp"
+
+#ifdef _WIN32
+ #ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+ #endif // WIN32_LEAN_AND_MEAN
+ #include "windows.h"
+
+ //#define _POSIX_
+ #include "io.h"
+#else
+ #include <sys/mman.h> // mmap, munmap.
+ #include <sys/stat.h>
+ #include <sys/types.h> // struct stat.
+ #include <unistd.h> // sysconf.
+#endif // _WIN32
+#include <errno.h>
+#include <fcntl.h>
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace guard
+{
+
+#ifdef _WIN32
+windows_handle::windows_handle( handle_t const handle )
+ :
+ handle_( handle )
+{}
+
+windows_handle::~windows_handle()
+{
+ BOOST_VERIFY
+ (
+ ( ::CloseHandle( handle_ ) != false ) ||
+ ( handle_ == 0 || handle_ == INVALID_HANDLE_VALUE )
+ );
+}
+
+windows_handle::handle_t const & windows_handle::handle() const
+{
+ return handle_;
+}
+#endif // _WIN32
+
+posix_handle::posix_handle( handle_t const handle )
+ :
+ handle_( handle )
+{}
+
+#ifdef _WIN32
+posix_handle::posix_handle( windows_handle::handle_t const native_handle )
+ :
+ handle_( ::_open_osfhandle( reinterpret_cast<intptr_t>( native_handle ), _O_APPEND ) )
+{
+ if ( handle_ == -1 )
+ {
+ BOOST_VERIFY
+ (
+ ( ::CloseHandle( native_handle ) != false ) ||
+ ( native_handle == 0 || native_handle == INVALID_HANDLE_VALUE )
+ );
+ }
+}
+#endif // _WIN32
+
+posix_handle::~posix_handle()
+{
+ BOOST_VERIFY
+ (
+ ( ::close( handle() ) == 0 ) ||
+ (
+ ( handle() == -1 ) &&
+ ( errno == EBADF )
+ )
+ );
+}
+
+
+posix_handle::handle_t const & posix_handle::handle() const
+{
+ return handle_;
+}
+
+
+native_handle_guard create_file( char const * const file_name, file_flags const & flags )
+{
+ BOOST_ASSERT( file_name );
+#ifdef _WIN32
+ HANDLE const file_handle
+ (
+ ::CreateFileA
+ (
+ file_name, flags.desired_access, flags.share_mode, 0, flags.creation_disposition, flags.flags_and_attributes, 0
+ )
+ );
+ BOOST_ASSERT( ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) || ( ::GetLastError() == ERROR_ALREADY_EXISTS ) );
+ return native_handle_guard( file_handle );
+#else
+
+#endif // _WIN32
+}
+
+//------------------------------------------------------------------------------
+} // guard
+
+
+bool set_file_size( guard::native_handle_t const file_handle, unsigned int const desired_size )
+{
+#ifdef _WIN32
+ // It is 'OK' to send null/invalid handles to Windows functions (they will
+ // simply fail), this simplifies error handling (it is enough to go through
+ // all the logic, inspect the final result and then throw on error).
+ DWORD const new_size( ::SetFilePointer( file_handle, desired_size, 0, FILE_BEGIN ) );
+ BOOST_ASSERT( ( new_size == desired_size ) || ( file_handle == INVALID_HANDLE_VALUE ) );
+ ignore_unused_variable_warning( new_size );
+
+ BOOL const success( ::SetEndOfFile( file_handle ) );
+
+ BOOST_VERIFY( ( ::SetFilePointer( file_handle, 0, 0, FILE_BEGIN ) == 0 ) || ( file_handle == INVALID_HANDLE_VALUE ) );
+
+ return success != false;
+#else
+
+#endif // _WIN32
+}
+
+
+std::size_t get_file_size( guard::native_handle_t const file_handle )
+{
+#ifdef _WIN32
+ DWORD const file_size( ::GetFileSize( file_handle, 0 ) );
+ BOOST_ASSERT( ( file_size != INVALID_FILE_SIZE ) || ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) );
+ return file_size;
+#else
+
+#endif // _WIN32
+}
+
+
+unsigned int const file_flags::handle_access_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_READ , O_RDONLY );
+unsigned int const file_flags::handle_access_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_WRITE , O_WRONLY );
+unsigned int const file_flags::handle_access_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_EXECUTE, O_RDONLY );
+
+unsigned int const file_flags::share_mode::none = BOOST_AUX_IO_WIN32_OR_POSIX( 0 , 0 );
+unsigned int const file_flags::share_mode::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_READ , 0 );
+unsigned int const file_flags::share_mode::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_WRITE , 0 );
+unsigned int const file_flags::share_mode::remove = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_DELETE, 0 );
+
+unsigned int const file_flags::system_hints::random_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_RANDOM_ACCESS , O_RANDOM );
+unsigned int const file_flags::system_hints::sequential_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_SEQUENTIAL_SCAN , O_SEQUENTIAL );
+unsigned int const file_flags::system_hints::non_cached = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, O_DIRECT );
+unsigned int const file_flags::system_hints::delete_on_close = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_DELETE_ON_CLOSE , O_TEMPORARY );
+unsigned int const file_flags::system_hints::temporary = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_TEMPORARY , O_SHORT_LIVED );
+
+unsigned int const file_flags::on_construction_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_READONLY, S_IRUSR );
+unsigned int const file_flags::on_construction_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IWUSR );
+unsigned int const file_flags::on_construction_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IXUSR );
+
+file_flags file_flags::create
+(
+ unsigned int const handle_access_flags ,
+ unsigned int const share_mode ,
+ open_policy const open_flags ,
+ unsigned int const system_hints ,
+ unsigned int const on_construction_rights
+)
+{
+ file_flags const flags =
+ {
+ #ifdef _WIN32
+ handle_access_flags, // desired_access
+ share_mode, // share_mode
+ open_flags, // creation_disposition
+ system_hints
+ ||
+ (
+ ( on_construction_rights & FILE_ATTRIBUTE_NORMAL )
+ ? ( on_construction_rights & ~FILE_ATTRIBUTE_READONLY )
+ : on_construction_rights
+ ) // flags_and_attributes
+ #else
+ ( ( handle_access_flags == O_RDONLY | O_WRONLY ) ? O_RDWR : handle_access_flags )
+ ||
+ open_flags
+ ||
+ system_hints,
+ on_construction_rights
+ #endif // _WIN32
+ };
+
+ return flags;
+}
+
+
+file_flags file_flags::create_for_opening_existing_files( unsigned int const handle_access_flags, unsigned int const share_mode , bool const truncate, unsigned int const system_hints )
+{
+ return create( handle_access_flags, share_mode, truncate ? open_and_truncate_existing : open_existing, system_hints, 0 );
+}
+
+
+unsigned int const mapping_flags::handle_access_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_READ , PROT_READ );
+unsigned int const mapping_flags::handle_access_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_WRITE , PROT_WRITE );
+unsigned int const mapping_flags::handle_access_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_EXECUTE, PROT_EXEC );
+
+unsigned int const mapping_flags::share_mode::shared = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_SHARED );
+unsigned int const mapping_flags::share_mode::hidden = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_COPY, MAP_PRIVATE );
+
+unsigned int const mapping_flags::system_hint::strict_target_address = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_FIXED );
+unsigned int const mapping_flags::system_hint::lock_to_ram = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , MAP_LOCKED );
+unsigned int const mapping_flags::system_hint::reserve_page_file_space = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_RESERVE, /*khm#1*/MAP_NORESERVE );
+unsigned int const mapping_flags::system_hint::precommit = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , MAP_POPULATE );
+unsigned int const mapping_flags::system_hint::uninitialized = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_UNINITIALIZED );
+
+
+mapping_flags mapping_flags::create
+(
+ unsigned int handle_access_flags,
+ unsigned int share_mode ,
+ unsigned int system_hints
+)
+{
+ mapping_flags flags;
+#ifdef _WIN32
+ flags.create_mapping_flags = ( handle_access_flags & handle_access_rights::execute ) ? PAGE_EXECUTE : PAGE_NOACCESS;
+ if ( share_mode & share_mode::hidden ) // WRITECOPY
+ flags.create_mapping_flags *= 8;
+ else
+ if ( handle_access_flags & handle_access_rights::write )
+ flags.create_mapping_flags *= 4;
+ else
+ //if ( handle_access_flags & handle_access_rights::read )
+ flags.create_mapping_flags *= 2;
+
+ flags.create_mapping_flags |= system_hints;
+
+ flags.map_view_flags = handle_access_flags;
+#else
+ flags.protection = handle_access_rights;
+ flags.flags = share_mode | system_hints;
+ if ( ( system_hints & system_hint::reserve_page_file_space ) ) /*khm#1*/
+ flags.flags &= ~MAP_NORESERVE;
+ else
+ flags.flags |= MAP_NORESERVE;
+#endif // _WIN32
+
+ return flags;
+}
+
+
+memory_mapping::memory_mapping
+(
+ guard::native_handle_t const object_handle,
+ mapping_flags const & flags,
+ std::size_t const desired_size
+)
+{
+#ifdef _WIN32
+ // Implementation note:
+ // Mapped views hold internal references to the following handles so we do
+ // not need to hold/store them ourselves:
+ // http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
+ // (26.03.2010.) (Domagoj Saric)
+
+ // CreateFileMapping accepts INVALID_HANDLE_VALUE as valid input but only if
+ // the size parameter is not null.
+ guard::windows_handle const mapping
+ (
+ ::CreateFileMapping( object_handle, 0, flags.create_mapping_flags, 0, desired_size, 0 )
+ );
+ BOOST_ASSERT
+ (
+ !mapping.handle() || ( object_handle == INVALID_HANDLE_VALUE ) || ( desired_size != 0 )
+ );
+
+ BOOST_ASSERT( this->empty() );
+
+ iterator const view_start( static_cast<iterator>( ::MapViewOfFile( mapping.handle(), flags.map_view_flags, 0, 0, desired_size ) ) );
+ iterator const view_end
+ (
+ ( view_start && ( object_handle != INVALID_HANDLE_VALUE ) )
+ ? view_start + desired_size
+ : view_start
+ );
+ /// \todo Convert these constructors to factory functions to avoid the
+ /// anti-pattern of a fallible-yet-nonthrowing constructor.
+ /// (10.10.2010.) (Domagoj Saric)
+ iterator_range::operator = ( iterator_range( view_start, view_end ) );
+#else
+
+#endif // _WIN32
+}
+
+
+memory_mapping::~memory_mapping()
+{
+#ifdef _WIN32
+ BOOST_VERIFY( ::UnmapViewOfFile( begin() ) || this->empty() );
+#else
+
+#endif // _WIN32
+}
+
+
+memory_mapped_source::memory_mapped_source( guard::native_handle_t const object_handle, unsigned int const desiredSize )
+ :
+ memory_mapping
+ (
+ object_handle,
+ mapping_flags::create
+ (
+ mapping_flags::handle_access_rights::read,
+ mapping_flags::share_mode::shared,
+ mapping_flags::system_hint::uninitialized
+ ),
+ desiredSize
+ )
+{
+}
+
+
+memory_mapped_source map_read_only_file( char const * const file_name )
+{
+ using namespace guard;
+
+ native_handle_guard const file_handle
+ (
+ create_file
+ (
+ file_name,
+ file_flags::create_for_opening_existing_files
+ (
+ file_flags::handle_access_rights::read,
+ file_flags::share_mode ::read,
+ false,
+ file_flags::system_hints ::sequential_access
+ )
+ )
+ );
+
+ return memory_mapped_source( file_handle.handle(), get_file_size( file_handle.handle() ) );
+}
+
+
+//------------------------------------------------------------------------------
+} // boost
+//------------------------------------------------------------------------------

Added: sandbox/gil/boost/gil/extension/io2/detail/memory_mapping.hpp
==============================================================================
--- (empty file)
+++ sandbox/gil/boost/gil/extension/io2/detail/memory_mapping.hpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -0,0 +1,275 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file memory_mapping.hpp
+/// ------------------------
+///
+/// Copyright (c) Domagoj Saric 2010.
+///
+/// Use, modification and distribution is subject to the Boost Software License, Version 1.0.
+/// (See accompanying file LICENSE_1_0.txt or copy at
+/// http://www.boost.org/LICENSE_1_0.txt)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#pragma once
+#ifndef memory_mapping_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
+#define memory_mapping_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
+//------------------------------------------------------------------------------
+#include "boost/assert.hpp"
+#include "boost/noncopyable.hpp"
+#include "boost/range/iterator_range.hpp"
+
+#ifndef _WIN32
+ #include "fcntl.h"
+#endif // _WIN32
+
+#ifdef _WIN32
+ #define BOOST_AUX_IO_WIN32_OR_POSIX( win32, posix ) win32
+#else
+ #define BOOST_AUX_IO_WIN32_OR_POSIX( win32, posix ) posix
+#endif
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+
+// Implementation note:
+// Using structs with public members and factory functions to enable (almost)
+// zero-overhead 'link-time' conversion to native flag formats and to allow the
+// user to modify the created flags or create fully custom ones so that specific
+// platform-dependent use-cases, not otherwise covered through the generic
+// interface, can also be covered.
+// (10.10.2010.) (Domagoj Saric)
+
+struct file_flags
+{
+ struct handle_access_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ struct share_mode
+ {
+ static unsigned int const none ;
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const remove;
+ };
+
+ enum open_policy
+ {
+ create_new = BOOST_AUX_IO_WIN32_OR_POSIX( 1, O_CREAT | O_EXCL ),
+ create_new_or_truncate_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 2, O_CREAT | O_TRUNC ),
+ open_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 3, 0 ),
+ open_or_create = BOOST_AUX_IO_WIN32_OR_POSIX( 4, O_CREAT ),
+ open_and_truncate_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 5, O_TRUNC )
+ };
+
+ struct system_hints
+ {
+ static unsigned int const random_access ;
+ static unsigned int const sequential_access;
+ static unsigned int const non_cached ;
+ static unsigned int const delete_on_close ;
+ static unsigned int const temporary ;
+ };
+
+ struct on_construction_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ static file_flags create
+ (
+ unsigned int handle_access_flags ,
+ unsigned int share_mode ,
+ open_policy ,
+ unsigned int system_hints ,
+ unsigned int on_construction_rights
+ );
+
+ static file_flags create_for_opening_existing_files
+ (
+ unsigned int handle_access_flags,
+ unsigned int share_mode ,
+ bool truncate ,
+ unsigned int system_hints
+ );
+
+#ifdef _WIN32
+ unsigned long desired_access ;
+ unsigned long share_mode ;
+ unsigned long creation_disposition;
+ unsigned long flags_and_attributes;
+#else
+ int oflag;
+ int pmode;
+#endif // _WIN32
+};
+
+struct mapping_flags
+{
+ struct handle_access_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ struct share_mode
+ {
+ static unsigned int const shared;
+ static unsigned int const hidden;
+ };
+
+ struct system_hint
+ {
+ static unsigned int const strict_target_address ;
+ static unsigned int const lock_to_ram ;
+ static unsigned int const reserve_page_file_space;
+ static unsigned int const precommit ;
+ static unsigned int const uninitialized ;
+ };
+
+ static mapping_flags create
+ (
+ unsigned int handle_access_rights,
+ unsigned int share_mode ,
+ unsigned int system_hints
+ );
+
+#ifdef _WIN32
+ unsigned int create_mapping_flags;
+ unsigned int map_view_flags;
+#else
+ int protection;
+ int flags ;
+#endif // _WIN32
+};
+
+namespace guard
+{
+//------------------------------------------------------------------------------
+
+#ifdef _WIN32
+class windows_handle : noncopyable
+{
+public:
+ typedef void * handle_t;
+
+ explicit windows_handle( handle_t );
+ ~windows_handle();
+
+ handle_t const & handle() const;
+
+private:
+ handle_t const handle_;
+};
+#endif // _WIN32
+
+class posix_handle : noncopyable
+{
+public:
+ typedef int handle_t;
+
+ explicit posix_handle( handle_t );
+
+ #ifdef _WIN32
+ explicit posix_handle( windows_handle::handle_t );
+ #endif // _WIN32
+
+ ~posix_handle();
+
+ handle_t const & handle() const;
+
+private:
+ handle_t const handle_;
+};
+
+
+#ifdef _WIN32
+ typedef windows_handle native_handle_guard;
+#else
+ typedef posix_handle native_handle_guard;
+#endif // _WIN32
+typedef native_handle_guard::handle_t native_handle_t;
+
+
+native_handle_guard create_file( char const * file_name, file_flags const & );
+native_handle_guard create_file( char const * file_name, file_flags const &, unsigned int desired_size );
+
+//------------------------------------------------------------------------------
+} // namespace guard
+
+bool set_file_size( guard::native_handle_t, std::size_t desired_size );
+std::size_t get_file_size( guard::native_handle_t );
+
+
+typedef iterator_range<unsigned char const *> memory_chunk_t;//...zzz...this implicitly constructs from a string literal...
+typedef iterator_range<unsigned char *> writable_memory_chunk_t;
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class memory_mapping
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class memory_mapping
+ :
+ private writable_memory_chunk_t,
+ private boost::noncopyable
+{
+public:
+ memory_mapping
+ (
+ guard::native_handle_t,
+ mapping_flags const &,
+ unsigned int desired_size
+ );
+ ~memory_mapping();
+
+ operator writable_memory_chunk_t const & () const { return memory_range(); }
+
+protected:
+ writable_memory_chunk_t const & memory_range() const { return *this; }
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class memory_mapped_source
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class memory_mapped_source : private memory_mapping
+{
+public:
+ memory_mapped_source( guard::native_handle_t, unsigned int desired_size );
+
+ operator memory_chunk_t const & () const
+ {
+ //writable_memory_chunk_t const & writable( *this );
+ writable_memory_chunk_t const & writable( memory_mapping::memory_range() );
+ memory_chunk_t const & readonly( reinterpret_cast<memory_chunk_t const &>( writable ) );
+ BOOST_ASSERT( readonly == writable );
+ return readonly;
+ }
+
+protected:
+ memory_chunk_t const & memory_range() const { return *this; }
+};
+
+
+memory_mapped_source map_read_only_file( char const * file_name );
+
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+#endif // memory_mapping_hpp

Modified: sandbox/gil/boost/gil/extension/io2/detail/shared.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/shared.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/shared.hpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -19,7 +19,6 @@
 #ifndef shared_hpp__DA4F9174_EBAA_43E8_BEDD_A273BBA88CE7
 #define shared_hpp__DA4F9174_EBAA_43E8_BEDD_A273BBA88CE7
 //------------------------------------------------------------------------------
-#include <boost/range/iterator_range.hpp>
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -45,10 +44,6 @@
 
 //------------------------------------------------------------------------------
 } // namespace detail
-
-typedef iterator_range<unsigned char const *> memory_chunk_t;
-typedef iterator_range<unsigned char *> writable_memory_chunk_t;
-
 //------------------------------------------------------------------------------
 } // namespace gil
 //------------------------------------------------------------------------------

Modified: sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -18,7 +18,7 @@
 #ifndef windows_shared_hpp__9337A434_D2F6_43F2_93C8_4CE66C07B74D
 #define windows_shared_hpp__9337A434_D2F6_43F2_93C8_4CE66C07B74D
 //------------------------------------------------------------------------------
-#include "shared.hpp"
+#include "windows_shared_istreams.hpp"
 
 #include "boost/array.hpp"
 #include "boost/assert.hpp"

Modified: sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -19,7 +19,9 @@
 #ifndef windows_shared_istreams_hpp__A8D022F0_BBFA_4496_8252_8FD1F6A28DF7
 #define windows_shared_istreams_hpp__A8D022F0_BBFA_4496_8252_8FD1F6A28DF7
 //------------------------------------------------------------------------------
-#include "shared.hpp"
+#include "boost/gil/utilities.hpp"
+
+#include "boost/range/iterator_range.hpp"
 
 #include "objbase.h"
 #include "objidl.h"
@@ -27,6 +29,11 @@
 //------------------------------------------------------------------------------
 namespace boost
 {
+
+//...zzz...duplicated from memory_mapping.hpp...clean this up...
+typedef iterator_range<unsigned char const *> memory_chunk_t;
+typedef iterator_range<unsigned char *> writable_memory_chunk_t;
+
 //------------------------------------------------------------------------------
 namespace gil
 {
@@ -304,8 +311,8 @@
     }
 
 protected:
- unsigned char * pCurrentPosition_;
- writable_memory_chunk_t const memory_chunk_;
+ unsigned char * pCurrentPosition_;
+ writable_memory_chunk_t const memory_chunk_ ;
 };
 
 

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 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -281,20 +281,19 @@
 
     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<writable_memory_chunk_t const &, detail::writable_memory_chunk_for_IStream_extender<gp_image> >
+ 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_chunk_t const &, detail::memory_chunk_for_IStream_extender<gp_image> >
> readers;
 
- typedef mpl::map5
+ 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>,
- mpl::pair<memory_chunk_t const &, detail::gp_writer>
+ mpl::pair<FILE &, detail::gp_writer>
> writers;
 
     typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
@@ -323,13 +322,15 @@
         template <typename View>
         void set_bitmapdata_for_view( View const & view )
         {
+ using namespace detail;
+
             BOOST_STATIC_ASSERT( is_supported<typename get_original_view_t<View>::type>::value );
 
             Width = view.width();
             Height = view.height();
             Stride = view.pixels().row_size();
             PixelFormat = view_to_native_format::apply<View>::value;
- Scan0 = detail::formatted_image_base::get_raw_data( view );
+ 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 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -423,10 +423,11 @@
     template <class View>
     struct is_supported : mpl::bool_<view_to_native_format::apply<View>::value != JCS_UNKNOWN> {};
 
- typedef mpl::map2
+ typedef mpl::map3
             <
- mpl::pair<FILE &, libjpeg_image>,
- mpl::pair<char const *, libjpeg_image>
+ mpl::pair<memory_chunk_t const &, detail::seekable_input_memory_range_extender<libjpeg_image> >,
+ mpl::pair<FILE &, libjpeg_image >,
+ mpl::pair<char const *, detail::input_c_str_for_mmap_extender <libjpeg_image> >
> readers;
 
     typedef mpl::map2
@@ -536,7 +537,7 @@
     //}
 
 public: /// \ingroup Construction
- explicit libjpeg_image( FILE & file )
+ explicit libjpeg_image( memory_chunk_t & memory_chunk )
         :
         libjpeg_base( for_decompressor() )
     {
@@ -545,23 +546,21 @@
                 throw_jpeg_error();
         #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
 
- setup_source( file );
+ setup_source( memory_chunk );
 
         read_header();
     }
 
- explicit libjpeg_image( char const * const file_name )
+ explicit libjpeg_image( FILE & file )
         :
         libjpeg_base( for_decompressor() )
     {
- BOOST_ASSERT( file_name );
-
         #ifndef BOOST_GIL_THROW_THROUGH_C_SUPPORTED
             if ( setjmp( error_handler_target() ) )
                 throw_jpeg_error();
         #endif // BOOST_GIL_THROW_THROUGH_C_SUPPORTED
 
- setup_source( file_name );
+ setup_source( file );
 
         read_header();
     }
@@ -621,6 +620,8 @@
     template <class MyView, class TargetView, class Converter>
     void generic_convert_to_prepared_view( TargetView const & view, Converter const & converter ) const
     {
+ using namespace detail;
+
         typedef typename MyView::value_type pixel_t;
         std::size_t const scanline_length ( decompressor().image_width * decompressor().num_components );
         scoped_ptr<JSAMPLE> const p_scanline_buffer( new JSAMPLE[ scanline_length ] );
@@ -651,8 +652,10 @@
         {
             read_scanline( scanline );
 
- pixel_t const * p_source_pixel( gil_reinterpret_cast_c<pixel_t const *>( scanline ) );
- typename TargetView::x_iterator p_target_pixel( view.row_begin( scanline_index ) );
+ typedef typename get_original_view_t<TargetView>::type::x_iterator target_x_iterator;
+
+ pixel_t const * p_source_pixel( gil_reinterpret_cast_c<pixel_t const *>( scanline ) );
+ target_x_iterator p_target_pixel( original_view( view ).row_begin( scanline_index ) );
             while ( p_source_pixel < gil_reinterpret_cast_c<pixel_t const *>( scanlineEnd ) )
             {
                 converter( *p_source_pixel, *p_target_pixel );
@@ -797,19 +800,35 @@
     // Unextracted "libjpeg_reader" interface.
     void setup_source()
     {
- source_manager_.next_input_byte = read_buffer_.begin();
- source_manager_.bytes_in_buffer = 0;
-
         BOOST_ASSERT( decompressor().src == NULL );
         decompressor().src = &source_manager_;
     }
 
+ void setup_source( memory_chunk_t & memory_chunk )
+ {
+ setup_source();
+
+ decompressor().client_data = &memory_chunk;
+
+ source_manager_.next_input_byte = memory_chunk.begin();
+ source_manager_.bytes_in_buffer = memory_chunk.size ();
+
+ source_manager_.init_source = &init_memory_chunk_source;
+ source_manager_.fill_input_buffer = &fill_memory_chunk_buffer;
+ source_manager_.skip_input_data = &skip_memory_chunk_data ;
+ source_manager_.resync_to_restart = &jpeg_resync_to_restart ;
+ source_manager_.term_source = &term_memory_chunk_source;
+ }
+
     void setup_source( FILE & file )
     {
         setup_source();
 
         decompressor().client_data = &file;
 
+ source_manager_.next_input_byte = read_buffer_.begin();
+ source_manager_.bytes_in_buffer = 0;
+
         source_manager_.init_source = &init_FILE_source ;
         source_manager_.fill_input_buffer = &fill_FILE_buffer ;
         source_manager_.skip_input_data = &skip_FILE_data ;
@@ -817,14 +836,6 @@
         source_manager_.term_source = &term_FILE_source ;
     }
 
- void setup_source( char const * const p_file_name )
- {
- FILE * const p_file( /*std*/::fopen( p_file_name, "rb" ) );
- if ( !p_file )
- throw_jpeg_error();
- setup_source( *p_file );
- source_manager_.term_source = &term_and_close_FILE_source;
- }
 
     static void __cdecl init_FILE_source( j_decompress_ptr const p_cinfo )
     {
@@ -883,7 +894,7 @@
         }
     }
 
- static void __cdecl term_FILE_source( j_decompress_ptr /*p_cinfo*/ )
+ static void __cdecl term_FILE_source( j_decompress_ptr /*p_cinfo*/ )
     {
     }
 
@@ -894,6 +905,70 @@
         BOOST_VERIFY( /*std*/::fclose( static_cast<FILE *>( reader( p_cinfo ).decompressor().client_data ) ) == 0 );
     }
 
+ static void __cdecl init_memory_chunk_source( j_decompress_ptr /*p_cinfo*/ )
+ {
+ }
+
+ static boolean __cdecl fill_memory_chunk_buffer( j_decompress_ptr const p_cinfo )
+ {
+ libjpeg_image & reader( reader( p_cinfo ) );
+
+ memory_chunk_t & memory_chunk( *static_cast<memory_chunk_t *>( reader.decompressor().client_data ) );
+
+ std::size_t const read_size
+ (
+ std::min<std::size_t>
+ (
+ reader.read_buffer_.size(),
+ memory_chunk .size()
+ )
+ );
+
+ std::memcpy( reader.read_buffer_.begin(), memory_chunk.begin(), read_size );
+ memory_chunk.advance_begin( read_size );
+
+ if ( read_size != 0 )
+ {
+ reader.source_manager_.next_input_byte = memory_chunk.begin();
+ reader.source_manager_.bytes_in_buffer = read_size;
+ }
+ else
+ {
+ // Insert a fake EOI marker (see the comment for the default library
+ // implementation).
+ static unsigned char const fake_eoi[ 2 ] = { 0xFF, JPEG_EOI };
+ reader.source_manager_.next_input_byte = fake_eoi;
+ reader.source_manager_.bytes_in_buffer = 2;
+ }
+
+ return true;
+ }
+
+ static void __cdecl skip_memory_chunk_data( j_decompress_ptr const p_cinfo, long num_bytes )
+ {
+ libjpeg_image & reader( reader( p_cinfo ) );
+
+ if ( static_cast<std::size_t>( num_bytes ) <= reader.source_manager_.bytes_in_buffer )
+ {
+ reader.source_manager_.next_input_byte += num_bytes;
+ reader.source_manager_.bytes_in_buffer -= num_bytes;
+ }
+ else
+ {
+ memory_chunk_t & memory_chunk( *static_cast<memory_chunk_t *>( reader.decompressor().client_data ) );
+
+ num_bytes -= reader.source_manager_.bytes_in_buffer;
+ BOOST_ASSERT( num_bytes <= memory_chunk.size() ); //...failure?
+ memory_chunk.advance_begin( num_bytes );
+ reader.source_manager_.next_input_byte = memory_chunk.begin();
+ reader.source_manager_.bytes_in_buffer = 0;
+ }
+ }
+
+ static void __cdecl term_memory_chunk_source( j_decompress_ptr /*p_cinfo*/ )
+ {
+ }
+
     static libjpeg_image & reader( j_decompress_ptr const p_cinfo )
     {
         libjpeg_image & reader( static_cast<libjpeg_image &>( base( gil_reinterpret_cast<j_common_ptr>( p_cinfo ) ) ) );
@@ -903,7 +978,7 @@
 
 private:
     jpeg_source_mgr source_manager_;
- array<JOCTET, 4096> read_buffer_ ;
+ array<JOCTET, 4096> read_buffer_ ;//...zzz...extract to a wrapper...not needed for in memory sources...
 };
 
 #if defined(BOOST_MSVC)

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 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -213,8 +213,6 @@
 ///
 /// \class libpng_base
 ///
-/// \brief
-///
 ////////////////////////////////////////////////////////////////////////////////
 
 class libpng_base : public lib_object_t
@@ -230,6 +228,7 @@
         lib_object_t( p_png, ::png_create_info_struct( p_png ) )
     {}
 
+ //...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 )
@@ -392,15 +391,16 @@
     template <class View>
     struct is_supported : detail::is_view_supported<View> {};
 
- typedef mpl::map2
+ typedef mpl::map3
             <
- mpl::pair<FILE &, libpng_image >,
- mpl::pair<char const *, detail::input_c_str_for_c_file_extender<libpng_image> >
+ mpl::pair<memory_chunk_t const &, detail::seekable_input_memory_range_extender<libpng_image> >,
+ mpl::pair<FILE &, libpng_image >,
+ mpl::pair<char const *, detail::input_c_str_for_mmap_extender <libpng_image> >
> readers;
 
     typedef mpl::map2
             <
- mpl::pair<FILE &, detail::libpng_writer_FILE >,
+ mpl::pair<FILE &, detail::libpng_writer_FILE >,
                 mpl::pair<char const *, detail::output_c_str_for_c_file_extender<detail::libpng_writer_FILE> >
> writers;
 
@@ -488,7 +488,7 @@
             cleanup_and_throw_libpng_error();
 
         #ifdef PNG_NO_STDIO
- ::png_set_read_fn( &png_object(), &file, &png_read_data );
+ ::png_set_read_fn( &png_object(), &file, &png_FILE_read_data );
         #else
             ::png_init_io( &png_object(), &file );
         #endif
@@ -496,6 +496,18 @@
         init();
     }
 
+ explicit libpng_image( memory_chunk_t & in_memory_image )
+ :
+ libpng_base( ::png_create_read_struct_2( PNG_LIBPNG_VER_STRING, NULL, &detail::png_error_function, &detail::png_warning_function, NULL, NULL, NULL ) )
+ {
+ if ( !successful_creation() )
+ cleanup_and_throw_libpng_error();
+ //png_rw_ptr
+ ::png_set_read_fn( &png_object(), &in_memory_image, &png_memory_chunk_read_data );
+
+ init();
+ }
+
     ~libpng_image()
     {
         destroy_read_struct();
@@ -692,9 +704,10 @@
         ::png_read_row( &png_object(), p_row, NULL );
     }
 
- static void PNGAPI png_read_data( png_structp const png_ptr, png_bytep const data, png_size_t const length )
+ static void PNGAPI png_FILE_read_data( png_structp const png_ptr, png_bytep const data, png_size_t const length )
     {
- BOOST_ASSERT( png_ptr );
+ BOOST_ASSERT( png_ptr );
+ BOOST_ASSERT( png_ptr->io_ptr );
 
         png_size_t const read_size
         (
@@ -704,6 +717,22 @@
         if ( read_size != length )
             detail::png_error_function( png_ptr, "Read Error" );
     }
+
+ static void PNGAPI png_memory_chunk_read_data( png_structp const png_ptr, png_bytep const data, png_size_t const length )
+ {
+ BOOST_ASSERT( png_ptr );
+ BOOST_ASSERT( png_ptr->io_ptr );
+
+ memory_chunk_t & memory_chunk( *static_cast<memory_chunk_t *>( png_ptr->io_ptr ) );
+
+ if ( length <= static_cast<std::size_t>( memory_chunk.size() ) )
+ {
+ std::memcpy( data, memory_chunk.begin(), length );
+ memory_chunk.advance_begin( length );
+ }
+ else
+ detail::png_error_function( png_ptr, "Read Error" );
+ }
 };
 
 

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 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -198,7 +198,7 @@
 
 inline int FILE_map_proc( thandle_t /*handle*/, tdata_t * /*pbase*/, toff_t * /*psize*/ )
 {
- return 0;
+ return false;
 }
 
 inline void FILE_unmap_proc( thandle_t /*handle*/, tdata_t /*base*/, toff_t /*size*/ )
@@ -206,6 +206,54 @@
 }
 
 
+inline tsize_t memory_read_proc( thandle_t /*handle*/, tdata_t /*buf*/, tsize_t /*size*/ )
+{
+ BOOST_ASSERT( !"Should not get called." );
+ __assume( false );
+ return 0;
+}
+
+inline tsize_t memory_write_proc( thandle_t /*handle*/, tdata_t /*buf*/, tsize_t /*size*/ )
+{
+ BOOST_ASSERT( !"Should not get called." );
+ __assume( false );
+ return 0;
+}
+
+inline toff_t memory_seek_proc( thandle_t /*handle*/, toff_t /*off*/, int /*whence*/ )
+{
+ BOOST_ASSERT( !"Should not get called." );
+ __assume( false );
+ return 0;
+}
+
+inline int memory_close_proc( thandle_t /*handle*/ )
+{
+ return 0;
+}
+
+inline toff_t memory_size_proc( thandle_t /*handle*/ )
+{
+ BOOST_ASSERT( !"Should not get called." );
+ __assume( false );
+ return 0;
+}
+
+inline int memory_map_proc( thandle_t const handle, tdata_t * const pbase, toff_t * const psize )
+{
+ BOOST_ASSERT( handle );
+ BOOST_ASSERT( pbase );
+ BOOST_ASSERT( psize );
+ *pbase = static_cast<tdata_t>( const_cast<memory_chunk_t::value_type *>( gil_reinterpret_cast<memory_chunk_t *>( handle )->begin() ) );
+ *psize = gil_reinterpret_cast<memory_chunk_t *>( handle )->size ();
+ return true;
+}
+
+inline void memory_unmap_proc( thandle_t /*handle*/, tdata_t /*base*/, toff_t /*size*/ )
+{
+}
+
+
 #if defined(BOOST_MSVC)
 # pragma warning( push )
 # pragma warning( disable : 4127 ) // "conditional expression is constant"
@@ -313,6 +361,27 @@
         construction_check();
     }
 
+ explicit libtiff_base( memory_chunk_t & in_memory_image )
+ :
+ p_tiff_
+ (
+ ::TIFFClientOpen
+ (
+ "", "M",
+ &in_memory_image,
+ &detail::memory_read_proc,
+ &detail::memory_write_proc,
+ &detail::memory_seek_proc,
+ &detail::memory_close_proc,
+ &detail::memory_size_proc,
+ &detail::memory_map_proc,
+ &detail::memory_unmap_proc
+ )
+ )
+ {
+ construction_check();
+ }
+
     __declspec( nothrow )
     ~libtiff_base()
     {
@@ -516,9 +585,7 @@
         unsigned const bits_per_sample ( get_field<uint16>( TIFFTAG_BITSPERSAMPLE ) );
         unsigned const sample_format ( get_field<uint16>( TIFFTAG_SAMPLEFORMAT ) );
         unsigned const planar_configuration( get_field<uint16>( TIFFTAG_PLANARCONFIG ) );
- //...mrmlj...
- unsigned /*const*/ photometric ( get_field<uint16>( TIFFTAG_PHOTOMETRIC ) ); if ( photometric == PHOTOMETRIC_MINISWHITE ) photometric = PHOTOMETRIC_MINISBLACK;
-
+ unsigned const photometric ( get_field<uint16>( TIFFTAG_PHOTOMETRIC ) );
         unsigned const orientation ( get_field<uint16>( TIFFTAG_ORIENTATION ) );
 
         unsigned ink_set( 0 );

Modified: sandbox/gil/boost/gil/extension/io2/wic_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/wic_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/wic_image.hpp 2010-10-10 11:10:08 EDT (Sun, 10 Oct 2010)
@@ -307,20 +307,19 @@
 
     typedef mpl::map6
     <
- mpl::pair<char const *, wic_image >,
- mpl::pair<wchar_t const *, wic_image >,
- mpl::pair<HANDLE , wic_image >,
- mpl::pair<IStream &, wic_image >,
- mpl::pair<FILE &, detail::input_FILE_for_IStream_extender <wic_image> >,
- mpl::pair<writable_memory_chunk_t const &, detail::writable_memory_chunk_for_IStream_extender<wic_image> >
+ mpl::pair<char const *, wic_image >,
+ mpl::pair<wchar_t const *, wic_image >,
+ mpl::pair<HANDLE , wic_image >,
+ mpl::pair<IStream &, wic_image >,
+ mpl::pair<FILE &, detail::input_FILE_for_IStream_extender <wic_image> >,
+ mpl::pair<memory_chunk_t const &, detail::memory_chunk_for_IStream_extender<wic_image> >
> readers;
 
- typedef mpl::map4
+ typedef mpl::map3
     <
         mpl::pair<char const *, detail::output_c_str_for_c_file_extender<detail::output_FILE_for_IStream_extender <detail::wic_writer> > >,
         mpl::pair<IStream &, detail::wic_writer >,
- mpl::pair<FILE &, detail::output_FILE_for_IStream_extender <detail::wic_writer> >,
- mpl::pair<memory_chunk_t const &, detail::memory_chunk_for_IStream_extender<detail::wic_writer> >
+ mpl::pair<FILE &, detail::output_FILE_for_IStream_extender <detail::wic_writer> >
> writers;
 
     typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
@@ -418,6 +417,7 @@
         typedef point2<std::ptrdiff_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 ) );
         verify_result( frame_decoder().GetSize( gil_reinterpret_cast<UINT *>( &result.x ), gil_reinterpret_cast<UINT *>( &result.y ) ) );
         return result;
     }


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