WIP. Scale cover art option. Seems to work
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_BASE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_BASE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
|
||||
#include <boost/gil/utilities.hpp>
|
||||
#include <boost/gil/color_convert.hpp>
|
||||
#include <boost/gil/bit_aligned_pixel_reference.hpp>
|
||||
#include <boost/gil/bit_aligned_pixel_iterator.hpp>
|
||||
|
||||
#include <boost/gil/extension/toolbox/gil_extensions.hpp>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "io_error.hpp"
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
struct format_tag {};
|
||||
|
||||
template< typename Property >
|
||||
struct property_base
|
||||
{
|
||||
typedef Property type;
|
||||
};
|
||||
|
||||
template<typename FormatTag> struct is_format_tag : is_base_and_derived< format_tag
|
||||
, FormatTag
|
||||
> {};
|
||||
|
||||
struct image_read_settings_base
|
||||
{
|
||||
protected:
|
||||
|
||||
image_read_settings_base()
|
||||
: _top_left( 0, 0 )
|
||||
, _dim ( 0, 0 )
|
||||
{}
|
||||
|
||||
image_read_settings_base( const point_t& top_left
|
||||
, const point_t& dim
|
||||
)
|
||||
: _top_left( top_left )
|
||||
, _dim ( dim )
|
||||
{}
|
||||
|
||||
public:
|
||||
|
||||
point_t _top_left;
|
||||
point_t _dim;
|
||||
};
|
||||
|
||||
/**
|
||||
* Boolean meta function, mpl::true_ if the pixel type \a PixelType is supported
|
||||
* by the image format identified with \a FormatTag.
|
||||
* \todo the name is_supported is to generic, pick something more IO realted.
|
||||
*/
|
||||
// Depending on image type the parameter Pixel can be a reference type
|
||||
// for bit_aligned images or a pixel for byte images.
|
||||
template< typename Pixel, typename FormatTag > struct is_read_supported {};
|
||||
template< typename Pixel, typename FormatTag > struct is_write_supported {};
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
template< typename Property >
|
||||
struct property_base
|
||||
{
|
||||
typedef Property type;
|
||||
};
|
||||
|
||||
struct read_support_true { BOOST_STATIC_CONSTANT( bool, is_supported = true ); };
|
||||
struct read_support_false { BOOST_STATIC_CONSTANT( bool, is_supported = false ); };
|
||||
struct write_support_true { BOOST_STATIC_CONSTANT( bool, is_supported = true ); };
|
||||
struct write_support_false{ BOOST_STATIC_CONSTANT( bool, is_supported = false ); };
|
||||
|
||||
class no_log {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename FormatTag> struct image_read_info;
|
||||
template<typename FormatTag> struct image_read_settings;
|
||||
template<typename FormatTag, typename Log = typename detail::no_log > struct image_write_info;
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_BASE_HPP
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_BIT_OPERATIONS_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_BIT_OPERATIONS_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning \n
|
||||
///
|
||||
/// \date 2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
// 1110 1100 -> 0011 0111
|
||||
template< typename Buffer
|
||||
, typename IsBitAligned
|
||||
>
|
||||
struct mirror_bits
|
||||
{
|
||||
mirror_bits( bool ) {}
|
||||
|
||||
void operator() ( Buffer& ) {}
|
||||
};
|
||||
|
||||
|
||||
// The functor will generate a lookup table since the
|
||||
// mirror operation is quite costly.
|
||||
template< typename Buffer >
|
||||
struct mirror_bits< Buffer
|
||||
, mpl::true_
|
||||
>
|
||||
{
|
||||
mirror_bits( bool apply_operation = true )
|
||||
: _apply_operation( apply_operation )
|
||||
{
|
||||
if( _apply_operation == true )
|
||||
{
|
||||
byte_t i = 0;
|
||||
do
|
||||
{
|
||||
_lookup[i] = mirror( i );
|
||||
}
|
||||
while( i++ != 255 );
|
||||
}
|
||||
}
|
||||
|
||||
void operator() ( Buffer& buf )
|
||||
{
|
||||
if( _apply_operation == true )
|
||||
{
|
||||
for_each( buf.begin()
|
||||
, buf.end()
|
||||
, boost::bind( &mirror_bits< Buffer
|
||||
, mpl::true_
|
||||
>::lookup
|
||||
, *this
|
||||
, _1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void lookup( byte_t& c )
|
||||
{
|
||||
c = _lookup[ c ];
|
||||
}
|
||||
|
||||
static byte_t mirror( byte_t c )
|
||||
{
|
||||
byte_t result = 0;
|
||||
for( int i = 0; i < 8; ++i )
|
||||
{
|
||||
result = result << 1;
|
||||
result |= ( c & 1 );
|
||||
c = c >> 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool _apply_operation;
|
||||
|
||||
array< byte_t, 256 > _lookup;
|
||||
};
|
||||
|
||||
|
||||
// 0011 1111 -> 1100 0000
|
||||
template< typename Buffer
|
||||
, typename IsBitAligned
|
||||
>
|
||||
struct negate_bits
|
||||
{
|
||||
void operator() ( Buffer& ) {}
|
||||
};
|
||||
|
||||
template< typename Buffer >
|
||||
struct negate_bits< Buffer, mpl::true_ >
|
||||
{
|
||||
void operator() ( Buffer& buf )
|
||||
{
|
||||
for_each( buf.begin()
|
||||
, buf.end()
|
||||
, negate_bits< Buffer, mpl::true_ >::negate
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static void negate( byte_t& b )
|
||||
{
|
||||
b = ~b;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 11101100 -> 11001110
|
||||
template< typename Buffer
|
||||
, typename IsBitAligned
|
||||
>
|
||||
struct swap_half_bytes
|
||||
{
|
||||
void operator() ( Buffer& ) {}
|
||||
};
|
||||
|
||||
template< typename Buffer >
|
||||
struct swap_half_bytes< Buffer
|
||||
, mpl::true_
|
||||
>
|
||||
{
|
||||
void operator() ( Buffer& buf )
|
||||
{
|
||||
for_each( buf.begin()
|
||||
, buf.end()
|
||||
, swap_half_bytes< Buffer, mpl::true_ >::swap
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static void swap( byte_t& c )
|
||||
{
|
||||
c = (( c << 4 ) & 0xF0 ) | (( c >> 4 ) & 0x0F );
|
||||
}
|
||||
};
|
||||
|
||||
template< typename Buffer >
|
||||
struct do_nothing
|
||||
{
|
||||
do_nothing() {}
|
||||
|
||||
void operator() ( Buffer& ) {}
|
||||
};
|
||||
|
||||
/// Count consecutive zeros on the right
|
||||
template< typename T >
|
||||
inline
|
||||
unsigned int trailing_zeros( T x )
|
||||
throw()
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
x = ~x & (x - 1);
|
||||
|
||||
while( x )
|
||||
{
|
||||
n = n + 1;
|
||||
x = x >> 1;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Counts ones in a bit-set
|
||||
template< typename T >
|
||||
inline
|
||||
unsigned int count_ones( T x )
|
||||
throw()
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
while( x )
|
||||
{
|
||||
// clear the least significant bit set
|
||||
x &= x - 1;
|
||||
++n;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_BIT_OPERATIONS_HPP
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright 2007-2008 Andreas Pokorny, Christian Henning
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_CONVERSION_POLICIES_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_CONVERSION_POLICIES_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Andreas Pokorny, Christian Henning \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <boost/gil/image_view_factory.hpp>
|
||||
|
||||
namespace boost{namespace gil{ namespace detail {
|
||||
|
||||
struct read_and_no_convert
|
||||
{
|
||||
public:
|
||||
typedef void* color_converter_type;
|
||||
|
||||
template< typename InIterator
|
||||
, typename OutIterator
|
||||
>
|
||||
void read( const InIterator& /* begin */
|
||||
, const InIterator& /* end */
|
||||
, OutIterator /* out */
|
||||
, typename disable_if< typename pixels_are_compatible< typename std::iterator_traits<InIterator>::value_type
|
||||
, typename std::iterator_traits<OutIterator>::value_type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
io_error( "Data cannot be copied because the pixels are incompatible." );
|
||||
}
|
||||
|
||||
template< typename InIterator
|
||||
, typename OutIterator
|
||||
>
|
||||
void read( const InIterator& begin
|
||||
, const InIterator& end
|
||||
, OutIterator out
|
||||
, typename enable_if< typename pixels_are_compatible< typename std::iterator_traits<InIterator>::value_type
|
||||
, typename std::iterator_traits<OutIterator>::value_type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
std::copy( begin
|
||||
, end
|
||||
, out
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename CC>
|
||||
struct read_and_convert
|
||||
{
|
||||
public:
|
||||
typedef CC color_converter_type;
|
||||
CC _cc;
|
||||
|
||||
read_and_convert( color_converter_type const& cc )
|
||||
: _cc(cc) {}
|
||||
|
||||
template< typename InIterator
|
||||
, typename OutIterator
|
||||
>
|
||||
void read( const InIterator& begin
|
||||
, const InIterator& end
|
||||
, OutIterator out
|
||||
)
|
||||
{
|
||||
typedef color_convert_deref_fn< typename std::iterator_traits<InIterator>::reference
|
||||
, typename std::iterator_traits<OutIterator>::value_type //reference?
|
||||
, CC
|
||||
> deref_t;
|
||||
|
||||
std::transform( begin
|
||||
, end
|
||||
, out
|
||||
, deref_t( _cc )
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_CONVERSION_POLICIES_HPP
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
Copyright 2005-2007 Adobe Systems Incorporated
|
||||
|
||||
Use, modification and distribution are 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).
|
||||
|
||||
See http://opensource.adobe.com/gil for most recent version including documentation.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_TOOLBOX_DYNAMIC_IMAGES_HPP_INCLUDED
|
||||
#define BOOST_GIL_EXTENSION_TOOLBOX_DYNAMIC_IMAGES_HPP_INCLUDED
|
||||
|
||||
/// \file
|
||||
/// \brief Generic io functions for dealing with dynamic images
|
||||
//
|
||||
/// \author Hailin Jin and Lubomir Bourdev \n
|
||||
/// Adobe Systems Incorporated
|
||||
/// \date 2005-2007 \n Last updated May 30, 2006
|
||||
|
||||
#include <boost/mpl/at.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
#include <boost/gil/gil_config.hpp>
|
||||
#include <boost/gil/extension/io_new/detail/io_error.hpp>
|
||||
#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
// need this for various meta functions.
|
||||
struct any_image_pixel_t {};
|
||||
struct any_image_channel_t {};
|
||||
struct any_image_color_space_t {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <long N>
|
||||
struct construct_matched_t {
|
||||
template <typename Images,typename Pred>
|
||||
static bool apply(any_image<Images>& im,Pred pred) {
|
||||
if (pred.template apply<typename mpl::at_c<Images,N-1>::type>()) {
|
||||
typename mpl::at_c<Images,N-1>::type x;
|
||||
im.move_in(x);
|
||||
return true;
|
||||
} else return construct_matched_t<N-1>::apply(im,pred);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct construct_matched_t<0> {
|
||||
template <typename Images,typename Pred>
|
||||
static bool apply(any_image<Images>&,Pred) {return false;}
|
||||
};
|
||||
|
||||
// A function object that can be passed to apply_operation.
|
||||
// Given a predicate IsSupported taking a view type and returning an MPL boolean,
|
||||
// calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
|
||||
template <typename IsSupported, typename OpClass>
|
||||
class dynamic_io_fnobj {
|
||||
OpClass* _op;
|
||||
|
||||
template <typename View>
|
||||
void apply(const View& view,mpl::true_ ) {_op->apply(view);}
|
||||
|
||||
template <typename View, typename Info >
|
||||
void apply( const View& view
|
||||
, const Info& info
|
||||
, const mpl::true_
|
||||
)
|
||||
{
|
||||
_op->apply( view, info );
|
||||
}
|
||||
|
||||
template <typename View>
|
||||
void apply(const View& /* view */ ,mpl::false_) {io_error("dynamic_io: unsupported view type for the given file format");}
|
||||
|
||||
template <typename View, typename Info >
|
||||
void apply( const View& /* view */
|
||||
, const Info& /* info */
|
||||
, const mpl::false_
|
||||
)
|
||||
{
|
||||
io_error( "dynamic_io: unsupported view type for the given file format" );
|
||||
}
|
||||
|
||||
public:
|
||||
dynamic_io_fnobj(OpClass* op) : _op(op) {}
|
||||
|
||||
typedef void result_type;
|
||||
|
||||
template <typename View>
|
||||
void operator()(const View& view) {apply(view,typename IsSupported::template apply<View>::type());}
|
||||
|
||||
template< typename View, typename Info >
|
||||
void operator()(const View& view, const Info& info )
|
||||
{
|
||||
apply( view
|
||||
, info
|
||||
, typename IsSupported::template apply< View >::type()
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// \brief Within the any_image, constructs an image with the given dimensions
|
||||
/// and a type that satisfies the given predicate
|
||||
template <typename Images,typename Pred>
|
||||
inline bool construct_matched(any_image<Images>& im,Pred pred) {
|
||||
return detail::construct_matched_t<mpl::size<Images>::value>::apply(im,pred);
|
||||
}
|
||||
|
||||
} } // namespace boost::gil
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_TOOLBOX_DYNAMIC_IMAGES_HPP_INCLUDED
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_IO_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_IO_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*!
|
||||
* \page iobackend Adding a new io backend
|
||||
* \section Overview of backend requirements
|
||||
* To add support for a new IO backend the following is required:
|
||||
* - a format tag, to identify the image format, derived from boost::gil::format_tag
|
||||
* - boolean meta function is_supported<PixelType,FormatTag> must be implemented for
|
||||
* the new format tag
|
||||
* - explicit specialisation of image_read_info<FormatTag> must be provided, containing
|
||||
* runtime information available before/at reading the image
|
||||
* - explicit specialisation of image_write_info<FormatTag> must be provided, containing
|
||||
* runtime encoding parameters for writing an image
|
||||
* - An image reader must be specialized:
|
||||
* \code
|
||||
* template<typename IODevice, typename ConversionPolicy>
|
||||
* struct boost::gil::detail::reader<IODevice,FormatTag,ConversionPolicy>
|
||||
* {
|
||||
* reader( IODevice & device )
|
||||
* reader( IODevice & device, typename ConversionPolicy::color_converter_type const& cc )
|
||||
* image_read_info<FormatTag> get_info();
|
||||
* template<typename Image>
|
||||
* void read_image( Image &, point_t const& top_left );
|
||||
* template<typename View>
|
||||
* void read_view( View &, point_t const& top_left );
|
||||
* };
|
||||
* \endcode
|
||||
* - An image writer must be specialized:
|
||||
* \code
|
||||
* \template <typename IODevice>
|
||||
* struct boost::gil::detail::writer<IODevice,FormatTag>
|
||||
* {
|
||||
* writer( IODevice & device )
|
||||
* template<typename View>
|
||||
* void apply( View const&, point_t const& top_left );
|
||||
* template<typename View>
|
||||
* void apply( View const&, point_t const& top_left, image_write_info<FormatTag> const& );
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Or instead of the items above implement overloads of read_view, read_and_convert_view, read_image,
|
||||
* read_and_convert_image, write_view and read_image_info.
|
||||
*
|
||||
* \section ConversionPolicy Interface of the ConversionPolicy
|
||||
* There are two different conversion policies in use, when reading images:
|
||||
* read_and_convert<ColorConverter> and read_and_no_convert. ColorConverter
|
||||
* can be a user defined color converter.
|
||||
*
|
||||
* \code
|
||||
* struct ConversionPolicy
|
||||
* {
|
||||
* template<typename InputIterator,typename OutputIterator>
|
||||
* void read( InputIterator in_begin, InputIterator in_end,
|
||||
* OutputIterator out_end );
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Methods like read_view and read_image are supposed to bail out with an
|
||||
* exception instead of converting the image
|
||||
*
|
||||
* \section IODevice Concept of IO Device
|
||||
* A Device is simply an object used to read and write data to and from a stream.
|
||||
* The IODevice was added as a template paramter to be able to replace the file_name
|
||||
* access functionality. This is only an interim solution, as soon as boost provides
|
||||
* a good IO library, interfaces/constraints provided by that library could be used.
|
||||
*
|
||||
* \code
|
||||
* concept IODevice
|
||||
* {
|
||||
* void IODevice::read( unsigned char* data, int count );
|
||||
* void IODevice::write( unsigned char* data, int count );
|
||||
* void IODevice::seek(long count, int whence);
|
||||
* void IODevice::flush();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* For the time being a boolean meta function must be specialized:
|
||||
* \code
|
||||
* namespace boost{namespace gil{namespace detail{
|
||||
* template<typename Device>
|
||||
* struct detail::is_input_device;
|
||||
* }}}
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_IO_HPP
|
||||
@@ -0,0 +1,507 @@
|
||||
/*
|
||||
Copyright 2007-2008 Andreas Pokorny, Christian Henning
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_IO_DEVICE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_IO_DEVICE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Andreas Pokorny, Christian Henning \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include "base.hpp"
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
template < typename T > struct buff_item
|
||||
{
|
||||
static const unsigned int size = sizeof( T );
|
||||
};
|
||||
|
||||
template <> struct buff_item< void >
|
||||
{
|
||||
static const unsigned int size = 1;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Implements the IODevice concept c.f. to \ref IODevice required by Image libraries like
|
||||
* libjpeg and libpng.
|
||||
*
|
||||
* \todo switch to a sane interface as soon as there is
|
||||
* something good in boost. I.E. the IOChains library
|
||||
* would fit very well here.
|
||||
*
|
||||
* This implementation is based on FILE*.
|
||||
*/
|
||||
template< typename FormatTag >
|
||||
class file_stream_device
|
||||
{
|
||||
public:
|
||||
|
||||
typedef FormatTag _tag_t;
|
||||
|
||||
public:
|
||||
struct read_tag {};
|
||||
struct write_tag {};
|
||||
|
||||
file_stream_device( std::string const& file_name, read_tag )
|
||||
: file(0),_close(true)
|
||||
{
|
||||
io_error_if( ( file = fopen( file_name.c_str(), "rb" )) == NULL
|
||||
, "file_stream_device: failed to open file" );
|
||||
}
|
||||
|
||||
file_stream_device( std::string const& file_name, write_tag )
|
||||
: file(0),_close(true)
|
||||
{
|
||||
io_error_if( ( file = fopen( file_name.c_str(), "wb" )) == NULL
|
||||
, "file_stream_device: failed to open file" );
|
||||
}
|
||||
|
||||
file_stream_device( FILE * filep)
|
||||
: file(filep),_close(false)
|
||||
{
|
||||
}
|
||||
|
||||
~file_stream_device()
|
||||
{
|
||||
if(_close)
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int getc_unchecked()
|
||||
{
|
||||
return std::getc( file );
|
||||
}
|
||||
|
||||
char getc()
|
||||
{
|
||||
int ch;
|
||||
|
||||
if(( ch = std::getc( file )) == EOF )
|
||||
io_error( "file_stream_device: unexpected EOF" );
|
||||
|
||||
return ( char ) ch;
|
||||
}
|
||||
|
||||
std::size_t read( byte_t* data
|
||||
, std::size_t count )
|
||||
{
|
||||
return fread( data, 1, static_cast<int>( count ), file );
|
||||
}
|
||||
|
||||
/// Reads array
|
||||
template< typename T
|
||||
, int N
|
||||
>
|
||||
size_t read( T (&buf)[N] )
|
||||
{
|
||||
return read( buf, N );
|
||||
}
|
||||
|
||||
/// Reads byte
|
||||
uint8_t read_int8() throw()
|
||||
{
|
||||
byte_t m[1];
|
||||
|
||||
read( m );
|
||||
return m[0];
|
||||
}
|
||||
|
||||
/// Reads 16 bit little endian integer
|
||||
uint16_t read_int16() throw()
|
||||
{
|
||||
byte_t m[2];
|
||||
|
||||
read( m );
|
||||
return (m[1] << 8) | m[0];
|
||||
}
|
||||
|
||||
/// Reads 32 bit little endian integer
|
||||
uint32_t read_int32() throw()
|
||||
{
|
||||
byte_t m[4];
|
||||
|
||||
read( m );
|
||||
return (m[3] << 24) | (m[2] << 16) | (m[1] << 8) | m[0];
|
||||
}
|
||||
|
||||
/// Writes number of elements from a buffer
|
||||
template < typename T >
|
||||
size_t write(const T *buf, size_t cnt) throw()
|
||||
{
|
||||
return fwrite( buf, buff_item<T>::size, cnt, file );
|
||||
}
|
||||
|
||||
/// Writes array
|
||||
template < typename T
|
||||
, size_t N
|
||||
>
|
||||
size_t write( const T (&buf)[N] ) throw()
|
||||
{
|
||||
return write( buf, N );
|
||||
}
|
||||
|
||||
/// Writes byte
|
||||
void write_int8( uint8_t x ) throw()
|
||||
{
|
||||
byte_t m[1] = { x };
|
||||
write(m);
|
||||
}
|
||||
|
||||
/// Writes 16 bit little endian integer
|
||||
void write_int16( uint16_t x ) throw()
|
||||
{
|
||||
byte_t m[2];
|
||||
|
||||
m[0] = byte_t( x >> 0 );
|
||||
m[1] = byte_t( x >> 8 );
|
||||
|
||||
write( m );
|
||||
}
|
||||
|
||||
/// Writes 32 bit little endian integer
|
||||
void write_int32( uint32_t x ) throw()
|
||||
{
|
||||
byte_t m[4];
|
||||
|
||||
m[0] = byte_t( x >> 0 );
|
||||
m[1] = byte_t( x >> 8 );
|
||||
m[2] = byte_t( x >> 16 );
|
||||
m[3] = byte_t( x >> 24 );
|
||||
|
||||
write( m );
|
||||
}
|
||||
|
||||
|
||||
//!\todo replace with std::ios::seekdir?
|
||||
void seek( long count, int whence = SEEK_SET )
|
||||
{
|
||||
fseek(file, count, whence );
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
fflush( file );
|
||||
}
|
||||
|
||||
/// Prints formatted ASCII text
|
||||
void print_line( const std::string& line )
|
||||
{
|
||||
fwrite( line.c_str(), sizeof( char ), line.size(), file );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
file_stream_device( file_stream_device const& );
|
||||
file_stream_device& operator=( file_stream_device const& );
|
||||
|
||||
//@todo: why not fstream?
|
||||
FILE* file;
|
||||
|
||||
bool _close;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Input stream device
|
||||
*/
|
||||
template< typename FormatTag >
|
||||
class istream_device
|
||||
{
|
||||
public:
|
||||
istream_device( std::istream& in )
|
||||
: _in( in ) {}
|
||||
|
||||
int getc_unchecked()
|
||||
{
|
||||
return _in.get();
|
||||
}
|
||||
|
||||
char getc()
|
||||
{
|
||||
int ch;
|
||||
|
||||
if(( ch = _in.get() ) == EOF )
|
||||
io_error( "file_stream_device: unexpected EOF" );
|
||||
|
||||
return ( char ) ch;
|
||||
}
|
||||
|
||||
std::size_t read( byte_t* data
|
||||
, std::size_t count )
|
||||
{
|
||||
std::streamsize cr = 0;
|
||||
|
||||
do
|
||||
{
|
||||
_in.peek();
|
||||
std::streamsize c = _in.readsome( reinterpret_cast< char* >( data )
|
||||
, static_cast< std::streamsize >( count ));
|
||||
|
||||
count -= static_cast< std::size_t >( c );
|
||||
data += c;
|
||||
cr += c;
|
||||
|
||||
} while( count && _in );
|
||||
|
||||
return static_cast< std::size_t >( cr );
|
||||
}
|
||||
|
||||
/// Reads array
|
||||
template< typename T
|
||||
, int N
|
||||
>
|
||||
size_t read( T (&buf)[N] )
|
||||
{
|
||||
return read( buf, N );
|
||||
}
|
||||
|
||||
/// Reads byte
|
||||
uint8_t read_int8() throw()
|
||||
{
|
||||
byte_t m[1];
|
||||
|
||||
read( m );
|
||||
return m[0];
|
||||
}
|
||||
|
||||
/// Reads 16 bit little endian integer
|
||||
uint16_t read_int16() throw()
|
||||
{
|
||||
byte_t m[2];
|
||||
|
||||
read( m );
|
||||
return (m[1] << 8) | m[0];
|
||||
}
|
||||
|
||||
/// Reads 32 bit little endian integer
|
||||
uint32_t read_int32() throw()
|
||||
{
|
||||
byte_t m[4];
|
||||
|
||||
read( m );
|
||||
return (m[3] << 24) | (m[2] << 16) | (m[1] << 8) | m[0];
|
||||
}
|
||||
|
||||
void seek( long count, int whence = SEEK_SET )
|
||||
{
|
||||
_in.seekg( count
|
||||
, whence == SEEK_SET ? std::ios::beg
|
||||
:( whence == SEEK_CUR ? std::ios::cur
|
||||
: std::ios::end )
|
||||
);
|
||||
}
|
||||
|
||||
void write( const byte_t* data
|
||||
, std::size_t count )
|
||||
{
|
||||
io_error( "Bad io error." );
|
||||
}
|
||||
|
||||
void flush() {}
|
||||
|
||||
private:
|
||||
|
||||
std::istream& _in;
|
||||
};
|
||||
|
||||
/**
|
||||
* Output stream device
|
||||
*/
|
||||
template< typename FormatTag >
|
||||
class ostream_device
|
||||
{
|
||||
public:
|
||||
ostream_device( std::ostream & out )
|
||||
: _out( out )
|
||||
{
|
||||
}
|
||||
|
||||
size_t read( byte_t* data
|
||||
, std::size_t count )
|
||||
{
|
||||
io_error( "Bad io error." );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void seek( long count, int whence )
|
||||
{
|
||||
_out.seekp( count
|
||||
, whence == SEEK_SET
|
||||
? std::ios::beg
|
||||
: ( whence == SEEK_CUR
|
||||
?std::ios::cur
|
||||
:std::ios::end )
|
||||
);
|
||||
}
|
||||
|
||||
void write( const byte_t* data
|
||||
, std::size_t count )
|
||||
{
|
||||
_out.write( reinterpret_cast<char const*>( data )
|
||||
, static_cast<std::streamsize>( count )
|
||||
);
|
||||
}
|
||||
|
||||
/// Writes array
|
||||
template < typename T
|
||||
, size_t N
|
||||
>
|
||||
void write( const T (&buf)[N] ) throw()
|
||||
{
|
||||
write( buf, N );
|
||||
}
|
||||
|
||||
/// Writes byte
|
||||
void write_int8( uint8_t x ) throw()
|
||||
{
|
||||
byte_t m[1] = { x };
|
||||
write(m);
|
||||
}
|
||||
|
||||
/// Writes 16 bit little endian integer
|
||||
void write_int16( uint16_t x ) throw()
|
||||
{
|
||||
byte_t m[2];
|
||||
|
||||
m[0] = byte_t( x >> 0 );
|
||||
m[1] = byte_t( x >> 8 );
|
||||
|
||||
write( m );
|
||||
}
|
||||
|
||||
/// Writes 32 bit little endian integer
|
||||
void write_int32( uint32_t x ) throw()
|
||||
{
|
||||
byte_t m[4];
|
||||
|
||||
m[0] = byte_t( x >> 0 );
|
||||
m[1] = byte_t( x >> 8 );
|
||||
m[2] = byte_t( x >> 16 );
|
||||
m[3] = byte_t( x >> 24 );
|
||||
|
||||
write( m );
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
_out << std::flush;
|
||||
}
|
||||
|
||||
/// Prints formatted ASCII text
|
||||
void print_line( const std::string& line )
|
||||
{
|
||||
_out << line;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::ostream& _out;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Metafunction to detect input devices.
|
||||
* Should be replaced by an external facility in the future.
|
||||
*/
|
||||
template< typename IODevice > struct is_input_device : mpl::false_{};
|
||||
template< typename FormatTag > struct is_input_device< file_stream_device< FormatTag > > : mpl::true_{};
|
||||
template< typename FormatTag > struct is_input_device< istream_device< FormatTag > > : mpl::true_{};
|
||||
|
||||
template< typename FormatTag
|
||||
, typename T
|
||||
, typename D = void
|
||||
>
|
||||
struct is_adaptable_input_device : mpl::false_{};
|
||||
|
||||
template< typename FormatTag
|
||||
, typename T
|
||||
>
|
||||
struct is_adaptable_input_device< FormatTag
|
||||
, T
|
||||
, typename enable_if< mpl::or_< is_base_and_derived< std::istream, T >
|
||||
, is_same < std::istream, T >
|
||||
>
|
||||
>::type
|
||||
> : mpl::true_
|
||||
{
|
||||
typedef istream_device< FormatTag > device_type;
|
||||
};
|
||||
|
||||
template< typename FormatTag >
|
||||
struct is_adaptable_input_device< FormatTag
|
||||
, FILE*
|
||||
, void
|
||||
>
|
||||
: mpl::true_
|
||||
{
|
||||
typedef file_stream_device< FormatTag > device_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Metafunction to detect output devices.
|
||||
* Should be replaced by an external facility in the future.
|
||||
*/
|
||||
template<typename IODevice> struct is_output_device : mpl::false_{};
|
||||
|
||||
template< typename FormatTag > struct is_output_device< file_stream_device< FormatTag > > : mpl::true_{};
|
||||
template< typename FormatTag > struct is_output_device< ostream_device < FormatTag > > : mpl::true_{};
|
||||
|
||||
template< typename FormatTag
|
||||
, typename IODevice
|
||||
, typename D = void
|
||||
>
|
||||
struct is_adaptable_output_device : mpl::false_ {};
|
||||
|
||||
template< typename FormatTag
|
||||
, typename T
|
||||
> struct is_adaptable_output_device< FormatTag
|
||||
, T
|
||||
, typename enable_if< mpl::or_< is_base_and_derived< std::ostream, T >
|
||||
, is_same < std::ostream, T >
|
||||
>
|
||||
>::type
|
||||
> : mpl::true_
|
||||
{
|
||||
typedef ostream_device< FormatTag > device_type;
|
||||
};
|
||||
|
||||
template<typename FormatTag> struct is_adaptable_output_device<FormatTag,FILE*,void>
|
||||
: mpl::true_
|
||||
{
|
||||
typedef file_stream_device< FormatTag > device_type;
|
||||
};
|
||||
|
||||
template< typename Device, typename FormatTag, typename ConversionPolicy > class reader;
|
||||
template< typename Device, typename FormatTag, typename Log = no_log > class writer;
|
||||
|
||||
template< typename Device, typename FormatTag > class dynamic_image_reader;
|
||||
template< typename Device, typename FormatTag, typename Log = no_log > class dynamic_image_writer;
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_IO_DEVICE_HPP
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_IO_ERROR_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_IO_ERROR_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning \n
|
||||
///
|
||||
/// \date 2010 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
inline
|
||||
void io_error( const std::string& descr )
|
||||
{
|
||||
throw std::ios_base::failure( descr );
|
||||
}
|
||||
|
||||
inline
|
||||
void io_error_if( bool expr, const std::string& descr )
|
||||
{
|
||||
if( expr )
|
||||
io_error( descr );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_IO_ERROR_HPP
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright 2007-2008 Andreas Pokorny, Christian Henning
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_PATH_SPEC_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_PATH_SPEC_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Andreas Pokorny, Christian Henning \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cstdlib>
|
||||
#include <malloc.h>
|
||||
|
||||
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
|
||||
namespace boost{ namespace gil{ namespace detail{
|
||||
|
||||
template<typename P> struct is_supported_path_spec : mpl::false_ {};
|
||||
template<> struct is_supported_path_spec< std::string > : mpl::true_ {};
|
||||
template<> struct is_supported_path_spec< std::wstring > : mpl::true_ {};
|
||||
template<> struct is_supported_path_spec< const char* > : mpl::true_ {};
|
||||
template<> struct is_supported_path_spec< char* > : mpl::true_ {};
|
||||
|
||||
template<int i> struct is_supported_path_spec<const char [i]> : mpl::true_ {};
|
||||
template<int i> struct is_supported_path_spec<char [i]> : mpl::true_ {};
|
||||
|
||||
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
|
||||
template<typename String, typename Traits>
|
||||
struct is_supported_path_spec<filesystem::basic_path<String,Traits> > : mpl::true_
|
||||
{};
|
||||
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
|
||||
|
||||
inline std::string convert_to_string( std::string const& obj)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline std::string convert_to_string( std::wstring const& s )
|
||||
{
|
||||
std::size_t len = wcslen( s.c_str() );
|
||||
char* c = reinterpret_cast<char*>( alloca( len ));
|
||||
wcstombs( c, s.c_str(), len );
|
||||
|
||||
return std::string( c, c + len );
|
||||
}
|
||||
|
||||
inline std::string convert_to_string( const char* str )
|
||||
{
|
||||
return std::string( str );
|
||||
}
|
||||
|
||||
inline std::string convert_to_string( char* str )
|
||||
{
|
||||
return std::string( str );
|
||||
}
|
||||
|
||||
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
|
||||
template<typename String, typename T>
|
||||
inline std::string convert_to_string( filesystem::basic_path<String,T> const& path )
|
||||
{
|
||||
return convert_to_string( path.string() );
|
||||
}
|
||||
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
|
||||
|
||||
}}}
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_PATH_SPEC_HPP
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_READ_AND_CONVERT_IMAGE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_READ_AND_CONVERT_IMAGE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include "base.hpp"
|
||||
#include "io_device.hpp"
|
||||
#include "path_spec.hpp"
|
||||
#include "conversion_policies.hpp"
|
||||
|
||||
namespace boost{ namespace gil {
|
||||
|
||||
/// \ingroup IO
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \param cc Color converter function object.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename Image
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( Device& file
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, const ColorConverter& cc
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_input_device< Device >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef detail::read_and_convert< ColorConverter > reader_color_convert;
|
||||
|
||||
detail::reader< Device
|
||||
, FormatTag
|
||||
, reader_color_convert
|
||||
> reader( file
|
||||
, cc
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_image( img
|
||||
, reader.get_info()
|
||||
);
|
||||
|
||||
reader.apply( view( img ));
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \param cc Color converter function object.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename Image
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( Device& file
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, const ColorConverter& cc
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
device_type dev( file );
|
||||
|
||||
read_and_convert_image( dev
|
||||
, img
|
||||
, settings
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \param cc Color converter function object.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Image
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( const String& file_name
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, const ColorConverter& cc
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
read_and_convert_image( device
|
||||
, img
|
||||
, settings
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param cc Color converter function object.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Image
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( const String& file_name
|
||||
, Image& img
|
||||
, const ColorConverter& cc
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_image( file_name
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param cc Color converter function object.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( Device& device
|
||||
, Image& img
|
||||
, const ColorConverter& cc
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< mpl::or_< detail::is_input_device< Device >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_image( device
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( const String& file_name
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_image( file_name
|
||||
, img
|
||||
, settings
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( Device& device
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< mpl::or_< detail::is_input_device< Device >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_image( device
|
||||
, img
|
||||
, settings
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( const String& file_name
|
||||
, Image& img
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_image( file_name
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_image( Device& device
|
||||
, Image& img
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< mpl::or_< detail::is_input_device< Device >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_image( device
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_READ_AND_CONVERT_IMAGE_HPP
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_READ_AND_CONVERT_VIEW_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_READ_AND_CONVERT_VIEW_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include "base.hpp"
|
||||
#include "io_device.hpp"
|
||||
#include "path_spec.hpp"
|
||||
#include "conversion_policies.hpp"
|
||||
|
||||
namespace boost{ namespace gil {
|
||||
|
||||
/// \ingroup IO
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \param cc Color converter function object.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( Device& file
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, const ColorConverter& cc
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_input_device< Device >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef detail::read_and_convert< ColorConverter > reader_color_convert;
|
||||
|
||||
detail::reader< Device
|
||||
, FormatTag
|
||||
, reader_color_convert
|
||||
> reader( file
|
||||
, cc
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_view( view
|
||||
, reader.get_info()
|
||||
);
|
||||
|
||||
reader.apply( view );
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \param cc Color converter function object.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( Device& file
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, const ColorConverter& cc
|
||||
, typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
|
||||
device_type dev( file );
|
||||
|
||||
read_and_convert_view( dev
|
||||
, view
|
||||
, settings
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \param cc Color converter function object.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename View
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( const String& file_name
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, const ColorConverter& cc
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
read_and_convert_view( device
|
||||
, view
|
||||
, settings
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param cc Color converter function object.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename View
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( const String& file_name
|
||||
, const View& view
|
||||
, const ColorConverter& cc
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_view( file_name
|
||||
, view
|
||||
, image_read_settings< FormatTag >()
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param cc Color converter function object.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename View
|
||||
, typename ColorConverter
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( Device& device
|
||||
, const View& view
|
||||
, const ColorConverter& cc
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< mpl::or_< detail::is_input_device< Device >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_view( device
|
||||
, view
|
||||
, image_read_settings< FormatTag >()
|
||||
, cc
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( const String& file_name
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_view( file_name
|
||||
, view
|
||||
, settings
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( Device& device
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< mpl::or_< detail::is_input_device< Device >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_view( device
|
||||
, view
|
||||
, settings
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( const String& file_name
|
||||
, const View& view
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_view( file_name
|
||||
, view
|
||||
, image_read_settings< FormatTag >()
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads and color-converts an image view. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_and_convert_view( Device& device
|
||||
, const View& view
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< mpl::or_< detail::is_input_device< Device >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_and_convert_view( device
|
||||
, view
|
||||
, image_read_settings< FormatTag >()
|
||||
, default_color_converter()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_READ_AND_CONVERT_VIEW_HPP
|
||||
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_READ_IMAGE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_READ_IMAGE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include <boost/gil/extension/toolbox/dynamic_images.hpp>
|
||||
|
||||
#include "base.hpp"
|
||||
#include "io_device.hpp"
|
||||
#include "path_spec.hpp"
|
||||
#include "conversion_policies.hpp"
|
||||
|
||||
namespace boost{ namespace gil {
|
||||
|
||||
/// \ingroup IO
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< detail::is_input_device< Device >
|
||||
, is_format_tag < FormatTag >
|
||||
, is_read_supported < typename get_pixel_type< typename Image::view_t >::type
|
||||
, FormatTag
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::reader< Device
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
> reader( file
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_image( img
|
||||
, reader.get_info()
|
||||
);
|
||||
|
||||
reader.apply( view( img ));
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
, is_read_supported< typename get_pixel_type< typename Image::view_t >::type
|
||||
, FormatTag
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
|
||||
device_type dev(file);
|
||||
detail::reader< device_type
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
> reader( dev
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_image( img
|
||||
, reader.get_info()
|
||||
);
|
||||
|
||||
reader.apply( view( img ));
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( const String& file_name
|
||||
, Image& img
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
|
||||
, is_format_tag< FormatTag >
|
||||
, is_read_supported< typename get_pixel_type< typename Image::view_t >::type
|
||||
, FormatTag
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::file_stream_device<FormatTag>::read_tag read_tag;
|
||||
|
||||
detail::file_stream_device<FormatTag> device( detail::convert_to_string( file_name )
|
||||
, read_tag()
|
||||
);
|
||||
|
||||
read_image( device
|
||||
, img
|
||||
, settings
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, Image& img
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< detail::is_input_device< Device >
|
||||
, is_format_tag < FormatTag >
|
||||
, is_read_supported < typename get_pixel_type< typename Image::view_t >::type
|
||||
, FormatTag
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_image( file
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, Image& img
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
, is_read_supported< typename get_pixel_type< typename Image::view_t >::type
|
||||
, FormatTag
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag, Device >::device_type device_type;
|
||||
device_type dev( file );
|
||||
|
||||
read_image( dev
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Image
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( const String& file_name
|
||||
, Image& img
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
|
||||
, is_format_tag< FormatTag >
|
||||
, is_read_supported< typename get_pixel_type< typename Image::view_t >::type
|
||||
, FormatTag
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
read_image( device
|
||||
, img
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
///////////////////////////// dynamic images
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param images Dynamic image ( mpl::vector ). See boost::gil::dynamic_image extension.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
template < typename Device
|
||||
, typename Images
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, any_image< Images >& images
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< detail::is_input_device< Device >
|
||||
, is_format_tag < FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::dynamic_image_reader< Device
|
||||
, FormatTag
|
||||
> dyn_reader( file
|
||||
, settings
|
||||
);
|
||||
|
||||
dyn_reader.init_image( images
|
||||
, dyn_reader.get_info()
|
||||
);
|
||||
|
||||
dyn_reader.apply( images );
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param images Dynamic image ( mpl::vector ). See boost::gil::dynamic_image extension.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
|
||||
template < typename Device
|
||||
, typename Images
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, any_image< Images >& images
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
device_type dev( file );
|
||||
|
||||
detail::reader< device_type
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
> reader( dev
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_image( images
|
||||
, reader.get_info
|
||||
);
|
||||
|
||||
reader.apply( view( images ));
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param images Dynamic image ( mpl::vector ). See boost::gil::dynamic_image extension.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Images
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( const String& file_name
|
||||
, any_image< Images >& images
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::file_stream_device< FormatTag >::read_tag read_tag;
|
||||
|
||||
detail::file_stream_device<FormatTag> device( detail::convert_to_string( file_name )
|
||||
, read_tag()
|
||||
);
|
||||
|
||||
read_image( device
|
||||
, images
|
||||
, settings
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param images Dynamic image ( mpl::vector ). See boost::gil::dynamic_image extension.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Images
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, any_image< Images >& images
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< detail::is_input_device< Device >
|
||||
, is_format_tag < FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_image( file
|
||||
, images
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param images Dynamic image ( mpl::vector ). See boost::gil::dynamic_image extension.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename Images
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( Device& file
|
||||
, any_image< Images >& images
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
device_type dev( file );
|
||||
|
||||
read_image( dev
|
||||
, images
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image without conversion. Image memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param images Dynamic image ( mpl::vector ). See boost::gil::dynamic_image extension.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename Images
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_image( const String& file_name
|
||||
, any_image< Images >& images
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
|
||||
, is_format_tag< FormatTag >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
read_image( device
|
||||
, images
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_READ_IMAGE_HPP
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_IMAGE_READ_INFO_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_IMAGE_READ_INFO_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include "base.hpp"
|
||||
#include "io_device.hpp"
|
||||
#include "path_spec.hpp"
|
||||
|
||||
namespace boost{ namespace gil {
|
||||
|
||||
/// \ingroup IO
|
||||
|
||||
/// \brief Returns the image info. Image info is file format specific.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \return image_read_info object dependent on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
image_read_info< FormatTag >
|
||||
read_image_info( Device& file
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_input_device< Device >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
return detail::reader< Device
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
>( file
|
||||
, settings
|
||||
).get_info();
|
||||
}
|
||||
|
||||
/// \brief Returns the image info. Image info is file format specific.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \return image_read_info object dependent on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
image_read_info< FormatTag >
|
||||
read_image_info( Device& file
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_input_device< Device >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
return read_image_info( file
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// \brief Returns the image info. Image info is file format specific.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \return image_read_info object dependent on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
image_read_info<FormatTag>
|
||||
read_image_info( Device& file
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
|
||||
device_type dev( file );
|
||||
|
||||
return detail::reader< device_type
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
>( dev
|
||||
, settings
|
||||
).get_info();
|
||||
}
|
||||
|
||||
/// \brief Returns the image info. Image info is file format specific.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \return image_read_info object dependent on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
image_read_info< FormatTag >
|
||||
read_image_info( Device& file
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
|
||||
device_type dev( file );
|
||||
|
||||
return read_image_info( dev
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Returns the image info. Image info is file format specific.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \return image_read_info object dependent on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename String
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
image_read_info< FormatTag >
|
||||
read_image_info( const String& file_name
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > reader( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
return read_image_info( reader
|
||||
, settings
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Returns the image info. Image info is file format specific.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \return image_read_info object dependent on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename String
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
image_read_info< FormatTag >
|
||||
read_image_info( const String& file_name
|
||||
, const FormatTag&
|
||||
, typename enable_if< mpl::and_< is_format_tag< FormatTag >
|
||||
, detail::is_supported_path_spec< String >
|
||||
>
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > reader( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
return read_image_info( reader
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_IMAGE_READ_INFO_HPP
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_READ_VIEW_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_READ_VIEW_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include "base.hpp"
|
||||
#include "io_device.hpp"
|
||||
#include "path_spec.hpp"
|
||||
|
||||
namespace boost{ namespace gil {
|
||||
|
||||
/// \ingroup IO
|
||||
|
||||
/// \brief Reads an image view without conversion. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_view( Device& file
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_input_device< Device >::type
|
||||
, typename is_format_tag < FormatTag >::type
|
||||
, typename is_read_supported < typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::reader< Device
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
> reader( file
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_view( view
|
||||
, reader.get_info()
|
||||
);
|
||||
|
||||
reader.apply( view );
|
||||
}
|
||||
|
||||
/// \brief Reads an image view without conversion. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_view( Device& file
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::type
|
||||
, typename is_format_tag<FormatTag>::type
|
||||
, typename is_read_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::device_type device_type;
|
||||
|
||||
device_type dev( file );
|
||||
|
||||
detail::reader< device_type
|
||||
, FormatTag
|
||||
, detail::read_and_no_convert
|
||||
> reader( dev
|
||||
, settings
|
||||
);
|
||||
|
||||
reader.init_view( view
|
||||
, reader.get_info()
|
||||
);
|
||||
|
||||
reader.apply( view );
|
||||
}
|
||||
|
||||
/// \brief Reads an image view without conversion. No memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param settings Specifies read settings depending on the image format.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_view( const String& file_name
|
||||
, const View& view
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_read_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device<FormatTag> device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::read_tag()
|
||||
);
|
||||
|
||||
read_view( device
|
||||
, view
|
||||
, settings
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image view without conversion. No memory is allocated.
|
||||
/// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template < typename String
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_view( const String& file_name
|
||||
, const View& view
|
||||
, const FormatTag&
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_read_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_view( file_name
|
||||
, view
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
/// \brief Reads an image view without conversion. No memory is allocated.
|
||||
/// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
|
||||
/// \param view The image view in which the data is read into.
|
||||
/// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
|
||||
/// \throw std::ios_base::failure
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void read_view( Device& device
|
||||
, const View& view
|
||||
, const FormatTag&
|
||||
, typename enable_if< typename mpl::and_< typename is_format_tag< FormatTag >::type
|
||||
, typename mpl::or_< typename detail::is_input_device< Device >::type
|
||||
, typename detail::is_adaptable_input_device< FormatTag
|
||||
, Device
|
||||
>::type
|
||||
>::type
|
||||
, typename is_read_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
read_view( device
|
||||
, view
|
||||
, image_read_settings< FormatTag >()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_READ_VIEW_HPP
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_READER_BASE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_READER_BASE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "base.hpp"
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
/// Reader Base Class
|
||||
///
|
||||
/// It provides some basic functionality which is shared for all readers.
|
||||
/// For instance, it recreates images when necessary. It checks whether
|
||||
/// user supplied coordinates are valid.
|
||||
///
|
||||
/// @tparam FormatTag A format tag, like jpeg_tag.
|
||||
/// @tparam ConversionPolicy Conversion policy, see coversion_policies.hpp.
|
||||
template< typename FormatTag
|
||||
, typename ConversionPolicy
|
||||
>
|
||||
struct reader_base
|
||||
{
|
||||
public:
|
||||
|
||||
/// Initializes an image. But also does some check ups.
|
||||
///
|
||||
/// @tparam Image Image which implements boost::gil's ImageConcept.
|
||||
///
|
||||
/// @param img The image.
|
||||
/// @param info The image read info.
|
||||
template< typename Image >
|
||||
void init_image( Image& img
|
||||
, const image_read_info< FormatTag >& info
|
||||
)
|
||||
{
|
||||
_info = info;
|
||||
|
||||
setup( _settings._dim );
|
||||
|
||||
img.recreate( _settings._dim.x
|
||||
, _settings._dim.y
|
||||
);
|
||||
}
|
||||
|
||||
template< typename View >
|
||||
void init_view( const View& view
|
||||
, const image_read_info< FormatTag >& info
|
||||
)
|
||||
{
|
||||
_info = info;
|
||||
|
||||
setup( view.dimensions() );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
reader_base( const image_read_settings< FormatTag >& settings )
|
||||
: _settings( settings )
|
||||
{}
|
||||
reader_base( const typename ConversionPolicy::color_converter_type& cc
|
||||
, const image_read_settings< FormatTag >& settings
|
||||
)
|
||||
: _settings( settings )
|
||||
, _cc_policy( cc )
|
||||
{}
|
||||
|
||||
private:
|
||||
|
||||
void setup( const point_t& dim )
|
||||
{
|
||||
check_coordinates( dim );
|
||||
|
||||
if( dim == point_t( 0, 0 ))
|
||||
{
|
||||
_settings._dim.x = _info._width;
|
||||
_settings._dim.y = _info._height;
|
||||
}
|
||||
else
|
||||
{
|
||||
_settings._dim = dim;
|
||||
}
|
||||
}
|
||||
|
||||
void check_coordinates( const point_t& dim )
|
||||
{
|
||||
typedef point_t::value_type int_t;
|
||||
|
||||
int_t width = static_cast< int_t >( _info._width );
|
||||
int_t height = static_cast< int_t >( _info._height );
|
||||
|
||||
io_error_if( ( _settings._top_left.x < 0
|
||||
|| _settings._top_left.y < 0
|
||||
|| dim.x < 0
|
||||
|| dim.y < 0
|
||||
)
|
||||
, "User provided view has incorrect size." );
|
||||
|
||||
|
||||
io_error_if( ( ( width ) < _settings._top_left.x
|
||||
&& ( width ) <= dim.x
|
||||
&& ( height ) < _settings._top_left.y
|
||||
&& ( height ) <= dim.y )
|
||||
, "User provided view has incorrect size." );
|
||||
|
||||
io_error_if( ( ( _settings._top_left.x + dim.x ) > width
|
||||
|| ( _settings._top_left.y + dim.y ) > height
|
||||
)
|
||||
, "User provided view has incorrect size." );
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
image_read_settings< FormatTag > _settings;
|
||||
image_read_info< FormatTag > _info;
|
||||
|
||||
ConversionPolicy _cc_policy;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_READER_BASE_HPP
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_READ_HELPER_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_READ_HELPER_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief Helper for having one read implementation used for
|
||||
/// bit_aligned and byte images.
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/gil/extension/toolbox/gil_extensions.hpp>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
template< typename Pixel
|
||||
, typename DummyT = void
|
||||
>
|
||||
struct row_buffer_helper
|
||||
{
|
||||
typedef Pixel element_t;
|
||||
typedef std::vector< element_t > buffer_t;
|
||||
typedef typename buffer_t::iterator iterator_t;
|
||||
|
||||
row_buffer_helper( std::size_t width
|
||||
, bool
|
||||
)
|
||||
: _row_buffer( width )
|
||||
{}
|
||||
|
||||
element_t* data() { return &_row_buffer[0]; }
|
||||
|
||||
iterator_t begin() { return _row_buffer.begin(); }
|
||||
iterator_t end() { return _row_buffer.end(); }
|
||||
|
||||
buffer_t& buffer() { return _row_buffer; }
|
||||
|
||||
private:
|
||||
|
||||
buffer_t _row_buffer;
|
||||
};
|
||||
|
||||
template<typename Pixel >
|
||||
struct row_buffer_helper< Pixel
|
||||
, typename enable_if< typename mpl::and_< typename is_bit_aligned< Pixel >::type
|
||||
, typename is_homogeneous< Pixel >::type
|
||||
>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
typedef byte_t element_t;
|
||||
typedef std::vector< element_t > buffer_t;
|
||||
typedef Pixel pixel_type;
|
||||
typedef bit_aligned_pixel_iterator<pixel_type> iterator_t;
|
||||
|
||||
row_buffer_helper( std::size_t width
|
||||
, bool in_bytes
|
||||
)
|
||||
: _c( ( width
|
||||
* num_channels< pixel_type >::type::value
|
||||
* channel_type< pixel_type >::type::num_bits
|
||||
)
|
||||
>> 3
|
||||
)
|
||||
|
||||
, _r( width
|
||||
* num_channels< pixel_type >::type::value
|
||||
* channel_type< pixel_type >::type::num_bits
|
||||
- ( _c << 3 )
|
||||
)
|
||||
{
|
||||
if( in_bytes )
|
||||
{
|
||||
_row_buffer.resize( width );
|
||||
}
|
||||
else
|
||||
{
|
||||
// add one byte if there are remaining bits
|
||||
_row_buffer.resize( _c + ( _r!=0 ));
|
||||
}
|
||||
}
|
||||
|
||||
element_t* data() { return &_row_buffer[0]; }
|
||||
|
||||
iterator_t begin() { return iterator_t( &_row_buffer.front(),0 ); }
|
||||
iterator_t end() { return _r == 0 ? iterator_t( &_row_buffer.back() + 1, 0 )
|
||||
: iterator_t( &_row_buffer.back() , (int) _r );
|
||||
}
|
||||
|
||||
buffer_t& buffer() { return _row_buffer; }
|
||||
|
||||
private:
|
||||
|
||||
// For instance 25 pixels of rgb2 type would be:
|
||||
// overall 25 pixels * 3 channels * 2 bits/channel = 150 bits
|
||||
// c = 18 bytes
|
||||
// r = 6 bits
|
||||
|
||||
std::size_t _c; // number of full bytes
|
||||
std::size_t _r; // number of remaining bits
|
||||
|
||||
buffer_t _row_buffer;
|
||||
};
|
||||
|
||||
template< typename View
|
||||
, typename D = void
|
||||
>
|
||||
struct row_buffer_helper_view : row_buffer_helper< typename View::value_type >
|
||||
{
|
||||
row_buffer_helper_view( std::size_t width
|
||||
, bool in_bytes
|
||||
)
|
||||
: row_buffer_helper< typename View::value_type >( width
|
||||
, in_bytes
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
template< typename View >
|
||||
struct row_buffer_helper_view< View
|
||||
, typename enable_if< typename is_bit_aligned< typename View::value_type
|
||||
>::type
|
||||
>::type
|
||||
> : row_buffer_helper< typename View::reference >
|
||||
{
|
||||
row_buffer_helper_view( std::size_t width
|
||||
, bool in_bytes
|
||||
)
|
||||
: row_buffer_helper< typename View::reference >( width
|
||||
, in_bytes
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_DETAIL_READ_HELPER_HPP
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_BASE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_BASE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
|
||||
#include <boost/gil/image.hpp>
|
||||
#include <boost/gil/utilities.hpp>
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
#include <boost/gil/extension/toolbox/gray_alpha.hpp>
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
struct double_zero { static double apply() { return 0.0; } };
|
||||
struct double_one { static double apply() { return 1.0; } };
|
||||
|
||||
typedef scoped_channel_value< double, double_zero, double_one > bits64f;
|
||||
|
||||
typedef unsigned char byte_t;
|
||||
typedef std::vector< byte_t > byte_vector_t;
|
||||
|
||||
typedef point2< std::ptrdiff_t > point_t;
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<> struct is_floating_point< gil::bits32f > : mpl::true_ {};
|
||||
template<> struct is_floating_point< gil::bits64f > : mpl::true_ {};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
///@todo We should use boost::preprocessor here.
|
||||
|
||||
typedef bit_aligned_image1_type< 1, gray_layout_t >::type gray1_image_t;
|
||||
typedef bit_aligned_image1_type< 2, gray_layout_t >::type gray2_image_t;
|
||||
typedef bit_aligned_image1_type< 4, gray_layout_t >::type gray4_image_t;
|
||||
|
||||
typedef pixel< double, gray_layout_t > gray64f_pixel_t;
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
typedef pixel< double, gray_alpha_layout_t > gray_alpha64f_pixel_t;
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
typedef pixel< double, rgb_layout_t > rgb64f_pixel_t;
|
||||
typedef pixel< double, rgba_layout_t > rgba64f_pixel_t;
|
||||
|
||||
typedef image< gray64f_pixel_t , false > gray64f_image_t;
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
typedef image< gray_alpha32f_pixel_t, false > gray_alpha32f_image_t;
|
||||
typedef image< gray_alpha32f_pixel_t, true > gray_alpha32f_planar_image_t;
|
||||
typedef image< gray_alpha64f_pixel_t, false > gray_alpha64f_image_t;
|
||||
typedef image< gray_alpha64f_pixel_t, true > gray_alpha64f_planar_image_t;
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
typedef image< rgb64f_pixel_t , false > rgb64f_image_t;
|
||||
typedef image< rgb64f_pixel_t , true > rgb64f_planar_image_t;
|
||||
typedef image< rgba64f_pixel_t , false > rgba64f_image_t;
|
||||
typedef image< rgba64f_pixel_t , true > rgba64f_planar_image_t;
|
||||
|
||||
} // namespace details
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_BASE_HPP
|
||||
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
Use, modification and distribution are 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).
|
||||
*/
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_WRITE_VIEW_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_WRITE_VIEW_HPP
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
#include "base.hpp"
|
||||
#include "io_device.hpp"
|
||||
#include "path_spec.hpp"
|
||||
#include "conversion_policies.hpp"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief
|
||||
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
|
||||
///
|
||||
/// \date 2007-2008 \n
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace boost{ namespace gil {
|
||||
|
||||
/// \ingroup IO
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const View& view
|
||||
, const FormatTag&
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_output_device< Device >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_write_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::writer< Device
|
||||
, FormatTag
|
||||
> writer( device );
|
||||
|
||||
writer.apply( view );
|
||||
}
|
||||
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const View& view
|
||||
, const FormatTag& tag
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_write_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::device_type dev_t;
|
||||
dev_t dev( device );
|
||||
|
||||
write_view( dev
|
||||
, view
|
||||
, tag
|
||||
);
|
||||
}
|
||||
|
||||
template< typename String
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void write_view( const String& file_name
|
||||
, const View& view
|
||||
, const FormatTag& tag
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_write_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device<FormatTag> device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device<FormatTag>::write_tag()
|
||||
);
|
||||
|
||||
write_view( device
|
||||
, view
|
||||
, tag
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup IO
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
, typename Log
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const View& view
|
||||
, const image_write_info<FormatTag, Log>& info
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_output_device< Device >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_write_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::writer< Device
|
||||
, FormatTag
|
||||
, Log
|
||||
> writer( device );
|
||||
|
||||
writer.apply( view
|
||||
, info );
|
||||
}
|
||||
|
||||
template< typename Device
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
, typename Log
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const View& view
|
||||
, const image_write_info< FormatTag, Log >& info
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_write_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::device_type dev( device );
|
||||
|
||||
write_view( dev
|
||||
, view
|
||||
, info
|
||||
);
|
||||
}
|
||||
|
||||
template< typename String
|
||||
, typename View
|
||||
, typename FormatTag
|
||||
, typename Log
|
||||
>
|
||||
inline
|
||||
void write_view( const String& file_name
|
||||
, const View& view
|
||||
, const image_write_info< FormatTag, Log >& info
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
, typename is_write_supported< typename get_pixel_type< View >::type
|
||||
, FormatTag
|
||||
>::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::write_tag()
|
||||
);
|
||||
|
||||
write_view( device
|
||||
, view
|
||||
, info
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////// dynamic_image
|
||||
|
||||
// without image_write_info
|
||||
template< typename Device
|
||||
, typename Views
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const any_image_view< Views >& view
|
||||
, const FormatTag&
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_output_device< Device >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::dynamic_image_writer< Device
|
||||
, FormatTag
|
||||
> dyn_writer( device );
|
||||
|
||||
dyn_writer.apply( view );
|
||||
}
|
||||
|
||||
template< typename Device
|
||||
, typename Views
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const any_image_view< Views >& views
|
||||
, const FormatTag& tag
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typedef typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::device_type dev_t;
|
||||
dev_t dev( device );
|
||||
|
||||
write_view( dev
|
||||
, views
|
||||
, tag
|
||||
);
|
||||
}
|
||||
|
||||
template< typename String
|
||||
, typename Views
|
||||
, typename FormatTag
|
||||
>
|
||||
inline
|
||||
void write_view( const String& file_name
|
||||
, const any_image_view< Views >& views
|
||||
, const FormatTag& tag
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device<FormatTag> device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device<FormatTag>::write_tag()
|
||||
);
|
||||
|
||||
write_view( device
|
||||
, views
|
||||
, tag
|
||||
);
|
||||
}
|
||||
|
||||
// with image_write_info
|
||||
/// \ingroup IO
|
||||
template< typename Device
|
||||
, typename Views
|
||||
, typename FormatTag
|
||||
, typename Log
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const any_image_view< Views >& views
|
||||
, const image_write_info< FormatTag
|
||||
, Log
|
||||
>& info
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_output_device< Device >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::dynamic_image_writer< Device
|
||||
, FormatTag
|
||||
, Log
|
||||
> dyn_writer( device );
|
||||
|
||||
dyn_writer.apply( views
|
||||
, info
|
||||
);
|
||||
}
|
||||
|
||||
template< typename Device
|
||||
, typename Views
|
||||
, typename FormatTag
|
||||
, typename Log
|
||||
>
|
||||
inline
|
||||
void write_view( Device& device
|
||||
, const any_image_view< Views >& views
|
||||
, const image_write_info< FormatTag
|
||||
, Log
|
||||
>& info
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
typename detail::is_adaptable_output_device< FormatTag
|
||||
, Device
|
||||
>::device_type dev( device );
|
||||
|
||||
write_view( dev
|
||||
, views
|
||||
, info
|
||||
);
|
||||
}
|
||||
|
||||
template< typename String
|
||||
, typename Views
|
||||
, typename FormatTag
|
||||
, typename Log
|
||||
>
|
||||
inline
|
||||
void write_view( const String& file_name
|
||||
, const any_image_view< Views >& views
|
||||
, const image_write_info< FormatTag
|
||||
, Log
|
||||
>& info
|
||||
, typename enable_if< typename mpl::and_< typename detail::is_supported_path_spec< String >::type
|
||||
, typename is_format_tag< FormatTag >::type
|
||||
>::type
|
||||
>::type* /* ptr */ = 0
|
||||
)
|
||||
{
|
||||
detail::file_stream_device< FormatTag > device( detail::convert_to_string( file_name )
|
||||
, typename detail::file_stream_device< FormatTag >::write_tag()
|
||||
);
|
||||
|
||||
write_view( device
|
||||
, views
|
||||
, info
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_GIL_EXTENSION_IO_WRITE_VIEW_HPP
|
||||
Reference in New Issue
Block a user