|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65784 - in sandbox/gil/boost/gil/extension/io2: . detail
From: dsaritz_at_[hidden]
Date: 2010-10-06 12:17:47
Author: psiha
Date: 2010-10-06 12:17:45 EDT (Wed, 06 Oct 2010)
New Revision: 65784
URL: http://svn.boost.org/trac/boost/changeset/65784
Log:
Added file format selection functionality to writer implementations.
Refactored the writer wrapper classes and related functionality to better support the above change and writers/backends with only one supported file format.
Added the detail::is_offset_view<> metafunction.
Added a missing formatted_image<>::subview_for_offset<>() overload.
Fixed the formatted_image<>::convert_to_prepared_view_worker<>() member function.
Added the new accumulate_greater() utility member function to the cumulative_result class.
Fixed the LibTIFF backend format construction/deduction code.
Fixed the libtiff_image::generic_convert_to_prepared_view<>() member function.
Removed commented out code.
Added missing include directives.
Removed some no longer necessary debugging code.
Minor other refactoring and stylistic changes.
Added:
sandbox/gil/boost/gil/extension/io2/format_tags.hpp (contents, props changed)
Text files modified:
sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp | 21 +++
sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp | 7 +
sandbox/gil/boost/gil/extension/io2/formatted_image.hpp | 201 ++++++++++++++++++++++-----------------
sandbox/gil/boost/gil/extension/io2/gp_image.hpp | 69 +++++-------
sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp | 4
sandbox/gil/boost/gil/extension/io2/libpng_image.hpp | 5
sandbox/gil/boost/gil/extension/io2/libtiff_image.hpp | 118 ++++++++++++-----------
sandbox/gil/boost/gil/extension/io2/wic_image.hpp | 23 +++
8 files changed, 256 insertions(+), 192 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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -164,6 +164,13 @@
c_file_output_guard ( file_path ),
c_file_capable_class( c_file_guard::get() )
{}
+
+ template <typename A2> //...zzz...
+ output_c_str_for_c_file_extender( char const * const file_path, A2 const & a2 )
+ :
+ c_file_output_guard ( file_path ),
+ c_file_capable_class( c_file_guard::get(), a2 )
+ {}
};
@@ -178,11 +185,19 @@
public:
cumulative_result() : result_( true ) {}
- void accumulate( bool const new_result ) { result_ &= new_result; }
+ void accumulate( bool const new_result )
+ {
+ result_ &= new_result;
+ // Catch the error early when debugging...
+ BOOST_ASSERT( result_ );
+ }
+
template <typename T1, typename T2>
- void accumulate_equal( T1 const new_result, T2 const desired_result ) { accumulate( new_result == desired_result ); }
+ void accumulate_equal ( T1 const new_result, T2 const desired_result ) { accumulate( new_result == desired_result ); }
template <typename T>
- void accumulate_different( T const new_result, T const undesired_result ) { accumulate( new_result != undesired_result ); }
+ void accumulate_different( T const new_result, T const undesired_result ) { accumulate( new_result != undesired_result ); }
+ template <typename T1, typename T2>
+ void accumulate_greater ( T1 const new_result, T2 const threshold ) { accumulate( new_result > threshold ); }
void throw_if_error( char const * const description ) const { io_error_if_not( result_, description ); }
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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -119,6 +119,13 @@
FileWriteStream ( file ),
IStream_capable_class( static_cast<IStream &>( *this ) )
{}
+
+ template <typename A2> //...zzz...
+ output_FILE_for_IStream_extender( FILE & file, A2 const & a2 )
+ :
+ FileWriteStream ( file ),
+ IStream_capable_class( static_cast<IStream &>( *this ), a2 )
+ {}
};
Added: sandbox/gil/boost/gil/extension/io2/format_tags.hpp
==============================================================================
--- (empty file)
+++ sandbox/gil/boost/gil/extension/io2/format_tags.hpp 2010-10-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -0,0 +1,53 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file format_tags.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 format_tags_hpp__0635BCB5_83C1_493B_A29C_944BA9F4EF26
+#define format_tags_hpp__0635BCB5_83C1_493B_A29C_944BA9F4EF26
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace gil
+{
+//------------------------------------------------------------------------------
+
+//...zzz...synchronize changes with writer implementations...
+enum format_tag
+{
+ bmp,
+ gif,
+ jpeg,
+ png,
+ tiff,
+ tga,
+
+ number_of_known_formats
+};
+
+//struct bmp {};
+//struct gif {};
+//struct jpeg {};
+//struct png {};
+//struct tga {};
+//struct tiff {};
+
+//------------------------------------------------------------------------------
+} // namespace gil
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+#endif // format_tags_hpp
Modified: sandbox/gil/boost/gil/extension/io2/formatted_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/formatted_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/formatted_image.hpp 2010-10-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -19,10 +19,14 @@
#ifndef formatted_image_hpp__C34C1FB0_A4F5_42F3_9318_5805B88CFE49
#define formatted_image_hpp__C34C1FB0_A4F5_42F3_9318_5805B88CFE49
//------------------------------------------------------------------------------
+#include "format_tags.hpp"
#include "detail/io_error.hpp"
#include "detail/switch.hpp"
#include "boost/gil/extension/dynamic_image/any_image.hpp"
+#include "boost/gil/packed_pixel.hpp"
+#include "boost/gil/planar_pixel_iterator.hpp"
+#include "boost/gil/planar_pixel_reference.hpp"
#include "boost/gil/typedefs.hpp"
#include <boost/compressed_pair.hpp>
@@ -33,6 +37,7 @@
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/integral_c.hpp>
#include <boost/mpl/map.hpp>
+#include <boost/mpl/vector_c.hpp>
#ifdef _DEBUG
#include <boost/numeric/conversion/converter.hpp>
#include <boost/numeric/conversion/converter_policies.hpp>
@@ -56,37 +61,6 @@
struct ensure_formats_match {};
struct synchronize_formats {};
-
-//...zzz...test unrolled 24bit-16bit conversion
-//template <typename ChannelValue, typename Layout, typename BitField, typename ChannelRefVec>
-//void color_convert
-//(
-// pixel <ChannelValue, Layout> const & src,
-// packed_pixel<BitField, ChannelRefVec, Layout> & dst
-//)
-//{
-// struct bfield_t
-// {
-// BitField r : 5;
-// BitField g : 6;
-// BitField b : 5;
-// };
-// //BitField & fast_dst( reinterpret_cast<BitField &>( dst ) );
-// bfield_t & fast_dst( reinterpret_cast<bfield_t &>( dst._bitfield ) );
-//
-// unsigned char const source_max ( detail::unsigned_integral_max_value<ChannelValue>::value );
-// //unsigned char const rb_max( (1<<5)-1 );
-// //unsigned char const g_max( (1<<6)-1 );
-// unsigned int const rtmp( ( static_cast<unsigned short>( src[ 0 ] ) << 5 ) - src[ 0 ] );
-// unsigned int const btmp( ( static_cast<unsigned short>( src[ 2 ] ) << 5 ) - src[ 2 ] );
-// unsigned int const gtmp( ( static_cast<unsigned short>( src[ 1 ] ) << 6 ) - src[ 1 ] );
-//
-// fast_dst.r = ( rtmp / source_max ) + ( ( rtmp % source_max ) > ( source_max / 2 ) );
-// fast_dst.b = ( btmp / source_max ) + ( ( btmp % source_max ) > ( source_max / 2 ) );
-// fast_dst.g = ( gtmp / source_max ) + ( ( gtmp % source_max ) > ( source_max / 2 ) );
-//}
-
-
#if defined(BOOST_MSVC)
# pragma warning( push )
# pragma warning( disable : 4127 ) // "conditional expression is constant"
@@ -217,12 +191,12 @@
View const & original_view( View const & view ) { return view; }
template <typename Offset, class View>
-Offset const & get_offset( offset_view_t<View, Offset> const & offset_view ) { return offset_view.offset(); }
+Offset get_offset( View const & ) { return Offset(); }
template <typename Offset, class View>
-Offset get_offset( View const & ) { return Offset(); }
+Offset const & get_offset( offset_view_t<View, Offset> const & offset_view ) { return offset_view.offset(); }
template <typename Offset>
-Offset const & get_offset_x( Offset const & ) { return Offset(); }
+Offset get_offset_x( Offset const & ) { return Offset(); }
template <typename Offset>
Offset const & get_offset_x( point2<Offset> const & offset ) { return offset.x; }
@@ -242,67 +216,106 @@
NewView const & offset_new_view( NewView const & new_view, View const & ) { return new_view; }
+template <class View>
+struct is_offset_view : mpl::false_ {};
+
+template <class View, typename Offset>
+struct is_offset_view<offset_view_t<View, Offset> > : mpl::true_ {};
+
+
template <typename View > struct get_original_view_t;
template <typename Locator > struct get_original_view_t<image_view<Locator> > { typedef image_view<Locator> type; };
template <typename View, typename Offset> struct get_original_view_t<offset_view_t<View, Offset> > { typedef View type; };
-// Tag base classes for writer implementations.
-struct configure_on_write_writer {};
-struct open_on_write_writer {};
+
+////////////////////////////////////////////////////////////////////////////////
+// Wrappers that normalize wrapper interfaces.
+////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
///
-/// \class open_then_configure_writer_wrapper
+/// \class configure_on_write_writer
/// \internal
/// \brief Helper wrapper for backends/writers that first need to open the
/// target/file and then be configured for the desired view.
///
////////////////////////////////////////////////////////////////////////////////
-template <typename Writer, typename WriterTarget, typename ViewDataHolder>
-class open_then_configure_writer_wrapper : public Writer
+struct configure_on_write_writer
{
-public:
- template <typename View>
- open_then_configure_writer_wrapper( WriterTarget const target, View const & view )
- :
- Writer ( target ),
- view_data_( view )
- {}
+ template <typename Writer, typename WriterTarget, typename ViewDataHolder, format_tag DefaultFormat>
+ class wrapper : public Writer
+ {
+ public:
+ template <typename View>
+ wrapper( WriterTarget const & target, View const & view, format_tag const specified_format = DefaultFormat )
+ :
+ Writer ( target, specified_format ),
+ view_data_( view )
+ {}
- void write_default() { Writer::write_default( view_data_ ); }
- void write () { Writer::write ( view_data_ ); }
+ void write_default() { Writer::write_default( view_data_ ); }
+ void write () { Writer::write ( view_data_ ); }
-private:
- ViewDataHolder const view_data_;
+ private:
+ ViewDataHolder const view_data_;
+ };
+
+ template <typename Writer, typename WriterTarget, format_tag OnlyFormat>
+ class single_format_writer_wrapper : public Writer
+ {
+ public:
+ single_format_writer_wrapper( WriterTarget const & target, format_tag const specified_format = OnlyFormat )
+ :
+ Writer( target )
+ {
+ BOOST_VERIFY( specified_format == OnlyFormat );
+ }
+ };
};
////////////////////////////////////////////////////////////////////////////////
///
-/// \class configure_then_open_writer_wrapper
+/// \class open_on_write_writer
/// \internal
/// \brief Helper wrapper for backends/writers that first need to be configured
/// for/created from the desired view and then open the target/file.
///
////////////////////////////////////////////////////////////////////////////////
-template <typename Writer, typename WriterTarget>
-class configure_then_open_writer_wrapper : public Writer
+struct open_on_write_writer
{
-public:
- template <typename View>
- configure_then_open_writer_wrapper( WriterTarget const target, View const & view )
- :
- Writer ( view ),
- target_( target )
- {}
+ template <typename Writer, typename WriterTarget, typename ViewDataHolder, format_tag DefaultFormat>
+ class wrapper : public Writer
+ {
+ public:
+ template <typename View>
+ wrapper( WriterTarget const & target, View const & view, format_tag const specified_format = DefaultFormat )
+ :
+ Writer ( view ),
+ target_ ( target ),
+ specified_format_( specified_format )
+ {}
- void write_default() { Writer::write_default( target_ ); }
- void write () { Writer::write ( target_ ); }
+ void write_default() { Writer::write_default( target_, specified_format_ ); }
+ void write () { Writer::write ( target_, specified_format_ ); }
-private:
- WriterTarget const target_;
+ private:
+ typename call_traits<WriterTarget>::param_type const target_;
+ format_tag const specified_format_;
+ };
+
+ template <typename Writer, typename WriterTarget, format_tag OnlyFormat>
+ class single_format_writer_wrapper : public Writer
+ {
+ public:
+ template <typename View>
+ single_format_writer_wrapper( View const & view ) : Writer( view ) {}
+
+ void write_default( WriterTarget const & target, format_tag const specified_format = OnlyFormat ) { BOOST_VERIFY( specified_format == OnlyFormat ); Writer::write_default( target ); }
+ void write ( WriterTarget const & target, format_tag const specified_format = OnlyFormat ) { BOOST_VERIFY( specified_format == OnlyFormat ); Writer::write ( target ); }
+ };
};
@@ -312,7 +325,7 @@
///
////////////////////////////////////////////////////////////////////////////////
-class formatted_image_base : noncopyable
+class formatted_image_base : public /*khm private seems to bug MSVC++ 10 with the libtiff backend....*/ noncopyable
{
public:
typedef point2<std::ptrdiff_t> dimensions_t;
@@ -322,12 +335,8 @@
protected:
static bool dimensions_mismatch( dimensions_t const & mine, dimensions_t const & other ) { return mine != other; }
-
template <class View>
- static bool dimensions_mismatch( dimensions_t const & mine, View const & view )
- {
- return dimensions_mismatch( mine, view.dimensions() );
- }
+ static bool dimensions_mismatch( dimensions_t const & mine, View const & view ) { return dimensions_mismatch( mine, view.dimensions() ); }
template <class View, typename Offset>
static bool dimensions_mismatch( dimensions_t const & mine, offset_view_t<View, Offset> const & offset_view )
@@ -517,20 +526,32 @@
struct writer_for
{
private:
- typedef typename mpl::at<typename formatted_image_traits<Impl>::writers, Target>::type writer_t;
+ typedef typename formatted_image_traits<Impl>::supported_image_formats supported_image_formats;
+
+ BOOST_STATIC_CONSTANT( format_tag, default_format = mpl::front<supported_image_formats>::type::value );
+ BOOST_STATIC_CONSTANT( bool , single_format = mpl::size <supported_image_formats>::value == 1 );
+
+ typedef typename mpl::at
+ <
+ typename formatted_image_traits<Impl>::writers,
+ Target
+ >::type base_writer_t;
+
+ typedef typename mpl::if_c
+ <
+ single_format,
+ typename base_writer_t:: BOOST_NESTED_TEMPLATE single_format_writer_wrapper<base_writer_t, Target, default_format>,
+ base_writer_t
+ >::type first_layer_wrapper;
public:
- typedef typename mpl::if_
- <
- is_base_of<configure_on_write_writer, writer_t>,
- open_then_configure_writer_wrapper<writer_t, Target, typename formatted_image_traits<Impl>::writer_view_data_t>,
- typename mpl::if_
- <
- is_base_of<open_on_write_writer, writer_t>,
- configure_then_open_writer_wrapper<writer_t, Target>,
- writer_t
- >::type
- >::type type;
+ typedef typename base_writer_t::wrapper
+ <
+ first_layer_wrapper,
+ Target,
+ typename formatted_image_traits<Impl>::writer_view_data_t,
+ default_format
+ > type;
};
BOOST_STATIC_CONSTANT( bool, has_full_roi = (is_same<roi::offset_t, roi::point_t>::value) );
@@ -617,7 +638,7 @@
};
private:
- // ...zzz...MSVC++ 10 generates code to check whether this == 0.txt...investigate...
+ // ...zzz...MSVC++ 10 generates code to check whether this == 0...investigate...
Impl & impl() { __assume( this != 0 ); return static_cast<Impl &>( *this ); }
Impl const & impl() const { __assume( this != 0 ); return static_cast<Impl const &>( *this ); }
@@ -676,6 +697,9 @@
return finder.image_id_;
}
+ template <typename View>
+ static View const & subview_for_offset( View const & view ) { return view; }
+
template <typename View, typename Offset>
View subview_for_offset( offset_view_t<View, Offset> const & offset_view ) const
{
@@ -748,8 +772,7 @@
);
default_convert_to_worker( view, mpl::bool_<can_use_raw>() );
}
-
-
+
template <typename FormatConverter, typename View>
void copy_to( View const & view, ensure_dimensions_match, FormatConverter const & format_converter ) const
{
@@ -952,6 +975,7 @@
cc,
offset_new_view
(
+ // See the note for formatted_image_base::subview_for_offset()...
subview_for_offset( view ),
view
)
@@ -984,7 +1008,10 @@
if ( can_do_inplace_transform<View>( current_format ) )
{
view_data_t view_data( get_view_data( view ) );
- view_data.set_format( current_format );
+ if ( formatted_image_traits<Impl>::builtin_conversion )
+ view_data.set_format( current_format );
+ else
+ BOOST_ASSERT( current_format == impl().format() );
impl().raw_copy_to_prepared_view( view_data );
in_place_transform( current_image_format_id, original_view( view ), converter );
}
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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -25,8 +25,6 @@
#include "detail/windows_shared_istreams.hpp"
#include "formatted_image.hpp"
-#include "boost/gil/packed_pixel.hpp"
-
#include <boost/array.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/integral_c.hpp>
@@ -211,59 +209,48 @@
}
template <typename Target>
- void write_default( Target const & target )
+ void write_default( Target const & target, format_tag const format )
{
BOOST_ASSERT( lib_object().second == NULL );
- write( target );
+ write( target, format );
}
- void write( char const * const pFilename, CLSID const & encoderID = jpg_codec() ) const
+ void write( char const * const pFilename, format_tag const format ) const
{
- write( detail::wide_path( pFilename ), encoderID );
+ write( detail::wide_path( pFilename ), format );
}
- void write( wchar_t const * const pFilename, CLSID const & encoderID = jpg_codec() ) const
+ void write( wchar_t const * const pFilename, format_tag const format ) const
{
- save_to( pFilename, encoderID );
+ 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:
- void save_to_png( char const * const pFilename ) const { save_to( pFilename, png_codec() ); }
- void save_to_png( wchar_t const * const pFilename ) const { save_to( pFilename, png_codec() ); }
-
- void save_to( char const * const pFilename, CLSID const & encoderID ) const { save_to( detail::wide_path( pFilename ), encoderID ); }
- void save_to( wchar_t const * const pFilename, CLSID const & encoderID ) const
- {
- detail::ensure_result( Gdiplus::DllExports::GdipSaveImageToFile( lib_object().first, pFilename, &encoderID, lib_object().second ) );
- }
-
- static CLSID const & png_codec()
+ static CLSID const & encoder_id( format_tag const format )
{
- static CLSID const clsid = { 0x557cf406, 0x1a04, 0x11d3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
- return clsid;
- }
- static CLSID const & jpg_codec()
- {
- static CLSID const clsid = { 0x557CF401, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
- return clsid;
- }
- static CLSID const & tiff_codec()
- {
- static CLSID const clsid = { 0x557CF405, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
- return clsid;
- }
- static CLSID const & gif_codec()
- {
- static CLSID const clsid = { 0x557CF402, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
- return clsid;
- }
- static CLSID const & bmp_codec()
- {
- static CLSID const clsid = { 0x557CF400, 0x1A04, 0x11D3, 0x9A, 0x73, 0x00, 0x00, 0xF8, 0x1E, 0xF3, 0x2E };
- return clsid;
+ 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:
@@ -310,6 +297,8 @@
mpl::pair<memory_chunk_t const &, detail::gp_writer>
> writers;
+ typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
+
class view_data_t : public Gdiplus::BitmapData
{
public:
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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -22,6 +22,7 @@
#include "detail/libx_shared.hpp"
#include "detail/shared.hpp"
+#include <boost/array.hpp>
#include <boost/smart_ptr/scoped_ptr.hpp>
#define JPEG_INTERNALS
@@ -53,7 +54,6 @@
template <> struct gil_to_libjpeg_format<cmyk8_pixel_t, false> : mpl::integral_c<J_COLOR_SPACE, JCS_CMYK > {};
-
struct view_libjpeg_format
{
template <class View>
@@ -435,6 +435,8 @@
mpl::pair<char const *, detail::libjpeg_writer>
> writers;
+ typedef mpl::vector1_c<format_tag, jpeg> supported_image_formats;
+
typedef view_data_t writer_view_data_t;
BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( void * ) );
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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -404,6 +404,8 @@
mpl::pair<char const *, detail::output_c_str_for_c_file_extender<detail::libpng_writer_FILE> >
> writers;
+ typedef mpl::vector1_c<format_tag, png> supported_image_formats;
+
typedef view_data_t writer_view_data_t;
BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( void * ) );
@@ -532,7 +534,8 @@
BOOST_ASSERT( ( number_of_passes == 1 ) && "Missing interlaced support for the generic conversion case." );
ignore_unused_variable_warning( number_of_passes );
- skip_rows( get_offset<offset_t>( view ) );
+ if ( is_offset_view<TargetView>::value )
+ skip_rows( get_offset<offset_t>( view ) );
png_byte * const p_row ( p_row_buffer.get() );
png_byte const * const p_row_end( p_row + row_length );
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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -23,15 +23,18 @@
#include "detail/libx_shared.hpp"
#if BOOST_MPL_LIMIT_VECTOR_SIZE < 35
- ...error...libtiff support requires mpl vectors of size 35 or greater...
+...error...libtiff support requires mpl vectors of size 35 or greater...
#endif
#include <boost/array.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/smart_ptr/scoped_array.hpp>
-#include "tiff.h"
-#include "tiffio.h"
+extern "C"
+{
+ #include "tiff.h"
+ #include "tiffio.h"
+}
#include <cstdio>
#include <set>
@@ -54,17 +57,17 @@
#define LIBTIFF_FMT( param ) ( ( param ) << ( 0 + 3 + 5 ) )
#define LIBTIFF_PLANAR( param ) ( ( param ) << ( 0 + 3 + 5 + 3 ) )
#define LIBTIFF_PHOTOMETRIC( param ) ( ( param ) << ( 0 + 3 + 5 + 3 + 2 ) )
-#define LIBTIFF_INKSET( param ) ( ( param ) << ( 0 + 3 + 5 + 3 + 2 + 2 ) )
+#define LIBTIFF_INKSET( param ) ( ( param ) << ( 0 + 3 + 5 + 3 + 2 + 3 ) )
#define LIBTIFF_FORMAT( spp, bps, sample_format, planar_config, photometric_interpretation, inkset ) \
- ( \
+( \
LIBTIFF_SPP( spp ) | \
LIBTIFF_BPS( bps ) | \
LIBTIFF_FMT( sample_format ) | \
LIBTIFF_PLANAR( planar_config ) | \
LIBTIFF_PHOTOMETRIC( photometric_interpretation ) | \
LIBTIFF_INKSET( inkset ) \
- )
+)
union full_format_t
@@ -75,7 +78,7 @@
unsigned int bits_per_sample : 5;
unsigned int sample_format : 3;
unsigned int planar_configuration : 2;
- unsigned int photometric : 2;
+ unsigned int photometric : 3;
unsigned int ink_set : 2;
};
@@ -208,17 +211,16 @@
# pragma warning( disable : 4127 ) // "conditional expression is constant"
#endif
-
struct tiff_view_data_t
{
template <class View>
- explicit tiff_view_data_t( View const & view, generic_vertical_roi::offset_t const offset )
+ explicit tiff_view_data_t( View const & view, generic_vertical_roi::offset_t const offset = 0 )
:
- offset_ ( offset ),
- dimensions_( view.dimensions() ),
- stride_ ( view.pixels().row_size() )
+ dimensions_( view.dimensions() ),
+ stride_ ( view.pixels().row_size() ),
+ offset_ ( offset )
#ifdef _DEBUG
- ,format_id_( view_libtiff_format::apply<View>::value )
+ ,format_id_( view_libtiff_format::apply<View>::value )
#endif
{
set_buffers( view, is_planar<View>() );
@@ -230,11 +232,11 @@
ignore_unused_variable_warning( format );
}
- generic_vertical_roi::offset_t offset_;
- point2<std::ptrdiff_t> const & dimensions_;
- unsigned int stride_;
+ point2<std::ptrdiff_t> const & dimensions_ ;
+ unsigned int stride_ ;
unsigned int number_of_planes_;
- array<unsigned char *, 4> plane_buffers_;
+ array<unsigned char *, 4> plane_buffers_ ;
+ generic_vertical_roi::offset_t offset_ ;
#ifdef _DEBUG
unsigned int format_id_;
@@ -261,6 +263,7 @@
void operator=( tiff_view_data_t const & );
};
+
struct tiff_writer_view_data_t : public tiff_view_data_t
{
template <class View>
@@ -274,6 +277,7 @@
full_format_t format_;
};
+
class libtiff_base
{
public:
@@ -291,10 +295,10 @@
explicit libtiff_base( FILE & file )
:
p_tiff_
+ (
+ ::TIFFClientOpen
(
- ::TIFFClientOpen
- (
- "", "",
+ "", "",
&file,
&detail::FILE_read_proc,
&detail::FILE_write_proc,
@@ -303,13 +307,13 @@
&detail::FILE_size_proc,
&detail::FILE_map_proc,
&detail::FILE_unmap_proc
- )
)
+ )
{
construction_check();
}
-
+ __declspec( nothrow )
~libtiff_base()
{
::TIFFClose( &lib_object() );
@@ -332,7 +336,11 @@
TIFF * const p_tiff_;
};
-class libtiff_writer : public libtiff_base, public configure_on_write_writer
+
+class libtiff_writer
+ :
+ public libtiff_base,
+ public configure_on_write_writer
{
public:
explicit libtiff_writer( char const * const file_name ) : detail::libtiff_base( file_name, "w" ) {}
@@ -344,14 +352,14 @@
full_format_t::format_bitfield const format_bits( view.format_.bits );
//BOOST_ASSERT( ( format_bits.planar_configuration == PLANARCONFIG_CONTIG ) && "Add planar support..." );
- set_field( TIFFTAG_IMAGEWIDTH , view.dimensions_.x );
- set_field( TIFFTAG_IMAGELENGTH, view.dimensions_.y );
- set_field( TIFFTAG_BITSPERSAMPLE, format_bits.bits_per_sample );
- set_field( TIFFTAG_SAMPLESPERPIXEL, format_bits.samples_per_pixel );
- set_field( TIFFTAG_PLANARCONFIG, format_bits.planar_configuration );
- set_field( TIFFTAG_PHOTOMETRIC, format_bits.photometric );
- set_field( TIFFTAG_INKSET, format_bits.ink_set );
- set_field( TIFFTAG_SAMPLEFORMAT, format_bits.sample_format );
+ set_field( TIFFTAG_IMAGEWIDTH , view.dimensions_.x );
+ set_field( TIFFTAG_IMAGELENGTH , view.dimensions_.y );
+ set_field( TIFFTAG_BITSPERSAMPLE , format_bits.bits_per_sample );
+ set_field( TIFFTAG_SAMPLESPERPIXEL, format_bits.samples_per_pixel );
+ set_field( TIFFTAG_PLANARCONFIG , format_bits.planar_configuration );
+ set_field( TIFFTAG_PHOTOMETRIC , format_bits.photometric );
+ set_field( TIFFTAG_INKSET , format_bits.ink_set );
+ set_field( TIFFTAG_SAMPLEFORMAT , format_bits.sample_format );
set_field( TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT );
@@ -376,7 +384,7 @@
unsigned int const target_row( view.dimensions_.y );
while ( row < target_row )
{
- result.accumulate_equal( ::TIFFWriteScanline( &lib_object(), buf, row++, static_cast<tsample_t>( plane ) ), 1 );
+ result.accumulate_greater( ::TIFFWriteScanline( &lib_object(), buf, row++, static_cast<tsample_t>( plane ) ), 0 );
buf += view.stride_;
}
}
@@ -431,6 +439,8 @@
mpl::pair<FILE &, detail::libtiff_writer>
> writers;
+ typedef mpl::vector1_c<format_tag, tiff> supported_image_formats;
+
typedef detail::tiff_writer_view_data_t writer_view_data_t;
BOOST_STATIC_CONSTANT( unsigned int, desired_alignment = sizeof( void *) );
@@ -582,10 +592,6 @@
bool const starting_at_last_row( ( number_of_tiles - starting_tile ) <= tiles_per_row );
rows_to_read_per_tile = starting_at_last_row ? end_rows_to_read : tile_height;
}
-
- #ifdef _DEBUG
- std::memset( p_tile_buffer.get(), 0xFF, tile_size_bytes * ( nptcc ? source.format_bits().samples_per_pixel : 1 ) );
- #endif // _DEBUG
}
uint32 const tile_height;
@@ -680,7 +686,7 @@
unsigned int row( view_data.offset_ );
while ( row != ( view_data.offset_ + skip_result.rows_to_read_using_scanlines ) )
{
- result.accumulate_equal( ::TIFFReadScanline( &lib_object(), buf, row++, static_cast<tsample_t>( plane ) ), 1 );
+ result.accumulate_greater( ::TIFFReadScanline( &lib_object(), buf, row++, static_cast<tsample_t>( plane ) ), 0 );
buf += view_data.stride_;
}
@@ -689,7 +695,7 @@
{
for ( unsigned int strip( skip_result.starting_strip ); strip < number_of_strips; ++strip )
{
- result.accumulate_different( ::TIFFReadEncodedStrip( &lib_object(), strip, buf, view_strip_increment ), -1 );
+ result.accumulate_greater( ::TIFFReadEncodedStrip( &lib_object(), strip, buf, view_strip_increment ), 0 );
buf += view_strip_increment;
row += skip_result.rows_per_strip;
}
@@ -698,7 +704,7 @@
unsigned int const target_row( view_data.offset_ + view_data.dimensions_.y );
while ( row < target_row )
{
- result.accumulate_equal( ::TIFFReadScanline( &lib_object(), buf, row++, static_cast<tsample_t>( plane ) ), 1 );
+ result.accumulate_greater( ::TIFFReadScanline( &lib_object(), buf, row++, static_cast<tsample_t>( plane ) ), 0 );
buf += view_data.stride_;
}
}
@@ -707,7 +713,7 @@
result.throw_if_error();
}
-
+
////////////////////////////////////////////////////////////////////////////
//
// generic_convert_to_prepared_view()
@@ -720,10 +726,12 @@
/// (16.09.2010.) (Domagoj Saric)
///
////////////////////////////////////////////////////////////////////////////
-
+
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 get_original_view_t<TargetView>::type original_target_view_t;
typedef typename mpl::eval_if
@@ -942,8 +950,9 @@
for ( unsigned int plane( 0 ); plane < number_of_planes; ++plane )
{
tdata_t const p_buffer( &(*buffer_iterator)[ plane ] );
- skip_to_row( get_offset<offset_t>( view ), plane, p_buffer, result );
- result.accumulate_equal( ::TIFFReadScanline( &lib_object(), p_buffer, row, static_cast<tsample_t>( plane ) ), 1 );
+ //...zzz...yup...not the most efficient thing in the universe...
+ skip_to_row( get_offset<offset_t>( view ) + row, plane, p_buffer, result );
+ result.accumulate_greater( ::TIFFReadScanline( &lib_object(), p_buffer, row, static_cast<tsample_t>( plane ) ), 0 );
}
typename MyView ::x_iterator p_source_pixel( buffer_iterator );
typename original_target_view_t::x_iterator p_target_pixel( p_target.base() );
@@ -961,7 +970,8 @@
{
for ( unsigned int plane( 0 ); plane < number_of_planes; ++plane )
{
- skip_to_row( get_offset<offset_t>( view ), plane, scanline_buffer.begin(), result );
+ if ( is_offset_view<TargetView>::value )
+ skip_to_row( get_offset<offset_t>( view ), plane, scanline_buffer.begin(), result );
local_target_view_t const & target_view( adjust_target_to_my_view( original_view( view ), plane, is_planar<MyView>() ) );
target_y_iterator p_target( target_view.y_at( 0, 0 ) );
@@ -969,7 +979,7 @@
unsigned int const target_row( row + dimensions.y );
while ( row != target_row )
{
- result.accumulate_equal( ::TIFFReadScanline( &lib_object(), scanline_buffer.begin(), row++, static_cast<tsample_t>( plane ) ), 1 );
+ result.accumulate_greater( ::TIFFReadScanline( &lib_object(), scanline_buffer.begin(), row++, static_cast<tsample_t>( plane ) ), 0 );
my_pixel_t const * p_source_pixel( scanline_buffer.begin() );
target_x_iterator p_target_pixel( p_target.base() );
while ( p_source_pixel != scanline_buffer.end() )
@@ -1050,18 +1060,15 @@
}
typedef std::pair
- <
- scoped_array<unsigned char> const,
- unsigned char const * const
- > generic_scanline_buffer_t;
+ <
+ scoped_array<unsigned char> const,
+ unsigned char const * const
+ > generic_scanline_buffer_t;
static generic_scanline_buffer_t scanline_buffer_aux( TIFF & tiff )
{
unsigned int const scanlineSize( ::TIFFScanlineSize( &tiff ) );
unsigned char * const p_buffer( new unsigned char[ scanlineSize ] );
- #ifdef _DEBUG
- std::memset( p_buffer, 0xFF, scanlineSize );
- #endif // _DEBUG
return std::make_pair( p_buffer, p_buffer + scanlineSize );
}
@@ -1071,9 +1078,6 @@
{
unsigned int const scanlineSize( tiff.format_bits().bits_per_sample * tiff.dimensions().x / 8 );
unsigned char * const p_buffer( new unsigned char[ scanlineSize * tiff.format_bits().samples_per_pixel ] );
- #ifdef _DEBUG
- std::memset( p_buffer, 0xFF, scanlineSize * tiff.format_bits().samples_per_pixel );
- #endif // _DEBUG
return std::make_pair( p_buffer, p_buffer + scanlineSize );
}
@@ -1104,7 +1108,7 @@
generic_scanline_buffer_t const buffer_;
};
-
+ __declspec( nothrow )
skip_row_results_t skip_to_row
(
unsigned int const row_to_skip_to,
@@ -1134,7 +1138,7 @@
);
while ( row < row_to_skip_to )
{
- error_result.accumulate_equal( ::TIFFReadScanline( &lib_object(), buffer, row++, static_cast<tsample_t>( sample ) ), 1 );
+ error_result.accumulate_greater( ::TIFFReadScanline( &lib_object(), buffer, row++, static_cast<tsample_t>( sample ) ), 0 );
}
//BOOST_ASSERT( !row_to_skip_to || ( ::TIFFCurrentRow( &lib_object() ) == row_to_skip_to ) );
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-06 12:17:45 EDT (Wed, 06 Oct 2010)
@@ -202,9 +202,9 @@
lib_object_t & lib_object() { return lib_object_; }
public:
- wic_writer( IStream & target )
+ wic_writer( IStream & target, format_tag const format )
{
- create_encoder( GUID_ContainerFormatPng, target );
+ create_encoder( target, encoder_guid( format ) );
}
void write_default( wic_view_data_t const & view_data )
@@ -247,13 +247,28 @@
void write( wic_view_data_t const & view_data ) { write_default( view_data ); }
private:
- void create_encoder( GUID const & format, IStream & target )
+ void create_encoder( IStream & target, GUID const & format )
{
ensure_result( wic_factory<>::singleton().CreateEncoder( format, NULL, &lib_object().p_encoder_ ) );
ensure_result( lib_object().p_encoder_->Initialize( &target, WICBitmapEncoderNoCache ) );
ensure_result( lib_object().p_encoder_->CreateNewFrame( &lib_object().p_frame_, &lib_object().p_frame_parameters_ ) );
}
+ static GUID const & encoder_guid( format_tag const format )
+ {
+ static GUID const * const guids[ number_of_known_formats ] =
+ {
+ &GUID_ContainerFormatBmp,
+ &GUID_ContainerFormatGif,
+ &GUID_ContainerFormatJpeg,
+ &GUID_ContainerFormatPng,
+ &GUID_ContainerFormatTiff,
+ NULL // TGA
+ };
+ BOOST_ASSERT( guids[ format ] != NULL );
+ return *guids[ format ];
+ }
+
IWICBitmapFrameEncode & frame () { return *lib_object().p_frame_ ; }
IWICBitmapEncoder & encoder() { return *lib_object().p_encoder_; }
@@ -308,6 +323,8 @@
mpl::pair<memory_chunk_t const &, detail::memory_chunk_for_IStream_extender<detail::wic_writer> >
> writers;
+ typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
+
typedef detail::wic_view_data_t view_data_t ;
typedef view_data_t writer_view_data_t;
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