12 #ifndef GIL_COLOR_CONVERT_HPP
13 #define GIL_COLOR_CONVERT_HPP
29 #include <boost/config.hpp>
42 namespace boost {
namespace gil {
45 template <
typename P>
struct channel_type;
55 template <
typename C1,
typename C2>
62 template <
typename P1,
typename P2>
63 void operator()(
const P1& src, P2& dst)
const {
73 template <
typename RedChannel,
typename GreenChannel,
typename BlueChannel,
typename GrayChannelValue>
75 GrayChannelValue operator()(
const RedChannel& red,
const GreenChannel& green,
const BlueChannel& blue)
const {
76 return channel_convert<GrayChannelValue>(
float32_t(
77 channel_convert<float32_t>(red )*0.30f +
78 channel_convert<float32_t>(green)*0.59f +
79 channel_convert<float32_t>(blue )*0.11f) );
84 template <
typename GrayChannelValue>
86 GrayChannelValue operator()(uint8_t red, uint8_t green, uint8_t blue)
const {
87 return channel_convert<GrayChannelValue>(uint8_t(
88 ((uint32_t(red )*4915 + uint32_t(green)*9667 + uint32_t(blue )*1802) + 8192) >> 14));
92 template <
typename GrayChannel,
typename RedChannel,
typename GreenChannel,
typename BlueChannel>
93 typename channel_traits<GrayChannel>::value_type rgb_to_luminance(
const RedChannel& red,
const GreenChannel& green,
const BlueChannel& blue) {
94 return rgb_to_luminance_fn<RedChannel,GreenChannel,BlueChannel,
95 typename channel_traits<GrayChannel>::value_type>()(red,green,blue);
104 template <
typename P1,
typename P2>
105 void operator()(
const P1& src, P2& dst)
const {
119 template <
typename P1,
typename P2>
120 void operator()(
const P1& src, P2& dst)
const {
136 template <
typename P1,
typename P2>
137 void operator()(
const P1& src, P2& dst)
const {
139 detail::rgb_to_luminance<typename color_element_type<P2,gray_color_t>::type>(
155 template <
typename P1,
typename P2>
156 void operator()(
const P1& src, P2& dst)
const {
157 typedef typename channel_type<P2>::type T2;
184 template <
typename P1,
typename P2>
185 void operator()(
const P1& src, P2& dst)
const {
186 typedef typename channel_type<P1>::type T1;
188 channel_convert<typename color_element_type<P2,red_t>::type>(
193 channel_convert<typename color_element_type<P2,green_t>::type>(
198 channel_convert<typename color_element_type<P2,blue_t>::type>(
212 template <
typename P1,
typename P2>
213 void operator()(
const P1& src, P2& dst)
const {
215 channel_convert<typename color_element_type<P2,gray_t>::type>(
218 detail::rgb_to_luminance<
typename color_element_type<P1,black_t>::type>(
229 template <
typename Pixel>
230 typename channel_type<Pixel>::type alpha_or_max_impl(
const Pixel& p, mpl::true_) {
233 template <
typename Pixel>
234 typename channel_type<Pixel>::type alpha_or_max_impl(
const Pixel& , mpl::false_) {
235 return channel_traits<typename channel_type<Pixel>::type>::max_value();
240 template <
typename Pixel>
241 typename channel_type<Pixel>::type alpha_or_max(
const Pixel& p) {
242 return detail::alpha_or_max_impl(p, mpl::contains<
typename color_space_type<Pixel>::type,alpha_t>());
248 template <
typename C1>
250 template <
typename P1,
typename P2>
251 void operator()(
const P1& src, P2& dst)
const {
252 typedef typename channel_type<P2>::type T2;
268 template <
typename C2>
270 template <
typename P1,
typename P2>
271 void operator()(
const P1& src, P2& dst)
const {
272 typedef typename channel_type<P1>::type T1;
285 template <
typename P1,
typename P2>
286 void operator()(
const P1& src, P2& dst)
const {
298 template <
typename SrcP,
typename DstP>
299 void operator()(
const SrcP& src,DstP& dst)
const {
300 typedef typename color_space_type<SrcP>::type SrcColorSpace;
301 typedef typename color_space_type<DstP>::type DstColorSpace;
310 template <
typename SrcP,
typename DstP>
Magenta.
Definition: cmyk.hpp:42
channel_traits< Channel >::value_type channel_invert(Channel x)
Default implementation. Provide overloads for performance.
Definition: channel_algorithm.hpp:532
Support for grayscale color space and variants.
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept, PixelValueConcept, HomogeneousPixelBasedConcept.
Definition: metafunctions.hpp:44
Yellow.
Definition: cmyk.hpp:45
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:510
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:185
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:130
Green.
Definition: rgb.hpp:40
Same as channel_converter, except it takes the destination channel by reference, which allows us to m...
Definition: channel_algorithm.hpp:429
Support for CMYK color space and variants.
Alpha.
Definition: rgba.hpp:33
Color Convertion function object. To be specialized for every src/dst color space.
Definition: color_convert.hpp:56
Blue.
Definition: rgb.hpp:43
Traits for channels. Contains the following members:
Definition: channel.hpp:114
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:311
red * .3 + green * .59 + blue * .11 + .5
Definition: color_convert.hpp:74
Black.
Definition: cmyk.hpp:48
Red.
Definition: rgb.hpp:37
Gray.
Definition: gray.hpp:34
Cyan.
Definition: cmyk.hpp:39
class for color-converting one pixel to another
Definition: color_convert.hpp:297
pixel class and related utilities
Support for RGB color space and variants.
Support for RGBA color space and variants.
Various utilities not specific to the image library. Some are non-standard STL extensions or generic ...