VisionCpp  0.0.1
pixel.hpp
Go to the documentation of this file.
1 // This file is part of VisionCpp, a lightweight C++ template library
2 // for computer vision and image processing.
3 //
4 // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
5 //
6 // Contact: visioncpp@codeplay.com
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 
20 /// \file pixel.hpp
21 /// \brief This file contains definition of underlying pixel types used in
22 /// VisionCpp.
23 /// Generic form of the pixel is as follow: \n
24 /// {F/U/S}{SIZE_OF_CHANNEL}C{NUMBER_OF_CHANNELS} \n
25 /// F32C4 - represents float[4] \n
26 /// U8C3 - represents unsigned char[3] \n
27 
28 #ifndef VISIONCPP_INCLUDE_PIXEL_PIXEL_HPP_
29 #define VISIONCPP_INCLUDE_PIXEL_PIXEL_HPP_
30 
31 #include "../framework/tools/tuple.hpp"
32 
33 namespace visioncpp {
34 namespace internal {
35 template <bool conds, size_t K, typename PixelType, typename... Params>
37  /// \brief Assigns Value To Array
38  static void avta(PixelType &dt,
40  dt[K] = visioncpp::internal::tools::tuple::get<K>(t);
41  AssignValueToArray<K + 1 != sizeof...(Params), K + 1, PixelType,
42  Params...>::avta(dt, t);
43  }
44 };
45 
46 template <size_t K, typename PixelType, typename... Params>
47 struct AssignValueToArray<false, K, PixelType, Params...> {
48  /// \brief Assigns Value To Array
49  static void avta(PixelType &dt,
51 };
52 } // namespace internal
53 /// \brief Contains VisionCpp pixel type definitions.
54 namespace pixel {
55 #define REGISTER_OPERATORS(Op, T) \
56  template <typename RHSScalar> \
57  T &operator Op##=(const RHSScalar &val) { \
58  for (int i = 0; i < elements; i++) { \
59  m_data[i] Op## = val; \
60  } \
61  return *this; \
62  } \
63  T &operator Op##=(const T &val) { \
64  for (int i = 0; i < elements; i++) { \
65  m_data[i] Op## = val[i]; \
66  } \
67  return *this; \
68  } \
69  friend T operator Op(T lhs, const T &rhs) { \
70  for (int i = 0; i < elements; i++) { \
71  lhs[i] Op## = rhs[i]; \
72  } \
73  return lhs; \
74  }
75 // [TODO] This macro conflicts with the operator overload from computecpp 0.5
76 // template <typename RHSScalar> \
77 // friend T operator Op(T lhs, const RHSScalar &rhs) { \
78 // for (int i = 0; i < elements; i++) { \
79 // lhs[i] Op## = rhs; \
80 // } \
81 // return lhs; \
82 // }
83 
84 template <typename LHSScalar, size_t Channels>
85 struct Storage {
86  typedef LHSScalar data_type;
87  constexpr static size_t elements = Channels;
88  LHSScalar m_data[elements];
89  data_type operator[](unsigned int idx) const { return m_data[idx]; }
90  data_type &operator[](unsigned int idx) { return m_data[idx]; }
95  template <typename... P>
96  Storage(P... p) {
98  internal::AssignValueToArray<0 != sizeof...(P), 0, decltype(m_data),
99  P...>::avta(m_data, tp);
100  }
101 };
102 
103 /// \struct F32C1
104 /// \brief This struct is generalisation for three channels float that is
105 /// perfect for storing pixels of R.
107 
108 /// \struct F32C2
109 /// \brief This struct is generalisation for three channels float that is
110 /// perfect for storing pixels of RG and permutations.
112 
113 /// \struct F32C3
114 /// \brief This struct is generalisation for three channels float that is
115 /// perfect for storing pixels of RGB and permutations.
117 
118 /// \struct F32C4
119 /// \brief This struct is generalisation for three channels float that is
120 /// perfect for storing pixels of RGBA and permutations.
122 
123 /// \struct U8C1
124 /// \brief This struct is generalisation for three channels float that is
125 /// perfect for storing pixels of R.
127 
128 /// \struct U8C2
129 /// \brief This struct is generalisation for three channels unsigned char that
130 /// is perfect for storing pixels of RG and permutations.
132 
133 /// \struct U8C3
134 /// \brief This struct is generalisation for three channels unsigned char that
135 /// is perfect for storing pixels of RGB and permutations.
137 
138 /// \struct U8C4
139 /// \brief This struct is generalisation for three channels unsigned char that
140 /// is perfect for storing pixels of RGBA and permutations.
142 
143 } // end of pixel
144 } // namespace visioncpp
145 #endif // VISIONCPP_INCLUDE_PIXEL_PIXEL_HPP_
Tuple< Args... > make_tuple(Args... args)
make_tuple
Definition: tuple.hpp:153
Storage< unsigned char, 2 > U8C2
Definition: pixel.hpp:131
Storage< float, 2 > F32C2
Definition: pixel.hpp:111
Storage< float, 4 > F32C4
Definition: pixel.hpp:121
Storage< float, 1 > F32C1
Definition: pixel.hpp:106
Storage< unsigned char, 4 > U8C4
Definition: pixel.hpp:141
Storage< unsigned char, 1 > U8C1
Definition: pixel.hpp:126
Storage< unsigned char, 3 > U8C3
Definition: pixel.hpp:136
Storage< float, 3 > F32C3
Definition: pixel.hpp:116
VisionCpp namespace.
Definition: sycl/device.hpp:24
#define REGISTER_OPERATORS(Op, T)
Definition: pixel.hpp:55
static void avta(PixelType &dt, visioncpp::internal::tools::tuple::Tuple< Params... > &t)
Assigns Value To Array.
Definition: pixel.hpp:49
static void avta(PixelType &dt, visioncpp::internal::tools::tuple::Tuple< Params... > &t)
Assigns Value To Array.
Definition: pixel.hpp:38
The tuple is a fixed-size collection of heterogeneous values.
Definition: tuple.hpp:48
LHSScalar m_data[elements]
Definition: pixel.hpp:88
constexpr static size_t elements
Definition: pixel.hpp:87
data_type operator[](unsigned int idx) const
Definition: pixel.hpp:89
data_type & operator[](unsigned int idx)
Definition: pixel.hpp:90