feat():initial version

This commit is contained in:
2026-06-09 20:16:47 +08:00
commit 85fbb3188c
14809 changed files with 3044607 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
//
// Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_BASE_HPP
#define BOOST_GIL_IO_BASE_HPP
#include <boost/gil/extension/toolbox/toolbox.hpp>
#include <boost/gil/bit_aligned_pixel_reference.hpp>
#include <boost/gil/bit_aligned_pixel_iterator.hpp>
#include <boost/gil/color_convert.hpp>
#include <boost/gil/utilities.hpp>
#include <boost/gil/io/error.hpp>
#include <boost/gil/io/typedefs.hpp>
#include <istream>
#include <ostream>
#include <type_traits>
#include <vector>
namespace boost { namespace gil {
struct format_tag {};
template< typename Property >
struct property_base
{
using type = Property;
};
template<typename FormatTag>
struct is_format_tag : std::is_base_of<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:
void set( 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, std::true_type 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
{
using type = Property;
};
} // namespace detail
struct read_support_true { static constexpr bool is_supported = true; };
struct read_support_false { static constexpr bool is_supported = false; };
struct write_support_true { static constexpr bool is_supported = true; };
struct write_support_false{ static constexpr bool is_supported = false; };
class no_log {};
template< typename Device, typename FormatTag > struct reader_backend;
template< typename Device, typename FormatTag > struct writer_backend;
template< typename FormatTag > struct image_read_info;
template< typename FormatTag > struct image_read_settings;
template< typename FormatTag, typename Log = no_log > struct image_write_info;
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,197 @@
//
// Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_BIT_OPERATIONS_HPP
#define BOOST_GIL_IO_BIT_OPERATIONS_HPP
#include <boost/gil/io/typedefs.hpp>
#include <array>
#include <cstddef>
#include <type_traits>
namespace boost { namespace gil { namespace detail {
// 1110 1100 -> 0011 0111
template <typename Buffer, typename IsBitAligned>
struct mirror_bits
{
mirror_bits(bool) {};
void operator()(Buffer&) {}
void operator()(byte_t*, std::size_t){}
};
// The functor will generate a lookup table since the
// mirror operation is quite costly.
template <typename Buffer>
struct mirror_bits<Buffer, std::true_type>
{
mirror_bits(bool apply_operation = true)
: apply_operation_(apply_operation)
{
if(apply_operation_)
{
byte_t i = 0;
do
{
lookup_[i] = mirror(i);
}
while (i++ != 255);
}
}
void operator()(Buffer& buffer)
{
if (apply_operation_)
for_each(buffer.begin(), buffer.end(), [this](byte_t& c) { lookup(c); });
}
void operator()(byte_t *dst, std::size_t size)
{
for (std::size_t i = 0; i < size; ++i)
{
lookup(*dst);
++dst;
}
}
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;
}
std::array<byte_t, 256> lookup_;
bool apply_operation_;
};
// 0011 1111 -> 1100 0000
template <typename Buffer, typename IsBitAligned>
struct negate_bits
{
void operator()(Buffer&) {};
};
template <typename Buffer>
struct negate_bits<Buffer, std::true_type>
{
void operator()(Buffer& buffer)
{
for_each(buffer.begin(), buffer.end(),
negate_bits<Buffer, std::true_type>::negate);
}
void operator()(byte_t* dst, std::size_t size)
{
for (std::size_t i = 0; i < size; ++i)
{
negate(*dst);
++dst;
}
}
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, std::true_type>
{
void operator()(Buffer& buffer)
{
for_each(buffer.begin(), buffer.end(),
swap_half_bytes<Buffer, std::true_type>::swap);
}
void operator()(byte_t* dst, std::size_t size)
{
for (std::size_t i = 0; i < size; ++i)
{
swap(*dst);
++dst;
}
}
private:
static void swap(byte_t& c)
{
c = ((c << 4) & 0xF0) | ((c >> 4) & 0x0F);
}
};
template <typename Buffer>
struct do_nothing
{
do_nothing() = default;
void operator()(Buffer&) {}
};
/// Count consecutive zeros on the right
template <typename T>
inline unsigned int trailing_zeros(T x) noexcept
{
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) noexcept
{
unsigned int n = 0;
while (x)
{
// clear the least significant bit set
x &= x - 1;
++n;
}
return n;
}
}}} // namespace boost::gil::detail
#endif

View File

@@ -0,0 +1,106 @@
//
// Copyright 2007-2008 Christian Henning, Andreas Pokorny
//
// Distributed under 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_IO_CONVERSION_POLICIES_HPP
#define BOOST_GIL_IO_CONVERSION_POLICIES_HPP
#include <boost/gil/image_view_factory.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/error.hpp>
#include <algorithm>
#include <iterator>
#include <type_traits>
namespace boost{ namespace gil { namespace detail {
struct read_and_no_convert
{
public:
using color_converter_type = void *;
template <typename InIterator, typename OutIterator>
void read(
InIterator const& /*begin*/, InIterator const& /*end*/ , OutIterator /*out*/,
typename std::enable_if
<
mp11::mp_not
<
pixels_are_compatible
<
typename std::iterator_traits<InIterator>::value_type,
typename std::iterator_traits<OutIterator>::value_type
>
>::value
>::type* /*dummy*/ = nullptr)
{
io_error("Data cannot be copied because the pixels are incompatible.");
}
template <typename InIterator, typename OutIterator>
void read(InIterator const& begin, InIterator const& end, OutIterator out,
typename std::enable_if
<
pixels_are_compatible
<
typename std::iterator_traits<InIterator>::value_type,
typename std::iterator_traits<OutIterator>::value_type
>::value
>::type* /*dummy*/ = nullptr)
{
std::copy(begin, end, out);
}
};
template<typename CC>
struct read_and_convert
{
public:
using color_converter_type = default_color_converter;
CC _cc;
read_and_convert()
{}
read_and_convert( const color_converter_type& cc )
: _cc( cc )
{}
template< typename InIterator
, typename OutIterator
>
void read( const InIterator& begin
, const InIterator& end
, OutIterator out
)
{
using deref_t = color_convert_deref_fn<typename std::iterator_traits<InIterator>::reference
, typename std::iterator_traits<OutIterator>::value_type //reference?
, CC
>;
std::transform( begin
, end
, out
, deref_t( _cc )
);
}
};
/// is_read_only metafunction
/// \brief Determines if reader type is read only ( no conversion ).
template< typename Conversion_Policy >
struct is_read_only : std::false_type {};
template<>
struct is_read_only<detail::read_and_no_convert> : std::true_type {};
} // namespace detail
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,739 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny
//
// Distributed under 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_IO_DEVICE_HPP
#define BOOST_GIL_IO_DEVICE_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/base.hpp>
#include <cstdio>
#include <memory>
#include <type_traits>
namespace boost { namespace gil {
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#endif
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:
using format_tag_t = FormatTag;
public:
/// Used to overload the constructor.
struct read_tag {};
struct write_tag {};
///
/// Constructor
///
file_stream_device( const std::string& file_name
, read_tag tag = read_tag()
)
: file_stream_device(file_name.c_str(), tag)
{}
///
/// Constructor
///
file_stream_device( const char* file_name
, read_tag = read_tag()
)
{
FILE* file = nullptr;
io_error_if( ( file = fopen( file_name, "rb" )) == nullptr
, "file_stream_device: failed to open file for reading"
);
_file = file_ptr_t( file
, file_deleter
);
}
///
/// Constructor
///
file_stream_device( const std::string& file_name
, write_tag tag
)
: file_stream_device(file_name.c_str(), tag)
{}
///
/// Constructor
///
file_stream_device( const char* file_name
, write_tag
)
{
FILE* file = nullptr;
io_error_if( ( file = fopen( file_name, "wb" )) == nullptr
, "file_stream_device: failed to open file for writing"
);
_file = file_ptr_t( file
, file_deleter
);
}
///
/// Constructor
///
file_stream_device( FILE* file )
: _file( file
, file_deleter
)
{}
FILE* get() { return _file.get(); }
const FILE* get() const { return _file.get(); }
int getc_unchecked()
{
return std::getc( get() );
}
char getc()
{
int ch;
io_error_if( ( ch = std::getc( get() )) == EOF
, "file_stream_device: unexpected EOF"
);
return ( char ) ch;
}
///@todo: change byte_t* to void*
std::size_t read( byte_t* data
, std::size_t count
)
{
std::size_t num_elements = fread( data
, 1
, static_cast<int>( count )
, get()
);
///@todo: add compiler symbol to turn error checking on and off.
io_error_if( ferror( get() )
, "file_stream_device: file read error"
);
//libjpeg sometimes reads blocks in 4096 bytes even when the file is smaller than that.
//return value indicates how much was actually read
//returning less than "count" is not an error
return num_elements;
}
/// Reads array
template< typename T
, int N
>
void read( T (&buf)[N] )
{
io_error_if( read( buf, N ) < N
, "file_stream_device: file read error"
);
}
/// Reads byte
uint8_t read_uint8()
{
byte_t m[1];
read( m );
return m[0];
}
/// Reads 16 bit little endian integer
uint16_t read_uint16()
{
byte_t m[2];
read( m );
return (m[1] << 8) | m[0];
}
/// Reads 32 bit little endian integer
uint32_t read_uint32()
{
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 >
std::size_t write( const T* buf
, std::size_t count
)
{
std::size_t num_elements = fwrite( buf
, buff_item<T>::size
, count
, get()
);
//return value indicates how much was actually written
//returning less than "count" is not an error
return num_elements;
}
/// Writes array
template < typename T
, std::size_t N
>
void write( const T (&buf)[N] )
{
io_error_if( write( buf, N ) < N
, "file_stream_device: file write error"
);
return ;
}
/// Writes byte
void write_uint8( uint8_t x )
{
byte_t m[1] = { x };
write(m);
}
/// Writes 16 bit little endian integer
void write_uint16( uint16_t x )
{
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_uint32( uint32_t x )
{
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 seek( long count, int whence = SEEK_SET )
{
io_error_if( fseek( get()
, count
, whence
) != 0
, "file_stream_device: file seek error"
);
}
long int tell()
{
long int pos = ftell( get() );
io_error_if( pos == -1L
, "file_stream_device: file position error"
);
return pos;
}
void flush()
{
fflush( get() );
}
/// Prints formatted ASCII text
void print_line( const std::string& line )
{
std::size_t num_elements = fwrite( line.c_str()
, sizeof( char )
, line.size()
, get()
);
io_error_if( num_elements < line.size()
, "file_stream_device: line print error"
);
}
int error()
{
return ferror( get() );
}
private:
static void file_deleter( FILE* file )
{
if( file )
{
fclose( file );
}
}
private:
using file_ptr_t = std::shared_ptr<FILE> ;
file_ptr_t _file;
};
/**
* Input stream device
*/
template< typename FormatTag >
class istream_device
{
public:
istream_device( std::istream& in )
: _in( in )
{
// does the file exists?
io_error_if( !in
, "istream_device: Stream is not valid."
);
}
int getc_unchecked()
{
return _in.get();
}
char getc()
{
int ch;
io_error_if( ( ch = _in.get() ) == EOF
, "istream_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>
void read(T (&buf)[N])
{
read(buf, N);
}
/// Reads byte
uint8_t read_uint8()
{
byte_t m[1];
read( m );
return m[0];
}
/// Reads 16 bit little endian integer
uint16_t read_uint16()
{
byte_t m[2];
read( m );
return (m[1] << 8) | m[0];
}
/// Reads 32 bit little endian integer
uint32_t read_uint32()
{
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*, std::size_t)
{
io_error( "istream_device: 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 )
{
}
std::size_t read(byte_t *, std::size_t)
{
io_error( "ostream_device: 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
, std::size_t N
>
void write( const T (&buf)[N] )
{
write( buf, N );
}
/// Writes byte
void write_uint8( uint8_t x )
{
byte_t m[1] = { x };
write(m);
}
/// Writes 16 bit little endian integer
void write_uint16( uint16_t x )
{
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_uint32( uint32_t x )
{
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 : std::false_type{};
template< typename FormatTag > struct is_input_device< file_stream_device< FormatTag > > : std::true_type{};
template< typename FormatTag > struct is_input_device< istream_device< FormatTag > > : std::true_type{};
template< typename FormatTag
, typename T
, typename D = void
>
struct is_adaptable_input_device : std::false_type{};
template <typename FormatTag, typename T>
struct is_adaptable_input_device
<
FormatTag,
T,
typename std::enable_if
<
mp11::mp_or
<
std::is_base_of<std::istream, T>,
std::is_same<std::istream, T>
>::value
>::type
> : std::true_type
{
using device_type = istream_device<FormatTag>;
};
template< typename FormatTag >
struct is_adaptable_input_device< FormatTag
, FILE*
, void
>
: std::true_type
{
using device_type = file_stream_device<FormatTag>;
};
///
/// Metafunction to decide if a given type is an acceptable read device type.
///
template< typename FormatTag
, typename T
, typename D = void
>
struct is_read_device : std::false_type
{};
template <typename FormatTag, typename T>
struct is_read_device
<
FormatTag,
T,
typename std::enable_if
<
mp11::mp_or
<
is_input_device<FormatTag>,
is_adaptable_input_device<FormatTag, T>
>::value
>::type
> : std::true_type
{
};
/**
* Metafunction to detect output devices.
* Should be replaced by an external facility in the future.
*/
template<typename IODevice> struct is_output_device : std::false_type{};
template< typename FormatTag > struct is_output_device< file_stream_device< FormatTag > > : std::true_type{};
template< typename FormatTag > struct is_output_device< ostream_device < FormatTag > > : std::true_type{};
template< typename FormatTag
, typename IODevice
, typename D = void
>
struct is_adaptable_output_device : std::false_type {};
template <typename FormatTag, typename T>
struct is_adaptable_output_device
<
FormatTag,
T,
typename std::enable_if
<
mp11::mp_or
<
std::is_base_of<std::ostream, T>,
std::is_same<std::ostream, T>
>::value
>::type
> : std::true_type
{
using device_type = ostream_device<FormatTag>;
};
template<typename FormatTag> struct is_adaptable_output_device<FormatTag,FILE*,void>
: std::true_type
{
using device_type = file_stream_device<FormatTag>;
};
///
/// Metafunction to decide if a given type is an acceptable read device type.
///
template< typename FormatTag
, typename T
, typename D = void
>
struct is_write_device : std::false_type
{};
template <typename FormatTag, typename T>
struct is_write_device
<
FormatTag,
T,
typename std::enable_if
<
mp11::mp_or
<
is_output_device<FormatTag>,
is_adaptable_output_device<FormatTag, T>
>::value
>::type
> : std::true_type
{
};
} // namespace detail
template< typename Device, typename FormatTag > class scanline_reader;
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 {
template< typename T >
struct is_reader : std::false_type
{};
template< typename Device
, typename FormatTag
, typename ConversionPolicy
>
struct is_reader< reader< Device
, FormatTag
, ConversionPolicy
>
> : std::true_type
{};
template< typename T >
struct is_dynamic_image_reader : std::false_type
{};
template< typename Device
, typename FormatTag
>
struct is_dynamic_image_reader< dynamic_image_reader< Device
, FormatTag
>
> : std::true_type
{};
template< typename T >
struct is_writer : std::false_type
{};
template< typename Device
, typename FormatTag
>
struct is_writer< writer< Device
, FormatTag
>
> : std::true_type
{};
template< typename T >
struct is_dynamic_image_writer : std::false_type
{};
template< typename Device
, typename FormatTag
>
struct is_dynamic_image_writer< dynamic_image_writer< Device
, FormatTag
>
> : std::true_type
{};
} // namespace detail
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(pop)
#endif
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,104 @@
//
// Copyright 2005-2007 Adobe Systems Incorporated
//
// Distributed under 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_IO_DYNAMIC_IO_NEW_HPP
#define BOOST_GIL_IO_DYNAMIC_IO_NEW_HPP
#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/error.hpp>
#include <type_traits>
namespace boost { namespace gil {
namespace detail {
template <long N>
struct construct_matched_t
{
template <typename ...Images,typename Pred>
static bool apply(any_image<Images...>& img, Pred pred)
{
if (pred.template apply<mp11::mp_at_c<any_image<Images...>, N-1>>())
{
using image_t = mp11::mp_at_c<any_image<Images...>, N-1>;
image_t x;
img = std::move(x);
return true;
}
else
return construct_matched_t<N-1>::apply(img, 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 boolean integral coonstant,
// 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
{
private:
OpClass* _op;
template <typename View>
void apply(View const& view, std::true_type) { _op->apply(view); }
template <typename View, typename Info>
void apply(View const& view, Info const & info, const std::true_type) { _op->apply(view, info); }
template <typename View>
void apply(View const& /* view */, std::false_type)
{
io_error("dynamic_io: unsupported view type for the given file format");
}
template <typename View, typename Info >
void apply(View const& /* view */, Info const& /* info */, const std::false_type)
{
io_error("dynamic_io: unsupported view type for the given file format");
}
public:
dynamic_io_fnobj(OpClass* op) : _op(op) {}
using result_type = void;
template <typename View>
void operator()(View const& view)
{
apply(view, typename IsSupported::template apply<View>::type());
}
template< typename View, typename Info >
void operator()(View const& view, Info const& 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...>& img, Pred pred)
{
constexpr auto size = mp11::mp_size<any_image<Images...>>::value;
return detail::construct_matched_t<size>::apply(img, pred);
}
} } // namespace boost::gil
#endif

View File

@@ -0,0 +1,29 @@
//
// Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_ERROR_HPP
#define BOOST_GIL_IO_ERROR_HPP
#include <ios>
namespace boost { namespace gil {
inline void io_error(const char* descr)
{
throw std::ios_base::failure(descr);
}
inline void io_error_if(bool expr, const char* descr)
{
if (expr)
io_error(descr);
}
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,69 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_GET_READ_DEVICE_HPP
#define BOOST_GIL_IO_GET_READ_DEVICE_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <type_traits>
namespace boost { namespace gil {
template< typename T
, typename FormatTag
, class Enable = void
>
struct get_read_device
{};
template <typename Device, typename FormatTag>
struct get_read_device
<
Device,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using type = typename detail::is_adaptable_input_device
<
FormatTag,
Device
>::device_type;
};
template <typename String, typename FormatTag>
struct get_read_device
<
String,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using type = detail::file_stream_device<FormatTag>;
};
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,167 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_GET_READER_HPP
#define BOOST_GIL_IO_GET_READER_HPP
#include <boost/gil/io/get_read_device.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost { namespace gil {
/// \brief Helper metafunction to generate image reader type.
template
<
typename T,
typename FormatTag,
typename ConversionPolicy,
class Enable = void
>
struct get_reader {};
template <typename String, typename FormatTag, typename ConversionPolicy>
struct get_reader
<
String,
FormatTag,
ConversionPolicy,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_read_device<String, FormatTag>::type;
using type = reader<device_t, FormatTag, ConversionPolicy>;
};
template <typename Device, typename FormatTag, typename ConversionPolicy>
struct get_reader
<
Device,
FormatTag,
ConversionPolicy,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_read_device<Device, FormatTag>::type;
using type = reader<device_t, FormatTag, ConversionPolicy>;
};
/// \brief Helper metafunction to generate dynamic image reader type.
template <typename T, typename FormatTag, class Enable = void>
struct get_dynamic_image_reader
{
};
template <typename String, typename FormatTag>
struct get_dynamic_image_reader
<
String,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_read_device<String, FormatTag>::type;
using type = dynamic_image_reader<device_t, FormatTag>;
};
template <typename Device, typename FormatTag>
struct get_dynamic_image_reader
<
Device,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_read_device<Device, FormatTag>::type;
using type = dynamic_image_reader<device_t, FormatTag>;
};
/// \brief Helper metafunction to generate image backend type.
template <typename T, typename FormatTag, class Enable = void>
struct get_reader_backend
{
};
template <typename String, typename FormatTag>
struct get_reader_backend
<
String,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_read_device<String, FormatTag>::type;
using type = reader_backend<device_t, FormatTag>;
};
template <typename Device, typename FormatTag>
struct get_reader_backend
<
Device,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_read_device<Device, FormatTag>::type;
using type = reader_backend<device_t, FormatTag>;
};
/// \brief Helper metafunction to generate image scanline_reader type.
template <typename T, typename FormatTag>
struct get_scanline_reader
{
using device_t = typename get_read_device<T, FormatTag>::type;
using type = scanline_reader<device_t, FormatTag>;
};
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,61 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_GET_WRITE_DEVICE_HPP
#define BOOST_GIL_IO_GET_WRITE_DEVICE_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename T, typename FormatTag, class Enable = void>
struct get_write_device {};
template <typename Device, typename FormatTag>
struct get_write_device
<
Device,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_output_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using type =
typename detail::is_adaptable_output_device<FormatTag, Device>::device_type;
};
template <typename String, typename FormatTag>
struct get_write_device
<
String,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using type = detail::file_stream_device<FormatTag>;
};
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,105 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_GET_WRITER_HPP
#define BOOST_GIL_IO_GET_WRITER_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_write_device.hpp>
#include <type_traits>
namespace boost { namespace gil {
/// \brief Helper metafunction to generate writer type.
template <typename T, typename FormatTag, class Enable = void>
struct get_writer {};
template <typename String, typename FormatTag>
struct get_writer
<
String,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_write_device<String, FormatTag>::type;
using type = writer<device_t, FormatTag>;
};
template <typename Device, typename FormatTag>
struct get_writer
<
Device,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_output_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_write_device<Device, FormatTag>::type;
using type = writer<device_t, FormatTag>;
};
/// \brief Helper metafunction to generate dynamic image writer type.
template <typename T, typename FormatTag, class Enable = void>
struct get_dynamic_image_writer {};
template <typename String, typename FormatTag>
struct get_dynamic_image_writer
<
String,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_write_device<String, FormatTag>::type;
using type = dynamic_image_writer<device_t, FormatTag>;
};
template <typename Device, typename FormatTag>
struct get_dynamic_image_writer
<
Device,
FormatTag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_write_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type
>
{
using device_t = typename get_write_device<Device, FormatTag>::type;
using type = dynamic_image_writer<device_t, FormatTag>;
};
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,95 @@
//
// Copyright 2007-2008 Christian Henning, Andreas Pokorny
//
// Distributed under 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_IO_IO_HPP
#define BOOST_GIL_IO_IO_HPP
/*!
* \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::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::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

View File

@@ -0,0 +1,123 @@
//
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_MAKE_BACKEND_HPP
#define BOOST_GIL_IO_MAKE_BACKEND_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename String, typename FormatTag>
inline
auto make_reader_backend(
String const& file_name, image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<String, FormatTag>::type
{
using device_t = typename get_read_device<String, FormatTag>::type;
device_t device(
detail::convert_to_native_string(file_name),
typename detail::file_stream_device<FormatTag>::read_tag());
return reader_backend<device_t, FormatTag>(device, settings);
}
template <typename FormatTag>
inline
auto make_reader_backend(
std::wstring const& file_name, image_read_settings<FormatTag> const& settings)
-> typename get_reader_backend<std::wstring, FormatTag>::type
{
char const* str = detail::convert_to_native_string(file_name);
using device_t = typename get_read_device<std::wstring, FormatTag>::type;
device_t device(str, typename detail::file_stream_device<FormatTag>::read_tag());
delete[] str; // TODO: RAII
return reader_backend<device_t, FormatTag>(device, settings);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename FormatTag>
inline
auto make_reader_backend(
filesystem::path const& path,
image_read_settings<FormatTag> const& settings)
-> typename get_reader_backend<std::wstring, FormatTag>::type
{
return make_reader_backend(path.wstring(), settings);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_reader_backend(Device& io_dev, image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<Device, FormatTag>::type
{
using device_t = typename get_read_device<Device, FormatTag>::type;
device_t device(io_dev);
return reader_backend<device_t, FormatTag>(device, settings);
}
template <typename String, typename FormatTag>
inline
auto make_reader_backend(String const& file_name, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<String, FormatTag>::type
{
return make_reader_backend(file_name, image_read_settings<FormatTag>());
}
template <typename Device, typename FormatTag>
inline
auto make_reader_backend(Device& io_dev, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<Device, FormatTag>::type
{
return make_reader_backend(io_dev, image_read_settings<FormatTag>());
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,140 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_MAKE_DYNAMIC_IMAGE_READER_HPP
#define BOOST_GIL_IO_MAKE_DYNAMIC_IMAGE_READER_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename String, typename FormatTag>
inline
auto make_dynamic_image_reader(
String const& file_name, image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_reader<String, FormatTag>::type
{
using device_t = typename get_read_device<String, FormatTag>::type;
device_t device(
detail::convert_to_native_string(file_name),
typename detail::file_stream_device<FormatTag>::read_tag());
return typename get_dynamic_image_reader<String, FormatTag>::type(device, settings);
}
template <typename FormatTag>
inline
auto make_dynamic_image_reader(
std::wstring const& file_name, image_read_settings<FormatTag> const& settings)
-> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
{
char const* str = detail::convert_to_native_string(file_name);
using device_t = typename get_read_device<std::wstring, FormatTag>::type;
device_t device(str, typename detail::file_stream_device<FormatTag>::read_tag());
delete[] str; // TODO: RAII
return
typename get_dynamic_image_reader<std::wstring, FormatTag>::type(device, settings);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename FormatTag>
inline
auto make_dynamic_image_reader(
filesystem::path const& path, image_read_settings<FormatTag> const& settings)
-> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
{
return make_dynamic_image_reader(path.wstring(), settings);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_dynamic_image_reader(
Device& file, image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_reader<Device, FormatTag>::type
{
typename get_read_device<Device, FormatTag>::type device(file);
return typename get_dynamic_image_reader<Device, FormatTag>::type(device, settings);
}
// without image_read_settings
template <typename String, typename FormatTag>
inline
auto make_dynamic_image_reader(String const& file_name, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_reader<String, FormatTag>::type
{
return make_dynamic_image_reader(file_name, image_read_settings<FormatTag>());
}
template <typename FormatTag>
inline
auto make_dynamic_image_reader(std::wstring const& file_name, FormatTag const&)
-> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
{
return make_dynamic_image_reader(file_name, image_read_settings<FormatTag>());
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename FormatTag>
inline
auto make_dynamic_image_reader(filesystem::path const& path, FormatTag const&)
-> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
{
return make_dynamic_image_reader(path.wstring(), image_read_settings<FormatTag>());
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_dynamic_image_reader(Device& file, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_reader<Device, FormatTag>::type
{
return make_dynamic_image_reader(file, image_read_settings<FormatTag>());
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,166 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_MAKE_DYNAMIC_IMAGE_WRITER_HPP
#define BOOST_GIL_IO_MAKE_DYNAMIC_IMAGE_WRITER_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_writer.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename String, typename FormatTag>
inline
auto make_dynamic_image_writer(
String const& file_name, image_write_info<FormatTag> const& info,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_writer<String, FormatTag>::type
{
using deveice_t = typename get_write_device<String, FormatTag>::type;
deveice_t device(
detail::convert_to_native_string(file_name),
typename detail::file_stream_device<FormatTag>::write_tag());
return typename get_dynamic_image_writer<String, FormatTag>::type(device, info);
}
template< typename FormatTag >
inline
typename get_dynamic_image_writer< std::wstring
, FormatTag
>::type
make_dynamic_image_writer( const std::wstring& file_name
, const image_write_info< FormatTag >& info
)
{
const char* str = detail::convert_to_native_string( file_name );
typename get_write_device< std::wstring
, FormatTag
>::type device( str
, typename detail::file_stream_device< FormatTag >::write_tag()
);
delete[] str; // TODO: RAII
return typename get_dynamic_image_writer< std::wstring
, FormatTag
>::type( device
, info
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag >
inline
typename get_dynamic_image_writer< std::wstring
, FormatTag
>::type
make_dynamic_image_writer( const filesystem::path& path
, const image_write_info< FormatTag >& info
)
{
return make_dynamic_image_writer( path.wstring()
, info
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_dynamic_image_writer(Device& file, image_write_info<FormatTag> const& info,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_adaptable_output_device<FormatTag, Device>::type,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_writer<Device, FormatTag>::type
{
typename get_write_device<Device, FormatTag>::type device(file);
return typename get_dynamic_image_writer<Device, FormatTag>::type(device, info);
}
// no image_write_info
template <typename String, typename FormatTag>
inline
auto make_dynamic_image_writer(String const& file_name, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_writer<String, FormatTag>::type
{
return make_dynamic_image_writer(file_name, image_write_info<FormatTag>());
}
template< typename FormatTag >
inline
typename get_dynamic_image_writer< std::wstring
, FormatTag
>::type
make_dynamic_image_writer( const std::wstring& file_name
, const FormatTag&
)
{
return make_dynamic_image_writer( file_name
, image_write_info< FormatTag >()
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag >
inline
typename get_dynamic_image_writer< std::wstring
, FormatTag
>::type
make_dynamic_image_writer( const filesystem::path& path
, const FormatTag&
)
{
return make_dynamic_image_writer( path.wstring()
, image_write_info< FormatTag >()
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_dynamic_image_writer(Device& file, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_adaptable_output_device<FormatTag, Device>::type,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_dynamic_image_writer<Device, FormatTag>::type
{
return make_dynamic_image_writer(file, image_write_info<FormatTag>());
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,198 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_MAKE_READER_HPP
#define BOOST_GIL_IO_MAKE_READER_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename String, typename FormatTag, typename ConversionPolicy>
inline
auto make_reader(
String const&file_name,
image_read_settings<FormatTag> const& settings,
ConversionPolicy const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader<String, FormatTag, ConversionPolicy>::type
{
typename get_read_device<String, FormatTag>::type device(
detail::convert_to_native_string(file_name),
typename detail::file_stream_device<FormatTag>::read_tag());
return
typename get_reader<String, FormatTag, ConversionPolicy>::type(device, settings);
}
template< typename FormatTag
, typename ConversionPolicy
>
inline
typename get_reader< std::wstring
, FormatTag
, ConversionPolicy
>::type
make_reader( const std::wstring& file_name
, const image_read_settings< FormatTag >& settings
, const ConversionPolicy&
)
{
const char* str = detail::convert_to_native_string( file_name );
typename get_read_device< std::wstring
, FormatTag
>::type device( str
, typename detail::file_stream_device< FormatTag >::read_tag()
);
delete[] str; // TODO: RAII
return typename get_reader< std::wstring
, FormatTag
, ConversionPolicy
>::type( device
, settings
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag
, typename ConversionPolicy
>
inline
typename get_reader< std::wstring
, FormatTag
, ConversionPolicy
>::type
make_reader( const filesystem::path& path
, const image_read_settings< FormatTag >& settings
, const ConversionPolicy& cc
)
{
return make_reader( path.wstring()
, settings
, cc
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag, typename ConversionPolicy>
inline
auto make_reader(
Device& file,
image_read_settings<FormatTag> const& settings,
ConversionPolicy const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader<Device, FormatTag, ConversionPolicy>::type
{
typename get_read_device<Device, FormatTag>::type device(file);
return
typename get_reader<Device, FormatTag, ConversionPolicy>::type(device, settings);
}
// no image_read_settings
template <typename String, typename FormatTag, typename ConversionPolicy>
inline
auto make_reader(
String const&file_name,
FormatTag const&,
ConversionPolicy const& cc,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader<String, FormatTag, ConversionPolicy>::type
{
return make_reader(file_name, image_read_settings<FormatTag>(), cc);
}
template< typename FormatTag
, typename ConversionPolicy
>
inline
typename get_reader< std::wstring
, FormatTag
, ConversionPolicy
>::type
make_reader( const std::wstring& file_name
, const FormatTag&
, const ConversionPolicy& cc
)
{
return make_reader( file_name
, image_read_settings< FormatTag >()
, cc
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag
, typename ConversionPolicy
>
inline
typename get_reader< std::wstring
, FormatTag
, ConversionPolicy
>::type
make_reader( const filesystem::path& path
, const FormatTag&
, const ConversionPolicy& cc
)
{
return make_reader( path.wstring()
, image_read_settings< FormatTag >()
, cc
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag, typename ConversionPolicy>
inline
auto make_reader(
Device& file,
FormatTag const&,
ConversionPolicy const& cc,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader<Device, FormatTag, ConversionPolicy>::type
{
return make_reader(file, image_read_settings<FormatTag>(), cc);
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,100 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_MAKE_SCANLINE_READER_HPP
#define BOOST_GIL_IO_MAKE_SCANLINE_READER_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename String, typename FormatTag>
inline
auto make_scanline_reader(String const& file_name, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_scanline_reader<String, FormatTag>::type
{
using device_t = typename get_read_device<String, FormatTag>::type;
device_t device(
detail::convert_to_native_string(file_name),
typename detail::file_stream_device<FormatTag>::read_tag());
return typename get_scanline_reader<String, FormatTag>::type(
device, image_read_settings<FormatTag>());
}
template< typename FormatTag >
inline
typename get_scanline_reader< std::wstring
, FormatTag
>::type
make_scanline_reader( const std::wstring& file_name
, FormatTag const&
)
{
const char* str = detail::convert_to_native_string( file_name );
typename get_read_device< std::wstring
, FormatTag
>::type device( str
, typename detail::file_stream_device< FormatTag >::read_tag()
);
delete[] str;
return typename get_scanline_reader< std::wstring
, FormatTag
>::type( device
, image_read_settings< FormatTag >()
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag >
inline
typename get_scanline_reader< std::wstring
, FormatTag
>::type
make_scanline_reader( const filesystem::path& path
, FormatTag const&
)
{
return make_scanline_reader( path.wstring()
, image_read_settings< FormatTag >()
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_scanline_reader(Device& io_dev, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_scanline_reader<Device, FormatTag>::type
{
return make_scanline_reader(io_dev, image_read_settings<FormatTag>());
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,162 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under 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_IO_MAKE_WRITER_HPP
#define BOOST_GIL_IO_MAKE_WRITER_HPP
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/get_writer.hpp>
#include <type_traits>
namespace boost { namespace gil {
template <typename String, typename FormatTag>
inline
auto make_writer(String const& file_name, image_write_info<FormatTag> const& info,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value>::type* /*dummy*/ = nullptr)
-> typename get_writer<String, FormatTag>::type
{
typename get_write_device<String, FormatTag>::type device(
detail::convert_to_native_string(file_name),
typename detail::file_stream_device<FormatTag>::write_tag());
return typename get_writer<String, FormatTag>::type(device, info);
}
template< typename FormatTag >
inline
typename get_writer< std::wstring
, FormatTag
>::type
make_writer( const std::wstring& file_name
, const image_write_info< FormatTag >& info
)
{
const char* str = detail::convert_to_native_string( file_name );
typename get_write_device< std::wstring
, FormatTag
>::type device( str
, typename detail::file_stream_device< FormatTag >::write_tag()
);
delete[] str;
return typename get_writer< std::wstring
, FormatTag
>::type( device
, info
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag >
inline
typename get_writer< std::wstring
, FormatTag
>::type
make_writer( const filesystem::path& path
, const image_write_info< FormatTag >& info
)
{
return make_writer( path.wstring()
, info
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_writer(Device& file, image_write_info<FormatTag> const& info,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_adaptable_output_device<FormatTag, Device>::type,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_writer<Device, FormatTag>::type
{
typename get_write_device<Device, FormatTag>::type device(file);
return typename get_writer<Device, FormatTag>::type(device, info);
}
// no image_write_info
template <typename String, typename FormatTag>
inline
auto make_writer(String const& file_name, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_writer<String, FormatTag>::type
{
return make_writer(file_name, image_write_info<FormatTag>());
}
template< typename FormatTag >
inline
typename get_writer< std::wstring
, FormatTag
>::type
make_writer( const std::wstring& file_name
, const FormatTag&
)
{
return make_writer( file_name
, image_write_info< FormatTag >()
);
}
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template< typename FormatTag >
inline
typename get_writer< std::wstring
, FormatTag
>::type
make_writer( const filesystem::path& path
, const FormatTag& tag
)
{
return make_writer( path.wstring()
, tag
);
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template <typename Device, typename FormatTag>
inline
auto make_writer(Device& file, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_adaptable_output_device<FormatTag, Device>::type,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_writer<Device, FormatTag>::type
{
return make_writer(file, image_write_info<FormatTag>());
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,138 @@
//
// Copyright 2007-2008 Andreas Pokorny, Christian Henning
//
// Distributed under 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_IO_PATH_SPEC_HPP
#define BOOST_GIL_IO_PATH_SPEC_HPP
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
// Disable warning: conversion to 'std::atomic<int>::__integral_type {aka int}' from 'long int' may alter its value
#if defined(BOOST_CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#endif
#if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem/path.hpp>
#if defined(BOOST_CLANG)
#pragma clang diagnostic pop
#endif
#if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
#pragma GCC diagnostic pop
#endif
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
#include <cstdlib>
#include <string>
#include <type_traits>
namespace boost { namespace gil { namespace detail {
template<typename P> struct is_supported_path_spec : std::false_type {};
template<> struct is_supported_path_spec< std::string > : std::true_type {};
template<> struct is_supported_path_spec< const std::string > : std::true_type {};
template<> struct is_supported_path_spec< std::wstring > : std::true_type {};
template<> struct is_supported_path_spec< const std::wstring > : std::true_type {};
template<> struct is_supported_path_spec< const char* > : std::true_type {};
template<> struct is_supported_path_spec< char* > : std::true_type {};
template<> struct is_supported_path_spec< const wchar_t* > : std::true_type {};
template<> struct is_supported_path_spec< wchar_t* > : std::true_type {};
template<int i> struct is_supported_path_spec<const char [i]> : std::true_type {};
template<int i> struct is_supported_path_spec<char [i]> : std::true_type {};
template<int i> struct is_supported_path_spec<const wchar_t [i]> : std::true_type {};
template<int i> struct is_supported_path_spec<wchar_t [i]> : std::true_type {};
#ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
template<> struct is_supported_path_spec< filesystem::path > : std::true_type {};
template<> struct is_supported_path_spec< const filesystem::path > : std::true_type {};
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
///
/// convert_to_string
///
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
inline std::string convert_to_string( const filesystem::path& path )
{
return convert_to_string( path.string() );
}
#endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
///
/// convert_to_native_string
///
inline const char* convert_to_native_string( char* str )
{
return str;
}
inline const char* convert_to_native_string( const char* str )
{
return str;
}
inline const char* convert_to_native_string( const std::string& str )
{
return str.c_str();
}
inline const char* convert_to_native_string( const wchar_t* str )
{
std::size_t len = wcslen( str ) + 1;
char* c = new char[len];
wcstombs( c, str, len );
return c;
}
inline const char* convert_to_native_string( const std::wstring& str )
{
std::size_t len = wcslen( str.c_str() ) + 1;
char* c = new char[len];
wcstombs( c, str.c_str(), len );
return c;
}
} // namespace detail
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,269 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_READ_AND_CONVERT_IMAGE_HPP
#define BOOST_GIL_IO_READ_AND_CONVERT_IMAGE_HPP
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost{ namespace gil {
/// \ingroup IO
/// \brief Reads and color-converts an image. Image memory is allocated.
/// \param reader An image reader.
/// \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 Reader, typename Image>
inline
void read_and_convert_image(Reader& reader, Image& img,
typename std::enable_if
<
mp11::mp_and
<
detail::is_reader<Reader>,
is_format_tag<typename Reader::format_tag_t>
>::value
>::type* /*dummy*/ = nullptr)
{
reader.init_image(img, reader._settings);
reader.apply(view(img));
}
/// \brief Reads and color-converts an image. Image memory is allocated.
/// \param 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& device,
Image& img,
image_read_settings<FormatTag> const& settings,
ColorConverter const& cc,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
read_and_convert_image(reader, img);
}
/// \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(
String const& file_name,
Image& img,
image_read_settings<FormatTag> const& settings,
ColorConverter const& cc,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
read_and_convert_image(reader, img);
}
/// \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(
String const& file_name,
Image& img,
ColorConverter const& cc,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
read_and_convert_image(reader, img);
}
/// \brief Reads and color-converts an image. Image memory is allocated.
/// \param 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,
ColorConverter const& cc,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
read_and_convert_image(reader, img);
}
/// \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(
String const& file_name,
Image& img,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
read_and_convert_image(reader, img);
}
/// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
/// \param device 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,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, settings, read_and_convert_t{});
read_and_convert_image(reader, img);
}
/// \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(
String const& file_name,
Image& img,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
read_and_convert_image(reader, img);
}
/// \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,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, tag, read_and_convert_t{});
read_and_convert_image(reader, img);
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,273 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_READ_AND_CONVERT_VIEW_HPP
#define BOOST_GIL_IO_READ_AND_CONVERT_VIEW_HPP
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost{ namespace gil {
/// \ingroup IO
/// \brief Reads and color-converts an image view. No memory is allocated.
/// \param reader An image reader.
/// \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 Reader, typename View>
inline
void read_and_convert_view(Reader& reader, View const& view,
typename std::enable_if
<
mp11::mp_and
<
detail::is_reader<Reader>,
is_format_tag<typename Reader::format_tag_t>
>::value
>::type* /*dummy*/ = nullptr)
{
reader.check_image_size(view.dimensions());
reader.init_view(view, reader._settings);
reader.apply(view);
}
/// \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& device,
View const& view,
image_read_settings<FormatTag> const& settings,
ColorConverter const& cc,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
read_and_convert_view(reader, view);
}
/// \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(
String const& file_name,
View const& view,
image_read_settings<FormatTag> const& settings,
ColorConverter const& cc,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
read_and_convert_view(reader, view);
}
/// \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(
String const& file_name,
View const& view,
ColorConverter const& cc,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
read_and_convert_view(reader, view);
}
/// \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,
View const& view,
ColorConverter const& cc,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<ColorConverter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
read_and_convert_view(reader, view);
}
/// \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(
String const& file_name,
View const& view,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
read_and_convert_view(reader, view);
}
/// \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,
View const& view,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, settings, read_and_convert_t{});
read_and_convert_view(reader, view);
}
/// \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(
String const& file_name,
View const& view,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
read_and_convert_view(reader, view);
}
/// \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,
View const& view,
FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using read_and_convert_t = detail::read_and_convert<default_color_converter>;
using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
reader_t reader = make_reader(device, tag, read_and_convert_t{});
read_and_convert_view(reader, view);
}
}} // namespace boost::gill
#endif

View File

@@ -0,0 +1,288 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_READ_IMAGE_HPP
#define BOOST_GIL_IO_READ_IMAGE_HPP
#include <boost/gil/extension/toolbox/dynamic_images.hpp>
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost { namespace gil {
/// \ingroup IO
/// \brief Reads an image without conversion. Image memory is allocated.
/// \param reader An image reader.
/// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
/// \throw std::ios_base::failure
template <typename Reader, typename Image>
inline
void read_image(Reader reader, Image& img,
typename std::enable_if
<
mp11::mp_and
<
detail::is_reader<Reader>,
is_format_tag<typename Reader::format_tag_t>,
is_read_supported
<
typename get_pixel_type<typename Image::view_t>::type,
typename Reader::format_tag_t
>
>::value
>::type* /*dummy*/ = nullptr)
{
reader.init_image(img, reader._settings);
reader.apply(view(img));
}
/// \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,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>,
is_read_supported
<
typename get_pixel_type<typename Image::view_t>::type,
FormatTag
>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
read_image(reader, img);
}
/// \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, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>,
is_read_supported
<
typename get_pixel_type<typename Image::view_t>::type,
FormatTag
>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
read_image(reader, 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(
String const& file_name,
Image& img,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>,
is_read_supported
<
typename get_pixel_type<typename Image::view_t>::type,
FormatTag
>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
read_image(reader, 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 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(String const& file_name, Image& img, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and<detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>,
is_read_supported
<
typename get_pixel_type<typename Image::view_t>::type,
FormatTag
>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
read_image(reader, img);
}
///
template <typename Reader, typename ...Images>
inline
void read_image(Reader& reader, any_image<Images...>& images,
typename std::enable_if
<
mp11::mp_and
<
detail::is_dynamic_image_reader<Reader>,
is_format_tag<typename Reader::format_tag_t>
>::value
>::type* /*dummy*/ = nullptr)
{
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 (mp11::mp_list). 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,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
reader_t reader = make_dynamic_image_reader(file, settings);
read_image(reader, 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 (mp11::mp_list). 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, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
reader_t reader = make_dynamic_image_reader(file, tag);
read_image(reader, 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 (mp11::mp_list). 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(
String const& file_name,
any_image<Images...>& images,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
reader_t reader = make_dynamic_image_reader(file_name, settings);
read_image(reader, 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 (mp11::mp_list). 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(String const& file_name, any_image<Images...>& images, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
detail::is_supported_path_spec<String>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
reader_t reader = make_dynamic_image_reader(file_name, tag);
read_image(reader, images);
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,110 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_READ_IMAGE_INFO_HPP
#define BOOST_GIL_IO_READ_IMAGE_INFO_HPP
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost{ namespace gil {
/// \ingroup IO
/// \brief Returns the image format backend. Backend is 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
auto read_image_info(Device& file, image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<Device, FormatTag>::type
{
return make_reader_backend(file, settings);
}
/// \brief Returns the image format backend. Backend is 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
auto read_image_info(Device& file, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
detail::is_adaptable_input_device<FormatTag, Device>,
is_format_tag<FormatTag>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<Device, FormatTag>::type
{
return read_image_info(file, image_read_settings<FormatTag>());
}
/// \brief Returns the image format backend. Backend is 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
auto read_image_info(
String const& file_name, image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<String, FormatTag>::type
{
return make_reader_backend(file_name, settings);
}
/// \brief Returns the image format backend. Backend is 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
auto read_image_info(String const& file_name, FormatTag const&,
typename std::enable_if
<
mp11::mp_and
<
is_format_tag<FormatTag>,
detail::is_supported_path_spec<String>
>::value
>::type* /*dummy*/ = nullptr)
-> typename get_reader_backend<String, FormatTag>::type
{
return read_image_info(file_name, image_read_settings<FormatTag>());
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,174 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_READ_VIEW_HPP
#define BOOST_GIL_IO_READ_VIEW_HPP
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost { namespace gil {
/// \ingroup IO
/// \brief Reads an image view without conversion. No memory is allocated.
/// \param reader An image reader.
/// \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 Reader, typename View>
inline
void read_view(Reader reader, View const& view,
typename std::enable_if
<
mp11::mp_and
<
detail::is_reader<Reader>,
typename is_format_tag<typename Reader::format_tag_t>::type,
typename is_read_supported
<
typename get_pixel_type<View>::type,
typename Reader::format_tag_t
>::type
>::value
>::type* /*dummy*/ = nullptr)
{
reader.check_image_size(view.dimensions());
reader.init_view(view, reader._settings);
reader.apply(view);
}
/// \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,
View const& view,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_and
<
detail::is_read_device<FormatTag, Device>,
typename is_format_tag<FormatTag>::type,
typename is_read_supported
<
typename get_pixel_type<View>::type,
FormatTag
>::type
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
read_view(reader, view);
}
/// \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& file, View const& view, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
typename is_format_tag<FormatTag>::type,
detail::is_read_device<FormatTag, Device>,
typename is_read_supported
<
typename get_pixel_type<View>::type,
FormatTag
>::type
>::value>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
read_view(reader, 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(
String const& file_name,
View const& view,
image_read_settings<FormatTag> const& settings,
typename std::enable_if
<
mp11::mp_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
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
read_view(reader, 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 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(String const& file_name, View const& view, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_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
>::value
>::type* /*dummy*/ = nullptr)
{
using reader_t =
typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
read_view(reader, view);
}
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,126 @@
//
// Copyright 2007-2008 Christian Henning
//
// Distributed under 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_IO_READER_BASE_HPP
#define BOOST_GIL_IO_READER_BASE_HPP
#include <boost/gil/io/base.hpp>
#include <boost/assert.hpp>
namespace boost { namespace gil {
/// 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:
///
/// Default Constructor
///
reader_base()
:_cc_policy()
{}
///
/// Constructor
///
reader_base( const ConversionPolicy& cc )
:_cc_policy( cc )
{}
/// 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_settings< FormatTag >& settings
)
{
//setup( backend._settings._dim );
BOOST_ASSERT(settings._dim.x && settings._dim.y);
img.recreate( settings._dim.x
, settings._dim.y
);
}
template< typename View >
void init_view( const View& view
, const image_read_settings< FormatTag >&
)
{
setup( view.dimensions() );
}
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 */ )
{
//using int_t = point_t::value_type;
//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:
ConversionPolicy _cc_policy;
};
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,199 @@
//
// Copyright 2007-2008 Christian Henning
//
// Distributed under 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_IO_ROW_BUFFER_HELPER_HPP
#define BOOST_GIL_IO_ROW_BUFFER_HELPER_HPP
// TODO: Shall we move toolbox to core?
#include <boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp>
#include <boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp>
#include <boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/typedefs.hpp>
#include <cstddef>
#include <type_traits>
#include <vector>
namespace boost { namespace gil { namespace detail {
template< typename Pixel
, typename DummyT = void
>
struct row_buffer_helper
{
using element_t = Pixel;
using buffer_t = std::vector<element_t>;
using iterator_t = typename buffer_t::iterator;
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 std::enable_if
<
is_bit_aligned<Pixel>::value
>::type
>
{
using element_t = byte_t;
using buffer_t = std::vector<element_t>;
using pixel_type = Pixel;
using iterator_t = bit_aligned_pixel_iterator<pixel_type>;
row_buffer_helper(std::size_t width, bool in_bytes)
: _c{( width * pixel_bit_size< pixel_type >::value) >> 3}
, _r{width * pixel_bit_size< pixel_type >::value - (_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 Pixel>
struct row_buffer_helper
<
Pixel,
typename std::enable_if
<
mp11::mp_and
<
typename is_bit_aligned<Pixel>::type,
typename is_homogeneous<Pixel>::type
>::value
>
>
{
using element_t = byte_t;
using buffer_t = std::vector<element_t>;
using pixel_type = Pixel;
using iterator_t = bit_aligned_pixel_iterator<pixel_type>;
row_buffer_helper( std::size_t width
, bool in_bytes
)
: _c( ( width
* num_channels< pixel_type >::value
* channel_type< pixel_type >::type::num_bits
)
>> 3
)
, _r( width
* num_channels< pixel_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 std::enable_if
<
is_bit_aligned<typename View::value_type>::value
>::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

View File

@@ -0,0 +1,100 @@
//
// Copyright 2007-2008 Christian Henning
//
// Distributed under 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_IO_SCANLINE_READ_ITERATOR_HPP
#define BOOST_GIL_IO_SCANLINE_READ_ITERATOR_HPP
#include <boost/gil/io/error.hpp>
#include <boost/gil/io/typedefs.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <iterator>
#include <memory>
#include <vector>
namespace boost { namespace gil {
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#endif
/// Input iterator to read images.
template <typename Reader>
class scanline_read_iterator
: public boost::iterator_facade<scanline_read_iterator<Reader>, byte_t*, std::input_iterator_tag>
{
private:
using base_t = boost::iterator_facade
<
scanline_read_iterator<Reader>,
byte_t*,
std::input_iterator_tag
>;
public:
scanline_read_iterator(Reader& reader, int pos = 0)
: reader_(reader), pos_(pos)
{
buffer_ = std::make_shared<buffer_t>(buffer_t(reader_._scanline_length));
buffer_start_ = &buffer_->front();
}
private:
friend class boost::iterator_core_access;
void increment()
{
if (skip_scanline_)
{
reader_.skip(buffer_start_, pos_);
}
++pos_;
skip_scanline_ = true;
read_scanline_ = true;
}
bool equal(scanline_read_iterator const& rhs) const
{
return pos_ == rhs.pos_;
}
typename base_t::reference dereference() const
{
if (read_scanline_)
{
reader_.read(buffer_start_, pos_);
}
skip_scanline_ = false;
read_scanline_ = false;
return buffer_start_;
}
private:
Reader& reader_;
mutable int pos_ = 0;
mutable bool read_scanline_ = true;
mutable bool skip_scanline_ = true;
using buffer_t = std::vector<byte_t>;
using buffer_ptr_t = std::shared_ptr<buffer_t>;
buffer_ptr_t buffer_;
mutable byte_t* buffer_start_ = nullptr;
};
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(pop)
#endif
} // namespace gil
} // namespace boost
#endif

View File

@@ -0,0 +1,82 @@
//
// Copyright 2007-2008 Christian Henning
//
// Distributed under 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_IO_TYPEDEFS_HPP
#define BOOST_GIL_IO_TYPEDEFS_HPP
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
#include <boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp>
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
#include <boost/gil/image.hpp>
#include <boost/gil/point.hpp>
#include <boost/gil/utilities.hpp>
#include <type_traits>
#include <vector>
namespace boost { namespace gil {
struct double_zero { static double apply() { return 0.0; } };
struct double_one { static double apply() { return 1.0; } };
using byte_t = unsigned char;
using byte_vector_t = std::vector<byte_t>;
}} // namespace boost::gil
namespace boost {
template<> struct is_floating_point<gil::float32_t> : std::true_type {};
template<> struct is_floating_point<gil::float64_t> : std::true_type {};
} // namespace boost
namespace boost { namespace gil {
///@todo We should use boost::preprocessor here.
/// TODO: NO! Please do not use preprocessor here! --mloskot
using gray1_image_t = bit_aligned_image1_type<1, gray_layout_t>::type;
using gray2_image_t = bit_aligned_image1_type<2, gray_layout_t>::type;
using gray4_image_t = bit_aligned_image1_type<4, gray_layout_t>::type;
using gray6_image_t = bit_aligned_image1_type<6, gray_layout_t>::type;
using gray10_image_t = bit_aligned_image1_type<10, gray_layout_t>::type;
using gray12_image_t = bit_aligned_image1_type<12, gray_layout_t>::type;
using gray14_image_t = bit_aligned_image1_type<14, gray_layout_t>::type;
using gray24_image_t = bit_aligned_image1_type<24, gray_layout_t>::type;
using gray64f_pixel_t = pixel<double, gray_layout_t>;
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
using gray_alpha8_pixel_t = pixel<uint8_t, gray_alpha_layout_t>;
using gray_alpha16_pixel_t = pixel<uint16_t, gray_alpha_layout_t>;
using gray_alpha64f_pixel_t = pixel<double, gray_alpha_layout_t>;
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
using rgb64f_pixel_t = pixel<double, rgb_layout_t>;
using rgba64f_pixel_t = pixel<double, rgba_layout_t>;
using gray64f_image_t = image<gray64f_pixel_t, false>;
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
using gray_alpha8_image_t = image<gray_alpha8_pixel_t, false>;
using gray_alpha16_image_t = image<gray_alpha16_pixel_t, false>;
using gray_alpha32f_image_t = image<gray_alpha32f_pixel_t, false>;
using gray_alpha32f_planar_image_t = image<gray_alpha32f_pixel_t, true>;
using gray_alpha64f_image_t = image<gray_alpha64f_pixel_t, false>;
using gray_alpha64f_planar_image_t = image<gray_alpha64f_pixel_t, true>;
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
using rgb64f_image_t = image<rgb64f_pixel_t, false>;
using rgb64f_planar_image_t = image<rgb64f_pixel_t, true>;
using rgba64f_image_t = image<rgba64f_pixel_t, false>;
using rgba64f_planar_image_t = image<rgba64f_pixel_t, true>;
}} // namespace boost::gil
#endif

View File

@@ -0,0 +1,232 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// Distributed under 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_IO_WRITE_VIEW_HPP
#define BOOST_GIL_IO_WRITE_VIEW_HPP
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_writer.hpp>
#include <boost/gil/io/path_spec.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <type_traits>
namespace boost{ namespace gil {
/// \ingroup IO
template<typename Writer, typename View>
inline
void write_view(Writer& writer, View const& view,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_writer<Writer>::type,
typename is_format_tag<typename Writer::format_tag_t>::type,
typename is_write_supported
<
typename get_pixel_type<View>::type,
typename Writer::format_tag_t
>::type
>::value
>::type* /* ptr */ = nullptr)
{
writer.apply(view);
}
/// \ingroup IO
template<typename Device, typename View, typename FormatTag>
inline
void write_view(Device& device, View const& view, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_write_device<FormatTag, Device>::type,
typename is_format_tag<FormatTag>::type,
typename is_write_supported
<
typename get_pixel_type<View>::type,
FormatTag
>::type
>::value
>::type* /* ptr */ = nullptr)
{
using writer_t = typename get_writer<Device, FormatTag>::type;
writer_t writer = make_writer(device, tag);
write_view(writer, view);
}
/// \ingroup IO
template<typename String, typename View, typename FormatTag>
inline
void write_view(String const& file_name, View const& view, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_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
>::value
>::type* /* ptr */ = nullptr)
{
using writer_t = typename get_writer<String, FormatTag>::type;
writer_t writer = make_writer(file_name, tag);
write_view(writer, view);
}
/// \ingroup IO
template<typename Device, typename View, typename FormatTag, typename Log>
inline
void write_view(
Device& device, View const& view, image_write_info<FormatTag, Log> const& info,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_write_device<FormatTag, Device>::type,
typename is_format_tag<FormatTag>::type,
typename is_write_supported
<
typename get_pixel_type<View>::type,
FormatTag
>::type
>::value
>::type* /* ptr */ = nullptr)
{
using writer_t = typename get_writer<Device, FormatTag>::type;
writer_t writer = make_writer(device, info);
write_view(writer, view);
}
/// \ingroup IO
template<typename String, typename View, typename FormatTag, typename Log>
inline
void write_view(
String const& file_name, View const& view, image_write_info<FormatTag, Log> const& info,
typename std::enable_if
<
mp11::mp_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
>::value
>::type* /* ptr */ = nullptr)
{
using writer_t = typename get_writer<String, FormatTag>::type;
writer_t writer = make_writer(file_name, info);
write_view(writer, view);
}
////////////////////////////////////// dynamic_image
// without image_write_info
template <typename Writer, typename ...Views>
inline
void write_view(Writer& writer, any_image_view<Views...> const& view,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_dynamic_image_writer<Writer>::type,
typename is_format_tag<typename Writer::format_tag_t>::type
>::value
>::type * /* ptr */ = nullptr)
{
writer.apply(view);
}
// without image_write_info
template <typename Device, typename ...Views, typename FormatTag>
inline
void write_view(
Device& device, any_image_view<Views...> const& views, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_write_device<FormatTag, Device>::type,
typename is_format_tag<FormatTag>::type
>::value
>::type * /* ptr */ = 0)
{
using writer_t = typename get_dynamic_image_writer<Device, FormatTag>::type;
writer_t writer = make_dynamic_image_writer(device, tag);
write_view(writer, views);
}
template <typename String, typename ...Views, typename FormatTag>
inline
void write_view(
String const& file_name, any_image_view<Views...> const& views, FormatTag const& tag,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_supported_path_spec<String>::type,
typename is_format_tag<FormatTag>::type
>::value
>::type * /* ptr */ = nullptr)
{
using writer_t = typename get_dynamic_image_writer<String, FormatTag>::type;
writer_t writer = make_dynamic_image_writer(file_name, tag);
write_view(writer, views);
}
// with image_write_info
/// \ingroup IO
template <typename Device, typename ...Views, typename FormatTag, typename Log>
inline
void write_view(
Device& device, any_image_view<Views...> const& views, image_write_info<FormatTag, Log> const& info,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_write_device<FormatTag, Device>::type,
typename is_format_tag<FormatTag>::type
>::value
>::type * /* ptr */ = 0)
{
using writer_t = typename get_dynamic_image_writer<Device, FormatTag>::type;
writer_t writer = make_dynamic_image_writer(device, info);
write_view(writer, views);
}
template <typename String, typename ...Views, typename FormatTag, typename Log>
inline
void write_view(
String const& file_name, any_image_view<Views...> const& views, image_write_info<FormatTag, Log> const& info,
typename std::enable_if
<
mp11::mp_and
<
typename detail::is_supported_path_spec<String>::type,
typename is_format_tag<FormatTag>::type
>::value
>::type * /* ptr */ = nullptr)
{
using writer_t = typename get_dynamic_image_writer<String, FormatTag>::type;
writer_t writer = make_dynamic_image_writer(file_name, info);
write_view(writer, views);
}
}} // namespace boost::gil
#endif