IDSpeakIPL  v1.8.0
peak_ipl_pixel_line.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <utility>
21 #include <vector>
22 
26 namespace peak
27 {
28 namespace ipl
29 {
30 
34 class PixelLine
35 {
36 public:
40  struct Channel
41  {
42  std::vector<uint32_t> Values;
43  };
44 
45 public:
46  PixelLine() = delete;
47 
59  explicit PixelLine(const Image& image, peak::ipl::Orientation orientation, size_t offset);
60 
67  virtual ~PixelLine();
68 
80  PixelLine(const PixelLine& other);
81 
93  PixelLine& operator=(const PixelLine& other);
94 
103  PixelLine(PixelLine&& other) noexcept;
104 
113  PixelLine& operator=(PixelLine&& other) noexcept;
114 
124 
134 
144  PEAK_IPL_NO_DISCARD size_t Offset() const;
145 
154  PEAK_IPL_NO_DISCARD std::vector<Channel> Channels() const;
155 
156 private:
157  PEAK_IPL_PIXEL_LINE_HANDLE m_backendHandle{};
158 };
159 
163 class PixelRow : public PixelLine
164 {
165 public:
166  PixelRow() = delete;
167  explicit PixelRow(const Image& image, size_t row);
168  ~PixelRow() override = default;
169  PixelRow(const PixelRow& other) = default;
170  PixelRow& operator=(const PixelRow& other) = default;
171  PixelRow(PixelRow&& other) = default;
172  PixelRow& operator=(PixelRow&& other) = default;
173 };
174 
178 class PixelColumn : public PixelLine
179 {
180 public:
181  PixelColumn() = delete;
182  explicit PixelColumn(const Image& image, size_t column);
183  ~PixelColumn() override = default;
184  PixelColumn(const PixelColumn& other) = default;
185  PixelColumn& operator=(const PixelColumn& other) = default;
186  PixelColumn(PixelColumn&& other) = default;
187  PixelColumn& operator=(PixelColumn&& other) = default;
188 };
189 
190 inline PixelRow::PixelRow(const Image& image, size_t row)
191  : PixelLine(image, peak::ipl::Orientation::Horizontal, row)
192 {}
193 
194 inline PixelColumn::PixelColumn(const Image& image, size_t column)
195  : PixelLine(image, peak::ipl::Orientation::Vertical, column)
196 {}
197 
198 
199 inline PixelLine::PixelLine(const Image& image, peak::ipl::Orientation orientation, size_t offset)
200 {
202  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_Construct(ImageBackendAccessor::BackendHandle(image),
203  static_cast<PEAK_IPL_ORIENTATION>(orientation), offset, &m_backendHandle);
204  });
205 }
206 
208 {
209  if (m_backendHandle)
210  {
211  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_Destruct(m_backendHandle);
212  }
213 }
214 
215 inline PixelLine::PixelLine(const PixelLine& other)
216 {
217  if (other.m_backendHandle)
218  {
219  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_Acquire(other.m_backendHandle); });
220  }
221 
222  m_backendHandle = other.m_backendHandle;
223 }
224 
226 {
227  if (this != &other)
228  {
229  if (m_backendHandle)
230  {
231  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_Destruct(m_backendHandle);
232  }
233 
234  if (other.m_backendHandle)
235  {
237  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_Acquire(other.m_backendHandle); });
238  }
239  }
240 
241  m_backendHandle = other.m_backendHandle;
242 
243  return *this;
244 }
245 
246 inline PixelLine::PixelLine(PixelLine&& other) noexcept
247 {
248  *this = std::move(other);
249 }
250 
251 inline PixelLine& PixelLine::operator=(PixelLine&& other) noexcept
252 {
253  if (this != &other)
254  {
255  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_Destruct(m_backendHandle);
256  m_backendHandle = other.m_backendHandle;
257  other.m_backendHandle = nullptr;
258  }
259 
260  return *this;
261 }
262 
264 {
266 
269  m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
270  });
271 
272  return pixelFormatName;
273 }
274 
276 {
278 
281  m_backendHandle, reinterpret_cast<PEAK_IPL_ORIENTATION*>(&orientation));
282  });
283 
284  return orientation;
285 }
286 
287 inline size_t PixelLine::Offset() const
288 {
289  size_t offset = 0;
290 
292  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_GetOffset(m_backendHandle, &offset); });
293 
294  return offset;
295 }
296 
297 inline std::vector<PixelLine::Channel> PixelLine::Channels() const
298 {
299  std::vector<Channel> channels;
300 
301  size_t numChannels = 0;
303  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_PixelLine_GetNumChannels(m_backendHandle, &numChannels); });
304 
305  for (size_t ch = 0; ch < numChannels; ++ch)
306  {
307  size_t valueListSize = 0;
310  m_backendHandle, ch, nullptr, &valueListSize);
311  });
312  std::vector<uint32_t> valueList(valueListSize);
315  m_backendHandle, ch, valueList.data(), &valueListSize);
316  });
317 
318  channels.emplace_back(Channel{ std::move(valueList) });
319  }
320 
321  return channels;
322 }
323 
324 } /* namespace ipl */
325 } /* namespace peak */
#define PEAK_IPL_NO_DISCARD
Definition: peak_ipl_backend.h:26
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
Represents the values of a horizontal or vertical line of pixels in an image.
Definition: peak_ipl_pixel_line.hpp:34
PixelFormatName
Enum holding the possible pixel format names.
Definition: peak_ipl_simple_types.hpp:38
PEAK_IPL_NO_DISCARD std::vector< Channel > Channels() const
Returns the number of the given pixel line&#39;s channels.
Definition: peak_ipl_pixel_line.hpp:297
PEAK_IPL_NO_DISCARD peak::ipl::Orientation Orientation() const
Returns the orientation of the given pixel line.
Definition: peak_ipl_pixel_line.hpp:275
PEAK_IPL_C_API PEAK_IPL_PixelLine_Acquire(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle)
Increase the reference count of a pixel line object.
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
struct PEAK_IPL_PIXEL_LINE * PEAK_IPL_PIXEL_LINE_HANDLE
Definition: peak_ipl_backend.h:362
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:39
Represents the values of the pixel line.
Definition: peak_ipl_pixel_line.hpp:40
PEAK_IPL_NO_DISCARD size_t Offset() const
Returns the offset of the given pixel line. (Vertical: Left - Horizontal: Top).
Definition: peak_ipl_pixel_line.hpp:287
PEAK_IPL_C_API PEAK_IPL_PixelLine_Construct(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_ORIENTATION orientation, size_t offset, PEAK_IPL_PIXEL_LINE_HANDLE *pixelLineHandle)
Creates a pixel line depending on the given orientation.
Orientation
Enum holding the possible orientation.
Definition: peak_ipl_simple_types.hpp:177
PEAK_IPL_C_API PEAK_IPL_PixelLine_GetOrientation(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle, PEAK_IPL_ORIENTATION *orientation)
Queries the orientation of the given pixel line.
PEAK_IPL_C_API PEAK_IPL_PixelLine_GetOffset(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle, size_t *offset)
Queries the offset of the given pixel line.
Represents the values for a horizontal line of pixels in an image.
Definition: peak_ipl_pixel_line.hpp:163
PixelLine & operator=(const PixelLine &other)
Copy assigment for PixelLine instance.
Definition: peak_ipl_pixel_line.hpp:225
PEAK_IPL_C_API PEAK_IPL_PixelLine_GetPixelFormat(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle, PEAK_IPL_PIXEL_FORMAT *pixelFormat)
Queries the pixel format of the given pixel line.
PEAK_IPL_C_API PEAK_IPL_PixelLine_GetValuesForChannel(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle, size_t channelIndex, uint32_t *values, size_t *valuesSize)
Queries the value list for the channel with the given index.
PEAK_IPL_NO_DISCARD peak::ipl::PixelFormatName PixelFormatName() const
Returns the pixel format of the given pixel line.
Definition: peak_ipl_pixel_line.hpp:263
std::vector< uint32_t > Values
Definition: peak_ipl_pixel_line.hpp:42
PEAK_IPL_C_API PEAK_IPL_PixelLine_GetNumChannels(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle, size_t *numChannels)
Queries the number of the given pixel line&#39;s channels.
virtual ~PixelLine()
Destructor for the PixelLine instance.
Definition: peak_ipl_pixel_line.hpp:207
Horizontal orientation.
Represents the values for a vertical line of pixels in an image.
Definition: peak_ipl_pixel_line.hpp:178
PEAK_IPL_C_API PEAK_IPL_PixelLine_Destruct(PEAK_IPL_PIXEL_LINE_HANDLE pixelLineHandle)
Destroys the pixel line associated with the given handle.
Vertical orientation.