add boost on mac
This commit is contained in:
235
macx64/include/boost/gil/extension/dynamic_image/algorithm.hpp
Normal file
235
macx64/include/boost/gil/extension/dynamic_image/algorithm.hpp
Normal file
@@ -0,0 +1,235 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
|
||||
|
||||
#include <boost/gil/extension/dynamic_image/any_image.hpp>
|
||||
|
||||
#include <boost/gil/algorithm.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \file
|
||||
/// \brief Some basic STL-style algorithms when applied to runtime type specified image views
|
||||
/// \author Lubomir Bourdev and Hailin Jin \n
|
||||
/// Adobe Systems Incorporated
|
||||
/// \date 2005-2007 \n Last updated on September 24, 2006
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
|
||||
{
|
||||
template <typename V1, typename V2>
|
||||
BOOST_FORCEINLINE
|
||||
bool apply_compatible(V1 const& v1, V2 const& v2) const
|
||||
{
|
||||
return equal_pixels(v1, v2);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsEqualPixels
|
||||
/// \tparam Types Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam View Model MutableImageViewConcept
|
||||
template <typename Types, typename View>
|
||||
bool equal_pixels(any_image_view<Types> const& src, View const& dst)
|
||||
{
|
||||
return apply_operation(
|
||||
src,
|
||||
std::bind(detail::equal_pixels_fn(), std::placeholders::_1, dst));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsEqualPixels
|
||||
/// \tparam View Model ImageViewConcept
|
||||
/// \tparam Types Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
template <typename View, typename Types>
|
||||
bool equal_pixels(View const& src, any_image_view<Types> const& dst)
|
||||
{
|
||||
return apply_operation(
|
||||
dst,
|
||||
std::bind(detail::equal_pixels_fn(), src, std::placeholders::_1));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsEqualPixels
|
||||
/// \tparam Types1 Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam Types2 Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
template <typename Types1, typename Types2>
|
||||
bool equal_pixels(any_image_view<Types1> const& src, any_image_view<Types2> const& dst)
|
||||
{
|
||||
return apply_operation(src, dst, detail::equal_pixels_fn());
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
|
||||
{
|
||||
template <typename View1, typename View2>
|
||||
BOOST_FORCEINLINE
|
||||
void apply_compatible(View1 const& src, View2 const& dst) const
|
||||
{
|
||||
copy_pixels(src,dst);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyPixels
|
||||
/// \tparam Types Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam View Model MutableImageViewConcept
|
||||
template <typename Types, typename View>
|
||||
void copy_pixels(any_image_view<Types> const& src, View const& dst)
|
||||
{
|
||||
apply_operation(src, std::bind(detail::copy_pixels_fn(), std::placeholders::_1, dst));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyPixels
|
||||
/// \tparam Types Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
/// \tparam View Model ImageViewConcept
|
||||
template <typename Types, typename View>
|
||||
void copy_pixels(View const& src, any_image_view<Types> const& dst)
|
||||
{
|
||||
apply_operation(dst, std::bind(detail::copy_pixels_fn(), src, std::placeholders::_1));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyPixels
|
||||
/// \tparam Types1 Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam Types2 Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
template <typename Types1, typename Types2>
|
||||
void copy_pixels(any_image_view<Types1> const& src, any_image_view<Types2> const& dst)
|
||||
{
|
||||
apply_operation(src, dst, detail::copy_pixels_fn());
|
||||
}
|
||||
|
||||
//forward declaration for default_color_converter (see full definition in color_convert.hpp)
|
||||
struct default_color_converter;
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
|
||||
/// \tparam Types Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam View Model MutableImageViewConcept
|
||||
/// \tparam CC Model ColorConverterConcept
|
||||
template <typename Types, typename View, typename CC>
|
||||
void copy_and_convert_pixels(any_image_view<Types> const& src, View const& dst, CC cc)
|
||||
{
|
||||
using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
|
||||
apply_operation(src, std::bind(cc_fn{cc}, std::placeholders::_1, dst));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
|
||||
/// \tparam Types Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam View Model MutableImageViewConcept
|
||||
template <typename Types, typename View>
|
||||
void copy_and_convert_pixels(any_image_view<Types> const& src, View const& dst)
|
||||
{
|
||||
using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
|
||||
apply_operation(src, std::bind(cc_fn{}, std::placeholders::_1, dst));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
|
||||
/// \tparam View Model ImageViewConcept
|
||||
/// \tparam Types Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
/// \tparam CC Model ColorConverterConcept
|
||||
template <typename View, typename Types, typename CC>
|
||||
void copy_and_convert_pixels(View const& src, any_image_view<Types> const& dst, CC cc)
|
||||
{
|
||||
using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
|
||||
apply_operation(dst, std::bind(cc_fn{cc}, src, std::placeholders::_1));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
|
||||
/// \tparam View Model ImageViewConcept
|
||||
/// \tparam Type Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
template <typename View, typename Types>
|
||||
void copy_and_convert_pixels(View const& src, any_image_view<Types> const& dst)
|
||||
{
|
||||
using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
|
||||
apply_operation(dst, std::bind(cc_fn{}, src, std::placeholders::_1));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
|
||||
/// \tparam Types1 Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam Types2 Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
/// \tparam CC Model ColorConverterConcept
|
||||
template <typename Types1, typename Types2, typename CC>
|
||||
void copy_and_convert_pixels(
|
||||
any_image_view<Types1> const& src,
|
||||
any_image_view<Types2> const& dst, CC cc)
|
||||
{
|
||||
apply_operation(src, dst, detail::copy_and_convert_pixels_fn<CC>(cc));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
|
||||
/// \tparam Types1 Model MPL Random Access Container of models of ImageViewConcept
|
||||
/// \tparam Types2 Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
template <typename Types1, typename Types2>
|
||||
void copy_and_convert_pixels(
|
||||
any_image_view<Types1> const& src,
|
||||
any_image_view<Types2> const& dst)
|
||||
{
|
||||
apply_operation(src, dst,
|
||||
detail::copy_and_convert_pixels_fn<default_color_converter>());
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <bool IsCompatible>
|
||||
struct fill_pixels_fn1
|
||||
{
|
||||
template <typename V, typename Value>
|
||||
static void apply(V const &src, Value const &val) { fill_pixels(src, val); }
|
||||
};
|
||||
|
||||
// copy_pixels invoked on incompatible images
|
||||
template <>
|
||||
struct fill_pixels_fn1<false>
|
||||
{
|
||||
template <typename V, typename Value>
|
||||
static void apply(V const &, Value const &) { throw std::bad_cast();}
|
||||
};
|
||||
|
||||
template <typename Value>
|
||||
struct fill_pixels_fn
|
||||
{
|
||||
fill_pixels_fn(Value const& val) : val_(val) {}
|
||||
|
||||
using result_type = void;
|
||||
template <typename V>
|
||||
result_type operator()(V const& view) const
|
||||
{
|
||||
fill_pixels_fn1
|
||||
<
|
||||
pixels_are_compatible
|
||||
<
|
||||
typename V::value_type,
|
||||
Value
|
||||
>::value
|
||||
>::apply(view, val_);
|
||||
}
|
||||
|
||||
Value val_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// \ingroup ImageViewSTLAlgorithmsFillPixels
|
||||
/// \brief fill_pixels for any image view. The pixel to fill with must be compatible with the current view
|
||||
/// \tparam Types Model MPL Random Access Container of models of MutableImageViewConcept
|
||||
template <typename Types, typename Value>
|
||||
void fill_pixels(any_image_view<Types> const& view, Value const& val)
|
||||
{
|
||||
apply_operation(view, detail::fill_pixels_fn<Value>(val));
|
||||
}
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#endif
|
||||
127
macx64/include/boost/gil/extension/dynamic_image/any_image.hpp
Normal file
127
macx64/include/boost/gil/extension/dynamic_image/any_image.hpp
Normal file
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
|
||||
|
||||
#include <boost/gil/extension/dynamic_image/any_image_view.hpp>
|
||||
#include <boost/gil/extension/dynamic_image/apply_operation.hpp>
|
||||
|
||||
#include <boost/gil/image.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4512) //assignment operator could not be generated
|
||||
#endif
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
namespace detail {
|
||||
template <typename T> struct get_view_t { using type = typename T::view_t; };
|
||||
template <typename Images> struct images_get_views_t : public mpl::transform<Images, get_view_t<mpl::_1> > {};
|
||||
|
||||
template <typename T> struct get_const_view_t { using type = typename T::const_view_t; };
|
||||
template <typename Images> struct images_get_const_views_t : public mpl::transform<Images, get_const_view_t<mpl::_1> > {};
|
||||
|
||||
struct recreate_image_fnobj
|
||||
{
|
||||
using result_type = void;
|
||||
point<std::ptrdiff_t> const& _dimensions;
|
||||
unsigned _alignment;
|
||||
|
||||
recreate_image_fnobj(point<std::ptrdiff_t> const& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {}
|
||||
template <typename Image>
|
||||
result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
|
||||
};
|
||||
|
||||
template <typename AnyView> // Models AnyViewConcept
|
||||
struct any_image_get_view {
|
||||
using result_type = AnyView;
|
||||
template <typename Image> result_type operator()( Image& img) const { return result_type(view(img)); }
|
||||
};
|
||||
|
||||
template <typename AnyConstView> // Models AnyConstViewConcept
|
||||
struct any_image_get_const_view {
|
||||
using result_type = AnyConstView;
|
||||
template <typename Image> result_type operator()(const Image& img) const { return result_type(const_view(img)); }
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// \ingroup ImageModel
|
||||
/// \brief Represents a run-time specified image. Note it does NOT model ImageConcept
|
||||
///
|
||||
/// Represents an image whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time.
|
||||
/// It is the runtime equivalent of \p image.
|
||||
/// Some of the requirements of ImageConcept, such as the \p value_type alias cannot be fulfilled, since the language does not allow runtime type specification.
|
||||
/// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image does not fully model ImageConcept.
|
||||
/// In particular, its \p view and \p const_view methods return \p any_image_view, which does not fully model ImageViewConcept. See \p any_image_view for more.
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename ImageTypes>
|
||||
class any_image : public make_variant_over<ImageTypes>::type {
|
||||
using parent_t = typename make_variant_over<ImageTypes>::type;
|
||||
public:
|
||||
using const_view_t = any_image_view<typename detail::images_get_const_views_t<ImageTypes>::type>;
|
||||
using view_t = any_image_view<typename detail::images_get_views_t<ImageTypes>::type>;
|
||||
using x_coord_t = std::ptrdiff_t;
|
||||
using y_coord_t = std::ptrdiff_t;
|
||||
using point_t = point<std::ptrdiff_t>;
|
||||
|
||||
any_image() : parent_t() {}
|
||||
template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
|
||||
template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
|
||||
any_image(const any_image& v) : parent_t((const parent_t&)v) {}
|
||||
template <typename Types> any_image(const any_image<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}
|
||||
|
||||
template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
|
||||
any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
|
||||
template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}
|
||||
|
||||
void recreate(const point_t& dims, unsigned alignment=1)
|
||||
{
|
||||
apply_operation(*this,detail::recreate_image_fnobj(dims,alignment));
|
||||
}
|
||||
|
||||
void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1)
|
||||
{
|
||||
recreate({width, height}, alignment);
|
||||
}
|
||||
|
||||
std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
|
||||
point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
|
||||
x_coord_t width() const { return dimensions().x; }
|
||||
y_coord_t height() const { return dimensions().y; }
|
||||
};
|
||||
|
||||
///@{
|
||||
/// \name view, const_view
|
||||
/// \brief Get an image view from a run-time instantiated image
|
||||
|
||||
/// \ingroup ImageModel
|
||||
|
||||
/// \brief Returns the non-constant-pixel view of any image. The returned view is any view.
|
||||
template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
|
||||
typename any_image<Types>::view_t view(any_image<Types>& anyImage) {
|
||||
return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
|
||||
}
|
||||
|
||||
/// \brief Returns the constant-pixel view of any image. The returned view is any view.
|
||||
template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
|
||||
typename any_image<Types>::const_view_t const_view(const any_image<Types>& anyImage) {
|
||||
return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
|
||||
}
|
||||
///@}
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
|
||||
|
||||
#include <boost/gil/dynamic_step.hpp>
|
||||
#include <boost/gil/image.hpp>
|
||||
#include <boost/gil/image_view.hpp>
|
||||
#include <boost/gil/point.hpp>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
namespace detail {
|
||||
template <typename View> struct get_const_t { using type = typename View::const_t; };
|
||||
template <typename Views> struct views_get_const_t : public mpl::transform<Views, get_const_t<mpl::_1> > {};
|
||||
}
|
||||
|
||||
template <typename View> struct dynamic_xy_step_transposed_type;
|
||||
|
||||
namespace detail {
|
||||
|
||||
// works for both image_view and image
|
||||
struct any_type_get_num_channels
|
||||
{
|
||||
using result_type = int;
|
||||
template <typename T>
|
||||
result_type operator()(const T&) const { return num_channels<T>::value; }
|
||||
};
|
||||
|
||||
// works for both image_view and image
|
||||
struct any_type_get_dimensions
|
||||
{
|
||||
using result_type = point<std::ptrdiff_t>;
|
||||
template <typename T>
|
||||
result_type operator()(const T& v) const { return v.dimensions(); }
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// CLASS any_image_view
|
||||
///
|
||||
/// \ingroup ImageViewModel
|
||||
/// \brief Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeConcept, Note that this class does NOT model ImageViewConcept
|
||||
///
|
||||
/// Represents a view whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time.
|
||||
/// It is the runtime equivalent of \p image_view.
|
||||
/// Some of the requirements of ImageViewConcept, such as the \p value_type alias cannot be fulfilled, since the language does not allow runtime type specification.
|
||||
/// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image_view does not fully model ImageViewConcept.
|
||||
/// However, many algorithms provide overloads taking runtime specified views and thus in many cases \p any_image_view can be used in places taking a view.
|
||||
///
|
||||
/// To perform an algorithm on any_image_view, put the algorithm in a function object and invoke it by calling \p apply_operation(runtime_view, algorithm_fn);
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename ImageViewTypes>
|
||||
class any_image_view : public make_variant_over<ImageViewTypes>::type {
|
||||
using parent_t = typename make_variant_over<ImageViewTypes>::type;
|
||||
public:
|
||||
using const_t = any_image_view<typename detail::views_get_const_t<ImageViewTypes>::type>;
|
||||
using x_coord_t = std::ptrdiff_t;
|
||||
using y_coord_t = std::ptrdiff_t;
|
||||
using point_t = point<std::ptrdiff_t>;
|
||||
|
||||
any_image_view() : parent_t() {}
|
||||
template <typename T> explicit any_image_view(const T& obj) : parent_t(obj) {}
|
||||
any_image_view(const any_image_view& v) : parent_t((const parent_t&)v) {}
|
||||
template <typename Types> any_image_view(const any_image_view<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}
|
||||
|
||||
template <typename T> any_image_view& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
|
||||
any_image_view& operator=(const any_image_view& v) { parent_t::operator=((const parent_t&)v); return *this;}
|
||||
template <typename Types> any_image_view& operator=(const any_image_view<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}
|
||||
|
||||
std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
|
||||
point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
|
||||
x_coord_t width() const { return dimensions().x; }
|
||||
y_coord_t height() const { return dimensions().y; }
|
||||
};
|
||||
|
||||
/////////////////////////////
|
||||
// HasDynamicXStepTypeConcept
|
||||
/////////////////////////////
|
||||
|
||||
template <typename IVTypes>
|
||||
struct dynamic_x_step_type<any_image_view<IVTypes>>
|
||||
{
|
||||
using type = any_image_view<typename mpl::transform<IVTypes, dynamic_x_step_type<mpl::_1>>::type>;
|
||||
};
|
||||
|
||||
/////////////////////////////
|
||||
// HasDynamicYStepTypeConcept
|
||||
/////////////////////////////
|
||||
|
||||
template <typename IVTypes>
|
||||
struct dynamic_y_step_type<any_image_view<IVTypes>>
|
||||
{
|
||||
using type = any_image_view<typename mpl::transform<IVTypes, dynamic_y_step_type<mpl::_1>>::type>;
|
||||
};
|
||||
|
||||
template <typename IVTypes>
|
||||
struct dynamic_xy_step_type<any_image_view<IVTypes>>
|
||||
{
|
||||
using type = any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_type<mpl::_1>>::type>;
|
||||
};
|
||||
|
||||
template <typename IVTypes>
|
||||
struct dynamic_xy_step_transposed_type<any_image_view<IVTypes>>
|
||||
{
|
||||
using type = any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_transposed_type<mpl::_1>>::type>;
|
||||
};
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_APPLY_OPERATION_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_APPLY_OPERATION_HPP
|
||||
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
|
||||
#ifdef BOOST_GIL_DOXYGEN_ONLY
|
||||
#undef BOOST_GIL_REDUCE_CODE_BLOAT
|
||||
#endif
|
||||
|
||||
// Implements apply_operation for variants.
|
||||
// Optionally performs type reduction.
|
||||
#ifdef BOOST_GIL_REDUCE_CODE_BLOAT
|
||||
|
||||
#include <boost/gil/extension/dynamic_image/reduce.hpp>
|
||||
|
||||
#else
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
/// \ingroup Variant
|
||||
/// \brief Invokes a generic mutable operation (represented as a unary function object) on a variant
|
||||
template <typename Types, typename UnaryOp>
|
||||
BOOST_FORCEINLINE
|
||||
auto apply_operation(variant<Types>& arg, UnaryOp op)
|
||||
#if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
|
||||
-> typename UnaryOp::result_type
|
||||
#endif
|
||||
{
|
||||
return apply_visitor(op, arg);
|
||||
}
|
||||
|
||||
/// \ingroup Variant
|
||||
/// \brief Invokes a generic constant operation (represented as a unary function object) on a variant
|
||||
template <typename Types, typename UnaryOp>
|
||||
BOOST_FORCEINLINE
|
||||
auto apply_operation(variant<Types> const& arg, UnaryOp op)
|
||||
#if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
|
||||
-> typename UnaryOp::result_type
|
||||
#endif
|
||||
{
|
||||
return apply_visitor(op, arg);
|
||||
}
|
||||
|
||||
/// \ingroup Variant
|
||||
/// \brief Invokes a generic constant operation (represented as a binary function object) on two variants
|
||||
template <typename Types1, typename Types2, typename BinaryOp>
|
||||
BOOST_FORCEINLINE
|
||||
auto apply_operation(
|
||||
variant<Types1> const& arg1,
|
||||
variant<Types2> const& arg2,
|
||||
BinaryOp op)
|
||||
#if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
|
||||
-> typename BinaryOp::result_type
|
||||
#endif
|
||||
{
|
||||
return apply_visitor(
|
||||
op, arg1, arg2);
|
||||
}
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#endif // defined(BOOST_GIL_REDUCE_CODE_BLOAT)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_DYNAMIC_AT_C_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_DYNAMIC_AT_C_HPP
|
||||
|
||||
#include <boost/mpl/at.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
// Constructs for static-to-dynamic integer convesion
|
||||
|
||||
#define GIL_AT_C_VALUE(z, N, text) mpl::at_c<IntTypes,S+N>::type::value,
|
||||
#define GIL_DYNAMIC_AT_C_LIMIT 226 // size of the maximum vector to handle
|
||||
|
||||
#define GIL_AT_C_LOOKUP(z, NUM, text) \
|
||||
template<std::size_t S> \
|
||||
struct at_c_fn<S,NUM> { \
|
||||
template <typename IntTypes, typename ValueType> inline \
|
||||
static ValueType apply(std::size_t index) { \
|
||||
static ValueType table[] = { \
|
||||
BOOST_PP_REPEAT(NUM, GIL_AT_C_VALUE, BOOST_PP_EMPTY) \
|
||||
}; \
|
||||
return table[index]; \
|
||||
} \
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
namespace at_c {
|
||||
template <std::size_t START, std::size_t NUM> struct at_c_fn;
|
||||
BOOST_PP_REPEAT(GIL_DYNAMIC_AT_C_LIMIT, GIL_AT_C_LOOKUP, BOOST_PP_EMPTY)
|
||||
|
||||
template <std::size_t QUOT> struct at_c_impl;
|
||||
|
||||
template <>
|
||||
struct at_c_impl<0> {
|
||||
template <typename IntTypes, typename ValueType> inline
|
||||
static ValueType apply(std::size_t index) {
|
||||
return at_c_fn<0,mpl::size<IntTypes>::value>::template apply<IntTypes,ValueType>(index);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct at_c_impl<1> {
|
||||
template <typename IntTypes, typename ValueType> inline
|
||||
static ValueType apply(std::size_t index) {
|
||||
const std::size_t SIZE=mpl::size<IntTypes>::value;
|
||||
const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
|
||||
switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
|
||||
case 0: return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
|
||||
case 1: return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
|
||||
};
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct at_c_impl<2> {
|
||||
template <typename IntTypes, typename ValueType> inline
|
||||
static ValueType apply(std::size_t index) {
|
||||
const std::size_t SIZE=mpl::size<IntTypes>::value;
|
||||
const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
|
||||
switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
|
||||
case 0: return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
|
||||
case 1: return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
|
||||
case 2: return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*2,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*2);
|
||||
};
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct at_c_impl<3> {
|
||||
template <typename IntTypes, typename ValueType> inline
|
||||
static ValueType apply(std::size_t index) {
|
||||
const std::size_t SIZE=mpl::size<IntTypes>::value;
|
||||
const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
|
||||
switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
|
||||
case 0: return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
|
||||
case 1: return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
|
||||
case 2: return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*2,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*2);
|
||||
case 3: return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*3,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*3);
|
||||
};
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// \brief Given an MPL Random Access Sequence and a dynamic index n, returns the value of the n-th element
|
||||
/// It constructs a lookup table at compile time
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename IntTypes, typename ValueType> inline
|
||||
ValueType at_c(std::size_t index) {
|
||||
const std::size_t Size=mpl::size<IntTypes>::value;
|
||||
return detail::at_c::at_c_impl<Size/GIL_DYNAMIC_AT_C_LIMIT>::template apply<IntTypes,ValueType>(index);
|
||||
}
|
||||
|
||||
#undef GIL_AT_C_VALUE
|
||||
#undef GIL_DYNAMIC_AT_C_LIMIT
|
||||
#undef GIL_AT_C_LOOKUP
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_DYNAMIC_IMAGE_ALL_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_DYNAMIC_IMAGE_ALL_HPP
|
||||
|
||||
#include <boost/gil/extension/dynamic_image/algorithm.hpp>
|
||||
#include <boost/gil/extension/dynamic_image/any_image.hpp>
|
||||
#include <boost/gil/extension/dynamic_image/apply_operation.hpp>
|
||||
#include <boost/gil/extension/dynamic_image/image_view_factory.hpp>
|
||||
#include <boost/gil.hpp> // FIXME: Include what you use!
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_IMAGE_VIEW_FACTORY_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_IMAGE_VIEW_FACTORY_HPP
|
||||
|
||||
#include <boost/gil/extension/dynamic_image/any_image_view.hpp>
|
||||
|
||||
#include <boost/gil/dynamic_step.hpp>
|
||||
#include <boost/gil/image_view_factory.hpp>
|
||||
#include <boost/gil/point.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
// Methods for constructing any image views from other any image views
|
||||
// Extends image view factory to runtime type-specified views (any_image_view)
|
||||
|
||||
namespace detail {
|
||||
template <typename Result> struct flipped_up_down_view_fn {
|
||||
using result_type = Result;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(flipped_up_down_view(src)); }
|
||||
};
|
||||
template <typename Result> struct flipped_left_right_view_fn {
|
||||
using result_type = Result;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(flipped_left_right_view(src)); }
|
||||
};
|
||||
template <typename Result> struct rotated90cw_view_fn {
|
||||
using result_type = Result;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(rotated90cw_view(src)); }
|
||||
};
|
||||
template <typename Result> struct rotated90ccw_view_fn {
|
||||
using result_type = Result;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(rotated90ccw_view(src)); }
|
||||
};
|
||||
template <typename Result> struct tranposed_view_fn {
|
||||
using result_type = Result;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(tranposed_view(src)); }
|
||||
};
|
||||
template <typename Result> struct rotated180_view_fn {
|
||||
using result_type = Result;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(rotated180_view(src)); }
|
||||
};
|
||||
|
||||
template <typename Result>
|
||||
struct subimage_view_fn
|
||||
{
|
||||
using result_type = Result;
|
||||
subimage_view_fn(point_t const& topleft, point_t const& dimensions)
|
||||
: _topleft(topleft), _size2(dimensions)
|
||||
{}
|
||||
|
||||
template <typename View>
|
||||
result_type operator()(const View& src) const
|
||||
{
|
||||
return result_type(subimage_view(src,_topleft,_size2));
|
||||
}
|
||||
|
||||
point_t _topleft;
|
||||
point_t _size2;
|
||||
};
|
||||
|
||||
template <typename Result>
|
||||
struct subsampled_view_fn
|
||||
{
|
||||
using result_type = Result;
|
||||
subsampled_view_fn(point_t const& step) : _step(step) {}
|
||||
|
||||
template <typename View>
|
||||
result_type operator()(const View& src) const
|
||||
{
|
||||
return result_type(subsampled_view(src,_step));
|
||||
}
|
||||
|
||||
point_t _step;
|
||||
};
|
||||
|
||||
template <typename Result> struct nth_channel_view_fn {
|
||||
using result_type = Result;
|
||||
nth_channel_view_fn(int n) : _n(n) {}
|
||||
int _n;
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(nth_channel_view(src,_n)); }
|
||||
};
|
||||
template <typename DstP, typename Result, typename CC = default_color_converter> struct color_converted_view_fn {
|
||||
using result_type = Result;
|
||||
color_converted_view_fn(CC cc = CC()): _cc(cc) {}
|
||||
|
||||
template <typename View> result_type operator()(const View& src) const { return result_type(color_converted_view<DstP>(src, _cc)); }
|
||||
|
||||
private:
|
||||
CC _cc;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
|
||||
/// \ingroup ImageViewTransformationsFlipUD
|
||||
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename dynamic_y_step_type<any_image_view<ViewTypes> >::type flipped_up_down_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::flipped_up_down_view_fn<typename dynamic_y_step_type<any_image_view<ViewTypes> >::type>());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsFlipLR
|
||||
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename dynamic_x_step_type<any_image_view<ViewTypes> >::type flipped_left_right_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::flipped_left_right_view_fn<typename dynamic_x_step_type<any_image_view<ViewTypes> >::type>());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsTransposed
|
||||
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type transposed_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::tranposed_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformations90CW
|
||||
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90cw_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::rotated90cw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformations90CCW
|
||||
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90ccw_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::rotated90ccw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformations180
|
||||
/// Models MPL Random Access Container of models of ImageViewConcept
|
||||
template <typename ViewTypes>
|
||||
inline auto rotated180_view(const any_image_view<ViewTypes>& src)
|
||||
-> typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type
|
||||
{
|
||||
using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
|
||||
return apply_operation(src, detail::rotated180_view_fn<step_type>());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsSubimage
|
||||
/// // Models MPL Random Access Container of models of ImageViewConcept
|
||||
template <typename ViewTypes>
|
||||
inline auto subimage_view(any_image_view<ViewTypes> const& src,
|
||||
point_t const& topleft, point_t const& dimensions)
|
||||
-> any_image_view<ViewTypes>
|
||||
{
|
||||
using subimage_view_fn = detail::subimage_view_fn<any_image_view<ViewTypes>>;
|
||||
return apply_operation(src, subimage_view_fn(topleft, dimensions));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsSubimage
|
||||
/// Models MPL Random Access Container of models of ImageViewConcept
|
||||
template <typename ViewTypes>
|
||||
inline auto subimage_view(any_image_view<ViewTypes> const& src,
|
||||
int xMin, int yMin, int width, int height)
|
||||
-> any_image_view<ViewTypes>
|
||||
{
|
||||
using subimage_view_fn = detail::subimage_view_fn<any_image_view<ViewTypes>>;
|
||||
return apply_operation(src, subimage_view_fn(point_t(xMin, yMin),point_t(width, height)));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsSubsampled
|
||||
/// Models MPL Random Access Container of models of ImageViewConcept
|
||||
template <typename ViewTypes>
|
||||
inline auto subsampled_view(any_image_view<ViewTypes> const& src, point_t const& step)
|
||||
-> typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type
|
||||
{
|
||||
using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
|
||||
using subsampled_view = detail::subsampled_view_fn<step_type>;
|
||||
return apply_operation(src, subsampled_view(step));
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsSubsampled
|
||||
/// Models MPL Random Access Container of models of ImageViewConcept
|
||||
template <typename ViewTypes>
|
||||
inline auto subsampled_view(any_image_view<ViewTypes> const& src, int xStep, int yStep)
|
||||
-> typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type
|
||||
{
|
||||
using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
|
||||
using subsampled_view_fn = detail::subsampled_view_fn<step_type>;
|
||||
return apply_operation(src, subsampled_view_fn(point_t(xStep, yStep)));
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template <typename View> struct get_nthchannel_type { using type = typename nth_channel_view_type<View>::type; };
|
||||
template <typename Views> struct views_get_nthchannel_type : public mpl::transform<Views, get_nthchannel_type<mpl::_1> > {};
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsNthChannel
|
||||
/// \brief Given a runtime source image view, returns the type of a runtime image view over a single channel of the source view
|
||||
template <typename ViewTypes>
|
||||
struct nth_channel_view_type<any_image_view<ViewTypes> > {
|
||||
using type = any_image_view<typename detail::views_get_nthchannel_type<ViewTypes>::type>;
|
||||
};
|
||||
|
||||
/// \ingroup ImageViewTransformationsNthChannel
|
||||
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename nth_channel_view_type<any_image_view<ViewTypes> >::type nth_channel_view(const any_image_view<ViewTypes>& src, int n) {
|
||||
return apply_operation(src,detail::nth_channel_view_fn<typename nth_channel_view_type<any_image_view<ViewTypes> >::type>(n));
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template <typename View, typename DstP, typename CC> struct get_ccv_type : public color_converted_view_type<View, DstP, CC> {};
|
||||
template <typename Views, typename DstP, typename CC> struct views_get_ccv_type : public mpl::transform<Views, get_ccv_type<mpl::_1,DstP,CC> > {};
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsColorConvert
|
||||
/// \brief Returns the type of a runtime-specified view, color-converted to a given pixel type with user specified color converter
|
||||
template <typename ViewTypes, typename DstP, typename CC>
|
||||
struct color_converted_view_type<any_image_view<ViewTypes>,DstP,CC>
|
||||
{
|
||||
using type = any_image_view<typename detail::views_get_ccv_type<ViewTypes, DstP, CC>::type>;
|
||||
};
|
||||
|
||||
/// \ingroup ImageViewTransformationsColorConvert
|
||||
/// \brief overload of generic color_converted_view with user defined color-converter
|
||||
template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type color_converted_view(const any_image_view<ViewTypes>& src, CC) {
|
||||
return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsColorConvert
|
||||
/// \brief Returns the type of a runtime-specified view, color-converted to a given pixel type with the default coor converter
|
||||
template <typename ViewTypes, typename DstP>
|
||||
struct color_converted_view_type<any_image_view<ViewTypes>,DstP>
|
||||
{
|
||||
using type = any_image_view<typename detail::views_get_ccv_type<ViewTypes, DstP, default_color_converter>::type>;
|
||||
};
|
||||
|
||||
/// \ingroup ImageViewTransformationsColorConvert
|
||||
/// \brief overload of generic color_converted_view with the default color-converter
|
||||
template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type color_converted_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
|
||||
}
|
||||
|
||||
|
||||
/// \ingroup ImageViewTransformationsColorConvert
|
||||
/// \brief overload of generic color_converted_view with user defined color-converter
|
||||
/// These are workarounds for GCC 3.4, which thinks color_converted_view is ambiguous with the same method for templated views (in gil/image_view_factory.hpp)
|
||||
template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type any_color_converted_view(const any_image_view<ViewTypes>& src, CC) {
|
||||
return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
|
||||
}
|
||||
|
||||
/// \ingroup ImageViewTransformationsColorConvert
|
||||
/// \brief overload of generic color_converted_view with the default color-converter
|
||||
/// These are workarounds for GCC 3.4, which thinks color_converted_view is ambiguous with the same method for templated views (in gil/image_view_factory.hpp)
|
||||
template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
|
||||
typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type any_color_converted_view(const any_image_view<ViewTypes>& src) {
|
||||
return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
|
||||
}
|
||||
|
||||
/// \}
|
||||
|
||||
} } // namespace boost::gil
|
||||
|
||||
#endif
|
||||
832
macx64/include/boost/gil/extension/dynamic_image/reduce.hpp
Normal file
832
macx64/include/boost/gil/extension/dynamic_image/reduce.hpp
Normal file
@@ -0,0 +1,832 @@
|
||||
//
|
||||
// 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_EXTENSION_DYNAMIC_IMAGE_GIL_REDUCE_HPP
|
||||
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_GIL_REDUCE_HPP
|
||||
|
||||
#ifdef BOOST_GIL_DOXYGEN_ONLY
|
||||
#undef BOOST_GIL_REDUCE_CODE_BLOAT
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_GIL_REDUCE_CODE_BLOAT
|
||||
|
||||
#include <boost/gil/extension/dynamic_image/dynamic_at_c.hpp>
|
||||
|
||||
#include <boost/gil/metafunctions.hpp>
|
||||
#include <boost/gil/typedefs.hpp>
|
||||
|
||||
#include <boost/mpl/back.hpp>
|
||||
#include <boost/mpl/insert.hpp>
|
||||
#include <boost/mpl/insert_range.hpp>
|
||||
#include <boost/mpl/long.hpp>
|
||||
#include <boost/mpl/logical.hpp>
|
||||
#include <boost/mpl/range_c.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
#include <boost/mpl/transform.hpp>
|
||||
|
||||
// Max number of cases in the cross-expension of binary operation for it to be reduced as unary
|
||||
#define GIL_BINARY_REDUCE_LIMIT 226
|
||||
|
||||
namespace boost { namespace mpl {
|
||||
|
||||
// Constructs for static-to-dynamic integer convesion
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
/// Mapping vector - represents the mapping of one type vector to another
|
||||
/// It is not a full-blown MPL Random Access Type sequence; just has at_c and size implemented
|
||||
///
|
||||
/// SrcTypes, DstTypes: MPL Random Access Type Sequences
|
||||
///
|
||||
/// Implements size and at_c to behave as if this is an MPL vector of integers
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
template <typename SrcTypes, typename DstTypes>
|
||||
struct mapping_vector {};
|
||||
|
||||
template <typename SrcTypes, typename DstTypes, long K>
|
||||
struct at_c<mapping_vector<SrcTypes,DstTypes>, K>
|
||||
{
|
||||
static const std::size_t value=size<DstTypes>::value - order<DstTypes, typename gil::at_c<SrcTypes,K>::type>::type::value +1;
|
||||
using type = size_t<value>;
|
||||
};
|
||||
|
||||
template <typename SrcTypes, typename DstTypes>
|
||||
struct size<mapping_vector<SrcTypes,DstTypes>>
|
||||
{
|
||||
using type = typename size<SrcTypes>::type;
|
||||
static const std::size_t value=type::value;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
/// copy_to_vector - copies a sequence (mpl::set) to vector.
|
||||
///
|
||||
/// Temporary solution because I couldn't get mpl::copy to do this.
|
||||
/// This is what I tried:
|
||||
/// mpl::copy<SET, mpl::back_inserter<mpl::vector<>>>::type;
|
||||
/// It works when SET is mpl::vector, but not when SET is mpl::set...
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
namespace detail {
|
||||
template <typename SFirst, std::size_t NLeft>
|
||||
struct copy_to_vector_impl {
|
||||
private:
|
||||
using T = typename deref<SFirst>::type;
|
||||
using next = typename next<SFirst>::type;
|
||||
using rest = typename copy_to_vector_impl<next, NLeft-1>::type;
|
||||
public:
|
||||
using type = typename push_front<rest, T>::type;
|
||||
};
|
||||
|
||||
template <typename SFirst>
|
||||
struct copy_to_vector_impl<SFirst,1>
|
||||
{
|
||||
using type = vector<typename deref<SFirst>::type>;
|
||||
};
|
||||
}
|
||||
|
||||
template <typename Src>
|
||||
struct copy_to_vector
|
||||
{
|
||||
using type = typename detail::copy_to_vector_impl<typename begin<Src>::type, size<Src>::value>::type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct copy_to_vector<set<>>
|
||||
{
|
||||
using type = vector0<>;
|
||||
};
|
||||
|
||||
} } // boost::mpl
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
///
|
||||
/// unary_reduce, binary_reduce - given an MPL Random Access Sequence,
|
||||
/// dynamically specified index to that container, the bits of an instance of the corresponding type and
|
||||
/// a generic operation, invokes the operation on the given type
|
||||
///
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
///
|
||||
/// \brief Unary reduce.
|
||||
///
|
||||
/// Given a set of types and an operation, reduces each type in the set (to reduced_t), then removes duplicates (to unique_t)
|
||||
/// To apply the operation, first constructs a lookup table that maps each element from Types to its place in unique_t and uses it to map
|
||||
/// the index to anther index (in map_index). Then invokes apply_operation_base on the unique types with the new index.
|
||||
///
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
template <typename Types, typename Op>
|
||||
struct unary_reduce_impl {
|
||||
using reduced_t = typename mpl::transform<Types, detail::reduce<Op, mpl::_1> >::type;
|
||||
using unique_t = typename mpl::copy<reduced_t, mpl::inserter<mpl::set<>, mpl::insert<mpl::_1,mpl::_2>>>::type;
|
||||
static const bool is_single=mpl::size<unique_t>::value==1;
|
||||
};
|
||||
|
||||
template <typename Types, typename Op, bool IsSingle=unary_reduce_impl<Types,Op>::is_single>
|
||||
struct unary_reduce : public unary_reduce_impl<Types,Op>
|
||||
{
|
||||
using reduced_t = typename unary_reduce_impl<Types,Op>::reduced_t;
|
||||
using unique_t = typename unary_reduce_impl<Types,Op>::unique_t;
|
||||
|
||||
static unsigned short inline map_index(std::size_t index)
|
||||
{
|
||||
using indices_t = typename mpl::mapping_vector<reduced_t, unique_t>;
|
||||
return gil::at_c<indices_t, unsigned short>(index);
|
||||
}
|
||||
template <typename Bits> BOOST_FORCEINLINE static typename Op::result_type applyc(const Bits& bits, std::size_t index, Op op) {
|
||||
return apply_operation_basec<unique_t>(bits,map_index(index),op);
|
||||
}
|
||||
|
||||
template <typename Bits> BOOST_FORCEINLINE static typename Op::result_type apply(Bits& bits, std::size_t index, Op op) {
|
||||
return apply_operation_base<unique_t>(bits,map_index(index),op);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Types, typename Op>
|
||||
struct unary_reduce<Types,Op,true> : public unary_reduce_impl<Types,Op> {
|
||||
using unique_t = typename unary_reduce_impl<Types,Op>::unique_t;
|
||||
static unsigned short inline map_index(std::size_t index) { return 0; }
|
||||
|
||||
template <typename Bits> BOOST_FORCEINLINE static typename Op::result_type applyc(const Bits& bits, std::size_t index, Op op) {
|
||||
return op(*gil_reinterpret_cast_c<const typename mpl::front<unique_t>::type*>(&bits));
|
||||
}
|
||||
|
||||
template <typename Bits> BOOST_FORCEINLINE static typename Op::result_type apply(Bits& bits, std::size_t index, Op op) {
|
||||
return op(*gil_reinterpret_cast<typename mpl::front<unique_t>::type*>(&bits));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
///
|
||||
/// \brief Binary reduce.
|
||||
///
|
||||
/// Given two sets of types, Types1 and Types2, first performs unary reduction on each. Then checks if the product of their sizes is above
|
||||
/// the GIL_BINARY_REDUCE_LIMIT limit. If so, the operation is too complex to be binary-reduced and uses a specialization of binary_reduce_impl
|
||||
/// to simply call the binary apply_operation_base (which performs two nested 1D apply operations)
|
||||
/// If the operation is not too complex, uses the other specialization of binary_reduce_impl to create a cross-product of the input types
|
||||
/// and performs unary reduction on the result (bin_reduced_t). To apply the binary operation, it simply invokes a unary apply_operation_base
|
||||
/// on the reduced cross-product types
|
||||
///
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
namespace detail {
|
||||
struct pair_generator {
|
||||
template <typename Vec2> struct apply
|
||||
{
|
||||
using type = std::pair<const typename mpl::at_c<Vec2,0>::type*, const typename mpl::at_c<Vec2,1>::type*>;
|
||||
};
|
||||
};
|
||||
|
||||
// When the types are not too large, applies reduce on their cross product
|
||||
template <typename Unary1, typename Unary2, typename Op, bool IsComplex>
|
||||
struct binary_reduce_impl
|
||||
{
|
||||
//private:
|
||||
using vec1_types = typename mpl::copy_to_vector<typename Unary1::unique_t>::type;
|
||||
using vec2_types = typename mpl::copy_to_vector<typename Unary2::unique_t>::type;
|
||||
|
||||
using BIN_TYPES = mpl::cross_vector<mpl::vector2<vec1_types, vec2_types>, pair_generator>;
|
||||
using bin_reduced_t = unary_reduce<BIN_TYPES,Op>;
|
||||
|
||||
static unsigned short inline map_index(std::size_t index1, std::size_t index2) {
|
||||
unsigned short r1=Unary1::map_index(index1);
|
||||
unsigned short r2=Unary2::map_index(index2);
|
||||
return bin_reduced_t::map_index(r2*mpl::size<vec1_types>::value + r1);
|
||||
}
|
||||
public:
|
||||
using unique_t = typename bin_reduced_t::unique_t
|
||||
|
||||
template <typename Bits1, typename Bits2>
|
||||
static typename Op::result_type inline apply(const Bits1& bits1, std::size_t index1, const Bits2& bits2, std::size_t index2, Op op) {
|
||||
std::pair<const void*,const void*> pr(&bits1, &bits2);
|
||||
return apply_operation_basec<unique_t>(pr, map_index(index1,index2),op);
|
||||
}
|
||||
};
|
||||
|
||||
// When the types are large performs a double-dispatch. Binary reduction is not done.
|
||||
template <typename Unary1, typename Unary2, typename Op>
|
||||
struct binary_reduce_impl<Unary1,Unary2,Op,true> {
|
||||
template <typename Bits1, typename Bits2>
|
||||
static typename Op::result_type inline apply(const Bits1& bits1, std::size_t index1, const Bits2& bits2, std::size_t index2, Op op) {
|
||||
return apply_operation_base<Unary1::unique_t,Unary2::unique_t>(bits1, index1, bits2, index2, op);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template <typename Types1, typename Types2, typename Op>
|
||||
struct binary_reduce
|
||||
{
|
||||
//private:
|
||||
using unary1_t = unary_reduce<Types1,Op>;
|
||||
using unary2_t = unary_reduce<Types2,Op>;
|
||||
|
||||
static const std::size_t CROSS_SIZE = mpl::size<typename unary1_t::unique_t>::value *
|
||||
mpl::size<typename unary2_t::unique_t>::value;
|
||||
|
||||
using impl = detail::binary_reduce_impl<unary1_t,unary2_t,Op, (CROSS_SIZE>GIL_BINARY_REDUCE_LIMIT)>;
|
||||
public:
|
||||
template <typename Bits1, typename Bits2>
|
||||
static typename Op::result_type inline apply(const Bits1& bits1, std::size_t index1, const Bits2& bits2, std::size_t index2, Op op) {
|
||||
return impl::apply(bits1,index1,bits2,index2,op);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Types, typename UnaryOp>
|
||||
BOOST_FORCEINLINE typename UnaryOp::result_type apply_operation(variant<Types>& arg, UnaryOp op) {
|
||||
return unary_reduce<Types,UnaryOp>::template apply(arg._bits, arg._index ,op);
|
||||
}
|
||||
|
||||
template <typename Types, typename UnaryOp>
|
||||
BOOST_FORCEINLINE typename UnaryOp::result_type apply_operation(const variant<Types>& arg, UnaryOp op) {
|
||||
return unary_reduce<Types,UnaryOp>::template applyc(arg._bits, arg._index ,op);
|
||||
}
|
||||
|
||||
template <typename Types1, typename Types2, typename BinaryOp>
|
||||
BOOST_FORCEINLINE typename BinaryOp::result_type apply_operation(const variant<Types1>& arg1, const variant<Types2>& arg2, BinaryOp op) {
|
||||
return binary_reduce<Types1,Types2,BinaryOp>::template apply(arg1._bits, arg1._index, arg2._bits, arg2._index, op);
|
||||
}
|
||||
|
||||
#undef GIL_BINARY_REDUCE_LIMIT
|
||||
|
||||
} } // namespace gil
|
||||
|
||||
|
||||
namespace boost { namespace mpl {
|
||||
///////////////////////////////////////////////////////
|
||||
/// \brief Represents the virtual cross-product of the types generated from VecOfVecs.
|
||||
/// \ingroup CrossVector
|
||||
/// INPUT:
|
||||
/// VecOfVecs - a vector of vector types. For example [ [A1,A2,A3], [B1,B2], [C1,C2,C3,C4] ]
|
||||
/// Each element must be a non-empty mpl vector
|
||||
/// TypeGen - a metafunction that generates a type from a vector of types, each of which can be
|
||||
/// selected from the corresponding vector in VecOfVecs. For example, [A1, B2, C4]
|
||||
///
|
||||
/// Represents the virtual cross-product of the types generated from VecOfVecs.
|
||||
/// For example, [ TypeGen[A1,B1,C1], TypeGen[A2,B1,C1], TypeGen[A3,B1,C1],
|
||||
/// TypeGen[A1,B2,C1], TypeGen[A2,B2,C1], TypeGen[A3,B2,C1],
|
||||
/// TypeGen[A1,B1,C2], TypeGen[A2,B1,C2], TypeGen[A3,B1,C2], ... ]
|
||||
///
|
||||
/// Models an immutable MPL Random Access Sequence
|
||||
/// Traversal, random-access, etc, is defined, but mutable operations,
|
||||
/// such as push_back and pop_front are not supported
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct cross_vector {};
|
||||
|
||||
/// \brief Iterator of cross_vector
|
||||
/// \ingroup CrossVectorIterator
|
||||
template <typename VecOfVecs, typename TypeGen, std::size_t K>
|
||||
struct cross_iterator
|
||||
{
|
||||
using category = mpl::random_access_iterator_tag;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
/// Implementation of the iterator functions of cross vector
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
/// \brief Dereferences a cross-vector iterator
|
||||
/// \ingroup CrossVectorIterator
|
||||
/// Creates a vector of the sizes of each type vector in VecOfVecs, then uses it as a basis
|
||||
/// to represent the iterator's position K as a vector of indices. Extracts the corresponding type of
|
||||
/// each input vector and passes the element types to the type generation function, which returns the dereferenced type
|
||||
template <typename VecOfVecs, typename TypeGen, std::size_t K>
|
||||
struct deref<cross_iterator<VecOfVecs,TypeGen,K>>
|
||||
{
|
||||
private:
|
||||
using DerefTypes = typename detail::select_subvector_c<VecOfVecs, K>::type;
|
||||
public:
|
||||
using type = typename TypeGen::template apply<DerefTypes>::type;
|
||||
};
|
||||
|
||||
/// \brief Increments a cross-vector iterator.
|
||||
/// \ingroup CrossVectorIterator
|
||||
template <typename VecOfVecs, typename TypeGen, std::size_t K>
|
||||
struct next<cross_iterator<VecOfVecs,TypeGen,K>>
|
||||
{
|
||||
using type = cross_iterator<VecOfVecs,TypeGen,K+1>;
|
||||
};
|
||||
|
||||
/// \brief Decrements a cross-vector iterator.
|
||||
/// \ingroup CrossVectorIterator
|
||||
template <typename VecOfVecs, typename TypeGen, std::size_t K>
|
||||
struct prior<cross_iterator<VecOfVecs,TypeGen,K>>
|
||||
{
|
||||
using type = cross_iterator<VecOfVecs,TypeGen,K-1>;
|
||||
};
|
||||
|
||||
/// \brief Advances a cross-vector iterator.
|
||||
/// \ingroup CrossVectorIterator
|
||||
template <typename VecOfVecs, typename TypeGen, std::size_t K, typename Distance>
|
||||
struct advance<cross_iterator<VecOfVecs,TypeGen,K>, Distance>
|
||||
{
|
||||
using type = cross_iterator<VecOfVecs,TypeGen,K+Distance::value>;
|
||||
};
|
||||
|
||||
/// \brief Computes the distance between two cross-vector iterator-s.
|
||||
/// \ingroup CrossVectorIterator
|
||||
// (shortened the names of the template arguments - otherwise doxygen cannot parse this...)
|
||||
template <typename VecOfVecs, typename TypeGen, std::size_t K1, std::size_t K2>
|
||||
struct distance<cross_iterator<VecOfVecs,TypeGen,K1>, cross_iterator<VecOfVecs,TypeGen,K2>>
|
||||
{
|
||||
using type = size_t<K2-K1>;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
/// Implementation of cross vector
|
||||
///////////////////////////////////////////////////////
|
||||
/// \brief Computes the size of a cross vector as the product of the sizes of all vectors in VecOfVecs
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct size<cross_vector<VecOfVecs,TypeGen>>
|
||||
{
|
||||
using type = typename fold<VecOfVecs, size_t<1>, times<_1, size<_2>>>::type;
|
||||
static const std::size_t value=type::value;
|
||||
};
|
||||
|
||||
/// \brief Determines whether a cross vector is empty
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct empty<cross_vector<VecOfVecs,TypeGen>> {
|
||||
using type = typename empty<VecOfVecs>::type;
|
||||
};
|
||||
|
||||
/// \brief Returns the K-th element of a cross vector
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen, typename K>
|
||||
struct at<cross_vector<VecOfVecs,TypeGen>, K>
|
||||
{
|
||||
private:
|
||||
using KthIterator = cross_iterator<VecOfVecs,TypeGen,K::value>;
|
||||
public:
|
||||
using type = typename deref<KthIterator>::type;
|
||||
};
|
||||
|
||||
/// \brief Returns an iterator to the first element of a cross vector
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct begin<cross_vector<VecOfVecs,TypeGen>>
|
||||
{
|
||||
using type = cross_iterator<VecOfVecs,TypeGen,0>;
|
||||
};
|
||||
|
||||
/// \brief Returns an iterator to the last element of a cross vector
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct end<cross_vector<VecOfVecs,TypeGen>>
|
||||
{
|
||||
private:
|
||||
using this_t = cross_vector<VecOfVecs,TypeGen>;
|
||||
public:
|
||||
using type = cross_iterator<VecOfVecs,TypeGen,size<this_t>::value>;
|
||||
};
|
||||
|
||||
/// \brief Returns the first element of a cross vector
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct front<cross_vector<VecOfVecs,TypeGen>> {
|
||||
private:
|
||||
using this_t = cross_vector<VecOfVecs,TypeGen>;
|
||||
public:
|
||||
using type = typename deref<typename begin<this_t>::type>::type;
|
||||
};
|
||||
|
||||
/// \brief Returns the last element of a cross vector
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen>
|
||||
struct back<cross_vector<VecOfVecs,TypeGen>>
|
||||
{
|
||||
private:
|
||||
using this_t = cross_vector<VecOfVecs,TypeGen>;
|
||||
using size = typename size<this_t>::type;
|
||||
using last_index = typename minus<size, size_t<1>>::type;
|
||||
public:
|
||||
using type = typename at<this_t, last_index>::type;
|
||||
};
|
||||
|
||||
/// \brief Transforms the elements of a cross vector
|
||||
/// \ingroup CrossVector
|
||||
template <typename VecOfVecs, typename TypeGen, typename OPP>
|
||||
struct transform<cross_vector<VecOfVecs,TypeGen>, OPP>
|
||||
{
|
||||
using Op = typename lambda<OPP>::type;
|
||||
struct adapter
|
||||
{
|
||||
template <typename Elements>
|
||||
struct apply
|
||||
{
|
||||
using orig_t = typename TypeGen::template apply<Elements>::type;
|
||||
using type = typename Op::template apply<orig_t>::type;
|
||||
};
|
||||
};
|
||||
using type = cross_vector<VecOfVecs, adapter>;
|
||||
};
|
||||
|
||||
} } // boost::mpl
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
template <typename Types, typename T> struct type_to_index;
|
||||
template <typename V> struct view_is_basic;
|
||||
struct rgb_t;
|
||||
struct lab_t;
|
||||
struct hsb_t;
|
||||
struct cmyk_t;
|
||||
struct rgba_t;
|
||||
struct error_t;
|
||||
|
||||
|
||||
namespace detail {
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Generic reduce operation
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
template <typename Op, typename T>
|
||||
struct reduce
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Unary reduce_view operation. Splits into basic and non-basic views.
|
||||
//// Algorithm-specific reduce should specialize for basic views
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Op, typename View, bool IsBasic>
|
||||
struct reduce_view_basic
|
||||
{
|
||||
using type = View;
|
||||
};
|
||||
|
||||
template <typename Op, typename Loc>
|
||||
struct reduce<Op, image_view<Loc>>
|
||||
: public reduce_view_basic<Op,image_view<Loc>,view_is_basic<image_view<Loc>>::value> {};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Unary reduce_image operation. Splits into basic and non-basic images.
|
||||
//// Algorithm-specific reduce should specialize for basic images
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Op, typename Img, bool IsBasic>
|
||||
struct reduce_image_basic
|
||||
{
|
||||
using type = Img;
|
||||
};
|
||||
|
||||
template <typename Op, typename V, typename Alloc>
|
||||
struct reduce<Op, image<V,Alloc>> : public reduce_image_basic<Op,image<V,Alloc>,image_is_basic<image<V,Alloc>>::value > {};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Binary reduce_view operation. Splits into basic and non-basic views.
|
||||
//// Algorithm-specific reduce should specialize for basic views
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Op, typename V1, typename V2, bool AreBasic>
|
||||
struct reduce_views_basic
|
||||
{
|
||||
using type = std::pair<const V1*, const V2*>;
|
||||
};
|
||||
|
||||
template <typename Op, typename L1, typename L2>
|
||||
struct reduce<Op, std::pair<const image_view<L1>*, const image_view<L2>*>>
|
||||
: public reduce_views_basic<Op,image_view<L1>,image_view<L2>,
|
||||
mpl::and_<view_is_basic<image_view<L1>>, view_is_basic<image_view<L2>>>::value >
|
||||
{};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Color space unary reduce operation. Reduce a color space to a base with the same number of channels
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
template <typename CS>
|
||||
struct reduce_color_space
|
||||
{
|
||||
using type = CS;
|
||||
};
|
||||
|
||||
template <> struct reduce_color_space<lab_t> { using type = rgb_t; };
|
||||
template <> struct reduce_color_space<hsb_t> { using type = rgb_t; };
|
||||
template <> struct reduce_color_space<cmyk_t> { using type = rgba_t; };
|
||||
|
||||
/*
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Color space binary reduce operation. Given a source and destination color spaces,
|
||||
//// returns a reduced source and destination color spaces that have the same mapping of channels
|
||||
////
|
||||
//// Precondition: The two color spaces must be compatible (i.e. must have the same set of channels)
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Vec, int Basis, int VecSize>
|
||||
struct type_vec_to_integer_impl {
|
||||
using last = typename mpl::back<Vec>::type;
|
||||
using rest = typename mpl::pop_back<Vec>::type;
|
||||
static const int value = type_vec_to_integer_impl<rest, Basis, VecSize-1>::value * Basis + last::value;
|
||||
};
|
||||
|
||||
template <typename Vec, int Basis>
|
||||
struct type_vec_to_integer_impl<Vec,Basis,0> {
|
||||
static const int value=0;
|
||||
};
|
||||
|
||||
template <typename Vec, int Basis=10>
|
||||
struct type_vec_to_integer {
|
||||
static const int value = type_vec_to_integer_impl<Vec,Basis, mpl::size<Vec>::value>::value;
|
||||
};
|
||||
|
||||
// Given two color spaces and the mapping of the channels between them, returns the reduced pair of color spaces
|
||||
// The default version performs no reduction
|
||||
template <typename SrcColorSpace, typename DstColorSpace, int Mapping>
|
||||
struct reduce_color_spaces_impl {
|
||||
using first_t = SrcColorSpace;
|
||||
using second_t = DstColorSpace;
|
||||
};
|
||||
|
||||
// 012: RGB-RGB, bgr-bgr, lab-lab, hsb-hsb
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,12> {
|
||||
using first_t = rgb_t;
|
||||
using second_t = rgb_t;
|
||||
};
|
||||
|
||||
// 210: RGB-bgr, bgr-RGB
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,210> {
|
||||
using first_t = rgb_t;
|
||||
using second_t = bgr_t;
|
||||
};
|
||||
|
||||
// 0123: RGBA-RGBA, bgra-bgra, argb-argb, abgr-abgr cmyk-cmyk
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,123> {
|
||||
using first_t = rgba_t;
|
||||
using second_t = rgba_t;
|
||||
};
|
||||
|
||||
// 3210: RGBA-abgr, bgra-argb, argb-bgra, abgr-RGBA
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,3210> {
|
||||
using first_t = rgba_t;
|
||||
using second_t = abgr_t;
|
||||
};
|
||||
|
||||
// 1230: RGBA-argb, bgra-abgr
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,1230> {
|
||||
using first_t = rgba_t;
|
||||
using second_t = argb_t;
|
||||
};
|
||||
|
||||
// 2103: RGBA-bgra, bgra-RGBA (uses subclass to ensure that base color space is not reduced to derived)
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,2103> {
|
||||
using first_t = rgba_t;
|
||||
using second_t = bgra_t;
|
||||
};
|
||||
|
||||
// 3012: argb-RGBA, abgr-bgra
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,3012> {
|
||||
using first_t = argb_t;
|
||||
using second_t = rgba_t;
|
||||
};
|
||||
|
||||
// 0321: argb-abgr, abgr-argb
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,321> {
|
||||
using first_t = argb_t;
|
||||
using second_t = abgr_t;
|
||||
};
|
||||
|
||||
template <typename SrcColorSpace, typename DstColorSpace>
|
||||
struct reduce_color_spaces {
|
||||
using src_order_t = typename channel_order<SrcColorSpace>::type;
|
||||
using dst_order_t = typename channel_order<DstColorSpace>::type;
|
||||
using mapping = typename mpl::transform<src_order_t, type_to_index<dst_order_t,mpl::_1>>::type;
|
||||
static const int mapping_val = type_vec_to_integer<mapping>::value;
|
||||
|
||||
using _first_t = typename reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,mapping_val>::first_t;
|
||||
using _second_t = typename reduce_color_spaces_impl<SrcColorSpace,DstColorSpace,mapping_val>::second_t;
|
||||
using swap_t = typename mpl::and_<color_space_is_base<DstColorSpace>, mpl::not_< color_space_is_base<_second_t>>>;
|
||||
public:
|
||||
using first_t = typename mpl::if_<swap_t, _second_t, _first_t>::type;
|
||||
using second_t = typename mpl::if_<swap_t, _first_t, _second_t>::type;
|
||||
};
|
||||
*/
|
||||
// TODO: Use the old code for reduce_color_spaces above to do color layout reduction
|
||||
template <typename SrcLayout, typename DstLayout>
|
||||
struct reduce_color_layouts
|
||||
{
|
||||
using first_t = SrcLayout;
|
||||
using second_t = DstLayout;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Reduce for copy_pixels
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
struct copy_pixels_fn;
|
||||
|
||||
/*
|
||||
// 1D reduce for copy_pixels reduces the channel to mutable and the color space to its base with same dimensions
|
||||
template <typename View>
|
||||
struct reduce_view_basic<copy_pixels_fn,View,true> {
|
||||
private:
|
||||
using color_space_t = typename reduce_color_space<typename View::color_space_t>::type color_space_t; // reduce the color space
|
||||
using layout_t = layout<color_space_t, typename View::channel_mapping_t>;
|
||||
public:
|
||||
using type = typename derived_view_type<View, use_default, layout_t, use_default, use_default, mpl::true_>::type;
|
||||
};
|
||||
*/
|
||||
// Incompatible views cannot be used in copy_pixels - will throw std::bad_cast
|
||||
template <typename V1, typename V2, bool Compatible>
|
||||
struct reduce_copy_pixop_compat
|
||||
{
|
||||
using type = error_t;
|
||||
};
|
||||
|
||||
// For compatible basic views, reduce their color spaces based on their channel mapping.
|
||||
// Make the source immutable and the destination mutable (they should already be that way)
|
||||
template <typename V1, typename V2>
|
||||
struct reduce_copy_pixop_compat<V1,V2,true>
|
||||
{
|
||||
using layout1 = layout<typename V1::color_space_t, typename V1::channel_mapping_t>;
|
||||
using layout2 = layout<typename V2::color_space_t, typename V2::channel_mapping_t>;
|
||||
|
||||
using L1 = typename reduce_color_layouts<layout1,layout2>::first_t;
|
||||
using L2 = typename reduce_color_layouts<layout1,layout2>::second_t;
|
||||
|
||||
using DV1 = typename derived_view_type<V1, use_default, L1, use_default, use_default, use_default, mpl::false_>::type;
|
||||
using DV2 = typename derived_view_type<V2, use_default, L2, use_default, use_default, use_default, mpl::true_ >::type;
|
||||
|
||||
using type = std::pair<const DV1*, const DV2*>;
|
||||
};
|
||||
|
||||
// The general 2D version branches into compatible and incompatible views
|
||||
template <typename V1, typename V2>
|
||||
struct reduce_views_basic<copy_pixels_fn, V1, V2, true>
|
||||
: public reduce_copy_pixop_compat<V1, V2, mpl::and_<views_are_compatible<V1,V2>, view_is_mutable<V2>>::value > {
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Reduce for variant destructor (basic views have no destructor)
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
struct destructor_op;
|
||||
template <typename View>
|
||||
struct reduce_view_basic<destructor_op,View,true>
|
||||
{
|
||||
using type = gray8_view_t;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Reduce for get_dimensions (basic views and images have the same structure and the dimensions are contained at the beginning)
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
struct any_type_get_dimensions;
|
||||
|
||||
template <typename View>
|
||||
struct reduce_view_basic<any_type_get_dimensions,View,true>
|
||||
{
|
||||
using type = gray8_view_t;
|
||||
};
|
||||
|
||||
template <typename Img>
|
||||
struct reduce_image_basic<any_type_get_dimensions,Img,true>
|
||||
{
|
||||
using type = gray8_image_t;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Reduce for get_num_channels (only color space matters)
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
struct any_type_get_num_channels;
|
||||
|
||||
template <typename View>
|
||||
struct reduce_view_basic<any_type_get_num_channels,View,true>
|
||||
{
|
||||
using color_space_t = typename View::color_space_t::base;
|
||||
using type = typename view_type<uint8_t,typename reduce_color_space<color_space_t>::type>::type;
|
||||
};
|
||||
|
||||
template <typename Img>
|
||||
struct reduce_image_basic<any_type_get_num_channels,Img,true>
|
||||
{
|
||||
using color_space_t = typename Img::color_space_t::base;
|
||||
using type = typename image_type<uint8_t,typename reduce_color_space<color_space_t>::type>::type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Reduce for resample_pixels (same as copy_pixels)
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Sampler, typename MapFn> struct resample_pixels_fn;
|
||||
|
||||
template <typename S, typename M, typename V, bool IsBasic>
|
||||
struct reduce_view_basic<resample_pixels_fn<S,M>, V, IsBasic> : public reduce_view_basic<copy_pixels_fn, V, IsBasic> {};
|
||||
|
||||
template <typename S, typename M, typename V1, typename V2, bool IsBasic>
|
||||
struct reduce_views_basic<resample_pixels_fn<S,M>, V1, V2, IsBasic> : public reduce_views_basic<copy_pixels_fn, V1, V2, IsBasic> {};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Reduce for copy_and_convert_pixels
|
||||
//// (the only reduction could be made when views are compatible and have the same mapping, planarity and stepness)
|
||||
////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template <typename CC> class copy_and_convert_pixels_fn;
|
||||
|
||||
// the only thing for 1D reduce is making them all mutable...
|
||||
template <typename CC, typename View, bool IsBasic>
|
||||
struct reduce_view_basic<copy_and_convert_pixels_fn<CC>, View, IsBasic>
|
||||
: public derived_view_type<View, use_default, use_default, use_default, use_default, mpl::true_> {
|
||||
};
|
||||
|
||||
// For 2D reduce, if they have the same channels and color spaces (i.e. the same pixels) then copy_and_convert is just copy.
|
||||
// In this case, reduce their common color space. In general make the first immutable and the second mutable
|
||||
template <typename CC, typename V1, typename V2, bool AreBasic>
|
||||
struct reduce_views_basic<copy_and_convert_pixels_fn<CC>, V1, V2, AreBasic>
|
||||
{
|
||||
using Same = is_same<typename V1::pixel_t, typename V2::pixel_t>;
|
||||
|
||||
using CsR = reduce_color_space<typename V1::color_space_t::base>;
|
||||
using Cs1 = typename mpl::if_<Same, typename CsR::type, typename V1::color_space_t>::type;
|
||||
using Cs2 = typename mpl::if_<Same, typename CsR::type, typename V2::color_space_t>::type;
|
||||
|
||||
using DV1 = typename derived_view_type<V1, use_default, layout<Cs1, typename V1::channel_mapping_t>, use_default, use_default, mpl::false_>::type;
|
||||
using DV2 = typename derived_view_type<V2, use_default, layout<Cs2, typename V2::channel_mapping_t>, use_default, use_default, mpl::true_ >::type;
|
||||
|
||||
using type = std::pair<const DV1*, const DV2*>;
|
||||
};
|
||||
|
||||
|
||||
//integral_image_generator
|
||||
//resize_clobber_image_fnobj
|
||||
//image_default_construct_fnobj
|
||||
//fill_converted_pixels_fn
|
||||
//std::bind(gil::detail::copy_pixels_fn(), std::placeholders::_1, dst)
|
||||
//std::bind(gil::detail::copy_pixels_fn(), src, std::placeholders::_1)
|
||||
|
||||
//std::bind(detail::copy_and_convert_pixels_fn(), std::placeholders::_1, dst)
|
||||
//std::bind(detail::copy_and_convert_pixels_fn(), src, std::placeholders::_1)
|
||||
//gil::detail::fill_pixels_fn<Value>(val)
|
||||
|
||||
//detail::copy_construct_in_place_fn<base_t>
|
||||
//detail::equal_to_fn<typename variant<Types>::base_t>
|
||||
|
||||
//detail::any_image_get_view<typename any_image<Types>::view_t>
|
||||
//detail::any_image_get_const_view<typename any_image<Types>::view_t>
|
||||
//detail::flipped_up_down_view_fn<any_image_view<ViewTypes>>
|
||||
//detail::flipped_left_right_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t>
|
||||
//detail::tranposed_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t>
|
||||
//detail::rotated90cw_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t>
|
||||
//detail::rotated90ccw_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t>
|
||||
//detail::rotated180_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t>
|
||||
//detail::subimage_view_fn<any_image_view<ViewTypes>>
|
||||
//detail::subsampled_view_fn<typename any_image_view<ViewTypes>::dynamic_step_t>
|
||||
//detail::nth_channel_view_fn<typename nth_channel_view_type<any_image_view<ViewTypes>>
|
||||
//detail::color_converted_view_fn<DstP,typename color_convert_view_type<any_image_view<ViewTypes>, DstP>::type >
|
||||
}
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#endif // defined(BOOST_GIL_REDUCE_CODE_BLOAT)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user