IDS peak IPL  v1.4.0
peak_ipl_image.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
16 
17 #include <cstddef>
18 #include <cstdint>
19 #include <utility>
20 
21 namespace
22 {
23 class ImageBackendAccessor;
24 }
25 
29 namespace peak
30 {
31 namespace ipl
32 {
33 
37 class Image
38 {
39 public:
47  Image();
60  Image(const peak::ipl::PixelFormat& pixelFormat, size_t width, size_t height);
79  Image(
80  const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer, size_t bufferSize, size_t width, size_t height);
81  ~Image();
82  Image(const Image& other) = delete;
83  Image& operator=(const Image& other) = delete;
84  Image(Image&& other) noexcept;
85  Image& operator=(Image&& other) noexcept;
86 
96  size_t Width() const;
97 
107  size_t Height() const;
108 
122  uint8_t* PixelPointer(size_t xPos, size_t yPos) const;
123 
133  size_t ByteCount() const;
134 
145 
155  uint8_t* Data() const;
156 
171  Image ConvertTo(const peak::ipl::PixelFormat& outputPixelFormat,
173 
192  Image ConvertTo(const peak::ipl::PixelFormat& outputPixelFormat, uint8_t* outputImageBuffer,
193  size_t outputImageBufferSize,
195 
205  Image Clone() const;
206 
216  bool Empty() const;
217 
218 private:
219  friend ImageBackendAccessor;
220  explicit Image(PEAK_IPL_IMAGE_HANDLE imageHandle) noexcept;
221  PEAK_IPL_IMAGE_HANDLE m_backendHandle{};
222 };
223 
224 } /* namespace ipl */
225 } /* namespace peak */
226 
227 namespace
228 {
229 
230 // helper class to access the C-backend of the Image, which are hidden from the public interface
231 class ImageBackendAccessor
232 {
233 public:
234  static PEAK_IPL_IMAGE_HANDLE BackendHandle(const peak::ipl::Image& image)
235  {
236  return image.m_backendHandle;
237  }
238  static peak::ipl::Image CreateImage(PEAK_IPL_IMAGE_HANDLE imageHandle)
239  {
240  return peak::ipl::Image(imageHandle);
241  }
242 };
243 
244 } /* namespace */
245 
247 
248 namespace peak
249 {
250 namespace ipl
251 {
252 
253 inline Image::Image()
254 {
257  });
258 }
259 
260 inline Image::Image(const peak::ipl::PixelFormat& pixelFormat, size_t width, size_t height)
261 {
264  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormat.PixelFormatName()), width, height, &m_backendHandle);
265  });
266 }
267 
269  const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer, size_t bufferSize, size_t width, size_t height)
270 {
273  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormat.PixelFormatName()), buffer, bufferSize, width, height,
274  &m_backendHandle);
275  });
276 }
277 
278 inline Image::Image(PEAK_IPL_IMAGE_HANDLE imageHandle) noexcept
279  : m_backendHandle(imageHandle)
280 {}
281 
283 {
284  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_Destruct(m_backendHandle);
285 }
286 
287 inline Image::Image(Image&& other) noexcept
288 {
289  *this = std::move(other);
290 }
291 
292 inline Image& Image::operator=(Image&& other) noexcept
293 {
294  if (this != &other)
295  {
296  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_Destruct(m_backendHandle);
297  m_backendHandle = other.m_backendHandle;
298  other.m_backendHandle = nullptr;
299  }
300 
301  return *this;
302 }
303 
304 inline size_t Image::Width() const
305 {
306  size_t width = 0;
307 
308  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetWidth(m_backendHandle, &width); });
309 
310  return width;
311 }
312 
313 inline size_t Image::Height() const
314 {
315  size_t height = 0;
316 
317  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetHeight(m_backendHandle, &height); });
318 
319  return height;
320 }
321 
322 inline uint8_t* Image::PixelPointer(size_t xPos, size_t yPos) const
323 {
324  uint8_t* pixelPosition = nullptr;
325 
327  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetPixelPointer(m_backendHandle, xPos, yPos, &pixelPosition);
328  });
329 
330  return pixelPosition;
331 }
332 
333 inline size_t Image::ByteCount() const
334 {
335  size_t byteCount = 0;
336 
338  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetByteCount(m_backendHandle, &byteCount); });
339 
340  return byteCount;
341 }
342 
344 {
346 
349  m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
350  });
351 
352  return peak::ipl::PixelFormat{ pixelFormatName };
353 }
354 
355 inline uint8_t* Image::Data() const
356 {
357  uint8_t* data = nullptr;
358 
359  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetData(m_backendHandle, &data); });
360 
361  return data;
362 }
363 
365  const peak::ipl::PixelFormat& outputPixelFormat, peak::ipl::ConversionMode conversionMode) const
366 {
367  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
369  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_ConvertTo(m_backendHandle,
370  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()),
371  static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode), &outputImageHandle);
372  });
373 
374  return ImageBackendAccessor::CreateImage(outputImageHandle);
375 }
376 
377 inline Image Image::ConvertTo(const peak::ipl::PixelFormat& outputPixelFormat, uint8_t* outputImageBuffer,
378  size_t outputImageBufferSize, peak::ipl::ConversionMode conversionMode) const
379 {
380  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
383  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
384  outputImageBufferSize, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode), &outputImageHandle);
385  });
386 
387  return ImageBackendAccessor::CreateImage(outputImageHandle);
388 }
389 
390 inline Image Image::Clone() const
391 {
392  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
394  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_Clone(m_backendHandle, &outputImageHandle); });
395 
396  return ImageBackendAccessor::CreateImage(outputImageHandle);
397 }
398 
399 inline bool Image::Empty() const
400 {
401  return (m_backendHandle == nullptr) || (PixelFormat().PixelFormatName() == PixelFormatName::Invalid);
402 }
403 
404 } /* namespace ipl */
405 } /* namespace peak */
PEAK_IPL_C_API PEAK_IPL_Image_GetData(PEAK_IPL_IMAGE_HANDLE imageHandle, uint8_t **data)
Queries the data pointer of the given image.
PEAK_IPL_C_API PEAK_IPL_Image_GetPixelFormat(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT *pixelFormat)
Queries the pixel format of the given image.
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToBuffer(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Stores the data of the current image converted to the given pixel format into a destination buffer an...
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
Image()
Creates an empty image, i.e. with size 0x0 and invalid pixel format.
Definition: peak_ipl_image.hpp:253
Image ConvertTo(const peak::ipl::PixelFormat &outputPixelFormat, peak::ipl::ConversionMode conversionMode=peak::ipl::ConversionMode::Fast) const
Returns a new created image containing the data of the current image converted to the given pixel for...
Definition: peak_ipl_image.hpp:364
PixelFormatName
Enum holding the possible pixel format names.
Definition: peak_ipl_simple_types.hpp:38
size_t ByteCount() const
Returns the size of the given image in number of bytes.
Definition: peak_ipl_image.hpp:333
PEAK_IPL_C_API PEAK_IPL_Image_Clone(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Returns a new created image containing the data of the current image as deep copy.
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:16
Definition: peak_ipl_backend.h:55
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:128
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:37
PEAK_IPL_C_API PEAK_IPL_Image_GetHeight(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *height)
Queries the height of the given image.
ConversionMode
Enum holding the possible conversion modes.
Definition: peak_ipl_simple_types.hpp:28
size_t Height() const
Returns the height.
Definition: peak_ipl_image.hpp:313
PEAK_IPL_C_API PEAK_IPL_Image_GetPixelPointer(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t xPos, size_t yPos, uint8_t **pixelPointer)
Queries the pointer to the given pixel position.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:238
PEAK_IPL_C_API PEAK_IPL_Image_ConvertTo(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image containing the data of the current image converted to the given pixel format...
~Image()
Definition: peak_ipl_image.hpp:282
Image Clone() const
Returns a new created image containing the data of the current image as deep copy.
Definition: peak_ipl_image.hpp:390
peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition: peak_ipl_pixel_format.hpp:67
PEAK_IPL_C_API PEAK_IPL_Image_ConstructFromBuffer(PEAK_IPL_PIXEL_FORMAT pixelFormat, uint8_t *buffer, uint64_t bufferSize, size_t width, size_t height, PEAK_IPL_IMAGE_HANDLE *imageHandle)
Creates an image from a given buffer.
PEAK_IPL_C_API PEAK_IPL_Image_GetWidth(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *width)
Queries the width of the given image.
uint8_t * Data() const
Returns the pointer to the first pixel position in dependency on the size of the pixel format...
Definition: peak_ipl_image.hpp:355
PEAK_IPL_C_API PEAK_IPL_Image_GetByteCount(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *byteCount)
Queries the size of the given image in number of bytes.
size_t Width() const
Returns the width.
Definition: peak_ipl_image.hpp:304
uint8_t * PixelPointer(size_t xPos, size_t yPos) const
Returns the pixel pointer to the given pixel position in dependency of the size of the pixel format...
Definition: peak_ipl_image.hpp:322
bool Empty() const
Checks whether the image is empty.
Definition: peak_ipl_image.hpp:399
Represents a pixel format and its specific properties.
Definition: peak_ipl_pixel_format.hpp:31
PEAK_IPL_C_API PEAK_IPL_Image_Construct(PEAK_IPL_PIXEL_FORMAT pixelFormat, size_t width, size_t height, PEAK_IPL_IMAGE_HANDLE *imageHandle)
Creates an image.
peak::ipl::PixelFormat PixelFormat() const
Returns the pixel format.
Definition: peak_ipl_image.hpp:343
PEAK_IPL_C_API PEAK_IPL_Image_Destruct(PEAK_IPL_IMAGE_HANDLE imageHandle)
Destroys the image associated with the given handle.
Image & operator=(const Image &other)=delete