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 auto operator()(
const RedChannel& red,
const GreenChannel& green,
const BlueChannel& blue)
const -> GrayChannelValue
68 return channel_convert<GrayChannelValue>(
float32_t(
69 channel_convert<float32_t>(red )*0.30f +
70 channel_convert<float32_t>(green)*0.59f +
71 channel_convert<float32_t>(blue )*0.11f) );
76 template <
typename GrayChannelValue>
78 auto operator()(uint8_t red, uint8_t green, uint8_t blue)
const -> GrayChannelValue
80 return channel_convert<GrayChannelValue>(uint8_t(
81 ((uint32_t(red )*4915 + uint32_t(green)*9667 + uint32_t(blue )*1802) + 8192) >> 14));
85 template <
typename GrayChannel,
typename RedChannel,
typename GreenChannel,
typename BlueChannel>
86 auto rgb_to_luminance(
const RedChannel& red,
const GreenChannel& green,
const BlueChannel& blue) ->
typename channel_traits<GrayChannel>::value_type
88 return rgb_to_luminance_fn<RedChannel,GreenChannel,BlueChannel,
89 typename channel_traits<GrayChannel>::value_type>()(red,green,blue);
98 template <
typename P1,
typename P2>
99 void operator()(
const P1& src, P2& dst)
const {
115 template <
typename P1,
typename P2>
116 void operator()(
const P1& src, P2& dst)
const {
118 channel_traits<typename color_element_type<P2, cyan_t >::type>::min_value();
120 channel_traits<typename color_element_type<P2, magenta_t>::type>::min_value();
122 channel_traits<typename color_element_type<P2, yellow_t >::type>::min_value();
132 template <
typename P1,
typename P2>
133 void operator()(
const P1& src, P2& dst)
const {
135 detail::rgb_to_luminance<typename color_element_type<P2,gray_color_t>::type>(
159 template <
typename SrcPixel,
typename DstPixel>
160 void operator()(SrcPixel
const& src, DstPixel& dst)
const
171 uint_t k = (std::min)(c,(std::min)(m,y));
175 uint_t
const dst_max = channel_traits<uint_t>::max_value();
176 uint_t
const s_div =
static_cast<uint_t
>(dst_max - k);
179 double const s = dst_max /
static_cast<double>(s_div);
180 c =
static_cast<uint_t
>((c - k) * s);
181 m =
static_cast<uint_t
>((m - k) * s);
182 y =
static_cast<uint_t
>((y - k) * s);
187 c = channel_traits<uint_t>::min_value();
188 m = channel_traits<uint_t>::min_value();
189 y = channel_traits<uint_t>::min_value();
208 template <
typename P1,
typename P2>
209 void operator()(
const P1& src, P2& dst)
const {
212 channel_convert<typename color_element_type<P2,red_t>::type>(
214 (std::min)(channel_traits<T1>::max_value(),
217 channel_convert<typename color_element_type<P2,green_t>::type>(
219 (std::min)(channel_traits<T1>::max_value(),
222 channel_convert<typename color_element_type<P2,blue_t>::type>(
224 (std::min)(channel_traits<T1>::max_value(),
236 template <
typename P1,
typename P2>
237 void operator()(
const P1& src, P2& dst)
const {
239 channel_convert<typename color_element_type<P2,gray_color_t>::type>(
242 detail::rgb_to_luminance<
typename color_element_type<P1,black_t>::type>(
254 template <
typename Pixel>
259 template <
typename Pixel>
260 auto alpha_or_max_impl(Pixel
const&, std::false_type) ->
typename channel_type<Pixel>::type
262 return channel_traits<typename channel_type<Pixel>::type>::max_value();
268 template <
typename Pixel>
269 auto alpha_or_max(Pixel
const& p) ->
typename channel_type<Pixel>::type
271 return detail::alpha_or_max_impl(
273 mp11::mp_contains<
typename color_space_type<Pixel>::type, alpha_t>());
279 template <
typename C1>
281 template <
typename P1,
typename P2>
282 void operator()(
const P1& src, P2& dst)
const {
299 template <
typename C2>
301 template <
typename P1,
typename P2>
302 void operator()(
const P1& src, P2& dst)
const {
316 template <
typename P1,
typename P2>
317 void operator()(
const P1& src, P2& dst)
const {
329 template <
typename SrcP,
typename DstP>
330 void operator()(
const SrcP& src,DstP& dst)
const {
331 using SrcColorSpace =
typename color_space_type<SrcP>::type;
332 using DstColorSpace =
typename color_space_type<DstP>::type;
341 template <
typename SrcP,
typename DstP>
auto channel_invert(Channel x) -> typename channel_traits< Channel >::value_type
Default implementation. Provide overloads for performance.
Definition: channel_algorithm.hpp:582
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:153
auto channel_multiply(Channel a, Channel b) -> typename channel_traits< Channel >::value_type
A function multiplying two channels. result = a * b / max_value.
Definition: channel_algorithm.hpp:561
auto get_color(ColorBase &cb, Color=Color()) -> typename color_element_reference_type< ColorBase, Color >::type
Mutable accessor to the element associated with a given color name.
Definition: color_base_algorithm.hpp:190
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:342
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Alpha.
Definition: rgba.hpp:22
Black.
Definition: cmyk.hpp:31
Blue.
Definition: rgb.hpp:30
Definition: color_convert.hpp:31
Cyan.
Definition: cmyk.hpp:22
Same as channel_converter, except it takes the destination channel by reference, which allows us to m...
Definition: channel_algorithm.hpp:471
Color Conversion function object. To be specialized for every src/dst color space.
Definition: color_convert.hpp:43
class for color-converting one pixel to another
Definition: color_convert.hpp:328
red * .3 + green * .59 + blue * .11 + .5
Definition: color_convert.hpp:65
Gray.
Definition: gray.hpp:18
Green.
Definition: rgb.hpp:27
Magenta.
Definition: cmyk.hpp:25
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept,...
Definition: pixel.hpp:106
Red.
Definition: rgb.hpp:24
Yellow.
Definition: cmyk.hpp:28