]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/gil/color_convert.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / color_convert.hpp
index 5d1da3fcbb94232e5beddd65b74dcec9858ab2cd..3ebcd0c651cfd6b71432e8e772689ef86f54b0bf 100644 (file)
@@ -1,53 +1,42 @@
-/*
-    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 GIL_COLOR_CONVERT_HPP
-#define GIL_COLOR_CONVERT_HPP
-
-////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
-/// \brief GIL default color space conversions
-/// \author Lubomir Bourdev and Hailin Jin \n
-///         Adobe Systems Incorporated
-/// \date   2005-2007 \n Last updated on January 30, 2007
-///
-/// Support for fast and simple color conversion. Accurate color conversion using color
-/// profiles can be supplied separately in a dedicated module
-///
-////////////////////////////////////////////////////////////////////////////////////////
-
+//
+// Copyright 2005-2007 Adobe Systems Incorporated
+//
+// Distributed under the Boost Software License, Version 1.0
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+#ifndef BOOST_GIL_COLOR_CONVERT_HPP
+#define BOOST_GIL_COLOR_CONVERT_HPP
+
+#include <boost/gil/channel_algorithm.hpp>
+#include <boost/gil/cmyk.hpp>
+#include <boost/gil/color_base_algorithm.hpp>
+#include <boost/gil/gray.hpp>
+#include <boost/gil/metafunctions.hpp>
+#include <boost/gil/pixel.hpp>
+#include <boost/gil/rgb.hpp>
+#include <boost/gil/rgba.hpp>
+#include <boost/gil/utilities.hpp>
+
+#include <algorithm>
 #include <functional>
-#include "gil_config.hpp"
-#include "channel_algorithm.hpp"
-#include "pixel.hpp"
-#include "gray.hpp"
-#include "rgb.hpp"
-#include "rgba.hpp"
-#include "cmyk.hpp"
-#include "metafunctions.hpp"
-#include "utilities.hpp"
-#include "color_base_algorithm.hpp"
+#include <type_traits>
 
 namespace boost { namespace gil {
 
+/// Support for fast and simple color conversion.
+/// Accurate color conversion using color profiles can be supplied separately in a dedicated module.
+
 // Forward-declare
 template <typename P> struct channel_type;
 
 ////////////////////////////////////////////////////////////////////////////////////////
-///                 
+///
 ///                 COLOR SPACE CONVERSION
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 
-/// \ingroup ColorConvert 
+/// \ingroup ColorConvert
 /// \brief Color Convertion function object. To be specialized for every src/dst color space
 template <typename C1, typename C2>
 struct default_color_converter_impl {};
@@ -70,10 +59,10 @@ namespace detail {
 template <typename RedChannel, typename GreenChannel, typename BlueChannel, typename GrayChannelValue>
 struct rgb_to_luminance_fn {
     GrayChannelValue operator()(const RedChannel& red, const GreenChannel& green, const BlueChannel& blue) const {
-        return channel_convert<GrayChannelValue>( bits32f(
-            channel_convert<bits32f>(red  )*0.30f + 
-            channel_convert<bits32f>(green)*0.59f + 
-            channel_convert<bits32f>(blue )*0.11f) );
+        return channel_convert<GrayChannelValue>(float32_t(
+            channel_convert<float32_t>(red  )*0.30f +
+            channel_convert<float32_t>(green)*0.59f +
+            channel_convert<float32_t>(blue )*0.11f) );
     }
 };
 
@@ -132,7 +121,7 @@ template <>
 struct default_color_converter_impl<rgb_t,gray_t> {
     template <typename P1, typename P2>
     void operator()(const P1& src, P2& dst) const {
-        get_color(dst,gray_color_t()) = 
+        get_color(dst,gray_color_t()) =
             detail::rgb_to_luminance<typename color_element_type<P2,gray_color_t>::type>(
                 get_color(src,red_t()), get_color(src,green_t()), get_color(src,blue_t())
             );
@@ -151,7 +140,7 @@ template <>
 struct default_color_converter_impl<rgb_t,cmyk_t> {
     template <typename P1, typename P2>
     void operator()(const P1& src, P2& dst) const {
-        typedef typename channel_type<P2>::type T2;
+        using T2 = typename channel_type<P2>::type;
         get_color(dst,cyan_t())    = channel_invert(channel_convert<T2>(get_color(src,red_t())));          // c = 1 - r
         get_color(dst,magenta_t()) = channel_invert(channel_convert<T2>(get_color(src,green_t())));        // m = 1 - g
         get_color(dst,yellow_t())  = channel_invert(channel_convert<T2>(get_color(src,blue_t())));         // y = 1 - b
@@ -180,22 +169,22 @@ template <>
 struct default_color_converter_impl<cmyk_t,rgb_t> {
     template <typename P1, typename P2>
     void operator()(const P1& src, P2& dst) const {
-        typedef typename channel_type<P1>::type T1;
+        using T1 = typename channel_type<P1>::type;
         get_color(dst,red_t())  =
             channel_convert<typename color_element_type<P2,red_t>::type>(
                 channel_invert<T1>(
-                    (std::min)(channel_traits<T1>::max_value(), 
-                             T1(get_color(src,cyan_t())*channel_invert(get_color(src,black_t()))+get_color(src,black_t())))));
+                    (std::min)(channel_traits<T1>::max_value(),
+                             T1(channel_multiply(get_color(src,cyan_t()),channel_invert(get_color(src,black_t())))+get_color(src,black_t())))));
         get_color(dst,green_t())=
             channel_convert<typename color_element_type<P2,green_t>::type>(
                 channel_invert<T1>(
-                    (std::min)(channel_traits<T1>::max_value(), 
-                             T1(get_color(src,magenta_t())*channel_invert(get_color(src,black_t()))+get_color(src,black_t())))));
+                    (std::min)(channel_traits<T1>::max_value(),
+                             T1(channel_multiply(get_color(src,magenta_t()),channel_invert(get_color(src,black_t())))+get_color(src,black_t())))));
         get_color(dst,blue_t()) =
             channel_convert<typename color_element_type<P2,blue_t>::type>(
                 channel_invert<T1>(
-                    (std::min)(channel_traits<T1>::max_value(), 
-                             T1(get_color(src,yellow_t())*channel_invert(get_color(src,black_t()))+get_color(src,black_t())))));
+                    (std::min)(channel_traits<T1>::max_value(),
+                             T1(channel_multiply(get_color(src,yellow_t()),channel_invert(get_color(src,black_t())))+get_color(src,black_t())))));
     }
 };
 
@@ -209,34 +198,41 @@ struct default_color_converter_impl<cmyk_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_t>::type>(
+            channel_convert<typename color_element_type<P2,gray_color_t>::type>(
                 channel_multiply(
                     channel_invert(
                        detail::rgb_to_luminance<typename color_element_type<P1,black_t>::type>(
-                            get_color(src,cyan_t()), 
-                            get_color(src,magenta_t()), 
+                            get_color(src,cyan_t()),
+                            get_color(src,magenta_t()),
                             get_color(src,yellow_t())
                        )
-                    ), 
+                    ),
                     channel_invert(get_color(src,black_t()))));
     }
 };
 
 namespace detail {
-template <typename Pixel> 
-typename channel_type<Pixel>::type alpha_or_max_impl(const Pixel& p, mpl::true_) {
+
+template <typename Pixel>
+auto alpha_or_max_impl(Pixel const& p, std::true_type) -> typename channel_type<Pixel>::type
+{
     return get_color(p,alpha_t());
 }
-template <typename Pixel> 
-typename channel_type<Pixel>::type alpha_or_max_impl(const Pixel&  , mpl::false_) {
+template <typename Pixel>
+auto alpha_or_max_impl(Pixel const&, std::false_type) -> typename channel_type<Pixel>::type
+{
     return channel_traits<typename channel_type<Pixel>::type>::max_value();
 }
+
 } // namespace detail
 
 // Returns max_value if the pixel has no alpha channel. Otherwise returns the alpha.
-template <typename Pixel> 
-typename channel_type<Pixel>::type alpha_or_max(const Pixel& p) {
-    return detail::alpha_or_max_impl(p, mpl::contains<typename color_space_type<Pixel>::type,alpha_t>());
+template <typename Pixel>
+auto alpha_or_max(Pixel const& p) -> typename channel_type<Pixel>::type
+{
+    return detail::alpha_or_max_impl(
+        p,
+        mp11::mp_contains<typename color_space_type<Pixel>::type, alpha_t>());
 }
 
 
@@ -246,7 +242,7 @@ template <typename C1>
 struct default_color_converter_impl<C1,rgba_t> {
     template <typename P1, typename P2>
     void operator()(const P1& src, P2& dst) const {
-        typedef typename channel_type<P2>::type T2;
+        using T2 = typename channel_type<P2>::type;
         pixel<T2,rgb_layout_t> tmp;
         default_color_converter_impl<C1,rgb_t>()(src,tmp);
         get_color(dst,red_t())  =get_color(tmp,red_t());
@@ -260,16 +256,16 @@ struct default_color_converter_impl<C1,rgba_t> {
 ///  \brief Converting RGBA to any pixel type. Note: Supports homogeneous pixels only.
 ///
 /// Done by multiplying the alpha to get to RGB, then converting the RGB to the target pixel type
-/// Note: This may be slower if the compiler doesn't optimize out constructing/destructing a temporary RGB pixel. 
+/// Note: This may be slower if the compiler doesn't optimize out constructing/destructing a temporary RGB pixel.
 ///       Consider rewriting if performance is an issue
 template <typename C2>
 struct default_color_converter_impl<rgba_t,C2> {
     template <typename P1, typename P2>
     void operator()(const P1& src, P2& dst) const {
-        typedef typename channel_type<P1>::type T1;
+        using T1 = typename channel_type<P1>::type;
         default_color_converter_impl<rgb_t,C2>()(
-            pixel<T1,rgb_layout_t>(channel_multiply(get_color(src,red_t()),  get_color(src,alpha_t())), 
-                                   channel_multiply(get_color(src,green_t()),get_color(src,alpha_t())), 
+            pixel<T1,rgb_layout_t>(channel_multiply(get_color(src,red_t()),  get_color(src,alpha_t())),
+                                   channel_multiply(get_color(src,green_t()),get_color(src,alpha_t())),
                                    channel_multiply(get_color(src,blue_t()), get_color(src,alpha_t())))
             ,dst);
     }
@@ -293,9 +289,9 @@ struct default_color_converter_impl<rgba_t,rgba_t> {
 /// \brief class for color-converting one pixel to another
 struct default_color_converter {
     template <typename SrcP, typename DstP>
-    void operator()(const SrcP& src,DstP& dst) const { 
-        typedef typename color_space_type<SrcP>::type SrcColorSpace;
-        typedef typename color_space_type<DstP>::type DstColorSpace;
+    void operator()(const SrcP& src,DstP& dst) const {
+        using SrcColorSpace = typename color_space_type<SrcP>::type;
+        using DstColorSpace = typename color_space_type<DstP>::type;
         default_color_converter_impl<SrcColorSpace,DstColorSpace>()(src,dst);
     }
 };