Turi Create  4.0
color_convert.hpp
1 /* Copyright © 2019 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at
5  * https://opensource.org/licenses/BSD-3-Clause
6  */
7 
8 #include <boost/gil/gil_all.hpp>
9 
10 namespace boost {
11 namespace gil {
12 // Define a color conversion rule NB in the boost::gil namespace
13 // RGB to RGBA
14 template <>
15 void color_convert<rgb8_pixel_t, rgba8_pixel_t>(const rgb8_pixel_t& src,
16  rgba8_pixel_t& dst) {
17  get_color(dst, red_t()) = get_color(src, red_t());
18  get_color(dst, green_t()) = get_color(src, green_t());
19  get_color(dst, blue_t()) = get_color(src, blue_t());
20 
21  using alpha_channel_t = color_element_type<rgba8_pixel_t, alpha_t>::type;
22  get_color(dst, alpha_t()) = channel_traits<alpha_channel_t>::max_value();
23 }
24 
25 // RGBA to RGB
26 template <>
27 void color_convert<rgba8_pixel_t, rgb8_pixel_t>(const rgba8_pixel_t& src,
28  rgb8_pixel_t& dst) {
29  get_color(dst, red_t()) = get_color(src, red_t());
30  get_color(dst, green_t()) = get_color(src, green_t());
31  get_color(dst, blue_t()) = get_color(src, blue_t());
32  // ignore the alpha channel
33 }
34 
35 } // namespace gil
36 } // namespace boost