Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mapnik/mapnik
...
head fork: mapnik/mapnik
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
263 boost/gil/extension/toolbox/hsl.hpp
@@ -0,0 +1,263 @@
+// Copyright 2007 Christian Henning.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+/*************************************************************************************************/
+
+#ifndef GIL_HSL_H
+#define GIL_HSL_H
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file
+/// \brief Support for HSL color space
+/// \author Christian Henning \n
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/gil/gil_all.hpp>
+
+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 ( max_color - min_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( std::abs( max_color - temp_red ) < 0.0001f )
+ {
+ // max_color is red
+ hue = ( temp_green - temp_blue )
+ / diff;
+
+ }
+ else if( std::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
+ // 4.0 + (r - g) / (maxColor - minColor)
+ hue = 4.f
+ + ( temp_red - temp_green )
+ / 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( std::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 boost::gil
+
+#endif // GIL_HSL_H
View
231 boost/gil/extension/toolbox/hsv.hpp
@@ -0,0 +1,231 @@
+// Copyright 2004 Christian Henning.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+/*************************************************************************************************/
+
+#ifndef GIL_HSV_H
+#define GIL_HSV_H
+
+////////////////////////////////////////////////////////////////////////////////////////
+/// \file
+/// \brief Support for HSV color space
+/// \author Christian Henning \n
+////////////////////////////////////////////////////////////////////////////////////////
+
+#include <boost/cast.hpp>
+#include <boost/gil/gil_all.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 boost::gil
+
+#endif // GIL_HSV_H
View
215 deps/agg/include/agg_pixfmt_rgba.h
@@ -31,6 +31,12 @@
#include "agg_color_rgba.h"
#include "agg_rendering_buffer.h"
+#include <boost/gil/gil_all.hpp>
+#include <boost/gil/extension/toolbox/hsl.hpp>
+#include <boost/gil/extension/toolbox/hsv.hpp>
+
+#include <iostream>
+
namespace agg
{
@@ -1470,7 +1476,200 @@ namespace agg
}
}
};
+
+ template <typename ColorT, typename Order>
+ struct comp_op_rgba_hue
+ {
+ typedef ColorT color_type;
+ typedef Order order_type;
+ typedef typename color_type::value_type value_type;
+ typedef typename color_type::calc_type calc_type;
+ typedef typename color_type::long_type long_type;
+ enum base_scale_e
+ {
+ base_shift = color_type::base_shift,
+ base_mask = color_type::base_mask
+ };
+
+ static AGG_INLINE void blend_pix(value_type* p,
+ unsigned sr, unsigned sg, unsigned sb,
+ unsigned sa, unsigned cover)
+ {
+ if (cover < 255)
+ {
+ sr = (sr * cover + 255) >> 8;
+ sg = (sg * cover + 255) >> 8;
+ sb = (sb * cover + 255) >> 8;
+ sa = (sa * cover + 255) >> 8;
+ }
+
+ if (sa > 0)
+ {
+ using namespace boost;
+ using namespace gil;
+ using namespace hsl_color_space;
+
+ rgb8_pixel_t rgb_src(sr,sg,sb);
+ rgb8_pixel_t rgb_dst(p[Order::R],p[Order::G],p[Order::B]);
+ hsl32f_pixel_t hsl_src,hsl_dst;
+ color_convert(rgb_src, hsl_src);
+ color_convert(rgb_dst, hsl_dst);
+ get_color(hsl_dst,hue_t()) = get_color(hsl_src,hue_t());
+ color_convert(hsl_dst, rgb_dst);
+ p[Order::R] = get_color(rgb_dst,red_t());
+ p[Order::G] = get_color(rgb_dst,green_t());
+ p[Order::B] = get_color(rgb_dst,blue_t());
+ calc_type da = p[Order::A];
+ p[Order::A] = (value_type)(sa + da - ((sa * da + base_mask) >> base_shift));
+ }
+ }
+ };
+
+ template <typename ColorT, typename Order>
+ struct comp_op_rgba_saturation
+ {
+ typedef ColorT color_type;
+ typedef Order order_type;
+ typedef typename color_type::value_type value_type;
+ typedef typename color_type::calc_type calc_type;
+ typedef typename color_type::long_type long_type;
+ enum base_scale_e
+ {
+ base_shift = color_type::base_shift,
+ base_mask = color_type::base_mask
+ };
+
+ static AGG_INLINE void blend_pix(value_type* p,
+ unsigned sr, unsigned sg, unsigned sb,
+ unsigned sa, unsigned cover)
+ {
+ if (cover < 255)
+ {
+ sr = (sr * cover + 255) >> 8;
+ sg = (sg * cover + 255) >> 8;
+ sb = (sb * cover + 255) >> 8;
+ sa = (sa * cover + 255) >> 8;
+ }
+
+ if (sa > 0)
+ {
+ using namespace boost;
+ using namespace gil;
+ using namespace hsl_color_space;
+
+ rgb8_pixel_t rgb_src(sr,sg,sb);
+ rgb8_pixel_t rgb_dst(p[Order::R],p[Order::G],p[Order::B]);
+ hsl32f_pixel_t hsl_src,hsl_dst;
+ color_convert( rgb_src, hsl_src);
+ color_convert( rgb_dst, hsl_dst);
+ get_color(hsl_dst,saturation_t()) = get_color(hsl_src,saturation_t());
+ color_convert(hsl_dst, rgb_dst);
+ p[Order::R] = get_color(rgb_dst,red_t());
+ p[Order::G] = get_color(rgb_dst,green_t());
+ p[Order::B] = get_color(rgb_dst,blue_t());
+ calc_type da = p[Order::A];
+ p[Order::A] = (value_type)(sa + da - ((sa * da + base_mask) >> base_shift));
+ }
+ }
+ };
+
+ template <typename ColorT, typename Order>
+ struct comp_op_rgba_color
+ {
+ typedef ColorT color_type;
+ typedef Order order_type;
+ typedef typename color_type::value_type value_type;
+ typedef typename color_type::calc_type calc_type;
+ typedef typename color_type::long_type long_type;
+ enum base_scale_e
+ {
+ base_shift = color_type::base_shift,
+ base_mask = color_type::base_mask
+ };
+
+ static AGG_INLINE void blend_pix(value_type* p,
+ unsigned sr, unsigned sg, unsigned sb,
+ unsigned sa, unsigned cover)
+ {
+ if (cover < 255)
+ {
+ sr = (sr * cover + 255) >> 8;
+ sg = (sg * cover + 255) >> 8;
+ sb = (sb * cover + 255) >> 8;
+ sa = (sa * cover + 255) >> 8;
+ }
+
+ if (sa > 0)
+ {
+ using namespace boost;
+ using namespace gil;
+ using namespace hsl_color_space;
+
+ rgb8_pixel_t rgb_src(sr,sg,sb);
+ rgb8_pixel_t rgb_dst(p[Order::R],p[Order::G],p[Order::B]);
+ hsl32f_pixel_t hsl_src,hsl_dst;
+ color_convert( rgb_src, hsl_src);
+ color_convert( rgb_dst, hsl_dst);
+ get_color(hsl_dst,hue_t()) = get_color(hsl_src,hue_t());
+ get_color(hsl_dst,saturation_t()) = get_color(hsl_src,saturation_t());
+ color_convert(hsl_dst, rgb_dst);
+ p[Order::R] = get_color(rgb_dst,red_t());
+ p[Order::G] = get_color(rgb_dst,green_t());
+ p[Order::B] = get_color(rgb_dst,blue_t());
+ calc_type da = p[Order::A];
+ p[Order::A] = (value_type)(sa + da - ((sa * da + base_mask) >> base_shift));
+ }
+ }
+ };
+
+
+ template <typename ColorT, typename Order>
+ struct comp_op_rgba_luminosity
+ {
+ typedef ColorT color_type;
+ typedef Order order_type;
+ typedef typename color_type::value_type value_type;
+ typedef typename color_type::calc_type calc_type;
+ typedef typename color_type::long_type long_type;
+ enum base_scale_e
+ {
+ base_shift = color_type::base_shift,
+ base_mask = color_type::base_mask
+ };
+ static AGG_INLINE void blend_pix(value_type* p,
+ unsigned sr, unsigned sg, unsigned sb,
+ unsigned sa, unsigned cover)
+ {
+ if (cover < 255)
+ {
+ sr = (sr * cover + 255) >> 8;
+ sg = (sg * cover + 255) >> 8;
+ sb = (sb * cover + 255) >> 8;
+ sa = (sa * cover + 255) >> 8;
+ }
+
+ if (sa > 0)
+ {
+ using namespace boost;
+ using namespace gil;
+ using namespace hsl_color_space;
+
+ rgb8_pixel_t rgb_src(sr,sg,sb);
+ rgb8_pixel_t rgb_dst(p[Order::R],p[Order::G],p[Order::B]);
+ hsl32f_pixel_t hsl_src,hsl_dst;
+ color_convert( rgb_src, hsl_src);
+ color_convert( rgb_dst, hsl_dst);
+ get_color(hsl_dst,lightness_t()) = get_color(hsl_src,lightness_t());
+ color_convert(hsl_dst, rgb_dst);
+ p[Order::R] = get_color(rgb_dst,red_t());
+ p[Order::G] = get_color(rgb_dst,green_t());
+ p[Order::B] = get_color(rgb_dst,blue_t());
+ calc_type da = p[Order::A];
+ p[Order::A] = (value_type)(sa + da - ((sa * da + base_mask) >> base_shift));
+ }
+ }
+ };
//======================================================comp_op_table_rgba
template<class ColorT, class Order> struct comp_op_table_rgba
@@ -1520,6 +1719,10 @@ namespace agg
comp_op_rgba_invert_rgb <ColorT,Order>::blend_pix,
comp_op_rgba_grain_merge<ColorT,Order>::blend_pix,
comp_op_rgba_grain_extract<ColorT,Order>::blend_pix,
+ comp_op_rgba_hue<ColorT,Order>::blend_pix,
+ comp_op_rgba_saturation<ColorT,Order>::blend_pix,
+ comp_op_rgba_color<ColorT,Order>::blend_pix,
+ comp_op_rgba_luminosity<ColorT,Order>::blend_pix,
0
};
@@ -1557,15 +1760,13 @@ namespace agg
comp_op_invert_rgb, //----comp_op_invert_rgb
comp_op_grain_merge, //----comp_op_grain_merge_rgb
comp_op_grain_extract, //----comp_op_grain_extract_rgb
+ comp_op_hue, //----comp_op_hue
+ comp_op_saturation, //----comp_op_saturation
+ comp_op_color, //----comp_op_color
+ comp_op_luminosity, //----comp_op_luminosity
end_of_comp_op_e
};
-
-
-
-
-
-
-
+
//====================================================comp_op_adaptor_rgba
template<class ColorT, class Order> struct comp_op_adaptor_rgba
{
View
6 include/mapnik/image_compositing.hpp
@@ -70,7 +70,11 @@ enum composite_mode_e
invert,
invert_rgb,
grain_merge,
- grain_extract
+ grain_extract,
+ hue,
+ saturation,
+ _color,
+ luminosity
};
MAPNIK_DECL boost::optional<composite_mode_e> comp_op_from_string(std::string const& name);
View
6 src/cairo_renderer.cpp
@@ -385,10 +385,14 @@ class cairo_context : private boost::noncopyable
case invert_rgb:
case grain_merge:
case grain_extract:
+ case hue:
+ case saturation:
+ case _color:
+ case luminosity:
break;
}
}
-
+
void set_line_join(line_join_e join)
{
if (join == MITER_JOIN)
View
4 src/image_compositing.cpp
@@ -70,6 +70,10 @@ static const comp_op_lookup_type comp_lookup = boost::assign::list_of<comp_op_lo
(invert_rgb,"invert-rgb")
(grain_merge,"grain-merge")
(grain_extract,"grain-extract")
+ (hue,"hue")
+ (saturation,"saturation")
+ (_color,"color")
+ (luminosity,"luminosity")
;
boost::optional<composite_mode_e> comp_op_from_string(std::string const& name)
View
2  src/parse_transform.cpp
@@ -22,6 +22,8 @@
#include <mapnik/parse_transform.hpp>
#include <mapnik/transform_expression_grammar.hpp>
+#include <mapnik/transform_processor.hpp>
+#include <mapnik/debug.hpp>
#include <boost/make_shared.hpp>

No commit comments for this range

Something went wrong with that request. Please try again.