color_space.rst 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Color Space and Layout
  2. ======================
  3. .. contents::
  4. :local:
  5. :depth: 2
  6. Overview
  7. --------
  8. A color space captures the set and interpretation of channels comprising a
  9. pixel. In Boost.GIL, color space is defined as an MPL random access sequence
  10. containing the types of all elements in the color space.
  11. Two color spaces are considered *compatible* if they are equal (i.e. have the
  12. same set of colors in the same order).
  13. .. seealso::
  14. - `ColorSpaceConcept<ColorSpace> <reference/structboost_1_1gil_1_1_color_space_concept.html>`_
  15. - `ColorSpacesCompatibleConcept<ColorSpace1,ColorSpace2> <reference/structboost_1_1gil_1_1_color_spaces_compatible_concept.html>`_
  16. - `ChannelMappingConcept<Mapping> <reference/structboost_1_1gil_1_1_channel_mapping_concept.html>`_
  17. Models
  18. ------
  19. GIL currently provides the following color spaces:
  20. - ``gray_t``
  21. - ``rgb_t``
  22. - ``rgba_t``
  23. - ``cmyk_t``
  24. It also provides unnamed N-channel color spaces of two to five channels:
  25. - ``devicen_t<2>``
  26. - ``devicen_t<3>``
  27. - ``devicen_t<4>``
  28. - ``devicen_t<5>``
  29. Besides the standard layouts, it also provides:
  30. - ``bgr_layout_t``
  31. - ``bgra_layout_t``
  32. - ``abgr_layout_t``
  33. - ``argb_layout_t``
  34. As an example, here is how GIL defines the RGBA color space::
  35. .. code-block:: cpp
  36. struct red_t {};
  37. struct green_t {};
  38. struct blue_t {};
  39. struct alpha_t {};
  40. rgba_t = using mpl::vector4<red_t, green_t, blue_t, alpha_t>;
  41. The ordering of the channels in the color space definition specifies their
  42. semantic order. For example, ``red_t`` is the first semantic channel of
  43. ``rgba_t``. While there is a unique semantic ordering of the channels in a
  44. color space, channels may vary in their physical ordering in memory
  45. The mapping of channels is specified by ``ChannelMappingConcept``, which is
  46. an MPL random access sequence of integral types.
  47. A color space and its associated mapping are often used together.
  48. Thus they are grouped in GIL's layout:
  49. .. code-block:: cpp
  50. template
  51. <
  52. typename ColorSpace,
  53. typename ChannelMapping = mpl::range_c<int, 0, mpl::size<ColorSpace>::value>
  54. >
  55. struct layout
  56. {
  57. using color_space_t = ColorSpace;
  58. using channel_mapping_t = ChannelMapping;
  59. };
  60. Here is how to create layouts for the RGBA color space:
  61. .. code-block:: cpp
  62. using rgba_layout_t = layout<rgba_t>; // default ordering is 0,1,2,3...
  63. using bgra_layout_t = layout<rgba_t, mpl::vector4_c<int,2,1,0,3>>;
  64. using argb_layout_t = layout<rgba_t, mpl::vector4_c<int,1,2,3,0>>;
  65. using abgr_layout_t = layout<rgba_t, mpl::vector4_c<int,3,2,1,0>>;