8 #ifndef BOOST_GIL_COLOR_CONVERT_HPP     9 #define BOOST_GIL_COLOR_CONVERT_HPP    11 #include <boost/gil/channel_algorithm.hpp>    12 #include <boost/gil/cmyk.hpp>    13 #include <boost/gil/color_base_algorithm.hpp>    14 #include <boost/gil/gray.hpp>    15 #include <boost/gil/metafunctions.hpp>    16 #include <boost/gil/pixel.hpp>    17 #include <boost/gil/rgb.hpp>    18 #include <boost/gil/rgba.hpp>    19 #include <boost/gil/utilities.hpp>    23 #include <type_traits>    25 namespace boost { 
namespace gil {
    41 template <
typename C1, 
typename C2>
    45         std::is_same<C1, C2>::value,
    46         "default_color_converter_impl not specialized for given color spaces");
    53     template <
typename P1, 
typename P2>
    54     void operator()(
const P1& src, P2& dst)
 const {
    64 template <
typename RedChannel, 
typename GreenChannel, 
typename BlueChannel, 
typename GrayChannelValue>
    66     GrayChannelValue operator()(
const RedChannel& red, 
const GreenChannel& green, 
const BlueChannel& blue)
 const {
    67         return channel_convert<GrayChannelValue>(
float32_t(
    68             channel_convert<float32_t>(red  )*0.30f +
    69             channel_convert<float32_t>(green)*0.59f +
    70             channel_convert<float32_t>(blue )*0.11f) );
    75 template <
typename GrayChannelValue>
    77     GrayChannelValue operator()(uint8_t red, uint8_t green, uint8_t blue)
 const {
    78         return channel_convert<GrayChannelValue>(uint8_t(
    79             ((uint32_t(red  )*4915 + uint32_t(green)*9667 + uint32_t(blue )*1802) + 8192) >> 14));
    83 template <
typename GrayChannel, 
typename RedChannel, 
typename GreenChannel, 
typename BlueChannel>
    84 typename channel_traits<GrayChannel>::value_type rgb_to_luminance(
const RedChannel& red, 
const GreenChannel& green, 
const BlueChannel& blue) {
    85     return rgb_to_luminance_fn<RedChannel,GreenChannel,BlueChannel,
    86                                typename channel_traits<GrayChannel>::value_type>()(red,green,blue);
    95     template <
typename P1, 
typename P2>
    96     void operator()(
const P1& src, P2& dst)
 const {
   112     template <
typename P1, 
typename P2>
   113     void operator()(
const P1& src, P2& dst)
 const {
   115             channel_traits<typename color_element_type<P2, cyan_t   >::type>::min_value();
   117             channel_traits<typename color_element_type<P2, magenta_t>::type>::min_value();
   119             channel_traits<typename color_element_type<P2, yellow_t >::type>::min_value();
   129     template <
typename P1, 
typename P2>
   130     void operator()(
const P1& src, P2& dst)
 const {
   132             detail::rgb_to_luminance<typename color_element_type<P2,gray_color_t>::type>(
   158     template <
typename SrcPixel, 
typename DstPixel>
   159     void operator()(SrcPixel 
const& src, DstPixel& dst)
 const   170         dst_t 
const k = (std::min)(c, (std::min)(m, y));           
   174         dst_t 
const dst_max = channel_traits<dst_t>::max_value();
   175         dst_t 
const s_div   = dst_max - k;
   178             double const s              = dst_max / static_cast<double>(s_div);
   202     template <
typename P1, 
typename P2>
   203     void operator()(
const P1& src, P2& dst)
 const {
   206             channel_convert<typename color_element_type<P2,red_t>::type>(
   208                     (std::min)(channel_traits<T1>::max_value(),
   211             channel_convert<typename color_element_type<P2,green_t>::type>(
   213                     (std::min)(channel_traits<T1>::max_value(),
   216             channel_convert<typename color_element_type<P2,blue_t>::type>(
   218                     (std::min)(channel_traits<T1>::max_value(),
   230     template <
typename P1, 
typename P2>
   231     void operator()(
const P1& src, P2& dst)
 const  {
   233             channel_convert<typename color_element_type<P2,gray_color_t>::type>(
   236                        detail::rgb_to_luminance<
typename color_element_type<P1,black_t>::type>(
   248 template <
typename Pixel>
   253 template <
typename Pixel>
   254 auto alpha_or_max_impl(Pixel 
const&, std::false_type) -> 
typename channel_type<Pixel>::type
   256     return channel_traits<typename channel_type<Pixel>::type>::max_value();
   262 template <
typename Pixel>
   263 auto alpha_or_max(Pixel 
const& p) -> 
typename channel_type<Pixel>::type
   265     return detail::alpha_or_max_impl(
   267         mp11::mp_contains<
typename color_space_type<Pixel>::type, alpha_t>());
   273 template <
typename C1>
   275     template <
typename P1, 
typename P2>
   276     void operator()(
const P1& src, P2& dst)
 const {
   293 template <
typename C2>
   295     template <
typename P1, 
typename P2>
   296     void operator()(
const P1& src, P2& dst)
 const {
   310     template <
typename P1, 
typename P2>
   311     void operator()(
const P1& src, P2& dst)
 const {
   323     template <
typename SrcP, 
typename DstP>
   324     void operator()(
const SrcP& src,DstP& dst)
 const {
   325         using SrcColorSpace = 
typename color_space_type<SrcP>::type;
   326         using DstColorSpace = 
typename color_space_type<DstP>::type;
   335 template <
typename SrcP, 
typename DstP>
 Magenta.
Definition: cmyk.hpp:25
channel_traits< Channel >::value_type channel_invert(Channel x)
Default implementation. Provide overloads for performance.
Definition: channel_algorithm.hpp:559
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept,...
Definition: metafunctions.hpp:23
scoped_channel_value< float, float_point_zero< float >, float_point_one< float > > float32_t
32-bit floating point channel type with range [0.0f ... 1.0f]. Models ChannelValueConcept
Definition: typedefs.hpp:124
Yellow.
Definition: cmyk.hpp:28
channel_traits< Channel >::value_type channel_multiply(Channel a, Channel b)
A function multiplying two channels. result = a * b / max_value.
Definition: channel_algorithm.hpp:539
color_element_reference_type< ColorBase, Color >::type get_color(ColorBase &cb, Color=Color())
Mutable accessor to the element associated with a given color name.
Definition: color_base_algorithm.hpp:190
Green.
Definition: rgb.hpp:27
Same as channel_converter, except it takes the destination channel by reference, which allows us to m...
Definition: channel_algorithm.hpp:460
Alpha.
Definition: rgba.hpp:22
Definition: color_convert.hpp:31
Color Convertion function object. To be specialized for every src/dst color space.
Definition: color_convert.hpp:42
Blue.
Definition: rgb.hpp:30
void color_convert(const SrcP &src, DstP &dst)
helper function for converting one pixel to another using GIL default color-converters where ScrP mod...
Definition: color_convert.hpp:336
red * .3 + green * .59 + blue * .11 + .5
Definition: color_convert.hpp:65
Black.
Definition: cmyk.hpp:31
Red.
Definition: rgb.hpp:24
Gray.
Definition: gray.hpp:18
Cyan.
Definition: cmyk.hpp:22
class for color-converting one pixel to another
Definition: color_convert.hpp:322