|
Boost-Commit : |
Subject: [Test-list] svn:boost r82769 - in trunk/boost/gil/extension/toolbox: . color_converters color_spaces image_types metafunctions
From: chhenning_at_[hidden]
Date: 2013-02-06 20:37:50
Author: chhenning
Date: 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
New Revision: 82769
URL: http://svn.boost.org/trac/boost/changeset/82769
Log:
Toolbox extension inital commit.
Added:
trunk/boost/gil/extension/toolbox/
trunk/boost/gil/extension/toolbox/color_converters/
trunk/boost/gil/extension/toolbox/color_converters.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_converters/gray_to_rgba.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_converters/rgb_to_luminance.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/
trunk/boost/gil/extension/toolbox/color_spaces.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/cmyka.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/hsl.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/hsv.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/lab.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/color_spaces/xyz.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/dynamic_images.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/image_types/
trunk/boost/gil/extension/toolbox/image_types.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/image_types/indexed_image.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/
trunk/boost/gil/extension/toolbox/metafunctions.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/channel_type.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/channel_view.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/get_pixel_type.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/gil_extensions.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/is_similar.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp (contents, props changed)
trunk/boost/gil/extension/toolbox/toolbox.hpp (contents, props changed)
Added: trunk/boost/gil/extension/toolbox/color_converters.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_converters.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,25 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file color_converters.hpp
+/// \brief Color converters for toolbox extension.
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/extension/toolbox/color_converters/gray_to_rgba.hpp>
+#include <boost/gil/extension/toolbox/color_converters/rgb_to_luminance.hpp>
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_HPP
Added: trunk/boost/gil/extension/toolbox/color_converters/gray_to_rgba.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_converters/gray_to_rgba.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,49 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_GRAY_TO_RGBA_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_GRAY_TO_RGBA_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file
+/// \brief
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/color_convert.hpp>
+
+namespace boost{ namespace gil {
+
+/// This one is missing in gil ( color_convert.hpp ).
+template <>
+struct default_color_converter_impl<gray_t,rgba_t>
+{
+ template <typename P1, typename P2>
+ void operator()(const P1& src, P2& dst) const
+ {
+ get_color(dst,red_t()) =
+ channel_convert<typename color_element_type<P2, red_t >::type>(get_color(src,gray_color_t()));
+ get_color(dst,green_t())=
+ channel_convert<typename color_element_type<P2, green_t>::type>(get_color(src,gray_color_t()));
+ get_color(dst,blue_t()) =
+ channel_convert<typename color_element_type<P2, blue_t >::type>(get_color(src,gray_color_t()));
+
+ typedef typename channel_type< P2 >::type channel_t;
+ get_color(dst,alpha_t()) = channel_traits< channel_t >::max_value();
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // #define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_GRAY_TO_RGBA_HPP
+
Added: trunk/boost/gil/extension/toolbox/color_converters/rgb_to_luminance.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_converters/rgb_to_luminance.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,43 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_RGB_TO_LUMINANCE_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_RGB_TO_LUMINANCE_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file
+/// \brief
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/color_convert.hpp>
+
+namespace boost{ namespace gil { namespace detail {
+
+/// - performance specialization double
+/// - to eliminate compiler warning 4244
+template <typename GrayChannelValue>
+struct rgb_to_luminance_fn< double, double, double, GrayChannelValue >
+{
+ GrayChannelValue operator()( const double& red
+ , const double& green
+ , const double& blue ) const
+ {
+ return channel_convert<GrayChannelValue>( red * 0.30 + green * 0.59 + blue * 0.11 );
+ }
+};
+
+} // namespace detail
+} // namespace gil
+} // namespace boost
+
+#endif // #define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_CONVERTERS_RGB_TO_LUMINANCE_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,29 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file color_spaces.hpp
+/// \brief Color spaces for toolbox extension.
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/extension/toolbox/color_spaces/cmyka.hpp>
+#include <boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp>
+#include <boost/gil/extension/toolbox/color_spaces/hsl.hpp>
+#include <boost/gil/extension/toolbox/color_spaces/hsv.hpp>
+#include <boost/gil/extension/toolbox/color_spaces/lab.hpp>
+#include <boost/gil/extension/toolbox/color_spaces/xyz.hpp>
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces/cmyka.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces/cmyka.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,87 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_CMYKA_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_CMYKA_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file cmyka.hpp
+/// \brief Support for cmyka color space.
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost\gil\rgba.hpp>
+#include <boost\gil\cmyk.hpp>
+
+#include <boost\gil\color_convert.hpp>
+#include <boost\gil\typedefs.hpp>
+
+namespace boost{ namespace gil {
+
+/// \ingroup ColorSpaceModel
+typedef mpl::vector5<cyan_t,magenta_t,yellow_t,black_t,alpha_t> cmyka_t;
+
+/// \ingroup LayoutModel
+typedef layout<cmyka_t> cmyka_layout_t;
+
+
+GIL_DEFINE_ALL_TYPEDEFS(8, cmyka)
+GIL_DEFINE_ALL_TYPEDEFS(8s, cmyka)
+GIL_DEFINE_ALL_TYPEDEFS(16, cmyka)
+GIL_DEFINE_ALL_TYPEDEFS(16s,cmyka)
+GIL_DEFINE_ALL_TYPEDEFS(32 ,cmyka)
+GIL_DEFINE_ALL_TYPEDEFS(32s,cmyka)
+GIL_DEFINE_ALL_TYPEDEFS(32f,cmyka)
+
+///// \ingroup ColorConvert
+///// \brief Converting CMYKA to any pixel type. Note: Supports homogeneous pixels only.
+//template <typename C2>
+//struct default_color_converter_impl<cmyka_t,C2> {
+// template <typename P1, typename P2>
+// void operator()(const P1& src, P2& dst) const {
+// typedef typename channel_type<P1>::type T1;
+// default_color_converter_impl<cmyk_t,C2>()(
+// pixel<T1,cmyk_layout_t>(channel_multiply(get_color(src,cyan_t()), get_color(src,alpha_t())),
+// channel_multiply(get_color(src,magenta_t()),get_color(src,alpha_t())),
+// channel_multiply(get_color(src,yellow_t()), get_color(src,alpha_t())),
+// channel_multiply(get_color(src,black_t()), get_color(src,alpha_t())))
+// ,dst);
+// }
+//};
+template <>
+struct default_color_converter_impl<cmyka_t,rgba_t> {
+ template <typename P1, typename P2>
+ void operator()(const P1& src, P2& dst) const {
+ typedef typename channel_type<P1>::type T1;
+ default_color_converter_impl<cmyk_t,rgba_t>()(
+ pixel<T1,cmyk_layout_t>(get_color(src,cyan_t()),
+ get_color(src,magenta_t()),
+ get_color(src,yellow_t()),
+ get_color(src,black_t()))
+ ,dst);
+ }
+};
+
+/// \ingroup ColorConvert
+/// \brief Unfortunately CMYKA to CMYKA must be explicitly provided - otherwise we get ambiguous specialization error.
+template <>
+struct default_color_converter_impl<cmyka_t,cmyka_t> {
+ template <typename P1, typename P2>
+ void operator()(const P1& src, P2& dst) const {
+ static_for_each(src,dst,default_channel_converter());
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_CMYKA_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,104 @@
+/*
+ Copyright 2012 Andreas Pokorny
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file gray_alpha.hpp
+/// \brief Support for gray_alpha color space.
+/// \author Andreas Pokorny \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/mpl/contains.hpp>
+
+#include <boost/gil/gil_config.hpp>
+#include <boost/gil/color_convert.hpp>
+#include <boost/gil/gray.hpp>
+#include <boost/gil/typedefs.hpp>
+
+namespace boost{ namespace gil {
+
+typedef mpl::vector2<gray_color_t,alpha_t> gray_alpha_t;
+
+typedef layout<gray_alpha_t> gray_alpha_layout_t;
+typedef layout<gray_alpha_layout_t, mpl::vector2_c<int,1,0> > alpha_gray_layout_t;
+
+GIL_DEFINE_BASE_TYPEDEFS(8, alpha_gray)
+GIL_DEFINE_BASE_TYPEDEFS(8s, alpha_gray)
+GIL_DEFINE_BASE_TYPEDEFS(16, alpha_gray)
+GIL_DEFINE_BASE_TYPEDEFS(16s,alpha_gray)
+GIL_DEFINE_BASE_TYPEDEFS(32 ,alpha_gray)
+GIL_DEFINE_BASE_TYPEDEFS(32s,alpha_gray)
+GIL_DEFINE_BASE_TYPEDEFS(32f,alpha_gray)
+
+GIL_DEFINE_ALL_TYPEDEFS(8, gray_alpha)
+GIL_DEFINE_ALL_TYPEDEFS(8s, gray_alpha)
+GIL_DEFINE_ALL_TYPEDEFS(16, gray_alpha)
+GIL_DEFINE_ALL_TYPEDEFS(16s,gray_alpha)
+GIL_DEFINE_ALL_TYPEDEFS(32 ,gray_alpha)
+GIL_DEFINE_ALL_TYPEDEFS(32s,gray_alpha)
+GIL_DEFINE_ALL_TYPEDEFS(32f,gray_alpha)
+
+/// \ingroup ColorConvert
+/// \brief Gray Alpha to RGBA
+template <>
+struct default_color_converter_impl<gray_alpha_t,rgba_t> {
+ template <typename P1, typename P2>
+ void operator()(const P1& src, P2& dst) const {
+ get_color(dst,red_t()) =
+ channel_convert<typename color_element_type<P2, red_t>::type>(get_color(src,gray_color_t()));
+ get_color(dst,green_t())=
+ channel_convert<typename color_element_type<P2, green_t>::type>(get_color(src,gray_color_t()));
+ get_color(dst,blue_t()) =
+ channel_convert<typename color_element_type<P2, blue_t>::type>(get_color(src,gray_color_t()));
+ get_color(dst,alpha_t()) =
+ channel_convert<typename color_element_type<P2, alpha_t>::type>(get_color(src,alpha_t()));
+ }
+};
+
+/// \brief Gray Alpha to RGB
+template <>
+struct default_color_converter_impl<gray_alpha_t,rgb_t> {
+ template <typename P1, typename P2>
+ void operator()(const P1& src, P2& dst) const {
+ get_color(dst,red_t()) =
+ channel_convert<typename color_element_type<P2, red_t>::type>(
+ channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
+ );
+ get_color(dst,green_t()) =
+ channel_convert<typename color_element_type<P2, green_t>::type>(
+ channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
+ );
+ get_color(dst,blue_t()) =
+ channel_convert<typename color_element_type<P2, blue_t>::type>(
+ channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
+ );
+ }
+};
+
+/// \brief Gray Alpha to Gray
+template <>
+struct default_color_converter_impl<gray_alpha_t,gray_t> {
+ template <typename P1, typename P2>
+ void operator()(const P1& src, P2& dst) const {
+ get_color(dst,gray_color_t()) =
+ channel_convert<typename color_element_type<P2, gray_color_t>::type>(
+ channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
+ );
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces/hsl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces/hsl.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,266 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSL_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSL_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file hsl.hpp
+/// \brief Support for HSL color space
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+namespace boost{ namespace gil {
+
+/// \addtogroup ColorNameModel
+/// \{
+namespace hsl_color_space
+{
+/// \brief Hue
+struct hue_t {};
+/// \brief Saturation
+struct saturation_t {};
+/// \brief Lightness
+struct lightness_t {};
+}
+/// \}
+
+/// \ingroup ColorSpaceModel
+typedef mpl::vector3< hsl_color_space::hue_t
+ , hsl_color_space::saturation_t
+ , hsl_color_space::lightness_t
+ > hsl_t;
+
+/// \ingroup LayoutModel
+typedef layout<hsl_t> hsl_layout_t;
+
+
+GIL_DEFINE_ALL_TYPEDEFS( 32f, hsl );
+
+/// \ingroup ColorConvert
+/// \brief RGB to HSL
+template <>
+struct default_color_converter_impl< rgb_t, hsl_t >
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst ) const
+ {
+ using namespace hsl_color_space;
+
+ // only bits32f for hsl is supported
+ bits32f temp_red = channel_convert<bits32f>( get_color( src, red_t() ));
+ bits32f temp_green = channel_convert<bits32f>( get_color( src, green_t() ));
+ bits32f temp_blue = channel_convert<bits32f>( get_color( src, blue_t() ));
+
+ bits32f hue, saturation, lightness;
+
+ bits32f min_color = (std::min)( temp_red, (std::min)( temp_green, temp_blue ));
+ bits32f max_color = (std::max)( temp_red, (std::max)( temp_green, temp_blue ));
+
+ if( abs( min_color - max_color ) < 0.001 )
+ {
+ // rgb color is gray
+
+ hue = 0.f;
+ saturation = 0.f;
+
+ // doesn't matter which rgb channel we use.
+ lightness = temp_red;
+ }
+ else
+ {
+
+ bits32f diff = max_color - min_color;
+
+ // lightness calculation
+
+ lightness = ( min_color + max_color ) / 2.f;
+
+ // saturation calculation
+
+ if( lightness < 0.5f )
+ {
+ saturation = diff
+ / ( min_color + max_color );
+ }
+ else
+ {
+ saturation = ( max_color - min_color )
+ / ( 2.f - diff );
+
+ }
+
+ // hue calculation
+ if( abs( max_color - temp_red ) < 0.0001f )
+ {
+ // max_color is red
+ hue = ( temp_green - temp_blue )
+ / diff;
+
+ }
+ else if( abs( max_color - temp_green) < 0.0001f )
+ {
+ // max_color is green
+ // 2.0 + (b - r) / (maxColor - minColor);
+ hue = 2.f
+ + ( temp_blue - temp_red )
+ / diff;
+
+ }
+ else
+ {
+ // max_color is blue
+ hue = 4.f
+ + ( temp_red - temp_blue )
+ / diff;
+ }
+
+ hue /= 6.f;
+
+ if( hue < 0.f )
+ {
+ hue += 1.f;
+ }
+ }
+
+ get_color( dst,hue_t() ) = hue;
+ get_color( dst,saturation_t() ) = saturation;
+ get_color( dst,lightness_t() ) = lightness;
+ }
+};
+
+/// \ingroup ColorConvert
+/// \brief HSL to RGB
+template <>
+struct default_color_converter_impl<hsl_t,rgb_t>
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst) const
+ {
+ using namespace hsl_color_space;
+
+ bits32f red, green, blue;
+
+ if( abs( get_color( src, saturation_t() )) < 0.0001 )
+ {
+ // If saturation is 0, the color is a shade of gray
+ red = get_color( src, lightness_t() );
+ green = get_color( src, lightness_t() );
+ blue = get_color( src, lightness_t() );
+ }
+ else
+ {
+ float temp1, temp2;
+ float tempr, tempg, tempb;
+
+ //Set the temporary values
+ if( get_color( src, lightness_t() ) < 0.5 )
+ {
+ temp2 = get_color( src, lightness_t() )
+ * ( 1.f + get_color( src, saturation_t() ) );
+ }
+ else
+ {
+ temp2 = ( get_color( src, lightness_t() ) + get_color( src, saturation_t() ))
+ - ( get_color( src, lightness_t() ) * get_color( src, saturation_t() ));
+ }
+
+ temp1 = 2.f
+ * get_color( src, lightness_t() )
+ - temp2;
+
+ tempr = get_color( src, hue_t() ) + 1.f / 3.f;
+
+ if( tempr > 1.f )
+ {
+ tempr--;
+ }
+
+ tempg = get_color( src, hue_t() );
+ tempb = get_color( src, hue_t() ) - 1.f / 3.f;
+
+ if( tempb < 0.f )
+ {
+ tempb++;
+ }
+
+ //Red
+ if( tempr < 1.f / 6.f )
+ {
+ red = temp1 + ( temp2 - temp1 ) * 6.f * tempr;
+ }
+ else if( tempr < 0.5f )
+ {
+ red = temp2;
+ }
+ else if( tempr < 2.f / 3.f )
+ {
+ red = temp1 + (temp2 - temp1)
+ * (( 2.f / 3.f ) - tempr) * 6.f;
+ }
+ else
+ {
+ red = temp1;
+ }
+
+ //Green
+ if( tempg < 1.f / 6.f )
+ {
+ green = temp1 + ( temp2 - temp1 ) * 6.f * tempg;
+ }
+ else if( tempg < 0.5f )
+ {
+ green = temp2;
+ }
+ else if( tempg < 2.f / 3.f )
+ {
+ green = temp1 + ( temp2 - temp1 )
+ * (( 2.f / 3.f ) - tempg) * 6.f;
+ }
+ else
+ {
+ green = temp1;
+ }
+
+ //Blue
+ if( tempb < 1.f / 6.f )
+ {
+ blue = temp1 + (temp2 - temp1) * 6.f * tempb;
+ }
+ else if( tempb < 0.5f )
+ {
+ blue = temp2;
+ }
+ else if( tempb < 2.f / 3.f )
+ {
+ blue = temp1 + (temp2 - temp1)
+ * (( 2.f / 3.f ) - tempb) * 6.f;
+ }
+ else
+ {
+ blue = temp1;
+ }
+ }
+
+ get_color(dst,red_t()) =
+ channel_convert<typename color_element_type< P2, red_t >::type>( red );
+ get_color(dst,green_t())=
+ channel_convert<typename color_element_type< P2, green_t >::type>( green );
+ get_color(dst,blue_t()) =
+ channel_convert<typename color_element_type< P2, blue_t >::type>( blue );
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSL_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces/hsv.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces/hsv.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,235 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSV_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSV_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file hsv.hpp
+/// \brief Support for HSV color space
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/cast.hpp>
+
+namespace boost{ namespace gil {
+
+/// \addtogroup ColorNameModel
+/// \{
+namespace hsv_color_space
+{
+/// \brief Hue
+struct hue_t {};
+/// \brief Saturation
+struct saturation_t{};
+/// \brief Value
+struct value_t {};
+}
+/// \}
+
+/// \ingroup ColorSpaceModel
+typedef mpl::vector3< hsv_color_space::hue_t
+ , hsv_color_space::saturation_t
+ , hsv_color_space::value_t
+ > hsv_t;
+
+/// \ingroup LayoutModel
+typedef layout<hsv_t> hsv_layout_t;
+
+GIL_DEFINE_ALL_TYPEDEFS( 32f, hsv )
+
+/// \ingroup ColorConvert
+/// \brief RGB to HSV
+template <>
+struct default_color_converter_impl< rgb_t, hsv_t >
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst ) const
+ {
+ using namespace hsv_color_space;
+
+ // only bits32f for hsv is supported
+ bits32f temp_red = channel_convert<bits32f>( get_color( src, red_t() ));
+ bits32f temp_green = channel_convert<bits32f>( get_color( src, green_t() ));
+ bits32f temp_blue = channel_convert<bits32f>( get_color( src, blue_t() ));
+
+ bits32f hue, saturation, value;
+
+ bits32f min_color = (std::min)( temp_red, (std::min)( temp_green, temp_blue ));
+ bits32f max_color = (std::max)( temp_red, (std::max)( temp_green, temp_blue ));
+
+ value = max_color;
+
+ bits32f diff = max_color - min_color;
+
+ if( max_color < 0.0001f )
+ {
+ saturation = 0.f;
+ }
+ else
+ {
+ saturation = diff / max_color;
+ }
+
+
+ if( saturation < 0.0001f )
+ {
+ //it doesn't matter what value it has
+ hue = 0.f;
+ }
+ else
+ {
+ if( (std::abs)( boost::numeric_cast<int>(temp_red - max_color) ) < 0.0001f )
+ {
+ hue = ( temp_green - temp_blue )
+ / diff;
+ }
+ else if( temp_green == max_color )
+ {
+ hue = 2.f + ( temp_blue - temp_red )
+ / diff;
+ }
+ else
+ {
+ hue = 4.f + ( temp_red - temp_green )
+ / diff;
+ }
+
+ //to bring it to a number between 0 and 1
+ hue /= 6.f;
+
+ if( hue < 0.f )
+ {
+ hue++;
+ }
+ }
+
+ get_color( dst, hue_t() ) = hue;
+ get_color( dst, saturation_t() ) = saturation;
+ get_color( dst, value_t() ) = value;
+ }
+};
+
+/// \ingroup ColorConvert
+/// \brief HSV to RGB
+template <>
+struct default_color_converter_impl<hsv_t,rgb_t>
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst) const
+ {
+ using namespace hsv_color_space;
+
+ bits32f red, green, blue;
+
+ //If saturation is 0, the color is a shade of gray
+ if( abs( get_color( src, saturation_t() )) < 0.0001f )
+ {
+ // If saturation is 0, the color is a shade of gray
+ red = get_color( src, value_t() );
+ green = get_color( src, value_t() );
+ blue = get_color( src, value_t() );
+ }
+ else
+ {
+ bits32f frac, p, q, t, h;
+ bits32 i;
+
+ //to bring hue to a number between 0 and 6, better for the calculations
+ h = get_color( src, hue_t() );
+ h *= 6.f;
+
+ i = static_cast<bits32>( floor( h ));
+
+ frac = h - i;
+
+ p = get_color( src, value_t() )
+ * ( 1.f - get_color( src, saturation_t() ));
+
+ q = get_color( src, value_t() )
+ * ( 1.f - ( get_color( src, saturation_t() ) * frac ));
+
+ t = get_color( src, value_t() )
+ * ( 1.f - ( get_color( src, saturation_t() ) * ( 1.f - frac )));
+
+ switch( i )
+ {
+ case 0:
+ {
+ red = get_color( src, value_t() );
+ green = t;
+ blue = p;
+
+ break;
+ }
+
+ case 1:
+ {
+ red = q;
+ green = get_color( src, value_t() );
+ blue = p;
+
+ break;
+ }
+
+ case 2:
+ {
+ red = p;
+ green = get_color( src, value_t() );
+ blue = t;
+
+ break;
+ }
+
+ case 3:
+ {
+ red = p;
+ green = q;
+ blue = get_color( src, value_t() );
+
+ break;
+ }
+
+ case 4:
+ {
+ red = t;
+ green = p;
+ blue = get_color( src, value_t() );
+
+ break;
+ }
+
+ case 5:
+ {
+ red = get_color( src, value_t() );
+ green = p;
+ blue = q;
+
+ break;
+ }
+
+ }
+ }
+
+ get_color(dst,red_t()) =
+ channel_convert<typename color_element_type< P2, red_t >::type>( red );
+ get_color(dst,green_t())=
+ channel_convert<typename color_element_type< P2, green_t >::type>( green );
+ get_color(dst,blue_t()) =
+ channel_convert<typename color_element_type< P2, blue_t >::type>( blue );
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_HSV_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces/lab.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces/lab.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,179 @@
+/*
+ Copyright 2012 Chung-Lin Wen
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_LAB_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_LAB_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file lab.hpp
+/// \brief Support for CIE Lab color space
+/// \author Chung-Lin Wen \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/cast.hpp>
+#include <boost/gil/gil_all.hpp>
+#include <boost/gil/extension/toolbox/color_spaces/xyz.hpp>
+
+namespace boost{ namespace gil {
+
+/// \addtogroup ColorNameModel
+/// \{
+namespace lab_color_space
+{
+/// \brief Luminance
+struct luminance_t {};
+/// \brief a Color Component
+struct a_color_opponent_t {};
+/// \brief b Color Component
+struct b_color_opponent_t {};
+}
+/// \}
+
+/// \ingroup ColorSpaceModel
+typedef mpl::vector3< lab_color_space::luminance_t
+ , lab_color_space::a_color_opponent_t
+ , lab_color_space::b_color_opponent_t
+ > lab_t;
+
+/// \ingroup LayoutModel
+typedef layout<lab_t> lab_layout_t;
+
+GIL_DEFINE_ALL_TYPEDEFS( 32f, lab );
+
+/// \ingroup ColorConvert
+/// \brief LAB to XYZ
+template <>
+struct default_color_converter_impl< lab_t, xyz_t >
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst ) const
+ {
+ using namespace lab_color_space;
+ using namespace xyz_color_space;
+
+ bits32f p = ((get_color(src, luminance_t()) + 16.f)/116.f);
+
+ get_color(dst, y_t()) =
+ 1.f * powf(p, 3.f);
+
+ get_color(dst, x_t()) =
+ 0.95047f * powf((p +
+ (get_color(src, a_color_opponent_t())/500.f)
+ ), 3.f);
+ get_color(dst, z_t()) =
+ 1.08883f * powf((p -
+ (get_color(src, b_color_opponent_t())/200.f)
+ ), 3.f);
+ }
+};
+
+/// \ingroup ColorConvert
+/// \brief XYZ to LAB
+/// \note I assume \c xyz_t
+template <>
+struct default_color_converter_impl< xyz_t, lab_t >
+{
+private:
+ /// \ref http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
+ GIL_FORCEINLINE
+ bits32f forward_companding(bits32f value) const
+ {
+ if (value > 216.f/24389.f)
+ {
+ return powf(value, 1.f/3.f);
+ }
+ else
+ {
+ return ((24389.f/27.f * value + 16.f)/116.f);
+ }
+ }
+
+public:
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst ) const
+ {
+ using namespace lab_color_space;
+
+ bits32f f_y =
+ forward_companding(
+ channel_convert<bits32f>(
+ get_color(src, xyz_color_space::y_t())
+ )
+ // / 1.f
+ );
+
+ bits32f f_x =
+ forward_companding(
+ channel_convert<bits32f>(
+ get_color(src, xyz_color_space::x_t())
+ )
+ * (1.f / 0.95047f) // if the compiler is smart, it should
+ // precalculate this, no?
+ );
+
+ bits32f f_z =
+ forward_companding(
+ channel_convert<bits32f>(
+ get_color(src, xyz_color_space::z_t())
+ )
+ * (1.f / 1.08883f) // if the compiler is smart, it should
+ // precalculate this, no?
+ );
+
+ get_color(dst, luminance_t()) =
+ 116.f * f_y - 16.f;
+
+ get_color(dst, a_color_opponent_t()) =
+ 500.f * (f_x - f_y);
+
+ get_color(dst, b_color_opponent_t()) =
+ 200.f * (f_y - f_z);
+ }
+};
+
+
+/// \ingroup ColorConvert
+/// \brief RGB to LAB
+template <>
+struct default_color_converter_impl< rgb_t, lab_t >
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst ) const
+ {
+ using namespace lab_color_space;
+
+ xyz32f_pixel_t xyz32f_temp_pixel;
+ default_color_converter_impl<rgb_t, xyz_t>()(src, xyz32f_temp_pixel);
+ default_color_converter_impl<xyz_t, lab_t>()(xyz32f_temp_pixel, dst);
+ }
+};
+
+/// \ingroup ColorConvert
+/// \brief LAB to RGB
+template <>
+struct default_color_converter_impl<lab_t,rgb_t>
+{
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst) const
+ {
+ using namespace lab_color_space;
+
+ xyz32f_pixel_t xyz32f_temp_pixel;
+ default_color_converter_impl<lab_t, xyz_t>()(src, xyz32f_temp_pixel);
+ default_color_converter_impl<xyz_t, rgb_t>()(xyz32f_temp_pixel, dst);
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_LAB_HPP
Added: trunk/boost/gil/extension/toolbox/color_spaces/xyz.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/color_spaces/xyz.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,163 @@
+/*
+ Copyright 2012 Chung-Lin Wen, Davide Anastasia
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_XYZ_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_XYZ_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file xyz.hpp
+/// \brief Support for CIE XYZ color space
+/// \author Chung-Lin Wen, Davide Anastasia \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/cast.hpp>
+
+namespace boost{ namespace gil {
+
+/// \addtogroup ColorNameModel
+/// \{
+namespace xyz_color_space
+{
+/// \brief x Color Component
+struct x_t {};
+/// \brief y Color Component
+struct y_t {};
+/// \brief z Color Component
+struct z_t {};
+}
+/// \}
+
+/// \ingroup ColorSpaceModel
+typedef mpl::vector3< xyz_color_space::x_t
+ , xyz_color_space::y_t
+ , xyz_color_space::z_t
+ > xyz_t;
+
+/// \ingroup LayoutModel
+typedef layout<xyz_t> xyz_layout_t;
+
+GIL_DEFINE_ALL_TYPEDEFS( 32f, xyz );
+
+/// \ingroup ColorConvert
+/// \brief RGB to XYZ
+/// Link
+/// \note rgb_t is assumed to be sRGB D65
+template <>
+struct default_color_converter_impl< rgb_t, xyz_t >
+{
+private:
+ GIL_FORCEINLINE
+ bits32f inverse_companding(bits32f sample) const
+ {
+ if ( sample > 0.04045f )
+ {
+ return powf((( sample + 0.055f ) / 1.055f ), 2.4f);
+ }
+ else
+ {
+ return ( sample / 12.92f );
+ }
+ }
+
+public:
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst ) const
+ {
+ using namespace xyz_color_space;
+
+ bits32f red(
+ inverse_companding(
+ channel_convert<bits32f>( get_color( src, red_t() ))
+ )
+ );
+ bits32f green(
+ inverse_companding(
+ channel_convert<bits32f>( get_color( src, green_t() ))
+ )
+ );
+ bits32f blue(
+ inverse_companding(
+ channel_convert<bits32f>( get_color( src, blue_t() ))
+ )
+ );
+
+ get_color( dst, x_t() ) =
+ red * 0.4124564f +
+ green * 0.3575761f +
+ blue * 0.1804375f;
+ get_color( dst, y_t() ) =
+ red * 0.2126729f +
+ green * 0.7151522f +
+ blue * 0.0721750f;
+ get_color( dst, z_t() ) =
+ red * 0.0193339f +
+ green * 0.1191920f +
+ blue * 0.9503041f;
+ }
+};
+
+/// \ingroup ColorConvert
+/// \brief XYZ to RGB
+template <>
+struct default_color_converter_impl<xyz_t,rgb_t>
+{
+private:
+ GIL_FORCEINLINE
+ bits32f companding(bits32f sample) const
+ {
+ if ( sample > 0.0031308f )
+ {
+ return ( 1.055f * powf( sample, 1.f/2.4f ) - 0.055f );
+ }
+ else
+ {
+ return ( 12.92f * sample );
+ }
+ }
+
+public:
+ template <typename P1, typename P2>
+ void operator()( const P1& src, P2& dst) const
+ {
+ using namespace xyz_color_space;
+
+ // Note: ideally channel_convert should be compiled out, because xyz_t
+ // is bits32f natively only
+ bits32f x( channel_convert<bits32f>( get_color( src, x_t() ) ) );
+ bits32f y( channel_convert<bits32f>( get_color( src, y_t() ) ) );
+ bits32f z( channel_convert<bits32f>( get_color( src, z_t() ) ) );
+
+ get_color(dst,red_t()) =
+ channel_convert<typename color_element_type<P2, red_t>::type>(
+ companding( x * 3.2404542f +
+ y * -1.5371385f +
+ z * -0.4985314f )
+ );
+ get_color(dst,green_t()) =
+ channel_convert<typename color_element_type<P2, green_t>::type>(
+ companding( x * -0.9692660f +
+ y * 1.8760108f +
+ z * 0.0415560f )
+ );
+ get_color(dst,blue_t()) =
+ channel_convert<typename color_element_type<P2, blue_t>::type>(
+ companding( x * 0.0556434f +
+ y * -0.2040259f +
+ z * 1.0572252f )
+ );
+ }
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_XYZ_HPP
Added: trunk/boost/gil/extension/toolbox/dynamic_images.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/dynamic_images.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,126 @@
+/*
+ Copyright 2005-2007 Adobe Systems Incorporated
+
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+
+ See http://opensource.adobe.com/gil for most recent version including documentation.
+*/
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_DYNAMIC_IMAGES_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_DYNAMIC_IMAGES_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file dynamic_images.hpp
+/// \brief Generic io functions for dealing with dynamic images.
+/// \author Hailin Jin, Lubomir Bourdev, and Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/gil/gil_config.hpp>
+#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
+
+namespace boost { namespace gil {
+
+// need this for various meta functions.
+struct any_image_pixel_t {};
+struct any_image_channel_t {};
+struct any_image_color_space_t {};
+
+namespace detail {
+
+template <long N>
+struct construct_matched_t {
+ template <typename Images,typename Pred>
+ static bool apply(any_image<Images>& im,Pred pred) {
+ if (pred.template apply<typename mpl::at_c<Images,N-1>::type>()) {
+ typename mpl::at_c<Images,N-1>::type x;
+ im.move_in(x);
+ return true;
+ } else return construct_matched_t<N-1>::apply(im,pred);
+ }
+};
+template <>
+struct construct_matched_t<0> {
+ template <typename Images,typename Pred>
+ static bool apply(any_image<Images>&,Pred) {return false;}
+};
+
+// A function object that can be passed to apply_operation.
+// Given a predicate IsSupported taking a view type and returning an MPL boolean,
+// calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
+template <typename IsSupported, typename OpClass>
+class dynamic_io_fnobj {
+ OpClass* _op;
+
+ template <typename View>
+ void apply(const View& view,mpl::true_ ) {_op->apply(view);}
+
+ template <typename View, typename Info >
+ void apply( const View& view
+ , const Info& info
+ , const mpl::true_
+ )
+ {
+ _op->apply( view, info );
+ }
+
+ template <typename View>
+ void apply(const View& /* view */ ,mpl::false_)
+ {
+ throw std::ios_base::failure( "dynamic_io: unsupported view type for the given file format" );
+ }
+
+ template <typename View, typename Info >
+ void apply( const View& /* view */
+ , const Info& /* info */
+ , const mpl::false_
+ )
+ {
+ throw std::ios_base::failure( "dynamic_io: unsupported view type for the given file format" );
+ }
+
+public:
+ dynamic_io_fnobj(OpClass* op) : _op(op) {}
+
+ typedef void result_type;
+
+ template <typename View>
+ void operator()(const View& view) {apply(view,typename IsSupported::template apply<View>::type());}
+
+ template< typename View, typename Info >
+ void operator()(const View& view, const Info& info )
+ {
+ apply( view
+ , info
+ , typename IsSupported::template apply< View >::type()
+ );
+ }
+
+};
+
+} // namespace detail
+
+/// \brief Within the any_image, constructs an image with the given dimensions
+/// and a type that satisfies the given predicate
+template <typename Images,typename Pred>
+inline bool construct_matched(any_image<Images>& im,Pred pred) {
+ return detail::construct_matched_t<mpl::size<Images>::value>::apply(im,pred);
+}
+
+template<>
+struct color_space_type< any_image_pixel_t >
+{
+ typedef any_image_color_space_t type;
+};
+
+
+} } // namespace boost::gil
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_DYNAMIC_IMAGES_HPP
Added: trunk/boost/gil/extension/toolbox/image_types.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/image_types.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,24 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IMAGE_TYPES_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IMAGE_TYPES_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file image_types.hpp
+/// \brief Image Types for toolbox extension.
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/extension/toolbox/image_types/indexed_image.hpp>
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IMAGE_TYPES_HPP
Added: trunk/boost/gil/extension/toolbox/image_types/indexed_image.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/image_types/indexed_image.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,364 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_IMAGE_TYPES_INDEXED_IMAGE_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_IMAGE_TYPES_INDEXED_IMAGE_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file indexed_image.hpp
+/// \brief Indexed Image extension
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/utility/enable_if.hpp>
+
+#include <boost/gil/image.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp>
+
+
+namespace boost{ namespace gil {
+
+typedef boost::gil::point2< std::ptrdiff_t > point_t;
+
+template< typename Locator >
+struct get_pixel_type_locator : mpl::if_< typename is_bit_aligned< typename Locator::value_type >::type
+ , typename Locator::reference
+ , typename Locator::value_type
+ > {};
+
+// used for virtual locator
+template< typename IndicesLoc
+ , typename PaletteLoc
+ >
+struct indexed_image_deref_fn_base
+{
+ typedef IndicesLoc indices_locator_t;
+ typedef PaletteLoc palette_locator_t;
+ //typedef typename get_pixel_type_locator< indices_locator_t >::type index_t;
+
+ typedef indexed_image_deref_fn_base const_t;
+ typedef typename PaletteLoc::value_type value_type;
+ typedef value_type reference;
+ typedef value_type const_reference;
+ typedef point_t argument_type;
+ typedef reference result_type;
+
+ static const bool is_mutable = false;
+
+ indexed_image_deref_fn_base() {}
+
+ indexed_image_deref_fn_base( const indices_locator_t& indices_loc
+ , const palette_locator_t& palette_loc
+ )
+ : _indices_loc( indices_loc )
+ , _palette_loc( palette_loc )
+ {}
+
+ void set_indices( const indices_locator_t& indices_loc ) { _indices_loc = indices_loc; }
+ void set_palette( const palette_locator_t& palette_loc ) { _palette_loc = palette_loc; }
+
+ const indices_locator_t& indices() const { return _indices_loc; }
+ const palette_locator_t& palette() const { return _palette_loc; }
+
+protected:
+
+ indices_locator_t _indices_loc;
+ palette_locator_t _palette_loc;
+};
+
+
+// used for virtual locator
+template< typename IndicesLoc
+ , typename PaletteLoc
+ , typename Enable = void // there is specilization for integral indices
+ >
+struct indexed_image_deref_fn : indexed_image_deref_fn_base< IndicesLoc
+ , PaletteLoc
+ >
+{
+ typedef indexed_image_deref_fn_base< IndicesLoc
+ , PaletteLoc
+ > base_t;
+
+
+ indexed_image_deref_fn()
+ : base_t()
+ {}
+
+ indexed_image_deref_fn( const typename base_t::indices_locator_t& indices_loc
+ , const typename base_t::palette_locator_t& palette_loc
+ )
+ : base_t( indices_loc
+ , palette_loc
+ )
+ {}
+
+ typename base_t::result_type operator()( const point_t& p ) const
+ {
+ return * this->_palette_loc.xy_at( at_c<0>( *this->_indices_loc.xy_at( p )), 0 );
+ }
+};
+
+
+template< typename IndicesLoc
+ , typename PaletteLoc
+ >
+struct indexed_image_deref_fn< IndicesLoc
+ , PaletteLoc
+ , typename boost::enable_if< boost::is_integral< typename IndicesLoc::value_type > >::type
+ > : indexed_image_deref_fn_base< IndicesLoc
+ , PaletteLoc
+ >
+{
+ typedef indexed_image_deref_fn_base< IndicesLoc
+ , PaletteLoc
+ > base_t;
+
+ indexed_image_deref_fn()
+ : base_t()
+ {}
+
+ indexed_image_deref_fn( const typename base_t::indices_locator_t& indices_loc
+ , const typename base_t::palette_locator_t& palette_loc
+ )
+ : base_t( indices_loc
+ , palette_loc
+ )
+ {}
+
+ typename base_t::result_type operator()( const point_t& p ) const
+ {
+ return *this->_palette_loc.xy_at( *this->_indices_loc.xy_at( p ), 0 );
+ }
+};
+
+template< typename IndicesLoc
+ , typename PaletteLoc
+ >
+struct indexed_image_locator_type
+{
+ typedef virtual_2d_locator< indexed_image_deref_fn< IndicesLoc
+ , PaletteLoc
+ >
+ , false
+ > type;
+};
+
+template< typename Locator > // indexed_image_locator_type< ... >::type
+class indexed_image_view : public image_view< Locator >
+{
+public:
+
+ typedef typename Locator::deref_fn_t deref_fn_t;
+ typedef typename deref_fn_t::indices_locator_t indices_locator_t;
+ typedef typename deref_fn_t::palette_locator_t palette_locator_t;
+
+ typedef indexed_image_view< Locator > const_t;
+
+ typedef image_view< indices_locator_t > indices_view_t;
+ typedef image_view< palette_locator_t > palette_view_t;
+
+ indexed_image_view()
+ : image_view< Locator >()
+ , _num_colors( 0 )
+ {}
+
+ indexed_image_view( const point_t& dimensions
+ , std::size_t num_colors
+ , const Locator& locator
+ )
+ : image_view< Locator >( dimensions, locator )
+ , _num_colors( num_colors )
+ {}
+
+ template< typename IndexedView >
+ indexed_image_view( const IndexedView& iv )
+ : image_view< Locator >( iv )
+ , _num_colors( iv._num_colors )
+ {}
+
+ const std::size_t num_colors() const { return _num_colors; }
+
+
+ const indices_locator_t& indices() const { return get_deref_fn().indices(); }
+ const palette_locator_t& palette() const { return get_deref_fn().palette(); }
+
+ const indices_view_t get_indices_view() const { return indices_view_t( this->dimensions(), indices() ); }
+ const palette_view_t get_palette_view() const { return palette_view_t( point_t( num_colors(), 1 )
+ , palette()
+ ); }
+
+private:
+
+ const deref_fn_t& get_deref_fn() const { return this->pixels().deref_fn(); }
+
+private:
+
+ template< typename Locator2 > friend class indexed_image_view;
+
+ std::size_t _num_colors;
+};
+
+
+template< typename Index
+ , typename Pixel
+ , typename IndicesAllocator = std::allocator< unsigned char >
+ , typename PalleteAllocator = std::allocator< unsigned char >
+ >
+class indexed_image
+{
+public:
+
+ typedef image< Index, false, IndicesAllocator > indices_t;
+ typedef image< Pixel, false, PalleteAllocator > palette_t;
+
+ typedef typename indices_t::view_t indices_view_t;
+ typedef typename palette_t::view_t palette_view_t;
+
+ typedef typename indices_t::const_view_t indices_const_view_t;
+ typedef typename palette_t::const_view_t palette_const_view_t;
+
+ typedef typename indices_view_t::locator indices_locator_t;
+ typedef typename palette_view_t::locator palette_locator_t;
+
+ typedef typename indexed_image_locator_type< indices_locator_t
+ , palette_locator_t
+ >::type locator_t;
+
+ typedef typename indices_t::coord_t x_coord_t;
+ typedef typename indices_t::coord_t y_coord_t;
+
+
+ typedef indexed_image_view< locator_t > view_t;
+ typedef typename view_t::const_t const_view_t;
+
+ indexed_image( const x_coord_t width = 0
+ , const y_coord_t height = 0
+ , const std::size_t num_colors = 1
+ , const std::size_t indices_alignment = 0
+ , const std::size_t palette_alignment = 0
+ )
+ : _indices( width , height, indices_alignment, IndicesAllocator() )
+ , _palette( num_colors, 1, palette_alignment, PalleteAllocator() )
+ {
+ init( point_t( width, height ), num_colors );
+ }
+
+ indexed_image( const point_t& dimensions
+ , const std::size_t num_colors = 1
+ , const std::size_t indices_alignment = 0
+ , const std::size_t palette_alignment = 0
+ )
+ : _indices( dimensions, indices_alignment, IndicesAllocator() )
+ , _palette( num_colors, 1, palette_alignment, PalleteAllocator() )
+ {
+ init( dimensions, num_colors );
+ }
+
+ indexed_image( const indexed_image& img )
+ : _indices( img._indices )
+ , _palette( img._palette )
+ {}
+
+ template <typename Pixel2, typename Index2>
+ indexed_image( const indexed_image< Pixel2, Index2 >& img )
+ {
+ _indices = img._indices;
+ _palette = img._palette;
+ }
+
+ indexed_image& operator= ( const indexed_image& img )
+ {
+ _indices = img._indices;
+ _palette = img._palette;
+
+ return *this;
+ }
+
+ indices_const_view_t get_indices_const_view() const { return static_cast< indices_const_view_t >( _view.get_indices_view()); }
+ palette_const_view_t get_palette_const_view() const { return static_cast< palette_const_view_t >( _view.get_palette_view()); }
+
+ indices_view_t get_indices_view() { return _view.get_indices_view(); }
+ palette_view_t get_palette_view() { return _view.get_palette_view(); }
+
+public:
+
+ view_t _view;
+
+private:
+
+ void init( const point_t& dimensions
+ , const std::size_t num_colors
+ )
+ {
+ typedef indexed_image_deref_fn< indices_locator_t
+ , palette_locator_t
+ > defer_fn_t;
+
+ defer_fn_t deref_fn( view( _indices ).xy_at( 0, 0 )
+ , view( _palette ).xy_at( 0, 0 )
+ );
+
+ locator_t locator( point_t( 0, 0 )
+ , point_t( 1, 1 )
+ , deref_fn
+ );
+
+ _view = view_t( dimensions
+ , num_colors
+ , locator
+ );
+ }
+
+private:
+
+ indices_t _indices;
+ palette_t _palette;
+};
+
+template< typename Index
+ , typename Pixel
+ >
+inline
+const typename indexed_image< Index, Pixel >::view_t& view( indexed_image< Index, Pixel >& img )
+{
+ return img._view;
+}
+
+template< typename Index
+ , typename Pixel
+ >
+inline
+const typename indexed_image< Index, Pixel >::const_view_t const_view( indexed_image< Index, Pixel >& img )
+{
+ return static_cast< const typename indexed_image< Index, Pixel >::const_view_t>( img._view );
+}
+
+// Whole image has one color and all indices are set to 0.
+template< typename Locator
+ , typename Value
+ >
+void fill_pixels( const indexed_image_view< Locator >& view
+ , const Value& value
+ )
+{
+ typedef indexed_image_view< Locator > view_t;
+
+ fill_pixels( view.get_indices_view(), typename view_t::indices_view_t::value_type( 0 ));
+ *view.get_palette_view().begin() = value;
+}
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_IMAGE_TYPES_INDEXED_IMAGE_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,31 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file metafunctions.hpp
+/// \brief Header for toolbox's metafunctions.
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/extension/toolbox/metafunctions/channel_type.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/channel_view.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/get_pixel_type.hpp>
+#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/is_similar.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp>
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/channel_type.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/channel_type.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,111 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_CHANNEL_TYPE_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_CHANNEL_TYPE_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file channel_type.hpp
+/// \brief channel_type metafunction.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/utility/enable_if.hpp>
+
+#include <boost/mpl/at.hpp>
+
+#include <boost/gil/bit_aligned_pixel_reference.hpp>
+#include <boost/gil/channel.hpp>
+
+#include <boost/gil/extension/toolbox/dynamic_images.hpp>
+
+#include <boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp>
+
+namespace boost{ namespace gil {
+
+/// channel_type metafunction
+/// \brief Generates the channel type for
+
+template <typename B, typename C, typename L, bool M>
+struct gen_chan_ref
+{
+ typedef packed_dynamic_channel_reference< B
+ , mpl::at_c< C, 0 >::type::value
+ , M
+ > type;
+};
+
+//! This implementation works for bit_algined_pixel_reference
+//! with a homogeneous channel layout.
+//! The result type will be a packed_dynamic_channel_reference, since the
+//! offset info will be missing.
+
+// bit_aligned_pixel_reference
+template <typename B, typename C, typename L, bool M>
+struct channel_type< bit_aligned_pixel_reference<B,C,L,M> >
+ : lazy_enable_if< is_homogeneous< bit_aligned_pixel_reference< B, C, L, M > >
+ , gen_chan_ref< B, C, L, M >
+ > {};
+
+template <typename B, typename C, typename L, bool M>
+struct channel_type<const bit_aligned_pixel_reference<B,C,L,M> >
+ : lazy_enable_if< is_homogeneous< bit_aligned_pixel_reference< B, C, L, M > >
+ , gen_chan_ref< B, C, L, M >
+ > {};
+
+template <typename B, typename C, typename L>
+struct gen_chan_ref_p
+{
+ typedef packed_dynamic_channel_reference< B
+ , get_num_bits< typename mpl::at_c<C,0>::type>::value
+ , true
+ > type;
+};
+
+// packed_pixel
+template < typename BitField
+ , typename ChannelRefVec
+ , typename Layout
+ >
+struct channel_type< packed_pixel< BitField
+ , ChannelRefVec
+ , Layout
+ >
+ > : lazy_enable_if< is_homogeneous< packed_pixel< BitField
+ , ChannelRefVec
+ , Layout
+ >
+ >
+ , gen_chan_ref_p< BitField
+ , ChannelRefVec
+ , Layout
+ >
+ > {};
+
+template <typename B, typename C, typename L>
+struct channel_type< const packed_pixel< B, C, L > >
+ : lazy_enable_if< is_homogeneous<packed_pixel< B, C, L > >
+ , gen_chan_ref_p< B, C, L >
+ >
+{};
+
+template<>
+struct channel_type< any_image_pixel_t >
+{
+ typedef any_image_channel_t type;
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_CHANNEL_TYPE_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/channel_view.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/channel_view.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,79 @@
+/*
+ Copyright 2010 Fabien Castan, Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP_INCLUDED
+#define BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP_INCLUDED
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file channel_view.hpp
+/// \brief Helper to generate channel_view type.
+/// \author Fabien Castan, Christian Henning \n
+///
+/// \date 2010 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/gil_all.hpp>
+
+namespace boost {
+namespace gil {
+
+template < typename Channel
+ , typename View
+ >
+struct channel_type_to_index
+{
+ static const int value = gil::detail::type_to_index< typename color_space_type< View >::type // color (mpl::vector)
+ , Channel // channel type
+ >::type::value; //< index of the channel in the color (mpl::vector)
+};
+
+template< typename Channel
+ , typename View
+ >
+struct channel_view_type : public kth_channel_view_type< channel_type_to_index< Channel
+ , View
+ >::value
+ , View
+ >
+{
+ static const int index = channel_type_to_index< Channel
+ , View
+ >::value;
+
+ typedef kth_channel_view_type< index
+ , View
+ > parent_t;
+
+ typedef typename parent_t::type type;
+
+
+ static type make( const View& src )
+ {
+ return parent_t::make( src );
+ }
+};
+
+/// \ingroup ImageViewTransformationsKthChannel
+template< typename Channel
+ , typename View
+ >
+typename channel_view_type< Channel
+ , View
+ >::type channel_view( const View& src )
+{
+ return channel_view_type< Channel
+ , View
+ >::make( src );
+}
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP_INCLUDED
Added: trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,60 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file get_num_bits.hpp
+/// \brief get_num_bits metafunction.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/channel.hpp>
+
+namespace boost{ namespace gil {
+
+/// get_num_bits metafunctions
+/// \brief Determines the numbers of bits for the given channel type.
+
+template <typename T>
+struct get_num_bits;
+
+template< typename B, int I, int S, bool M >
+struct get_num_bits< packed_channel_reference< B, I, S, M > >
+{
+ BOOST_STATIC_CONSTANT( int, value = S );
+};
+
+template<typename B,int I, int S, bool M>
+struct get_num_bits< const packed_channel_reference< B, I, S, M > >
+{
+ BOOST_STATIC_CONSTANT( int, value = S );
+};
+
+template<typename B, int I, bool M>
+struct get_num_bits< packed_dynamic_channel_reference< B, I, M > >
+{
+ BOOST_STATIC_CONSTANT( int, value = I );
+};
+
+template<typename b, int i, bool m>
+struct get_num_bits< const packed_dynamic_channel_reference< b, i, m > >
+{
+ BOOST_STATIC_CONSTANT( int, value = i );
+};
+
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/get_pixel_type.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/get_pixel_type.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,46 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_PIXEL_TYPE_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_PIXEL_TYPE_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file get_pixel_type.hpp
+/// \brief get_pixel_type metafunction.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/extension/toolbox/dynamic_images.hpp>
+#include <boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp>
+
+namespace boost{ namespace gil {
+
+/// get_pixel_type metafunction
+/// \brief Depending on Image this function generates either
+/// the pixel type or the reference type in case
+/// the image is bit_aligned.
+template< typename View >
+struct get_pixel_type : mpl::if_< typename is_bit_aligned< typename View::value_type >::type
+ , typename View::reference
+ , typename View::value_type
+ > {};
+
+template< typename ImageViewTypes >
+struct get_pixel_type< any_image_view< ImageViewTypes > >
+{
+ typedef any_image_pixel_t type;
+};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_PIXEL_TYPE_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/gil_extensions.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/gil_extensions.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,42 @@
+/*
+ Copyright 2010 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_GIL_EXTENSIONS_HPP_INCLUDED
+#define BOOST_GIL_EXTENSION_TOOLBOX_GIL_EXTENSIONS_HPP_INCLUDED
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file
+/// \brief Definitions of is_bit_aligned, is_homogeneous, and is_similar metafunctions and
+/// some other goodies.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2008 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/gil_all.hpp>
+
+
+#include <boost/mpl/if.hpp>
+
+#include <boost/gil/extension/toolbox/dynamic_images.hpp>
+
+namespace boost { namespace gil {
+
+
+/// other goodies
+
+
+
+
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_GIL_EXTENSIONS_HPP_INCLUDED
Added: trunk/boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,47 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_BIT_ALIGNED_TYPE_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_BIT_ALIGNED_TYPE_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file is_bit_aligned.hpp
+/// \brief is_bit_aligned metafunction.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/bit_aligned_pixel_reference.hpp>
+
+namespace boost{ namespace gil {
+
+/// is_bit_aligned metafunctions
+/// \brief Determines whether the given type is bit_aligned.
+
+template< typename PixelRef >
+struct is_bit_aligned : mpl::false_{};
+
+template <typename B, typename C, typename L, bool M>
+struct is_bit_aligned<bit_aligned_pixel_reference<B,C,L,M> > : mpl::true_{};
+
+template <typename B, typename C, typename L, bool M>
+struct is_bit_aligned<const bit_aligned_pixel_reference<B,C,L,M> > : mpl::true_{};
+
+template <typename B, typename C, typename L>
+struct is_bit_aligned<packed_pixel<B,C,L> > : mpl::true_{};
+
+template <typename B, typename C, typename L>
+struct is_bit_aligned<const packed_pixel<B,C,L> > : mpl::true_{};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_BIT_ALIGNED_TYPE_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,93 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_HOMOGENEOUS_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_HOMOGENEOUS_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file is_homogeneous.hpp
+/// \brief is_homogeneous metafunction
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/mpl/at.hpp>
+
+#include <boost/gil/pixel.hpp>
+
+
+namespace boost{ namespace gil {
+
+/// is_homogeneous metafunctions
+/// \brief Determines if a pixel types are homogeneous.
+
+template<typename C,typename CMP, int Next, int Last> struct is_homogeneous_impl;
+
+template<typename C,typename CMP, int Last>
+struct is_homogeneous_impl<C,CMP,Last,Last> : mpl::true_{};
+
+template<typename C,typename CMP, int Next, int Last>
+struct is_homogeneous_impl : mpl::and_< is_homogeneous_impl< C, CMP,Next + 1, Last >
+ , is_same< CMP, typename mpl::at_c<C,Next>::type
+ > > {};
+
+template < typename P > struct is_homogeneous : mpl::false_ {};
+
+// pixel
+template < typename C, typename L > struct is_homogeneous< pixel<C,L> > : mpl::true_ {};
+template < typename C, typename L > struct is_homogeneous<const pixel<C,L> > : mpl::true_ {};
+template < typename C, typename L > struct is_homogeneous< pixel<C,L>& > : mpl::true_ {};
+template < typename C, typename L > struct is_homogeneous<const pixel<C,L>& > : mpl::true_ {};
+
+// planar pixel reference
+template <typename Channel, typename ColorSpace>
+struct is_homogeneous< planar_pixel_reference< Channel, ColorSpace > > : mpl::true_ {};
+template <typename Channel, typename ColorSpace>
+struct is_homogeneous< const planar_pixel_reference< Channel, ColorSpace > > : mpl::true_ {};
+
+template<typename C,typename CMP, int I,int Last>
+struct is_homogeneous_impl_p {};
+
+// for packed_pixel
+template <typename B, typename C, typename L >
+struct is_homogeneous<packed_pixel< B, C, L > >
+ : is_homogeneous_impl_p< C
+ , typename mpl::at_c< C, 0 >::type
+ , 1
+ , mpl::size< C >::type::value
+ > {};
+
+template< typename B
+ , typename C
+ , typename L
+ >
+struct is_homogeneous< const packed_pixel< B, C, L > >
+ : is_homogeneous_impl_p< C
+ , typename mpl::at_c<C,0>::type
+ , 1
+ , mpl::size< C >::type::value
+ > {};
+
+// for bit_aligned_pixel_reference
+template <typename B, typename C, typename L, bool M>
+struct is_homogeneous<bit_aligned_pixel_reference<B,C,L,M> >
+ : is_homogeneous_impl<C,typename mpl::at_c<C,0>::type,1,mpl::size<C>::type::value>
+{};
+
+template <typename B, typename C, typename L, bool M>
+struct is_homogeneous<const bit_aligned_pixel_reference<B,C,L,M> >
+ : is_homogeneous_impl<C,typename mpl::at_c<C,0>::type,1,mpl::size<C>::type::value>
+{};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_HOMOGENEOUS_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/is_similar.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/is_similar.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,43 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_SIMILAR_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_SIMILAR_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file is_similar.hpp
+/// \brief is_similar metafunction.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/channel.hpp>
+
+namespace boost{ namespace gil {
+
+/// is_similar metafunctions
+/// \brief Determines if two pixel types are similar.
+
+template< typename A, typename B >
+struct is_similar : mpl::false_ {};
+
+template<typename A>
+struct is_similar< A, A > : mpl::true_ {};
+
+template<typename B,int I, int S, bool M, int I2>
+struct is_similar< packed_channel_reference< B, I, S, M >
+ , packed_channel_reference< B, I2, S, M >
+ > : mpl::true_ {};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_SIMILAR_HPP
Added: trunk/boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,55 @@
+/*
+ Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_PIXEL_BIT_SIZE_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_PIXEL_BIT_SIZE_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file pixel_bit_size.hpp
+/// \brief pixel_bit_size metafunction.
+/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/accumulate.hpp>
+
+#include <boost/gil/bit_aligned_pixel_reference.hpp>
+#include <boost/gil/packed_pixel.hpp>
+
+namespace boost{ namespace gil {
+
+/// pixel_bit_size metafunctions
+/// \brief Accumulates the all channel size.
+///
+/// \code
+/// typedef bit_aligned_image5_type< 16, 16, 16, 8, 8, devicen_layout_t< 5 > >::type image_t;
+/// const int size = pixel_bit_size<image_t::view_t::reference>::value;
+/// \endcode
+template< typename PixelRef >
+struct pixel_bit_size : mpl::int_<0> {};
+
+template <typename B, typename C, typename L, bool M>
+struct pixel_bit_size<bit_aligned_pixel_reference<B,C,L,M> > : mpl::int_< mpl::accumulate< C, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type::value >{};
+
+template <typename B, typename C, typename L, bool M>
+struct pixel_bit_size<const bit_aligned_pixel_reference<B,C,L,M> > : mpl::int_< mpl::accumulate< C, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type::value >{};
+
+template <typename B, typename C, typename L>
+struct pixel_bit_size<packed_pixel<B,C,L> > : mpl::int_< mpl::accumulate< C, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type::value >{};
+
+template <typename B, typename C, typename L>
+struct pixel_bit_size<const packed_pixel<B,C,L> > : mpl::int_< mpl::accumulate< C, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type::value >{};
+
+} // namespace gil
+} // namespace boost
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_PIXEL_BIT_SIZE_HPP
Added: trunk/boost/gil/extension/toolbox/toolbox.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/gil/extension/toolbox/toolbox.hpp 2013-02-06 20:37:47 EST (Wed, 06 Feb 2013)
@@ -0,0 +1,29 @@
+/*
+ Copyright 2012 Christian Henning
+ Use, modification and distribution are subject to the Boost Software License,
+ Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+*/
+
+/*************************************************************************************************/
+
+#ifndef BOOST_GIL_EXTENSION_TOOLBOX_TOOLBOX_HPP
+#define BOOST_GIL_EXTENSION_TOOLBOX_TOOLBOX_HPP
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file toolbox.hpp
+/// \brief Main header for toolbox extension.
+/// \author Christian Henning \n
+///
+/// \date 2012 \n
+///
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/extension/toolbox/color_converters.hpp>
+#include <boost/gil/extension/toolbox/color_spaces.hpp>
+#include <boost/gil/extension/toolbox/image_types.hpp>
+#include <boost/gil/extension/toolbox/metafunctions.hpp>
+
+#include <boost/gil/extension/toolbox/dynamic_images.hpp>
+
+#endif // BOOST_GIL_EXTENSION_TOOLBOX_TOOLBOX_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk