gray_alpha.hpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // Copyright 2012 Andreas Pokorny
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
  9. #define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
  10. #include <boost/gil/color_convert.hpp>
  11. #include <boost/gil/gray.hpp>
  12. #include <boost/gil/typedefs.hpp>
  13. #include <boost/gil/detail/mp11.hpp>
  14. namespace boost{ namespace gil {
  15. using gray_alpha_t = mp11::mp_list<gray_color_t,alpha_t>;
  16. using gray_alpha_layout_t = layout<gray_alpha_t>;
  17. using alpha_gray_layout_t = layout<gray_alpha_layout_t, mp11::mp_list_c<int,1,0>>;
  18. GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, alpha_gray)
  19. GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, alpha_gray)
  20. GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, alpha_gray)
  21. GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, alpha_gray)
  22. GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, alpha_gray)
  23. GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, alpha_gray)
  24. GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, alpha_gray)
  25. GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, gray_alpha)
  26. GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, gray_alpha)
  27. GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, gray_alpha)
  28. GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, gray_alpha)
  29. GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, gray_alpha)
  30. GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, gray_alpha)
  31. GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, gray_alpha)
  32. /// \ingroup ColorConvert
  33. /// \brief Gray Alpha to RGBA
  34. template <>
  35. struct default_color_converter_impl<gray_alpha_t,rgba_t> {
  36. template <typename P1, typename P2>
  37. void operator()(const P1& src, P2& dst) const {
  38. get_color(dst,red_t()) =
  39. channel_convert<typename color_element_type<P2, red_t>::type>(get_color(src,gray_color_t()));
  40. get_color(dst,green_t())=
  41. channel_convert<typename color_element_type<P2, green_t>::type>(get_color(src,gray_color_t()));
  42. get_color(dst,blue_t()) =
  43. channel_convert<typename color_element_type<P2, blue_t>::type>(get_color(src,gray_color_t()));
  44. get_color(dst,alpha_t()) =
  45. channel_convert<typename color_element_type<P2, alpha_t>::type>(get_color(src,alpha_t()));
  46. }
  47. };
  48. /// \brief Gray Alpha to RGB
  49. template <>
  50. struct default_color_converter_impl<gray_alpha_t,rgb_t> {
  51. template <typename P1, typename P2>
  52. void operator()(const P1& src, P2& dst) const {
  53. get_color(dst,red_t()) =
  54. channel_convert<typename color_element_type<P2, red_t>::type>(
  55. channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
  56. );
  57. get_color(dst,green_t()) =
  58. channel_convert<typename color_element_type<P2, green_t>::type>(
  59. channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
  60. );
  61. get_color(dst,blue_t()) =
  62. channel_convert<typename color_element_type<P2, blue_t>::type>(
  63. channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
  64. );
  65. }
  66. };
  67. /// \brief Gray Alpha to Gray
  68. template <>
  69. struct default_color_converter_impl<gray_alpha_t,gray_t> {
  70. template <typename P1, typename P2>
  71. void operator()(const P1& src, P2& dst) const {
  72. get_color(dst,gray_color_t()) =
  73. channel_convert<typename color_element_type<P2, gray_color_t>::type>(
  74. channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) )
  75. );
  76. }
  77. };
  78. } // namespace gil
  79. } // namespace boost
  80. #endif