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